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