Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* zoltrix radio plus driver for Linux radio support |
| 2 | * (c) 1998 C. van Schaik <carl@leg.uct.ac.za> |
| 3 | * |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 4 | * BUGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Due to the inconsistency in reading from the signal flags |
| 6 | * it is difficult to get an accurate tuned signal. |
| 7 | * |
| 8 | * It seems that the card is not linear to 0 volume. It cuts off |
| 9 | * at a low volume, and it is not possible (at least I have not found) |
| 10 | * to get fine volume control over the low volume range. |
| 11 | * |
| 12 | * Some code derived from code by Romolo Manfredini |
| 13 | * romolo@bicnet.it |
| 14 | * |
| 15 | * 1999-05-06 - (C. van Schaik) |
| 16 | * - Make signal strength and stereo scans |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 17 | * kinder to cpu while in delay |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * 1999-01-05 - (C. van Schaik) |
| 19 | * - Changed tuning to 1/160Mhz accuracy |
| 20 | * - Added stereo support |
| 21 | * (card defaults to stereo) |
| 22 | * (can explicitly force mono on the card) |
| 23 | * (can detect if station is in stereo) |
| 24 | * - Added unmute function |
| 25 | * - Reworked ioctl functions |
| 26 | * 2002-07-15 - Fix Stereo typo |
Mauro Carvalho Chehab | 2ab6529 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 27 | * |
| 28 | * 2006-07-24 - Converted to V4L2 API |
| 29 | * by Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | #include <linux/module.h> /* Modules */ |
| 33 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 34 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/delay.h> /* udelay, msleep */ |
| 36 | #include <asm/io.h> /* outb, outb_p */ |
| 37 | #include <asm/uaccess.h> /* copy to/from user */ |
Mauro Carvalho Chehab | 2ab6529 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 38 | #include <linux/videodev2.h> /* kernel radio structs */ |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 39 | #include <media/v4l2-common.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 40 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Mauro Carvalho Chehab | 2ab6529 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 42 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
| 43 | #define RADIO_VERSION KERNEL_VERSION(0,0,2) |
| 44 | |
| 45 | static struct v4l2_queryctrl radio_qctrl[] = { |
| 46 | { |
| 47 | .id = V4L2_CID_AUDIO_MUTE, |
| 48 | .name = "Mute", |
| 49 | .minimum = 0, |
| 50 | .maximum = 1, |
| 51 | .default_value = 1, |
| 52 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 53 | },{ |
| 54 | .id = V4L2_CID_AUDIO_VOLUME, |
| 55 | .name = "Volume", |
| 56 | .minimum = 0, |
| 57 | .maximum = 65535, |
| 58 | .step = 4096, |
| 59 | .default_value = 0xff, |
| 60 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 61 | } |
| 62 | }; |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #ifndef CONFIG_RADIO_ZOLTRIX_PORT |
| 65 | #define CONFIG_RADIO_ZOLTRIX_PORT -1 |
| 66 | #endif |
| 67 | |
| 68 | static int io = CONFIG_RADIO_ZOLTRIX_PORT; |
| 69 | static int radio_nr = -1; |
| 70 | |
| 71 | struct zol_device { |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 72 | unsigned long in_use; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | int port; |
| 74 | int curvol; |
| 75 | unsigned long curfreq; |
| 76 | int muted; |
| 77 | unsigned int stereo; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 78 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | static int zol_setvol(struct zol_device *dev, int vol) |
| 82 | { |
| 83 | dev->curvol = vol; |
| 84 | if (dev->muted) |
| 85 | return 0; |
| 86 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 87 | mutex_lock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | if (vol == 0) { |
| 89 | outb(0, io); |
| 90 | outb(0, io); |
| 91 | inb(io + 3); /* Zoltrix needs to be read to confirm */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 92 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | outb(dev->curvol-1, io); |
| 97 | msleep(10); |
| 98 | inb(io + 2); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 99 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static void zol_mute(struct zol_device *dev) |
| 104 | { |
| 105 | dev->muted = 1; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 106 | mutex_lock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | outb(0, io); |
| 108 | outb(0, io); |
| 109 | inb(io + 3); /* Zoltrix needs to be read to confirm */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 110 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static void zol_unmute(struct zol_device *dev) |
| 114 | { |
| 115 | dev->muted = 0; |
| 116 | zol_setvol(dev, dev->curvol); |
| 117 | } |
| 118 | |
| 119 | static int zol_setfreq(struct zol_device *dev, unsigned long freq) |
| 120 | { |
| 121 | /* tunes the radio to the desired frequency */ |
| 122 | unsigned long long bitmask, f, m; |
| 123 | unsigned int stereo = dev->stereo; |
| 124 | int i; |
| 125 | |
Alexey Klimov | b4be204 | 2008-10-09 13:46:59 -0300 | [diff] [blame] | 126 | if (freq == 0) { |
| 127 | printk(KERN_WARNING "zoltrix: received zero freq. Failed to set.\n"); |
| 128 | return -EINVAL; |
| 129 | } |
| 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | m = (freq / 160 - 8800) * 2; |
| 132 | f = (unsigned long long) m + 0x4d1c; |
| 133 | |
| 134 | bitmask = 0xc480402c10080000ull; |
| 135 | i = 45; |
| 136 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 137 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | outb(0, io); |
| 140 | outb(0, io); |
| 141 | inb(io + 3); /* Zoltrix needs to be read to confirm */ |
| 142 | |
| 143 | outb(0x40, io); |
| 144 | outb(0xc0, io); |
| 145 | |
| 146 | bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ ( stereo << 31)); |
| 147 | while (i--) { |
| 148 | if ((bitmask & 0x8000000000000000ull) != 0) { |
| 149 | outb(0x80, io); |
| 150 | udelay(50); |
| 151 | outb(0x00, io); |
| 152 | udelay(50); |
| 153 | outb(0x80, io); |
| 154 | udelay(50); |
| 155 | } else { |
| 156 | outb(0xc0, io); |
| 157 | udelay(50); |
| 158 | outb(0x40, io); |
| 159 | udelay(50); |
| 160 | outb(0xc0, io); |
| 161 | udelay(50); |
| 162 | } |
| 163 | bitmask *= 2; |
| 164 | } |
| 165 | /* termination sequence */ |
| 166 | outb(0x80, io); |
| 167 | outb(0xc0, io); |
| 168 | outb(0x40, io); |
| 169 | udelay(1000); |
| 170 | inb(io+2); |
| 171 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 172 | udelay(1000); |
| 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (dev->muted) |
| 175 | { |
| 176 | outb(0, io); |
| 177 | outb(0, io); |
| 178 | inb(io + 3); |
| 179 | udelay(1000); |
| 180 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 181 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 182 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | if(!dev->muted) |
| 185 | { |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 186 | zol_setvol(dev, dev->curvol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | /* Get signal strength */ |
| 192 | |
| 193 | static int zol_getsigstr(struct zol_device *dev) |
| 194 | { |
| 195 | int a, b; |
| 196 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 197 | mutex_lock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | outb(0x00, io); /* This stuff I found to do nothing */ |
| 199 | outb(dev->curvol, io); |
| 200 | msleep(20); |
| 201 | |
| 202 | a = inb(io); |
| 203 | msleep(10); |
| 204 | b = inb(io); |
| 205 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 206 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | if (a != b) |
| 209 | return (0); |
| 210 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 211 | if ((a == 0xcf) || (a == 0xdf) /* I found this out by playing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | || (a == 0xef)) /* with a binary scanner on the card io */ |
| 213 | return (1); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 214 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static int zol_is_stereo (struct zol_device *dev) |
| 218 | { |
| 219 | int x1, x2; |
| 220 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 221 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | outb(0x00, io); |
| 224 | outb(dev->curvol, io); |
| 225 | msleep(20); |
| 226 | |
| 227 | x1 = inb(io); |
| 228 | msleep(10); |
| 229 | x2 = inb(io); |
| 230 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 231 | mutex_unlock(&dev->lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | if ((x1 == x2) && (x1 == 0xcf)) |
| 234 | return 1; |
| 235 | return 0; |
| 236 | } |
| 237 | |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 238 | static int vidioc_querycap(struct file *file, void *priv, |
| 239 | struct v4l2_capability *v) |
| 240 | { |
| 241 | strlcpy(v->driver, "radio-zoltrix", sizeof(v->driver)); |
| 242 | strlcpy(v->card, "Zoltrix Radio", sizeof(v->card)); |
| 243 | sprintf(v->bus_info, "ISA"); |
| 244 | v->version = RADIO_VERSION; |
| 245 | v->capabilities = V4L2_CAP_TUNER; |
| 246 | return 0; |
| 247 | } |
| 248 | |
| 249 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 250 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 252 | struct zol_device *zol = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 254 | if (v->index > 0) |
| 255 | return -EINVAL; |
Mauro Carvalho Chehab | 2ab6529 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 256 | |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 257 | strcpy(v->name, "FM"); |
| 258 | v->type = V4L2_TUNER_RADIO; |
| 259 | v->rangelow = (88*16000); |
| 260 | v->rangehigh = (108*16000); |
| 261 | v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; |
| 262 | v->capability = V4L2_TUNER_CAP_LOW; |
| 263 | if (zol_is_stereo(zol)) |
| 264 | v->audmode = V4L2_TUNER_MODE_STEREO; |
| 265 | else |
| 266 | v->audmode = V4L2_TUNER_MODE_MONO; |
| 267 | v->signal = 0xFFFF*zol_getsigstr(zol); |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 272 | struct v4l2_tuner *v) |
| 273 | { |
| 274 | if (v->index > 0) |
| 275 | return -EINVAL; |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 280 | struct v4l2_frequency *f) |
| 281 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 282 | struct zol_device *zol = video_drvdata(file); |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 283 | |
| 284 | zol->curfreq = f->frequency; |
Alexey Klimov | b4be204 | 2008-10-09 13:46:59 -0300 | [diff] [blame] | 285 | if (zol_setfreq(zol, zol->curfreq) != 0) { |
| 286 | printk(KERN_WARNING "zoltrix: Set frequency failed.\n"); |
| 287 | return -EINVAL; |
| 288 | } |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 293 | struct v4l2_frequency *f) |
| 294 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 295 | struct zol_device *zol = video_drvdata(file); |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 296 | |
| 297 | f->type = V4L2_TUNER_RADIO; |
| 298 | f->frequency = zol->curfreq; |
| 299 | return 0; |
| 300 | } |
| 301 | |
| 302 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 303 | struct v4l2_queryctrl *qc) |
| 304 | { |
| 305 | int i; |
| 306 | |
| 307 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { |
| 308 | if (qc->id && qc->id == radio_qctrl[i].id) { |
| 309 | memcpy(qc, &(radio_qctrl[i]), |
| 310 | sizeof(*qc)); |
Mauro Carvalho Chehab | 2ab6529 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 311 | return 0; |
| 312 | } |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 313 | } |
| 314 | return -EINVAL; |
| 315 | } |
Mauro Carvalho Chehab | 2ab6529 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 316 | |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 317 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 318 | struct v4l2_control *ctrl) |
| 319 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 320 | struct zol_device *zol = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 322 | switch (ctrl->id) { |
| 323 | case V4L2_CID_AUDIO_MUTE: |
| 324 | ctrl->value = zol->muted; |
| 325 | return 0; |
| 326 | case V4L2_CID_AUDIO_VOLUME: |
| 327 | ctrl->value = zol->curvol * 4096; |
| 328 | return 0; |
| 329 | } |
| 330 | return -EINVAL; |
| 331 | } |
Mauro Carvalho Chehab | 2ab6529 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 332 | |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 333 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 334 | struct v4l2_control *ctrl) |
| 335 | { |
Hans Verkuil | c170ecf | 2008-08-23 08:32:09 -0300 | [diff] [blame] | 336 | struct zol_device *zol = video_drvdata(file); |
Mauro Carvalho Chehab | 2ab6529 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 337 | |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 338 | switch (ctrl->id) { |
| 339 | case V4L2_CID_AUDIO_MUTE: |
| 340 | if (ctrl->value) |
| 341 | zol_mute(zol); |
| 342 | else { |
| 343 | zol_unmute(zol); |
| 344 | zol_setvol(zol,zol->curvol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 346 | return 0; |
| 347 | case V4L2_CID_AUDIO_VOLUME: |
| 348 | zol_setvol(zol,ctrl->value/4096); |
| 349 | return 0; |
| 350 | } |
| 351 | zol->stereo = 1; |
Alexey Klimov | b4be204 | 2008-10-09 13:46:59 -0300 | [diff] [blame] | 352 | if (zol_setfreq(zol, zol->curfreq) != 0) { |
| 353 | printk(KERN_WARNING "zoltrix: Set frequency failed.\n"); |
| 354 | return -EINVAL; |
| 355 | } |
Mauro Carvalho Chehab | 2ab6529 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 356 | #if 0 |
| 357 | /* FIXME: Implement stereo/mono switch on V4L2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | if (v->mode & VIDEO_SOUND_STEREO) { |
| 359 | zol->stereo = 1; |
| 360 | zol_setfreq(zol, zol->curfreq); |
| 361 | } |
| 362 | if (v->mode & VIDEO_SOUND_MONO) { |
| 363 | zol->stereo = 0; |
| 364 | zol_setfreq(zol, zol->curfreq); |
| 365 | } |
Mauro Carvalho Chehab | 2ab6529 | 2006-08-08 09:10:04 -0300 | [diff] [blame] | 366 | #endif |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 367 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 370 | static int vidioc_g_audio(struct file *file, void *priv, |
| 371 | struct v4l2_audio *a) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 373 | if (a->index > 1) |
| 374 | return -EINVAL; |
| 375 | |
| 376 | strcpy(a->name, "Radio"); |
| 377 | a->capability = V4L2_AUDCAP_STEREO; |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 382 | { |
| 383 | *i = 0; |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 388 | { |
| 389 | if (i != 0) |
| 390 | return -EINVAL; |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | static int vidioc_s_audio(struct file *file, void *priv, |
| 395 | struct v4l2_audio *a) |
| 396 | { |
| 397 | if (a->index != 0) |
| 398 | return -EINVAL; |
| 399 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static struct zol_device zoltrix_unit; |
| 403 | |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 404 | static int zoltrix_exclusive_open(struct inode *inode, struct file *file) |
| 405 | { |
| 406 | return test_and_set_bit(0, &zoltrix_unit.in_use) ? -EBUSY : 0; |
| 407 | } |
| 408 | |
| 409 | static int zoltrix_exclusive_release(struct inode *inode, struct file *file) |
| 410 | { |
| 411 | clear_bit(0, &zoltrix_unit.in_use); |
| 412 | return 0; |
| 413 | } |
| 414 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 415 | static const struct file_operations zoltrix_fops = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
| 417 | .owner = THIS_MODULE, |
Hans Verkuil | 3ca685a | 2008-08-23 04:49:13 -0300 | [diff] [blame] | 418 | .open = zoltrix_exclusive_open, |
| 419 | .release = zoltrix_exclusive_release, |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 420 | .ioctl = video_ioctl2, |
Douglas Schilling Landgraf | 078ff79 | 2008-04-22 14:46:11 -0300 | [diff] [blame] | 421 | #ifdef CONFIG_COMPAT |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 422 | .compat_ioctl = v4l_compat_ioctl32, |
Douglas Schilling Landgraf | 078ff79 | 2008-04-22 14:46:11 -0300 | [diff] [blame] | 423 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | .llseek = no_llseek, |
| 425 | }; |
| 426 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 427 | static const struct v4l2_ioctl_ops zoltrix_ioctl_ops = { |
Douglas Landgraf | a1314b1 | 2007-04-20 18:23:38 -0300 | [diff] [blame] | 428 | .vidioc_querycap = vidioc_querycap, |
| 429 | .vidioc_g_tuner = vidioc_g_tuner, |
| 430 | .vidioc_s_tuner = vidioc_s_tuner, |
| 431 | .vidioc_g_audio = vidioc_g_audio, |
| 432 | .vidioc_s_audio = vidioc_s_audio, |
| 433 | .vidioc_g_input = vidioc_g_input, |
| 434 | .vidioc_s_input = vidioc_s_input, |
| 435 | .vidioc_g_frequency = vidioc_g_frequency, |
| 436 | .vidioc_s_frequency = vidioc_s_frequency, |
| 437 | .vidioc_queryctrl = vidioc_queryctrl, |
| 438 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 439 | .vidioc_s_ctrl = vidioc_s_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | }; |
| 441 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 442 | static struct video_device zoltrix_radio = { |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 443 | .name = "Zoltrix Radio Plus", |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 444 | .fops = &zoltrix_fops, |
| 445 | .ioctl_ops = &zoltrix_ioctl_ops, |
Hans Verkuil | aa5e90a | 2008-08-23 06:23:55 -0300 | [diff] [blame] | 446 | .release = video_device_release_empty, |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 447 | }; |
| 448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | static int __init zoltrix_init(void) |
| 450 | { |
| 451 | if (io == -1) { |
| 452 | printk(KERN_ERR "You must set an I/O address with io=0x???\n"); |
| 453 | return -EINVAL; |
| 454 | } |
| 455 | if ((io != 0x20c) && (io != 0x30c)) { |
| 456 | printk(KERN_ERR "zoltrix: invalid port, try 0x20c or 0x30c\n"); |
| 457 | return -ENXIO; |
| 458 | } |
| 459 | |
Hans Verkuil | 601e944 | 2008-08-23 07:24:07 -0300 | [diff] [blame] | 460 | video_set_drvdata(&zoltrix_radio, &zoltrix_unit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | if (!request_region(io, 2, "zoltrix")) { |
| 462 | printk(KERN_ERR "zoltrix: port 0x%x already in use\n", io); |
| 463 | return -EBUSY; |
| 464 | } |
| 465 | |
Hans Verkuil | cba99ae | 2008-09-03 17:11:58 -0300 | [diff] [blame] | 466 | if (video_register_device(&zoltrix_radio, VFL_TYPE_RADIO, radio_nr) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | release_region(io, 2); |
| 468 | return -EINVAL; |
| 469 | } |
| 470 | printk(KERN_INFO "Zoltrix Radio Plus card driver.\n"); |
| 471 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 472 | mutex_init(&zoltrix_unit.lock); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | /* mute card - prevents noisy bootups */ |
| 475 | |
| 476 | /* this ensures that the volume is all the way down */ |
| 477 | |
| 478 | outb(0, io); |
| 479 | outb(0, io); |
| 480 | msleep(20); |
| 481 | inb(io + 3); |
| 482 | |
| 483 | zoltrix_unit.curvol = 0; |
| 484 | zoltrix_unit.stereo = 1; |
| 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | MODULE_AUTHOR("C.van Schaik"); |
| 490 | MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus."); |
| 491 | MODULE_LICENSE("GPL"); |
| 492 | |
| 493 | module_param(io, int, 0); |
| 494 | MODULE_PARM_DESC(io, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)"); |
| 495 | module_param(radio_nr, int, 0); |
| 496 | |
| 497 | static void __exit zoltrix_cleanup_module(void) |
| 498 | { |
| 499 | video_unregister_device(&zoltrix_radio); |
| 500 | release_region(io, 2); |
| 501 | } |
| 502 | |
| 503 | module_init(zoltrix_init); |
| 504 | module_exit(zoltrix_cleanup_module); |
| 505 | |