1abed623cSOndrej Zary /* SF16-FMI, SF16-FMP and SF16-FMD radio driver for Linux radio support 21da177e4SLinus Torvalds * heavily based on rtrack driver... 31da177e4SLinus Torvalds * (c) 1997 M. Kirkwood 41da177e4SLinus Torvalds * (c) 1998 Petr Vandrovec, vandrove@vc.cvut.cz 51da177e4SLinus Torvalds * 6d9b01449SAlan Cox * Fitted to new interface by Alan Cox <alan@lxorguk.ukuu.org.uk> 71da177e4SLinus Torvalds * Made working and cleaned up functions <mikael.hedin@irf.se> 81da177e4SLinus Torvalds * Support for ISAPnP by Ladislav Michl <ladis@psi.cz> 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * Notes on the hardware 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * Frequency control is done digitally -- ie out(port,encodefreq(95.8)); 131da177e4SLinus Torvalds * No volume control - only mute/unmute - you have to use line volume 14abed623cSOndrej Zary * control on SB-part of SF16-FMI/SF16-FMP/SF16-FMD 151da177e4SLinus Torvalds * 16a2ef73afSMauro Carvalho Chehab * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> 171da177e4SLinus Torvalds */ 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds #include <linux/kernel.h> /* __setup */ 201da177e4SLinus Torvalds #include <linux/module.h> /* Modules */ 211da177e4SLinus Torvalds #include <linux/init.h> /* Initdata */ 22fb911ee8SPeter Osterlund #include <linux/ioport.h> /* request_region */ 231da177e4SLinus Torvalds #include <linux/delay.h> /* udelay */ 241da177e4SLinus Torvalds #include <linux/isapnp.h> 253593cab5SIngo Molnar #include <linux/mutex.h> 26c41269fdSHans Verkuil #include <linux/videodev2.h> /* kernel radio structs */ 27c41269fdSHans Verkuil #include <linux/io.h> /* outb, outb_p */ 28c41269fdSHans Verkuil #include <media/v4l2-device.h> 29c41269fdSHans Verkuil #include <media/v4l2-ioctl.h> 306b39023aSOndrej Zary #include "lm7000.h" 311da177e4SLinus Torvalds 32c41269fdSHans Verkuil MODULE_AUTHOR("Petr Vandrovec, vandrove@vc.cvut.cz and M. Kirkwood"); 33abed623cSOndrej Zary MODULE_DESCRIPTION("A driver for the SF16-FMI, SF16-FMP and SF16-FMD radio."); 34c41269fdSHans Verkuil MODULE_LICENSE("GPL"); 3529834c1aSMauro Carvalho Chehab MODULE_VERSION("0.0.3"); 361da177e4SLinus Torvalds 371da177e4SLinus Torvalds static int io = -1; 381da177e4SLinus Torvalds static int radio_nr = -1; 39c41269fdSHans Verkuil 40c41269fdSHans Verkuil module_param(io, int, 0); 41abed623cSOndrej Zary MODULE_PARM_DESC(io, "I/O address of the SF16-FMI/SF16-FMP/SF16-FMD card (0x284 or 0x384)"); 42c41269fdSHans Verkuil module_param(radio_nr, int, 0); 43c41269fdSHans Verkuil 44c41269fdSHans Verkuil struct fmi 45c41269fdSHans Verkuil { 46c41269fdSHans Verkuil struct v4l2_device v4l2_dev; 47c41269fdSHans Verkuil struct video_device vdev; 48c41269fdSHans Verkuil int io; 494b830374SOndrej Zary bool mute; 50c41269fdSHans Verkuil unsigned long curfreq; /* freq in kHz */ 51c41269fdSHans Verkuil struct mutex lock; 52c41269fdSHans Verkuil }; 53c41269fdSHans Verkuil 54c41269fdSHans Verkuil static struct fmi fmi_card; 55c41269fdSHans Verkuil static struct pnp_dev *dev; 5667cabf50SOndrej Zary bool pnp_attached; 571da177e4SLinus Torvalds 58c41269fdSHans Verkuil #define RSF16_MINFREQ (87 * 16000) 59c41269fdSHans Verkuil #define RSF16_MAXFREQ (108 * 16000) 601da177e4SLinus Torvalds 616b39023aSOndrej Zary #define FMI_BIT_TUN_CE (1 << 0) 626b39023aSOndrej Zary #define FMI_BIT_TUN_CLK (1 << 1) 636b39023aSOndrej Zary #define FMI_BIT_TUN_DATA (1 << 2) 646b39023aSOndrej Zary #define FMI_BIT_VOL_SW (1 << 3) 656b39023aSOndrej Zary #define FMI_BIT_TUN_STRQ (1 << 4) 666b39023aSOndrej Zary 67a5133b17SMauro Carvalho Chehab static void fmi_set_pins(void *handle, u8 pins) 681da177e4SLinus Torvalds { 696b39023aSOndrej Zary struct fmi *fmi = handle; 706b39023aSOndrej Zary u8 bits = FMI_BIT_TUN_STRQ; 716b39023aSOndrej Zary 726b39023aSOndrej Zary if (!fmi->mute) 736b39023aSOndrej Zary bits |= FMI_BIT_VOL_SW; 746b39023aSOndrej Zary 756b39023aSOndrej Zary if (pins & LM7000_DATA) 766b39023aSOndrej Zary bits |= FMI_BIT_TUN_DATA; 776b39023aSOndrej Zary if (pins & LM7000_CLK) 786b39023aSOndrej Zary bits |= FMI_BIT_TUN_CLK; 796b39023aSOndrej Zary if (pins & LM7000_CE) 806b39023aSOndrej Zary bits |= FMI_BIT_TUN_CE; 816b39023aSOndrej Zary 826b39023aSOndrej Zary mutex_lock(&fmi->lock); 836b39023aSOndrej Zary outb_p(bits, fmi->io); 846b39023aSOndrej Zary mutex_unlock(&fmi->lock); 851da177e4SLinus Torvalds } 861da177e4SLinus Torvalds 87c41269fdSHans Verkuil static inline void fmi_mute(struct fmi *fmi) 881da177e4SLinus Torvalds { 89c41269fdSHans Verkuil mutex_lock(&fmi->lock); 90c41269fdSHans Verkuil outb(0x00, fmi->io); 91c41269fdSHans Verkuil mutex_unlock(&fmi->lock); 921da177e4SLinus Torvalds } 931da177e4SLinus Torvalds 94c41269fdSHans Verkuil static inline void fmi_unmute(struct fmi *fmi) 951da177e4SLinus Torvalds { 96c41269fdSHans Verkuil mutex_lock(&fmi->lock); 97c41269fdSHans Verkuil outb(0x08, fmi->io); 98c41269fdSHans Verkuil mutex_unlock(&fmi->lock); 991da177e4SLinus Torvalds } 1001da177e4SLinus Torvalds 101c41269fdSHans Verkuil static inline int fmi_getsigstr(struct fmi *fmi) 1021da177e4SLinus Torvalds { 1031da177e4SLinus Torvalds int val; 1041da177e4SLinus Torvalds int res; 1051da177e4SLinus Torvalds 106c41269fdSHans Verkuil mutex_lock(&fmi->lock); 1074b830374SOndrej Zary val = fmi->mute ? 0x00 : 0x08; /* mute/unmute */ 108c41269fdSHans Verkuil outb(val, fmi->io); 109c41269fdSHans Verkuil outb(val | 0x10, fmi->io); 1101da177e4SLinus Torvalds msleep(143); /* was schedule_timeout(HZ/7) */ 111c41269fdSHans Verkuil res = (int)inb(fmi->io + 1); 112c41269fdSHans Verkuil outb(val, fmi->io); 1131da177e4SLinus Torvalds 114c41269fdSHans Verkuil mutex_unlock(&fmi->lock); 1151da177e4SLinus Torvalds return (res & 2) ? 0 : 0xFFFF; 1161da177e4SLinus Torvalds } 1171da177e4SLinus Torvalds 118c123b867SDouglas Landgraf static int vidioc_querycap(struct file *file, void *priv, 119c123b867SDouglas Landgraf struct v4l2_capability *v) 1201da177e4SLinus Torvalds { 121a2ef73afSMauro Carvalho Chehab strlcpy(v->driver, "radio-sf16fmi", sizeof(v->driver)); 122abed623cSOndrej Zary strlcpy(v->card, "SF16-FMI/FMP/FMD radio", sizeof(v->card)); 123c41269fdSHans Verkuil strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); 124c41269fdSHans Verkuil v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; 1251da177e4SLinus Torvalds return 0; 1261da177e4SLinus Torvalds } 127c123b867SDouglas Landgraf 128c123b867SDouglas Landgraf static int vidioc_g_tuner(struct file *file, void *priv, 129c123b867SDouglas Landgraf struct v4l2_tuner *v) 1301da177e4SLinus Torvalds { 131c41269fdSHans Verkuil struct fmi *fmi = video_drvdata(file); 1321da177e4SLinus Torvalds 133a2ef73afSMauro Carvalho Chehab if (v->index > 0) 1341da177e4SLinus Torvalds return -EINVAL; 135a2ef73afSMauro Carvalho Chehab 136c41269fdSHans Verkuil strlcpy(v->name, "FM", sizeof(v->name)); 137a2ef73afSMauro Carvalho Chehab v->type = V4L2_TUNER_RADIO; 1381d80db56SHans Verkuil v->rangelow = RSF16_MINFREQ; 1391d80db56SHans Verkuil v->rangehigh = RSF16_MAXFREQ; 140dc47b778SHans Verkuil v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; 14138092a44SHans Verkuil v->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW; 142a2ef73afSMauro Carvalho Chehab v->audmode = V4L2_TUNER_MODE_STEREO; 1431da177e4SLinus Torvalds v->signal = fmi_getsigstr(fmi); 1441da177e4SLinus Torvalds return 0; 1451da177e4SLinus Torvalds } 146a2ef73afSMauro Carvalho Chehab 147c123b867SDouglas Landgraf static int vidioc_s_tuner(struct file *file, void *priv, 148c123b867SDouglas Landgraf struct v4l2_tuner *v) 149c123b867SDouglas Landgraf { 150c41269fdSHans Verkuil return v->index ? -EINVAL : 0; 1511da177e4SLinus Torvalds } 152c123b867SDouglas Landgraf 153c123b867SDouglas Landgraf static int vidioc_s_frequency(struct file *file, void *priv, 154*b530a447SHans Verkuil const struct v4l2_frequency *f) 1551da177e4SLinus Torvalds { 156c41269fdSHans Verkuil struct fmi *fmi = video_drvdata(file); 157a2ef73afSMauro Carvalho Chehab 158a3a9e287SHans Verkuil if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) 159a3a9e287SHans Verkuil return -EINVAL; 160a2ef73afSMauro Carvalho Chehab if (f->frequency < RSF16_MINFREQ || 161a2ef73afSMauro Carvalho Chehab f->frequency > RSF16_MAXFREQ) 1621da177e4SLinus Torvalds return -EINVAL; 163c41269fdSHans Verkuil /* rounding in steps of 800 to match the freq 1641da177e4SLinus Torvalds that will be used */ 1656b39023aSOndrej Zary lm7000_set_freq((f->frequency / 800) * 800, fmi, fmi_set_pins); 1661da177e4SLinus Torvalds return 0; 1671da177e4SLinus Torvalds } 168c123b867SDouglas Landgraf 169c123b867SDouglas Landgraf static int vidioc_g_frequency(struct file *file, void *priv, 170c123b867SDouglas Landgraf struct v4l2_frequency *f) 1711da177e4SLinus Torvalds { 172c41269fdSHans Verkuil struct fmi *fmi = video_drvdata(file); 173a2ef73afSMauro Carvalho Chehab 174a3a9e287SHans Verkuil if (f->tuner != 0) 175a3a9e287SHans Verkuil return -EINVAL; 176a2ef73afSMauro Carvalho Chehab f->type = V4L2_TUNER_RADIO; 177a2ef73afSMauro Carvalho Chehab f->frequency = fmi->curfreq; 1781da177e4SLinus Torvalds return 0; 1791da177e4SLinus Torvalds } 180c123b867SDouglas Landgraf 181c123b867SDouglas Landgraf static int vidioc_queryctrl(struct file *file, void *priv, 182c123b867SDouglas Landgraf struct v4l2_queryctrl *qc) 1831da177e4SLinus Torvalds { 184c41269fdSHans Verkuil switch (qc->id) { 185c41269fdSHans Verkuil case V4L2_CID_AUDIO_MUTE: 186c41269fdSHans Verkuil return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1); 187a2ef73afSMauro Carvalho Chehab } 1881da177e4SLinus Torvalds return -EINVAL; 1891da177e4SLinus Torvalds } 190c123b867SDouglas Landgraf 191c123b867SDouglas Landgraf static int vidioc_g_ctrl(struct file *file, void *priv, 192c123b867SDouglas Landgraf struct v4l2_control *ctrl) 1931da177e4SLinus Torvalds { 194c41269fdSHans Verkuil struct fmi *fmi = video_drvdata(file); 195a2ef73afSMauro Carvalho Chehab 196a2ef73afSMauro Carvalho Chehab switch (ctrl->id) { 197a2ef73afSMauro Carvalho Chehab case V4L2_CID_AUDIO_MUTE: 1984b830374SOndrej Zary ctrl->value = fmi->mute; 199c123b867SDouglas Landgraf return 0; 200a2ef73afSMauro Carvalho Chehab } 201a2ef73afSMauro Carvalho Chehab return -EINVAL; 202a2ef73afSMauro Carvalho Chehab } 203c123b867SDouglas Landgraf 204c123b867SDouglas Landgraf static int vidioc_s_ctrl(struct file *file, void *priv, 205c123b867SDouglas Landgraf struct v4l2_control *ctrl) 206a2ef73afSMauro Carvalho Chehab { 207c41269fdSHans Verkuil struct fmi *fmi = video_drvdata(file); 208a2ef73afSMauro Carvalho Chehab 209a2ef73afSMauro Carvalho Chehab switch (ctrl->id) { 210a2ef73afSMauro Carvalho Chehab case V4L2_CID_AUDIO_MUTE: 211a2ef73afSMauro Carvalho Chehab if (ctrl->value) 212c41269fdSHans Verkuil fmi_mute(fmi); 213a2ef73afSMauro Carvalho Chehab else 214c41269fdSHans Verkuil fmi_unmute(fmi); 2154b830374SOndrej Zary fmi->mute = ctrl->value; 216c123b867SDouglas Landgraf return 0; 217a2ef73afSMauro Carvalho Chehab } 218a2ef73afSMauro Carvalho Chehab return -EINVAL; 2191da177e4SLinus Torvalds } 220c123b867SDouglas Landgraf 221c123b867SDouglas Landgraf static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 2221da177e4SLinus Torvalds { 223c123b867SDouglas Landgraf *i = 0; 224c123b867SDouglas Landgraf return 0; 225c123b867SDouglas Landgraf } 226c123b867SDouglas Landgraf 227c123b867SDouglas Landgraf static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 228c123b867SDouglas Landgraf { 229c41269fdSHans Verkuil return i ? -EINVAL : 0; 230c41269fdSHans Verkuil } 231c41269fdSHans Verkuil 232c41269fdSHans Verkuil static int vidioc_g_audio(struct file *file, void *priv, 233c41269fdSHans Verkuil struct v4l2_audio *a) 234c41269fdSHans Verkuil { 235c41269fdSHans Verkuil a->index = 0; 236c41269fdSHans Verkuil strlcpy(a->name, "Radio", sizeof(a->name)); 237c41269fdSHans Verkuil a->capability = V4L2_AUDCAP_STEREO; 238c123b867SDouglas Landgraf return 0; 239c123b867SDouglas Landgraf } 240c123b867SDouglas Landgraf 241c123b867SDouglas Landgraf static int vidioc_s_audio(struct file *file, void *priv, 2420e8025b9SHans Verkuil const struct v4l2_audio *a) 243c123b867SDouglas Landgraf { 244c41269fdSHans Verkuil return a->index ? -EINVAL : 0; 245c41269fdSHans Verkuil } 246c41269fdSHans Verkuil 247bec43661SHans Verkuil static const struct v4l2_file_operations fmi_fops = { 2481da177e4SLinus Torvalds .owner = THIS_MODULE, 24932958fddSHans Verkuil .unlocked_ioctl = video_ioctl2, 2501da177e4SLinus Torvalds }; 2511da177e4SLinus Torvalds 252a399810cSHans Verkuil static const struct v4l2_ioctl_ops fmi_ioctl_ops = { 253c123b867SDouglas Landgraf .vidioc_querycap = vidioc_querycap, 254c123b867SDouglas Landgraf .vidioc_g_tuner = vidioc_g_tuner, 255c123b867SDouglas Landgraf .vidioc_s_tuner = vidioc_s_tuner, 256c123b867SDouglas Landgraf .vidioc_g_audio = vidioc_g_audio, 257c123b867SDouglas Landgraf .vidioc_s_audio = vidioc_s_audio, 258c123b867SDouglas Landgraf .vidioc_g_input = vidioc_g_input, 259c123b867SDouglas Landgraf .vidioc_s_input = vidioc_s_input, 260c123b867SDouglas Landgraf .vidioc_g_frequency = vidioc_g_frequency, 261c123b867SDouglas Landgraf .vidioc_s_frequency = vidioc_s_frequency, 262c123b867SDouglas Landgraf .vidioc_queryctrl = vidioc_queryctrl, 263c123b867SDouglas Landgraf .vidioc_g_ctrl = vidioc_g_ctrl, 264c123b867SDouglas Landgraf .vidioc_s_ctrl = vidioc_s_ctrl, 2651da177e4SLinus Torvalds }; 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds /* ladis: this is my card. does any other types exist? */ 2684c62e976SGreg Kroah-Hartman static struct isapnp_device_id id_table[] = { 269abed623cSOndrej Zary /* SF16-FMI */ 2701da177e4SLinus Torvalds { ISAPNP_ANY_ID, ISAPNP_ANY_ID, 2711da177e4SLinus Torvalds ISAPNP_VENDOR('M','F','R'), ISAPNP_FUNCTION(0xad10), 0}, 272abed623cSOndrej Zary /* SF16-FMD */ 273abed623cSOndrej Zary { ISAPNP_ANY_ID, ISAPNP_ANY_ID, 274abed623cSOndrej Zary ISAPNP_VENDOR('M','F','R'), ISAPNP_FUNCTION(0xad12), 0}, 2751da177e4SLinus Torvalds { ISAPNP_CARD_END, }, 2761da177e4SLinus Torvalds }; 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds MODULE_DEVICE_TABLE(isapnp, id_table); 2791da177e4SLinus Torvalds 280a999337bSRandy Dunlap static int __init isapnp_fmi_probe(void) 2811da177e4SLinus Torvalds { 2821da177e4SLinus Torvalds int i = 0; 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds while (id_table[i].card_vendor != 0 && dev == NULL) { 2851da177e4SLinus Torvalds dev = pnp_find_dev(NULL, id_table[i].vendor, 2861da177e4SLinus Torvalds id_table[i].function, NULL); 2871da177e4SLinus Torvalds i++; 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds if (!dev) 2911da177e4SLinus Torvalds return -ENODEV; 2921da177e4SLinus Torvalds if (pnp_device_attach(dev) < 0) 2931da177e4SLinus Torvalds return -EAGAIN; 2941da177e4SLinus Torvalds if (pnp_activate_dev(dev) < 0) { 295c41269fdSHans Verkuil printk(KERN_ERR "radio-sf16fmi: PnP configure failed (out of resources?)\n"); 2961da177e4SLinus Torvalds pnp_device_detach(dev); 2971da177e4SLinus Torvalds return -ENOMEM; 2981da177e4SLinus Torvalds } 2991da177e4SLinus Torvalds if (!pnp_port_valid(dev, 0)) { 3001da177e4SLinus Torvalds pnp_device_detach(dev); 3011da177e4SLinus Torvalds return -ENODEV; 3021da177e4SLinus Torvalds } 3031da177e4SLinus Torvalds 3041da177e4SLinus Torvalds i = pnp_port_start(dev, 0); 305c41269fdSHans Verkuil printk(KERN_INFO "radio-sf16fmi: PnP reports card at %#x\n", i); 3061da177e4SLinus Torvalds 3071da177e4SLinus Torvalds return i; 3081da177e4SLinus Torvalds } 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds static int __init fmi_init(void) 3111da177e4SLinus Torvalds { 312c41269fdSHans Verkuil struct fmi *fmi = &fmi_card; 313c41269fdSHans Verkuil struct v4l2_device *v4l2_dev = &fmi->v4l2_dev; 31467cabf50SOndrej Zary int res, i; 31567cabf50SOndrej Zary int probe_ports[] = { 0, 0x284, 0x384 }; 316c41269fdSHans Verkuil 31767cabf50SOndrej Zary if (io < 0) { 31867cabf50SOndrej Zary for (i = 0; i < ARRAY_SIZE(probe_ports); i++) { 31967cabf50SOndrej Zary io = probe_ports[i]; 32067cabf50SOndrej Zary if (io == 0) { 3211da177e4SLinus Torvalds io = isapnp_fmi_probe(); 32267cabf50SOndrej Zary if (io < 0) 32367cabf50SOndrej Zary continue; 32467cabf50SOndrej Zary pnp_attached = 1; 3251da177e4SLinus Torvalds } 3261da177e4SLinus Torvalds if (!request_region(io, 2, "radio-sf16fmi")) { 32767cabf50SOndrej Zary if (pnp_attached) 328e08a8c9dSMauro Carvalho Chehab pnp_device_detach(dev); 32967cabf50SOndrej Zary io = -1; 33067cabf50SOndrej Zary continue; 33167cabf50SOndrej Zary } 33267cabf50SOndrej Zary if (pnp_attached || 33367cabf50SOndrej Zary ((inb(io) & 0xf9) == 0xf9 && (inb(io) & 0x4) == 0)) 33467cabf50SOndrej Zary break; 33567cabf50SOndrej Zary release_region(io, 2); 33667cabf50SOndrej Zary io = -1; 33767cabf50SOndrej Zary } 33867cabf50SOndrej Zary } else { 33967cabf50SOndrej Zary if (!request_region(io, 2, "radio-sf16fmi")) { 34067cabf50SOndrej Zary printk(KERN_ERR "radio-sf16fmi: port %#x already in use\n", io); 3411da177e4SLinus Torvalds return -EBUSY; 3421da177e4SLinus Torvalds } 34367cabf50SOndrej Zary if (inb(io) == 0xff) { 34467cabf50SOndrej Zary printk(KERN_ERR "radio-sf16fmi: card not present at %#x\n", io); 34567cabf50SOndrej Zary release_region(io, 2); 34667cabf50SOndrej Zary return -ENODEV; 34767cabf50SOndrej Zary } 34867cabf50SOndrej Zary } 34967cabf50SOndrej Zary if (io < 0) { 35067cabf50SOndrej Zary printk(KERN_ERR "radio-sf16fmi: no cards found\n"); 35167cabf50SOndrej Zary return -ENODEV; 35267cabf50SOndrej Zary } 35367cabf50SOndrej Zary 35467cabf50SOndrej Zary strlcpy(v4l2_dev->name, "sf16fmi", sizeof(v4l2_dev->name)); 35567cabf50SOndrej Zary fmi->io = io; 3561da177e4SLinus Torvalds 357c41269fdSHans Verkuil res = v4l2_device_register(NULL, v4l2_dev); 358c41269fdSHans Verkuil if (res < 0) { 359c41269fdSHans Verkuil release_region(fmi->io, 2); 36067cabf50SOndrej Zary if (pnp_attached) 361c41269fdSHans Verkuil pnp_device_detach(dev); 362c41269fdSHans Verkuil v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); 363c41269fdSHans Verkuil return res; 364c41269fdSHans Verkuil } 3651da177e4SLinus Torvalds 366c41269fdSHans Verkuil strlcpy(fmi->vdev.name, v4l2_dev->name, sizeof(fmi->vdev.name)); 367c41269fdSHans Verkuil fmi->vdev.v4l2_dev = v4l2_dev; 368c41269fdSHans Verkuil fmi->vdev.fops = &fmi_fops; 369c41269fdSHans Verkuil fmi->vdev.ioctl_ops = &fmi_ioctl_ops; 370c41269fdSHans Verkuil fmi->vdev.release = video_device_release_empty; 371c41269fdSHans Verkuil video_set_drvdata(&fmi->vdev, fmi); 3721da177e4SLinus Torvalds 373c41269fdSHans Verkuil mutex_init(&fmi->lock); 374c41269fdSHans Verkuil 37532958fddSHans Verkuil /* mute card - prevents noisy bootups */ 37632958fddSHans Verkuil fmi_mute(fmi); 37732958fddSHans Verkuil 378c41269fdSHans Verkuil if (video_register_device(&fmi->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { 379c41269fdSHans Verkuil v4l2_device_unregister(v4l2_dev); 380c41269fdSHans Verkuil release_region(fmi->io, 2); 38167cabf50SOndrej Zary if (pnp_attached) 382c41269fdSHans Verkuil pnp_device_detach(dev); 3831da177e4SLinus Torvalds return -EINVAL; 3841da177e4SLinus Torvalds } 3851da177e4SLinus Torvalds 386c41269fdSHans Verkuil v4l2_info(v4l2_dev, "card driver at 0x%x\n", fmi->io); 3871da177e4SLinus Torvalds return 0; 3881da177e4SLinus Torvalds } 3891da177e4SLinus Torvalds 390c41269fdSHans Verkuil static void __exit fmi_exit(void) 3911da177e4SLinus Torvalds { 392c41269fdSHans Verkuil struct fmi *fmi = &fmi_card; 393c41269fdSHans Verkuil 394c41269fdSHans Verkuil video_unregister_device(&fmi->vdev); 395c41269fdSHans Verkuil v4l2_device_unregister(&fmi->v4l2_dev); 396c41269fdSHans Verkuil release_region(fmi->io, 2); 39767cabf50SOndrej Zary if (dev && pnp_attached) 3981da177e4SLinus Torvalds pnp_device_detach(dev); 3991da177e4SLinus Torvalds } 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds module_init(fmi_init); 402c41269fdSHans Verkuil module_exit(fmi_exit); 403