blob: a11414f648d4f9279431b98d103450d4c8926bfd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* 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 Chehabacda0e72006-08-08 09:10:02 -030013 *
14 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 */
16
17#include <linux/module.h> /* Modules */
18#include <linux/init.h> /* Initdata */
Peter Osterlundfb911ee2005-09-13 01:25:15 -070019#include <linux/ioport.h> /* request_region */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/delay.h> /* udelay */
Mauro Carvalho Chehabacda0e72006-08-08 09:10:02 -030021#include <linux/videodev2.h> /* kernel radio structs */
Ingo Molnar3593cab2006-02-07 06:49:14 -020022#include <linux/mutex.h>
Mauro Carvalho Chehab1ddf5bc2006-08-08 09:10:06 -030023#include <linux/version.h> /* for KERNEL_VERSION MACRO */
Hans Verkuilc32a9d72009-03-06 13:53:26 -030024#include <linux/io.h> /* outb, outb_p */
Hans Verkuilc32a9d72009-03-06 13:53:26 -030025#include <media/v4l2-device.h>
26#include <media/v4l2-ioctl.h>
27
28MODULE_AUTHOR("Ziglio Frediano, freddy77@angelfire.com");
29MODULE_DESCRIPTION("A driver for the SF16FMR2 radio.");
30MODULE_LICENSE("GPL");
31
32static int io = 0x384;
33static int radio_nr = -1;
34
35module_param(io, int, 0);
36MODULE_PARM_DESC(io, "I/O address of the SF16FMR2 card (should be 0x384, if do not work try 0x284)");
37module_param(radio_nr, int, 0);
38
Mauro Carvalho Chehabacda0e72006-08-08 09:10:02 -030039#define RADIO_VERSION KERNEL_VERSION(0,0,2)
40
Mauro Carvalho Chehabb2cb2002008-04-22 14:46:03 -030041#define AUD_VOL_INDEX 1
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#undef DEBUG
44//#define DEBUG 1
45
46#ifdef DEBUG
47# define debug_print(s) printk s
48#else
49# define debug_print(s)
50#endif
51
52/* this should be static vars for module size */
Hans Verkuilc32a9d72009-03-06 13:53:26 -030053struct fmr2
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
Hans Verkuilc32a9d72009-03-06 13:53:26 -030055 struct v4l2_device v4l2_dev;
56 struct video_device vdev;
57 struct mutex lock;
58 int io;
Mauro Carvalho Chehabb2cb2002008-04-22 14:46:03 -030059 int curvol; /* 0-15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 int mute;
61 int stereo; /* card is producing stereo audio */
62 unsigned long curfreq; /* freq in kHz */
63 int card_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
Hans Verkuilc32a9d72009-03-06 13:53:26 -030066static struct fmr2 fmr2_card;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68/* hw precision is 12.5 kHz
Hans Verkuil1d80db52009-05-02 12:04:13 -030069 * It is only useful to give freq in interval of 200 (=0.0125Mhz),
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 * other bits will be truncated
71 */
Hans Verkuilc32a9d72009-03-06 13:53:26 -030072#define RSF16_ENCODE(x) ((x) / 200 + 856)
73#define RSF16_MINFREQ (87 * 16000)
74#define RSF16_MAXFREQ (108 * 16000)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Hans Verkuilc32a9d72009-03-06 13:53:26 -030076static inline void wait(int n, int io)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
Hans Verkuilc32a9d72009-03-06 13:53:26 -030078 for (; n; --n)
79 inb(io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
Hans Verkuilc32a9d72009-03-06 13:53:26 -030082static void outbits(int bits, unsigned int data, int nWait, int io)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 int bit;
Hans Verkuilc32a9d72009-03-06 13:53:26 -030085
86 for (; --bits >= 0;) {
87 bit = (data >> bits) & 1;
88 outb(bit, io);
89 wait(nWait, io);
90 outb(bit | 2, io);
91 wait(nWait, io);
92 outb(bit, io);
93 wait(nWait, io);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 }
95}
96
Hans Verkuilc32a9d72009-03-06 13:53:26 -030097static inline void fmr2_mute(int io)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Hans Verkuilc32a9d72009-03-06 13:53:26 -030099 outb(0x00, io);
100 wait(4, io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300103static inline void fmr2_unmute(int io)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300105 outb(0x04, io);
106 wait(4, io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300109static inline int fmr2_stereo_mode(int io)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300111 int n = inb(io);
112
113 outb(6, io);
114 inb(io);
115 n = ((n >> 3) & 1) ^ 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 debug_print((KERN_DEBUG "stereo: %d\n", n));
117 return n;
118}
119
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300120static int fmr2_product_info(struct fmr2 *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300122 int n = inb(dev->io);
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 n &= 0xC1;
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300125 if (n == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 /* this should support volume set */
127 dev->card_type = 12;
128 return 0;
129 }
130 /* not volume (mine is 11) */
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300131 dev->card_type = (n == 128) ? 11 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 return n;
133}
134
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300135static inline int fmr2_getsigstr(struct fmr2 *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300137 /* !!! works only if scanning freq */
138 int res = 0xffff;
139
140 outb(5, dev->io);
141 wait(4, dev->io);
142 if (!(inb(dev->io) & 1))
143 res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 debug_print((KERN_DEBUG "signal: %d\n", res));
145 return res;
146}
147
148/* set frequency and unmute card */
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300149static int fmr2_setfreq(struct fmr2 *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 unsigned long freq = dev->curfreq;
152
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300153 fmr2_mute(dev->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 /* 0x42 for mono output
156 * 0x102 forward scanning
157 * 0x182 scansione avanti
158 */
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300159 outbits(9, 0x2, 3, dev->io);
160 outbits(16, RSF16_ENCODE(freq), 2, dev->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300162 fmr2_unmute(dev->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 /* wait 0.11 sec */
165 msleep(110);
166
167 /* NOTE if mute this stop radio
168 you must set freq on unmute */
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300169 dev->stereo = fmr2_stereo_mode(dev->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 return 0;
171}
172
173/* !!! not tested, in my card this does't work !!! */
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300174static int fmr2_setvolume(struct fmr2 *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Mauro Carvalho Chehabb2cb2002008-04-22 14:46:03 -0300176 int vol[16] = { 0x021, 0x084, 0x090, 0x104,
177 0x110, 0x204, 0x210, 0x402,
178 0x404, 0x408, 0x410, 0x801,
179 0x802, 0x804, 0x808, 0x810 };
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300180 int i, a;
Mauro Carvalho Chehabb2cb2002008-04-22 14:46:03 -0300181 int n = vol[dev->curvol & 0x0f];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Mauro Carvalho Chehabb2cb2002008-04-22 14:46:03 -0300183 if (dev->card_type != 11)
184 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Mauro Carvalho Chehabb2cb2002008-04-22 14:46:03 -0300186 for (i = 12; --i >= 0; ) {
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300187 a = ((n >> i) & 1) << 6; /* if (a==0) a = 0; else a = 0x40; */
188 outb(a | 4, dev->io);
189 wait(4, dev->io);
190 outb(a | 0x24, dev->io);
191 wait(4, dev->io);
192 outb(a | 4, dev->io);
193 wait(4, dev->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
Mauro Carvalho Chehabb2cb2002008-04-22 14:46:03 -0300195 for (i = 6; --i >= 0; ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 a = ((0x18 >> i) & 1) << 6;
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300197 outb(a | 4, dev->io);
198 wait(4, dev->io);
199 outb(a | 0x24, dev->io);
200 wait(4, dev->io);
201 outb(a | 4, dev->io);
202 wait(4, dev->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 }
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300204 wait(4, dev->io);
205 outb(0x14, dev->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 return 0;
207}
208
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300209static int vidioc_querycap(struct file *file, void *priv,
210 struct v4l2_capability *v)
211{
212 strlcpy(v->driver, "radio-sf16fmr2", sizeof(v->driver));
213 strlcpy(v->card, "SF16-FMR2 radio", sizeof(v->card));
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300214 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300215 v->version = RADIO_VERSION;
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300216 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300217 return 0;
218}
219
220static int vidioc_g_tuner(struct file *file, void *priv,
221 struct v4l2_tuner *v)
222{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300223 struct fmr2 *fmr2 = video_drvdata(file);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300224
225 if (v->index > 0)
226 return -EINVAL;
227
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300228 strlcpy(v->name, "FM", sizeof(v->name));
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300229 v->type = V4L2_TUNER_RADIO;
230
Hans Verkuil1d80db52009-05-02 12:04:13 -0300231 v->rangelow = RSF16_MINFREQ;
232 v->rangehigh = RSF16_MAXFREQ;
Hans Verkuil38092a42009-05-02 12:06:15 -0300233 v->rxsubchans = fmr2->stereo ? V4L2_TUNER_SUB_STEREO :
234 V4L2_TUNER_SUB_MONO;
235 v->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW;
236 v->audmode = V4L2_TUNER_MODE_STEREO;
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300237 mutex_lock(&fmr2->lock);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300238 v->signal = fmr2_getsigstr(fmr2);
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300239 mutex_unlock(&fmr2->lock);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300240 return 0;
241}
242
243static int vidioc_s_tuner(struct file *file, void *priv,
244 struct v4l2_tuner *v)
245{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300246 return v->index ? -EINVAL : 0;
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300247}
248
249static int vidioc_s_frequency(struct file *file, void *priv,
250 struct v4l2_frequency *f)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300252 struct fmr2 *fmr2 = video_drvdata(file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300254 if (f->frequency < RSF16_MINFREQ ||
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300255 f->frequency > RSF16_MAXFREQ)
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300256 return -EINVAL;
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300257 /* rounding in steps of 200 to match the freq
258 that will be used */
259 fmr2->curfreq = (f->frequency / 200) * 200;
Mauro Carvalho Chehabacda0e72006-08-08 09:10:02 -0300260
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300261 /* set card freq (if not muted) */
262 if (fmr2->curvol && !fmr2->mute) {
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300263 mutex_lock(&fmr2->lock);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300264 fmr2_setfreq(fmr2);
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300265 mutex_unlock(&fmr2->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300267 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268}
269
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300270static int vidioc_g_frequency(struct file *file, void *priv,
271 struct v4l2_frequency *f)
272{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300273 struct fmr2 *fmr2 = video_drvdata(file);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300274
275 f->type = V4L2_TUNER_RADIO;
276 f->frequency = fmr2->curfreq;
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300277 return 0;
278}
279
280static int vidioc_queryctrl(struct file *file, void *priv,
281 struct v4l2_queryctrl *qc)
282{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300283 struct fmr2 *fmr2 = video_drvdata(file);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300284
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300285 switch (qc->id) {
286 case V4L2_CID_AUDIO_MUTE:
287 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
288 case V4L2_CID_AUDIO_VOLUME:
289 /* Only card_type == 11 implements volume */
290 if (fmr2->card_type == 11)
291 return v4l2_ctrl_query_fill(qc, 0, 15, 1, 0);
292 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300293 }
294 return -EINVAL;
295}
296
297static int vidioc_g_ctrl(struct file *file, void *priv,
298 struct v4l2_control *ctrl)
299{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300300 struct fmr2 *fmr2 = video_drvdata(file);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300301
302 switch (ctrl->id) {
303 case V4L2_CID_AUDIO_MUTE:
304 ctrl->value = fmr2->mute;
305 return 0;
306 case V4L2_CID_AUDIO_VOLUME:
307 ctrl->value = fmr2->curvol;
308 return 0;
309 }
310 return -EINVAL;
311}
312
313static int vidioc_s_ctrl(struct file *file, void *priv,
314 struct v4l2_control *ctrl)
315{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300316 struct fmr2 *fmr2 = video_drvdata(file);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300317
318 switch (ctrl->id) {
319 case V4L2_CID_AUDIO_MUTE:
320 fmr2->mute = ctrl->value;
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300321 break;
322 case V4L2_CID_AUDIO_VOLUME:
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300323 fmr2->curvol = ctrl->value;
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300324 break;
325 default:
326 return -EINVAL;
327 }
328
329#ifdef DEBUG
330 if (fmr2->curvol && !fmr2->mute)
331 printk(KERN_DEBUG "unmute\n");
332 else
333 printk(KERN_DEBUG "mute\n");
334#endif
335
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300336 mutex_lock(&fmr2->lock);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300337 if (fmr2->curvol && !fmr2->mute) {
338 fmr2_setvolume(fmr2);
Mauro Carvalho Chehabb2cb2002008-04-22 14:46:03 -0300339 /* Set frequency and unmute card */
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300340 fmr2_setfreq(fmr2);
341 } else
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300342 fmr2_mute(fmr2->io);
343 mutex_unlock(&fmr2->lock);
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300344 return 0;
345}
346
347static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
348{
349 *i = 0;
350 return 0;
351}
352
353static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
354{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300355 return i ? -EINVAL : 0;
356}
357
358static int vidioc_g_audio(struct file *file, void *priv,
359 struct v4l2_audio *a)
360{
361 a->index = 0;
362 strlcpy(a->name, "Radio", sizeof(a->name));
363 a->capability = V4L2_AUDCAP_STEREO;
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300364 return 0;
365}
366
367static int vidioc_s_audio(struct file *file, void *priv,
368 struct v4l2_audio *a)
369{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300370 return a->index ? -EINVAL : 0;
371}
372
Hans Verkuilbec43662008-12-30 06:58:20 -0300373static const struct v4l2_file_operations fmr2_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 .owner = THIS_MODULE,
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300375 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376};
377
Hans Verkuila3998102008-07-21 02:57:38 -0300378static const struct v4l2_ioctl_ops fmr2_ioctl_ops = {
Douglas Landgraf34ab9622007-04-23 17:51:37 -0300379 .vidioc_querycap = vidioc_querycap,
380 .vidioc_g_tuner = vidioc_g_tuner,
381 .vidioc_s_tuner = vidioc_s_tuner,
382 .vidioc_g_audio = vidioc_g_audio,
383 .vidioc_s_audio = vidioc_s_audio,
384 .vidioc_g_input = vidioc_g_input,
385 .vidioc_s_input = vidioc_s_input,
386 .vidioc_g_frequency = vidioc_g_frequency,
387 .vidioc_s_frequency = vidioc_s_frequency,
388 .vidioc_queryctrl = vidioc_queryctrl,
389 .vidioc_g_ctrl = vidioc_g_ctrl,
390 .vidioc_s_ctrl = vidioc_s_ctrl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391};
392
393static int __init fmr2_init(void)
394{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300395 struct fmr2 *fmr2 = &fmr2_card;
396 struct v4l2_device *v4l2_dev = &fmr2->v4l2_dev;
397 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300399 strlcpy(v4l2_dev->name, "sf16fmr2", sizeof(v4l2_dev->name));
400 fmr2->io = io;
401 fmr2->stereo = 1;
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300402 mutex_init(&fmr2->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300404 if (!request_region(fmr2->io, 2, "sf16fmr2")) {
405 v4l2_err(v4l2_dev, "request_region failed!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return -EBUSY;
407 }
408
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300409 res = v4l2_device_register(NULL, v4l2_dev);
410 if (res < 0) {
411 release_region(fmr2->io, 2);
412 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
413 return res;
414 }
415
416 strlcpy(fmr2->vdev.name, v4l2_dev->name, sizeof(fmr2->vdev.name));
417 fmr2->vdev.v4l2_dev = v4l2_dev;
418 fmr2->vdev.fops = &fmr2_fops;
419 fmr2->vdev.ioctl_ops = &fmr2_ioctl_ops;
420 fmr2->vdev.release = video_device_release_empty;
421 video_set_drvdata(&fmr2->vdev, fmr2);
422
423 if (video_register_device(&fmr2->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
424 v4l2_device_unregister(v4l2_dev);
425 release_region(fmr2->io, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 return -EINVAL;
427 }
428
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300429 v4l2_info(v4l2_dev, "SF16FMR2 radio card driver at 0x%x.\n", fmr2->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 /* mute card - prevents noisy bootups */
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300431 mutex_lock(&fmr2->lock);
432 fmr2_mute(fmr2->io);
433 fmr2_product_info(fmr2);
434 mutex_unlock(&fmr2->lock);
435 debug_print((KERN_DEBUG "card_type %d\n", fmr2->card_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 return 0;
437}
438
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300439static void __exit fmr2_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300441 struct fmr2 *fmr2 = &fmr2_card;
442
443 video_unregister_device(&fmr2->vdev);
444 v4l2_device_unregister(&fmr2->v4l2_dev);
445 release_region(fmr2->io, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
448module_init(fmr2_init);
Hans Verkuilc32a9d72009-03-06 13:53:26 -0300449module_exit(fmr2_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451#ifndef MODULE
452
453static int __init fmr2_setup_io(char *str)
454{
455 get_option(&str, &io);
456 return 1;
457}
458
459__setup("sf16fmr2=", fmr2_setup_io);
460
461#endif