Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* SF16FMR2 radio driver for Linux radio support |
| 2 | * heavily based on fmi driver... |
| 3 | * (c) 2000-2002 Ziglio Frediano, freddy77@angelfire.com |
| 4 | * |
| 5 | * Notes on the hardware |
| 6 | * |
| 7 | * Frequency control is done digitally -- ie out(port,encodefreq(95.8)); |
| 8 | * No volume control - only mute/unmute - you have to use line volume |
| 9 | * |
| 10 | * For read stereo/mono you must wait 0.1 sec after set frequency and |
| 11 | * card unmuted so I set frequency on unmute |
| 12 | * Signal handling seem to work only on autoscanning (not implemented) |
Mauro Carvalho Chehab | acda0e7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 13 | * |
| 14 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <linux/module.h> /* Modules */ |
| 18 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 19 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> /* udelay */ |
| 21 | #include <asm/io.h> /* outb, outb_p */ |
| 22 | #include <asm/uaccess.h> /* copy to/from user */ |
Mauro Carvalho Chehab | acda0e7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 23 | #include <linux/videodev2.h> /* kernel radio structs */ |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 24 | #include <media/v4l2-common.h> |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 25 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Mauro Carvalho Chehab | 1ddf5bc | 2006-08-08 09:10:06 -0300 | [diff] [blame] | 27 | static struct mutex lock; |
| 28 | |
| 29 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
Mauro Carvalho Chehab | acda0e7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 30 | #define RADIO_VERSION KERNEL_VERSION(0,0,2) |
| 31 | |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 32 | #define AUD_VOL_INDEX 1 |
| 33 | |
Mauro Carvalho Chehab | acda0e7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 34 | static struct v4l2_queryctrl radio_qctrl[] = { |
| 35 | { |
| 36 | .id = V4L2_CID_AUDIO_MUTE, |
| 37 | .name = "Mute", |
| 38 | .minimum = 0, |
| 39 | .maximum = 1, |
| 40 | .default_value = 1, |
| 41 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 42 | }, |
| 43 | [AUD_VOL_INDEX] = { |
Mauro Carvalho Chehab | acda0e7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 44 | .id = V4L2_CID_AUDIO_VOLUME, |
| 45 | .name = "Volume", |
| 46 | .minimum = 0, |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 47 | .maximum = 15, |
| 48 | .step = 1, |
| 49 | .default_value = 0, |
Mauro Carvalho Chehab | acda0e7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 50 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 51 | } |
| 52 | }; |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #undef DEBUG |
| 55 | //#define DEBUG 1 |
| 56 | |
| 57 | #ifdef DEBUG |
| 58 | # define debug_print(s) printk s |
| 59 | #else |
| 60 | # define debug_print(s) |
| 61 | #endif |
| 62 | |
| 63 | /* this should be static vars for module size */ |
| 64 | struct fmr2_device |
| 65 | { |
| 66 | int port; |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 67 | int curvol; /* 0-15 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | int mute; |
| 69 | int stereo; /* card is producing stereo audio */ |
| 70 | unsigned long curfreq; /* freq in kHz */ |
| 71 | int card_type; |
| 72 | __u32 flags; |
| 73 | }; |
| 74 | |
| 75 | static int io = 0x384; |
| 76 | static int radio_nr = -1; |
| 77 | |
| 78 | /* hw precision is 12.5 kHz |
Adrian Bunk | a58a414 | 2006-01-10 00:08:17 +0100 | [diff] [blame] | 79 | * It is only useful to give freq in intervall of 200 (=0.0125Mhz), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | * other bits will be truncated |
| 81 | */ |
| 82 | #define RSF16_ENCODE(x) ((x)/200+856) |
| 83 | #define RSF16_MINFREQ 87*16000 |
| 84 | #define RSF16_MAXFREQ 108*16000 |
| 85 | |
| 86 | static inline void wait(int n,int port) |
| 87 | { |
| 88 | for (;n;--n) inb(port); |
| 89 | } |
| 90 | |
| 91 | static void outbits(int bits, unsigned int data, int nWait, int port) |
| 92 | { |
| 93 | int bit; |
| 94 | for(;--bits>=0;) { |
| 95 | bit = (data>>bits) & 1; |
| 96 | outb(bit,port); |
| 97 | wait(nWait,port); |
| 98 | outb(bit|2,port); |
| 99 | wait(nWait,port); |
| 100 | outb(bit,port); |
| 101 | wait(nWait,port); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | static inline void fmr2_mute(int port) |
| 106 | { |
| 107 | outb(0x00, port); |
| 108 | wait(4,port); |
| 109 | } |
| 110 | |
| 111 | static inline void fmr2_unmute(int port) |
| 112 | { |
| 113 | outb(0x04, port); |
| 114 | wait(4,port); |
| 115 | } |
| 116 | |
| 117 | static inline int fmr2_stereo_mode(int port) |
| 118 | { |
| 119 | int n = inb(port); |
| 120 | outb(6,port); |
| 121 | inb(port); |
| 122 | n = ((n>>3)&1)^1; |
| 123 | debug_print((KERN_DEBUG "stereo: %d\n", n)); |
| 124 | return n; |
| 125 | } |
| 126 | |
| 127 | static int fmr2_product_info(struct fmr2_device *dev) |
| 128 | { |
| 129 | int n = inb(dev->port); |
| 130 | n &= 0xC1; |
| 131 | if (n == 0) |
| 132 | { |
| 133 | /* this should support volume set */ |
| 134 | dev->card_type = 12; |
| 135 | return 0; |
| 136 | } |
| 137 | /* not volume (mine is 11) */ |
| 138 | dev->card_type = (n==128)?11:0; |
| 139 | return n; |
| 140 | } |
| 141 | |
| 142 | static inline int fmr2_getsigstr(struct fmr2_device *dev) |
| 143 | { |
| 144 | /* !!! work only if scanning freq */ |
| 145 | int port = dev->port, res = 0xffff; |
| 146 | outb(5,port); |
| 147 | wait(4,port); |
| 148 | if (!(inb(port)&1)) res = 0; |
| 149 | debug_print((KERN_DEBUG "signal: %d\n", res)); |
| 150 | return res; |
| 151 | } |
| 152 | |
| 153 | /* set frequency and unmute card */ |
| 154 | static int fmr2_setfreq(struct fmr2_device *dev) |
| 155 | { |
| 156 | int port = dev->port; |
| 157 | unsigned long freq = dev->curfreq; |
| 158 | |
| 159 | fmr2_mute(port); |
| 160 | |
| 161 | /* 0x42 for mono output |
| 162 | * 0x102 forward scanning |
| 163 | * 0x182 scansione avanti |
| 164 | */ |
| 165 | outbits(9,0x2,3,port); |
| 166 | outbits(16,RSF16_ENCODE(freq),2,port); |
| 167 | |
| 168 | fmr2_unmute(port); |
| 169 | |
| 170 | /* wait 0.11 sec */ |
| 171 | msleep(110); |
| 172 | |
| 173 | /* NOTE if mute this stop radio |
| 174 | you must set freq on unmute */ |
| 175 | dev->stereo = fmr2_stereo_mode(port); |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | /* !!! not tested, in my card this does't work !!! */ |
| 180 | static int fmr2_setvolume(struct fmr2_device *dev) |
| 181 | { |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 182 | int vol[16] = { 0x021, 0x084, 0x090, 0x104, |
| 183 | 0x110, 0x204, 0x210, 0x402, |
| 184 | 0x404, 0x408, 0x410, 0x801, |
| 185 | 0x802, 0x804, 0x808, 0x810 }; |
| 186 | int i, a, port = dev->port; |
| 187 | int n = vol[dev->curvol & 0x0f]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 189 | if (dev->card_type != 11) |
| 190 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 192 | for (i = 12; --i >= 0; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | a = ((n >> i) & 1) << 6; /* if (a=0) a= 0; else a= 0x40; */ |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 194 | outb(a | 4, port); |
| 195 | wait(4, port); |
| 196 | outb(a | 0x24, port); |
| 197 | wait(4, port); |
| 198 | outb(a | 4, port); |
| 199 | wait(4, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 201 | for (i = 6; --i >= 0; ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | a = ((0x18 >> i) & 1) << 6; |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 203 | outb(a | 4, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | wait(4,port); |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 205 | outb(a | 0x24, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | wait(4,port); |
| 207 | outb(a|4, port); |
| 208 | wait(4,port); |
| 209 | } |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 210 | wait(4, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | outb(0x14, port); |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 216 | static int vidioc_querycap(struct file *file, void *priv, |
| 217 | struct v4l2_capability *v) |
| 218 | { |
| 219 | strlcpy(v->driver, "radio-sf16fmr2", sizeof(v->driver)); |
| 220 | strlcpy(v->card, "SF16-FMR2 radio", sizeof(v->card)); |
| 221 | sprintf(v->bus_info, "ISA"); |
| 222 | v->version = RADIO_VERSION; |
| 223 | v->capabilities = V4L2_CAP_TUNER; |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 228 | struct v4l2_tuner *v) |
| 229 | { |
| 230 | int mult; |
| 231 | struct video_device *dev = video_devdata(file); |
| 232 | struct fmr2_device *fmr2 = dev->priv; |
| 233 | |
| 234 | if (v->index > 0) |
| 235 | return -EINVAL; |
| 236 | |
| 237 | strcpy(v->name, "FM"); |
| 238 | v->type = V4L2_TUNER_RADIO; |
| 239 | |
| 240 | mult = (fmr2->flags & V4L2_TUNER_CAP_LOW) ? 1 : 1000; |
| 241 | v->rangelow = RSF16_MINFREQ/mult; |
| 242 | v->rangehigh = RSF16_MAXFREQ/mult; |
| 243 | v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_MODE_STEREO; |
| 244 | v->capability = fmr2->flags&V4L2_TUNER_CAP_LOW; |
| 245 | v->audmode = fmr2->stereo ? V4L2_TUNER_MODE_STEREO: |
| 246 | V4L2_TUNER_MODE_MONO; |
| 247 | mutex_lock(&lock); |
| 248 | v->signal = fmr2_getsigstr(fmr2); |
| 249 | mutex_unlock(&lock); |
| 250 | return 0; |
| 251 | } |
| 252 | |
| 253 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 254 | struct v4l2_tuner *v) |
| 255 | { |
| 256 | if (v->index > 0) |
| 257 | return -EINVAL; |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 262 | struct v4l2_frequency *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { |
| 264 | struct video_device *dev = video_devdata(file); |
| 265 | struct fmr2_device *fmr2 = dev->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 267 | if (!(fmr2->flags & V4L2_TUNER_CAP_LOW)) |
| 268 | f->frequency *= 1000; |
| 269 | if (f->frequency < RSF16_MINFREQ || |
| 270 | f->frequency > RSF16_MAXFREQ ) |
| 271 | return -EINVAL; |
| 272 | /*rounding in steps of 200 to match th freq |
| 273 | that will be used */ |
| 274 | fmr2->curfreq = (f->frequency/200)*200; |
Mauro Carvalho Chehab | acda0e7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 275 | |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 276 | /* set card freq (if not muted) */ |
| 277 | if (fmr2->curvol && !fmr2->mute) { |
| 278 | mutex_lock(&lock); |
| 279 | fmr2_setfreq(fmr2); |
| 280 | mutex_unlock(&lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 282 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 285 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 286 | struct v4l2_frequency *f) |
| 287 | { |
| 288 | struct video_device *dev = video_devdata(file); |
| 289 | struct fmr2_device *fmr2 = dev->priv; |
| 290 | |
| 291 | f->type = V4L2_TUNER_RADIO; |
| 292 | f->frequency = fmr2->curfreq; |
| 293 | if (!(fmr2->flags & V4L2_TUNER_CAP_LOW)) |
| 294 | f->frequency /= 1000; |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 299 | struct v4l2_queryctrl *qc) |
| 300 | { |
| 301 | int i; |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 302 | |
| 303 | for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 304 | if (qc->id && qc->id == radio_qctrl[i].id) { |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 305 | memcpy(qc, &radio_qctrl[i], sizeof(*qc)); |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 306 | return 0; |
| 307 | } |
| 308 | } |
| 309 | return -EINVAL; |
| 310 | } |
| 311 | |
| 312 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 313 | struct v4l2_control *ctrl) |
| 314 | { |
| 315 | struct video_device *dev = video_devdata(file); |
| 316 | struct fmr2_device *fmr2 = dev->priv; |
| 317 | |
| 318 | switch (ctrl->id) { |
| 319 | case V4L2_CID_AUDIO_MUTE: |
| 320 | ctrl->value = fmr2->mute; |
| 321 | return 0; |
| 322 | case V4L2_CID_AUDIO_VOLUME: |
| 323 | ctrl->value = fmr2->curvol; |
| 324 | return 0; |
| 325 | } |
| 326 | return -EINVAL; |
| 327 | } |
| 328 | |
| 329 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 330 | struct v4l2_control *ctrl) |
| 331 | { |
| 332 | struct video_device *dev = video_devdata(file); |
| 333 | struct fmr2_device *fmr2 = dev->priv; |
| 334 | |
| 335 | switch (ctrl->id) { |
| 336 | case V4L2_CID_AUDIO_MUTE: |
| 337 | fmr2->mute = ctrl->value; |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 338 | break; |
| 339 | case V4L2_CID_AUDIO_VOLUME: |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 340 | if (ctrl->value > radio_qctrl[AUD_VOL_INDEX].maximum) |
| 341 | fmr2->curvol = radio_qctrl[AUD_VOL_INDEX].maximum; |
| 342 | else |
| 343 | fmr2->curvol = ctrl->value; |
| 344 | |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 345 | break; |
| 346 | default: |
| 347 | return -EINVAL; |
| 348 | } |
| 349 | |
| 350 | #ifdef DEBUG |
| 351 | if (fmr2->curvol && !fmr2->mute) |
| 352 | printk(KERN_DEBUG "unmute\n"); |
| 353 | else |
| 354 | printk(KERN_DEBUG "mute\n"); |
| 355 | #endif |
| 356 | |
| 357 | mutex_lock(&lock); |
| 358 | if (fmr2->curvol && !fmr2->mute) { |
| 359 | fmr2_setvolume(fmr2); |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 360 | /* Set frequency and unmute card */ |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 361 | fmr2_setfreq(fmr2); |
| 362 | } else |
| 363 | fmr2_mute(fmr2->port); |
| 364 | mutex_unlock(&lock); |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | static int vidioc_g_audio(struct file *file, void *priv, |
| 369 | struct v4l2_audio *a) |
| 370 | { |
| 371 | if (a->index > 1) |
| 372 | return -EINVAL; |
| 373 | |
| 374 | strcpy(a->name, "Radio"); |
| 375 | a->capability = V4L2_AUDCAP_STEREO; |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 380 | { |
| 381 | *i = 0; |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 386 | { |
| 387 | if (i != 0) |
| 388 | return -EINVAL; |
| 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static int vidioc_s_audio(struct file *file, void *priv, |
| 393 | struct v4l2_audio *a) |
| 394 | { |
| 395 | if (a->index != 0) |
| 396 | return -EINVAL; |
| 397 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | static struct fmr2_device fmr2_unit; |
| 401 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 402 | static const struct file_operations fmr2_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | .owner = THIS_MODULE, |
| 404 | .open = video_exclusive_open, |
| 405 | .release = video_exclusive_release, |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 406 | .ioctl = video_ioctl2, |
Arnd Bergmann | 0d0fbf8 | 2006-01-09 15:24:57 -0200 | [diff] [blame] | 407 | .compat_ioctl = v4l_compat_ioctl32, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | .llseek = no_llseek, |
| 409 | }; |
| 410 | |
| 411 | static struct video_device fmr2_radio= |
| 412 | { |
| 413 | .owner = THIS_MODULE, |
| 414 | .name = "SF16FMR2 radio", |
| 415 | . type = VID_TYPE_TUNER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | .fops = &fmr2_fops, |
Douglas Landgraf | 34ab962 | 2007-04-23 17:51:37 -0300 | [diff] [blame] | 417 | .vidioc_querycap = vidioc_querycap, |
| 418 | .vidioc_g_tuner = vidioc_g_tuner, |
| 419 | .vidioc_s_tuner = vidioc_s_tuner, |
| 420 | .vidioc_g_audio = vidioc_g_audio, |
| 421 | .vidioc_s_audio = vidioc_s_audio, |
| 422 | .vidioc_g_input = vidioc_g_input, |
| 423 | .vidioc_s_input = vidioc_s_input, |
| 424 | .vidioc_g_frequency = vidioc_g_frequency, |
| 425 | .vidioc_s_frequency = vidioc_s_frequency, |
| 426 | .vidioc_queryctrl = vidioc_queryctrl, |
| 427 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 428 | .vidioc_s_ctrl = vidioc_s_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | }; |
| 430 | |
| 431 | static int __init fmr2_init(void) |
| 432 | { |
| 433 | fmr2_unit.port = io; |
| 434 | fmr2_unit.curvol = 0; |
| 435 | fmr2_unit.mute = 0; |
| 436 | fmr2_unit.curfreq = 0; |
| 437 | fmr2_unit.stereo = 1; |
Mauro Carvalho Chehab | acda0e7 | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 438 | fmr2_unit.flags = V4L2_TUNER_CAP_LOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | fmr2_unit.card_type = 0; |
| 440 | fmr2_radio.priv = &fmr2_unit; |
| 441 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 442 | mutex_init(&lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Douglas Schilling Landgraf | dd49f30 | 2008-01-27 14:29:51 -0300 | [diff] [blame] | 444 | if (!request_region(io, 2, "sf16fmr2")) { |
| 445 | printk(KERN_ERR "radio-sf16fmr2: request_region failed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | return -EBUSY; |
| 447 | } |
| 448 | |
Andrew Morton | 98512f7 | 2008-01-07 05:24:51 -0300 | [diff] [blame] | 449 | if (video_register_device(&fmr2_radio, VFL_TYPE_RADIO, radio_nr) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | release_region(io, 2); |
| 451 | return -EINVAL; |
| 452 | } |
| 453 | |
| 454 | printk(KERN_INFO "SF16FMR2 radio card driver at 0x%x.\n", io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | /* mute card - prevents noisy bootups */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 456 | mutex_lock(&lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | fmr2_mute(io); |
| 458 | fmr2_product_info(&fmr2_unit); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 459 | mutex_unlock(&lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | debug_print((KERN_DEBUG "card_type %d\n", fmr2_unit.card_type)); |
Mauro Carvalho Chehab | b2cb200 | 2008-04-22 14:46:03 -0300 | [diff] [blame^] | 461 | |
| 462 | /* Only card_type == 11 implements volume */ |
| 463 | if (fmr2_unit.card_type != 11) |
| 464 | radio_qctrl[AUD_VOL_INDEX].maximum = 1; |
| 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | MODULE_AUTHOR("Ziglio Frediano, freddy77@angelfire.com"); |
| 470 | MODULE_DESCRIPTION("A driver for the SF16FMR2 radio."); |
| 471 | MODULE_LICENSE("GPL"); |
| 472 | |
| 473 | module_param(io, int, 0); |
| 474 | MODULE_PARM_DESC(io, "I/O address of the SF16FMR2 card (should be 0x384, if do not work try 0x284)"); |
| 475 | module_param(radio_nr, int, 0); |
| 476 | |
| 477 | static void __exit fmr2_cleanup_module(void) |
| 478 | { |
| 479 | video_unregister_device(&fmr2_radio); |
| 480 | release_region(io,2); |
| 481 | } |
| 482 | |
| 483 | module_init(fmr2_init); |
| 484 | module_exit(fmr2_cleanup_module); |
| 485 | |
| 486 | #ifndef MODULE |
| 487 | |
| 488 | static int __init fmr2_setup_io(char *str) |
| 489 | { |
| 490 | get_option(&str, &io); |
| 491 | return 1; |
| 492 | } |
| 493 | |
| 494 | __setup("sf16fmr2=", fmr2_setup_io); |
| 495 | |
| 496 | #endif |