Ondrej Zary | abed623 | 2012-05-19 13:18:26 -0300 | [diff] [blame] | 1 | /* SF16-FMI, SF16-FMP and SF16-FMD radio driver for Linux radio support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * heavily based on rtrack driver... |
| 3 | * (c) 1997 M. Kirkwood |
| 4 | * (c) 1998 Petr Vandrovec, vandrove@vc.cvut.cz |
| 5 | * |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 6 | * Fitted to new interface by Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Made working and cleaned up functions <mikael.hedin@irf.se> |
| 8 | * Support for ISAPnP by Ladislav Michl <ladis@psi.cz> |
| 9 | * |
| 10 | * Notes on the hardware |
| 11 | * |
| 12 | * Frequency control is done digitally -- ie out(port,encodefreq(95.8)); |
| 13 | * No volume control - only mute/unmute - you have to use line volume |
Ondrej Zary | abed623 | 2012-05-19 13:18:26 -0300 | [diff] [blame] | 14 | * control on SB-part of SF16-FMI/SF16-FMP/SF16-FMD |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 15 | * |
Mauro Carvalho Chehab | a2ef73a | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 16 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #include <linux/kernel.h> /* __setup */ |
| 20 | #include <linux/module.h> /* Modules */ |
| 21 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 22 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/delay.h> /* udelay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/isapnp.h> |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 25 | #include <linux/mutex.h> |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 26 | #include <linux/videodev2.h> /* kernel radio structs */ |
| 27 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 28 | #include <media/v4l2-device.h> |
| 29 | #include <media/v4l2-ioctl.h> |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 30 | #include <media/v4l2-ctrls.h> |
Hans Verkuil | 0dc5d82 | 2013-02-03 09:51:59 -0300 | [diff] [blame] | 31 | #include <media/v4l2-event.h> |
Ondrej Zary | 6b39023 | 2012-06-13 17:25:44 -0300 | [diff] [blame] | 32 | #include "lm7000.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 34 | MODULE_AUTHOR("Petr Vandrovec, vandrove@vc.cvut.cz and M. Kirkwood"); |
Ondrej Zary | abed623 | 2012-05-19 13:18:26 -0300 | [diff] [blame] | 35 | MODULE_DESCRIPTION("A driver for the SF16-FMI, SF16-FMP and SF16-FMD radio."); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 36 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | 29834c1 | 2011-06-25 10:15:42 -0300 | [diff] [blame] | 37 | MODULE_VERSION("0.0.3"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 39 | static int io = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | static int radio_nr = -1; |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 41 | |
| 42 | module_param(io, int, 0); |
Ondrej Zary | abed623 | 2012-05-19 13:18:26 -0300 | [diff] [blame] | 43 | MODULE_PARM_DESC(io, "I/O address of the SF16-FMI/SF16-FMP/SF16-FMD card (0x284 or 0x384)"); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 44 | module_param(radio_nr, int, 0); |
| 45 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 46 | struct fmi |
| 47 | { |
| 48 | struct v4l2_device v4l2_dev; |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 49 | struct v4l2_ctrl_handler hdl; |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 50 | struct video_device vdev; |
| 51 | int io; |
Ondrej Zary | 4b83037 | 2009-12-10 17:06:44 -0300 | [diff] [blame] | 52 | bool mute; |
Ondrej Zary | d9ec089 | 2013-06-14 17:01:39 -0300 | [diff] [blame] | 53 | u32 curfreq; /* freq in kHz */ |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 54 | struct mutex lock; |
| 55 | }; |
| 56 | |
| 57 | static struct fmi fmi_card; |
| 58 | static struct pnp_dev *dev; |
Mauro Carvalho Chehab | 24c8f11 | 2014-09-24 15:42:11 -0300 | [diff] [blame] | 59 | static bool pnp_attached; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Hans Verkuil | 96bb42b | 2013-05-31 06:21:03 -0300 | [diff] [blame] | 61 | #define RSF16_MINFREQ (87U * 16000) |
| 62 | #define RSF16_MAXFREQ (108U * 16000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Ondrej Zary | 6b39023 | 2012-06-13 17:25:44 -0300 | [diff] [blame] | 64 | #define FMI_BIT_TUN_CE (1 << 0) |
| 65 | #define FMI_BIT_TUN_CLK (1 << 1) |
| 66 | #define FMI_BIT_TUN_DATA (1 << 2) |
| 67 | #define FMI_BIT_VOL_SW (1 << 3) |
| 68 | #define FMI_BIT_TUN_STRQ (1 << 4) |
| 69 | |
Mauro Carvalho Chehab | a5133b1 | 2012-10-27 13:43:05 -0300 | [diff] [blame] | 70 | static void fmi_set_pins(void *handle, u8 pins) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { |
Ondrej Zary | 6b39023 | 2012-06-13 17:25:44 -0300 | [diff] [blame] | 72 | struct fmi *fmi = handle; |
| 73 | u8 bits = FMI_BIT_TUN_STRQ; |
| 74 | |
| 75 | if (!fmi->mute) |
| 76 | bits |= FMI_BIT_VOL_SW; |
| 77 | |
| 78 | if (pins & LM7000_DATA) |
| 79 | bits |= FMI_BIT_TUN_DATA; |
| 80 | if (pins & LM7000_CLK) |
| 81 | bits |= FMI_BIT_TUN_CLK; |
| 82 | if (pins & LM7000_CE) |
| 83 | bits |= FMI_BIT_TUN_CE; |
| 84 | |
| 85 | mutex_lock(&fmi->lock); |
| 86 | outb_p(bits, fmi->io); |
| 87 | mutex_unlock(&fmi->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 90 | static inline void fmi_mute(struct fmi *fmi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 92 | mutex_lock(&fmi->lock); |
| 93 | outb(0x00, fmi->io); |
| 94 | mutex_unlock(&fmi->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 97 | static inline void fmi_unmute(struct fmi *fmi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 99 | mutex_lock(&fmi->lock); |
| 100 | outb(0x08, fmi->io); |
| 101 | mutex_unlock(&fmi->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 104 | static inline int fmi_getsigstr(struct fmi *fmi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
| 106 | int val; |
| 107 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 109 | mutex_lock(&fmi->lock); |
Ondrej Zary | 4b83037 | 2009-12-10 17:06:44 -0300 | [diff] [blame] | 110 | val = fmi->mute ? 0x00 : 0x08; /* mute/unmute */ |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 111 | outb(val, fmi->io); |
| 112 | outb(val | 0x10, fmi->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | msleep(143); /* was schedule_timeout(HZ/7) */ |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 114 | res = (int)inb(fmi->io + 1); |
| 115 | outb(val, fmi->io); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 116 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 117 | mutex_unlock(&fmi->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | return (res & 2) ? 0 : 0xFFFF; |
| 119 | } |
| 120 | |
Ondrej Zary | d9ec089 | 2013-06-14 17:01:39 -0300 | [diff] [blame] | 121 | static void fmi_set_freq(struct fmi *fmi) |
| 122 | { |
| 123 | fmi->curfreq = clamp(fmi->curfreq, RSF16_MINFREQ, RSF16_MAXFREQ); |
| 124 | /* rounding in steps of 800 to match the freq |
| 125 | that will be used */ |
| 126 | lm7000_set_freq((fmi->curfreq / 800) * 800, fmi, fmi_set_pins); |
| 127 | } |
| 128 | |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 129 | static int vidioc_querycap(struct file *file, void *priv, |
| 130 | struct v4l2_capability *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 132 | strlcpy(v->driver, "radio-sf16fmi", sizeof(v->driver)); |
Ondrej Zary | abed623 | 2012-05-19 13:18:26 -0300 | [diff] [blame] | 133 | strlcpy(v->card, "SF16-FMI/FMP/FMD radio", sizeof(v->card)); |
Ondrej Zary | 9291682 | 2013-06-14 17:01:38 -0300 | [diff] [blame] | 134 | strlcpy(v->bus_info, "ISA:radio-sf16fmi", sizeof(v->bus_info)); |
Hans Verkuil | f90842d | 2013-02-03 09:44:14 -0300 | [diff] [blame] | 135 | v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
| 136 | v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 137 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 140 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 141 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 143 | struct fmi *fmi = video_drvdata(file); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 144 | |
| 145 | if (v->index > 0) |
| 146 | return -EINVAL; |
| 147 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 148 | strlcpy(v->name, "FM", sizeof(v->name)); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 149 | v->type = V4L2_TUNER_RADIO; |
Hans Verkuil | 1d80db5 | 2009-05-02 12:04:13 -0300 | [diff] [blame] | 150 | v->rangelow = RSF16_MINFREQ; |
| 151 | v->rangehigh = RSF16_MAXFREQ; |
Hans Verkuil | dc47b77 | 2009-05-02 11:52:35 -0300 | [diff] [blame] | 152 | v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; |
Hans Verkuil | 38092a4 | 2009-05-02 12:06:15 -0300 | [diff] [blame] | 153 | v->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 154 | v->audmode = V4L2_TUNER_MODE_STEREO; |
| 155 | v->signal = fmi_getsigstr(fmi); |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static int vidioc_s_tuner(struct file *file, void *priv, |
Hans Verkuil | 2f73c7c | 2013-03-15 06:10:06 -0300 | [diff] [blame] | 160 | const struct v4l2_tuner *v) |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 161 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 162 | return v->index ? -EINVAL : 0; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | static int vidioc_s_frequency(struct file *file, void *priv, |
Hans Verkuil | b530a44 | 2013-03-19 04:09:26 -0300 | [diff] [blame] | 166 | const struct v4l2_frequency *f) |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 167 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 168 | struct fmi *fmi = video_drvdata(file); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 169 | |
Hans Verkuil | a3a9e28 | 2009-11-27 04:33:25 -0300 | [diff] [blame] | 170 | if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) |
| 171 | return -EINVAL; |
Ondrej Zary | d9ec089 | 2013-06-14 17:01:39 -0300 | [diff] [blame] | 172 | |
| 173 | fmi->curfreq = f->frequency; |
| 174 | fmi_set_freq(fmi); |
| 175 | |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 180 | struct v4l2_frequency *f) |
| 181 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 182 | struct fmi *fmi = video_drvdata(file); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 183 | |
Hans Verkuil | a3a9e28 | 2009-11-27 04:33:25 -0300 | [diff] [blame] | 184 | if (f->tuner != 0) |
| 185 | return -EINVAL; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 186 | f->type = V4L2_TUNER_RADIO; |
| 187 | f->frequency = fmi->curfreq; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 188 | return 0; |
| 189 | } |
| 190 | |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 191 | static int fmi_s_ctrl(struct v4l2_ctrl *ctrl) |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 192 | { |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 193 | struct fmi *fmi = container_of(ctrl->handler, struct fmi, hdl); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 194 | |
| 195 | switch (ctrl->id) { |
| 196 | case V4L2_CID_AUDIO_MUTE: |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 197 | if (ctrl->val) |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 198 | fmi_mute(fmi); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 199 | else |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 200 | fmi_unmute(fmi); |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 201 | fmi->mute = ctrl->val; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | return -EINVAL; |
| 205 | } |
| 206 | |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 207 | static const struct v4l2_ctrl_ops fmi_ctrl_ops = { |
| 208 | .s_ctrl = fmi_s_ctrl, |
| 209 | }; |
| 210 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 211 | static const struct v4l2_file_operations fmi_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | .owner = THIS_MODULE, |
Hans Verkuil | 0dc5d82 | 2013-02-03 09:51:59 -0300 | [diff] [blame] | 213 | .open = v4l2_fh_open, |
| 214 | .release = v4l2_fh_release, |
| 215 | .poll = v4l2_ctrl_poll, |
Hans Verkuil | 32958fd | 2010-11-14 09:36:23 -0300 | [diff] [blame] | 216 | .unlocked_ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 219 | static const struct v4l2_ioctl_ops fmi_ioctl_ops = { |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 220 | .vidioc_querycap = vidioc_querycap, |
| 221 | .vidioc_g_tuner = vidioc_g_tuner, |
| 222 | .vidioc_s_tuner = vidioc_s_tuner, |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 223 | .vidioc_g_frequency = vidioc_g_frequency, |
| 224 | .vidioc_s_frequency = vidioc_s_frequency, |
Hans Verkuil | 0dc5d82 | 2013-02-03 09:51:59 -0300 | [diff] [blame] | 225 | .vidioc_log_status = v4l2_ctrl_log_status, |
| 226 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
| 227 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | /* ladis: this is my card. does any other types exist? */ |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 231 | static struct isapnp_device_id id_table[] = { |
Ondrej Zary | abed623 | 2012-05-19 13:18:26 -0300 | [diff] [blame] | 232 | /* SF16-FMI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, |
| 234 | ISAPNP_VENDOR('M','F','R'), ISAPNP_FUNCTION(0xad10), 0}, |
Ondrej Zary | abed623 | 2012-05-19 13:18:26 -0300 | [diff] [blame] | 235 | /* SF16-FMD */ |
| 236 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, |
| 237 | ISAPNP_VENDOR('M','F','R'), ISAPNP_FUNCTION(0xad12), 0}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { ISAPNP_CARD_END, }, |
| 239 | }; |
| 240 | |
| 241 | MODULE_DEVICE_TABLE(isapnp, id_table); |
| 242 | |
Randy Dunlap | a999337 | 2008-01-23 02:39:39 -0300 | [diff] [blame] | 243 | static int __init isapnp_fmi_probe(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
| 245 | int i = 0; |
| 246 | |
| 247 | while (id_table[i].card_vendor != 0 && dev == NULL) { |
| 248 | dev = pnp_find_dev(NULL, id_table[i].vendor, |
| 249 | id_table[i].function, NULL); |
| 250 | i++; |
| 251 | } |
| 252 | |
| 253 | if (!dev) |
| 254 | return -ENODEV; |
| 255 | if (pnp_device_attach(dev) < 0) |
| 256 | return -EAGAIN; |
| 257 | if (pnp_activate_dev(dev) < 0) { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 258 | printk(KERN_ERR "radio-sf16fmi: PnP configure failed (out of resources?)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | pnp_device_detach(dev); |
| 260 | return -ENOMEM; |
| 261 | } |
| 262 | if (!pnp_port_valid(dev, 0)) { |
| 263 | pnp_device_detach(dev); |
| 264 | return -ENODEV; |
| 265 | } |
| 266 | |
| 267 | i = pnp_port_start(dev, 0); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 268 | printk(KERN_INFO "radio-sf16fmi: PnP reports card at %#x\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | return i; |
| 271 | } |
| 272 | |
| 273 | static int __init fmi_init(void) |
| 274 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 275 | struct fmi *fmi = &fmi_card; |
| 276 | struct v4l2_device *v4l2_dev = &fmi->v4l2_dev; |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 277 | struct v4l2_ctrl_handler *hdl = &fmi->hdl; |
Ondrej Zary | 67cabf5 | 2009-12-10 17:12:32 -0300 | [diff] [blame] | 278 | int res, i; |
| 279 | int probe_ports[] = { 0, 0x284, 0x384 }; |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 280 | |
Ondrej Zary | 67cabf5 | 2009-12-10 17:12:32 -0300 | [diff] [blame] | 281 | if (io < 0) { |
| 282 | for (i = 0; i < ARRAY_SIZE(probe_ports); i++) { |
| 283 | io = probe_ports[i]; |
| 284 | if (io == 0) { |
| 285 | io = isapnp_fmi_probe(); |
| 286 | if (io < 0) |
| 287 | continue; |
Mauro Carvalho Chehab | 8b4b681 | 2014-09-03 15:54:17 -0300 | [diff] [blame] | 288 | pnp_attached = true; |
Ondrej Zary | 67cabf5 | 2009-12-10 17:12:32 -0300 | [diff] [blame] | 289 | } |
| 290 | if (!request_region(io, 2, "radio-sf16fmi")) { |
| 291 | if (pnp_attached) |
| 292 | pnp_device_detach(dev); |
| 293 | io = -1; |
| 294 | continue; |
| 295 | } |
| 296 | if (pnp_attached || |
| 297 | ((inb(io) & 0xf9) == 0xf9 && (inb(io) & 0x4) == 0)) |
| 298 | break; |
| 299 | release_region(io, 2); |
| 300 | io = -1; |
| 301 | } |
| 302 | } else { |
| 303 | if (!request_region(io, 2, "radio-sf16fmi")) { |
| 304 | printk(KERN_ERR "radio-sf16fmi: port %#x already in use\n", io); |
| 305 | return -EBUSY; |
| 306 | } |
| 307 | if (inb(io) == 0xff) { |
| 308 | printk(KERN_ERR "radio-sf16fmi: card not present at %#x\n", io); |
| 309 | release_region(io, 2); |
| 310 | return -ENODEV; |
| 311 | } |
| 312 | } |
| 313 | if (io < 0) { |
| 314 | printk(KERN_ERR "radio-sf16fmi: no cards found\n"); |
| 315 | return -ENODEV; |
| 316 | } |
| 317 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 318 | strlcpy(v4l2_dev->name, "sf16fmi", sizeof(v4l2_dev->name)); |
| 319 | fmi->io = io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 321 | res = v4l2_device_register(NULL, v4l2_dev); |
| 322 | if (res < 0) { |
| 323 | release_region(fmi->io, 2); |
Ondrej Zary | 67cabf5 | 2009-12-10 17:12:32 -0300 | [diff] [blame] | 324 | if (pnp_attached) |
| 325 | pnp_device_detach(dev); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 326 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); |
| 327 | return res; |
| 328 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 329 | |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 330 | v4l2_ctrl_handler_init(hdl, 1); |
| 331 | v4l2_ctrl_new_std(hdl, &fmi_ctrl_ops, |
| 332 | V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1); |
| 333 | v4l2_dev->ctrl_handler = hdl; |
| 334 | if (hdl->error) { |
| 335 | res = hdl->error; |
| 336 | v4l2_err(v4l2_dev, "Could not register controls\n"); |
| 337 | v4l2_ctrl_handler_free(hdl); |
| 338 | v4l2_device_unregister(v4l2_dev); |
| 339 | return res; |
| 340 | } |
| 341 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 342 | strlcpy(fmi->vdev.name, v4l2_dev->name, sizeof(fmi->vdev.name)); |
| 343 | fmi->vdev.v4l2_dev = v4l2_dev; |
| 344 | fmi->vdev.fops = &fmi_fops; |
| 345 | fmi->vdev.ioctl_ops = &fmi_ioctl_ops; |
| 346 | fmi->vdev.release = video_device_release_empty; |
| 347 | video_set_drvdata(&fmi->vdev, fmi); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 348 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 349 | mutex_init(&fmi->lock); |
| 350 | |
Ondrej Zary | d9ec089 | 2013-06-14 17:01:39 -0300 | [diff] [blame] | 351 | /* mute card and set default frequency */ |
Mauro Carvalho Chehab | 8b4b681 | 2014-09-03 15:54:17 -0300 | [diff] [blame] | 352 | fmi->mute = true; |
Ondrej Zary | d9ec089 | 2013-06-14 17:01:39 -0300 | [diff] [blame] | 353 | fmi->curfreq = RSF16_MINFREQ; |
| 354 | fmi_set_freq(fmi); |
Hans Verkuil | 32958fd | 2010-11-14 09:36:23 -0300 | [diff] [blame] | 355 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 356 | if (video_register_device(&fmi->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 357 | v4l2_ctrl_handler_free(hdl); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 358 | v4l2_device_unregister(v4l2_dev); |
| 359 | release_region(fmi->io, 2); |
Ondrej Zary | 67cabf5 | 2009-12-10 17:12:32 -0300 | [diff] [blame] | 360 | if (pnp_attached) |
| 361 | pnp_device_detach(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | return -EINVAL; |
| 363 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 364 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 365 | v4l2_info(v4l2_dev, "card driver at 0x%x\n", fmi->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | return 0; |
| 367 | } |
| 368 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 369 | static void __exit fmi_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 371 | struct fmi *fmi = &fmi_card; |
| 372 | |
Hans Verkuil | 268d06b | 2013-02-03 09:51:06 -0300 | [diff] [blame] | 373 | v4l2_ctrl_handler_free(&fmi->hdl); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 374 | video_unregister_device(&fmi->vdev); |
| 375 | v4l2_device_unregister(&fmi->v4l2_dev); |
| 376 | release_region(fmi->io, 2); |
Ondrej Zary | 67cabf5 | 2009-12-10 17:12:32 -0300 | [diff] [blame] | 377 | if (dev && pnp_attached) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | pnp_device_detach(dev); |
| 379 | } |
| 380 | |
| 381 | module_init(fmi_init); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 382 | module_exit(fmi_exit); |