Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* SF16FMI radio driver for Linux radio support |
| 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 |
| 14 | * control on SB-part of SF16FMI |
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 | |
Andrew Morton | 2cd885a | 2006-08-08 09:10:09 -0300 | [diff] [blame] | 19 | #include <linux/version.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/kernel.h> /* __setup */ |
| 21 | #include <linux/module.h> /* Modules */ |
| 22 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 23 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/delay.h> /* udelay */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/isapnp.h> |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 26 | #include <linux/mutex.h> |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 27 | #include <linux/videodev2.h> /* kernel radio structs */ |
| 28 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 29 | #include <media/v4l2-device.h> |
| 30 | #include <media/v4l2-ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 32 | MODULE_AUTHOR("Petr Vandrovec, vandrove@vc.cvut.cz and M. Kirkwood"); |
| 33 | MODULE_DESCRIPTION("A driver for the SF16MI radio."); |
| 34 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 36 | static int io = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static int radio_nr = -1; |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 38 | |
| 39 | module_param(io, int, 0); |
| 40 | MODULE_PARM_DESC(io, "I/O address of the SF16MI card (0x284 or 0x384)"); |
| 41 | module_param(radio_nr, int, 0); |
| 42 | |
| 43 | #define RADIO_VERSION KERNEL_VERSION(0, 0, 2) |
| 44 | |
| 45 | struct fmi |
| 46 | { |
| 47 | struct v4l2_device v4l2_dev; |
| 48 | struct video_device vdev; |
| 49 | int io; |
| 50 | int curvol; /* 1 or 0 */ |
| 51 | unsigned long curfreq; /* freq in kHz */ |
| 52 | __u32 flags; |
| 53 | struct mutex lock; |
| 54 | }; |
| 55 | |
| 56 | static struct fmi fmi_card; |
| 57 | static struct pnp_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | /* freq is in 1/16 kHz to internal number, hw precision is 50 kHz */ |
| 60 | /* It is only useful to give freq in intervall of 800 (=0.05Mhz), |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 61 | * other bits will be truncated, e.g 92.7400016 -> 92.7, but |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * 92.7400017 -> 92.75 |
| 63 | */ |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 64 | #define RSF16_ENCODE(x) ((x) / 800 + 214) |
| 65 | #define RSF16_MINFREQ (87 * 16000) |
| 66 | #define RSF16_MAXFREQ (108 * 16000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 68 | static void outbits(int bits, unsigned int data, int io) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 70 | while (bits--) { |
| 71 | if (data & 1) { |
| 72 | outb(5, io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | udelay(6); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 74 | outb(7, io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | udelay(6); |
| 76 | } else { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 77 | outb(1, io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | udelay(6); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 79 | outb(3, io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | udelay(6); |
| 81 | } |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 82 | data >>= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 86 | static inline void fmi_mute(struct fmi *fmi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 88 | mutex_lock(&fmi->lock); |
| 89 | outb(0x00, fmi->io); |
| 90 | mutex_unlock(&fmi->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 93 | static inline void fmi_unmute(struct fmi *fmi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 95 | mutex_lock(&fmi->lock); |
| 96 | outb(0x08, fmi->io); |
| 97 | mutex_unlock(&fmi->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 100 | static inline int fmi_setfreq(struct fmi *fmi, unsigned long freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 102 | mutex_lock(&fmi->lock); |
| 103 | fmi->curfreq = freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 105 | outbits(16, RSF16_ENCODE(freq), fmi->io); |
| 106 | outbits(8, 0xC0, fmi->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | msleep(143); /* was schedule_timeout(HZ/7) */ |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 108 | mutex_unlock(&fmi->lock); |
| 109 | if (fmi->curvol) |
| 110 | fmi_unmute(fmi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 114 | static inline int fmi_getsigstr(struct fmi *fmi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | int val; |
| 117 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 119 | mutex_lock(&fmi->lock); |
| 120 | val = fmi->curvol ? 0x08 : 0x00; /* unmute/mute */ |
| 121 | outb(val, fmi->io); |
| 122 | outb(val | 0x10, fmi->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | msleep(143); /* was schedule_timeout(HZ/7) */ |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 124 | res = (int)inb(fmi->io + 1); |
| 125 | outb(val, fmi->io); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 126 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 127 | mutex_unlock(&fmi->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | return (res & 2) ? 0 : 0xFFFF; |
| 129 | } |
| 130 | |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 131 | static int vidioc_querycap(struct file *file, void *priv, |
| 132 | struct v4l2_capability *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 134 | strlcpy(v->driver, "radio-sf16fmi", sizeof(v->driver)); |
| 135 | strlcpy(v->card, "SF16-FMx radio", sizeof(v->card)); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 136 | strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 137 | v->version = RADIO_VERSION; |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 138 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 139 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 142 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 143 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 145 | int mult; |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 146 | struct fmi *fmi = video_drvdata(file); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 147 | |
| 148 | if (v->index > 0) |
| 149 | return -EINVAL; |
| 150 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 151 | strlcpy(v->name, "FM", sizeof(v->name)); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 152 | v->type = V4L2_TUNER_RADIO; |
| 153 | mult = (fmi->flags & V4L2_TUNER_CAP_LOW) ? 1 : 1000; |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 154 | v->rangelow = RSF16_MINFREQ / mult; |
| 155 | v->rangehigh = RSF16_MAXFREQ / mult; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 156 | v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_MODE_STEREO; |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 157 | v->capability = fmi->flags & V4L2_TUNER_CAP_LOW; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 158 | v->audmode = V4L2_TUNER_MODE_STEREO; |
| 159 | v->signal = fmi_getsigstr(fmi); |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 164 | struct v4l2_tuner *v) |
| 165 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 166 | return v->index ? -EINVAL : 0; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 170 | struct v4l2_frequency *f) |
| 171 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 172 | struct fmi *fmi = video_drvdata(file); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 173 | |
| 174 | if (!(fmi->flags & V4L2_TUNER_CAP_LOW)) |
| 175 | f->frequency *= 1000; |
| 176 | if (f->frequency < RSF16_MINFREQ || |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 177 | f->frequency > RSF16_MAXFREQ) |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 178 | return -EINVAL; |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 179 | /* rounding in steps of 800 to match the freq |
| 180 | that will be used */ |
| 181 | fmi_setfreq(fmi, (f->frequency / 800) * 800); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 186 | struct v4l2_frequency *f) |
| 187 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 188 | struct fmi *fmi = video_drvdata(file); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 189 | |
| 190 | f->type = V4L2_TUNER_RADIO; |
| 191 | f->frequency = fmi->curfreq; |
| 192 | if (!(fmi->flags & V4L2_TUNER_CAP_LOW)) |
| 193 | f->frequency /= 1000; |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 198 | struct v4l2_queryctrl *qc) |
| 199 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 200 | switch (qc->id) { |
| 201 | case V4L2_CID_AUDIO_MUTE: |
| 202 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 203 | } |
| 204 | return -EINVAL; |
| 205 | } |
| 206 | |
| 207 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 208 | struct v4l2_control *ctrl) |
| 209 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 210 | struct fmi *fmi = video_drvdata(file); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 211 | |
| 212 | switch (ctrl->id) { |
| 213 | case V4L2_CID_AUDIO_MUTE: |
| 214 | ctrl->value = fmi->curvol; |
| 215 | return 0; |
| 216 | } |
| 217 | return -EINVAL; |
| 218 | } |
| 219 | |
| 220 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 221 | struct v4l2_control *ctrl) |
| 222 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 223 | struct fmi *fmi = video_drvdata(file); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 224 | |
| 225 | switch (ctrl->id) { |
| 226 | case V4L2_CID_AUDIO_MUTE: |
| 227 | if (ctrl->value) |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 228 | fmi_mute(fmi); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 229 | else |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 230 | fmi_unmute(fmi); |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 231 | fmi->curvol = ctrl->value; |
| 232 | return 0; |
| 233 | } |
| 234 | return -EINVAL; |
| 235 | } |
| 236 | |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 237 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 238 | { |
| 239 | *i = 0; |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 244 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 245 | return i ? -EINVAL : 0; |
| 246 | } |
| 247 | |
| 248 | static int vidioc_g_audio(struct file *file, void *priv, |
| 249 | struct v4l2_audio *a) |
| 250 | { |
| 251 | a->index = 0; |
| 252 | strlcpy(a->name, "Radio", sizeof(a->name)); |
| 253 | a->capability = V4L2_AUDCAP_STEREO; |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int vidioc_s_audio(struct file *file, void *priv, |
| 258 | struct v4l2_audio *a) |
| 259 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 260 | return a->index ? -EINVAL : 0; |
| 261 | } |
| 262 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 263 | static const struct v4l2_file_operations fmi_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | .owner = THIS_MODULE, |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 265 | .ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | }; |
| 267 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 268 | static const struct v4l2_ioctl_ops fmi_ioctl_ops = { |
Douglas Landgraf | c123b86 | 2007-04-23 17:52:12 -0300 | [diff] [blame] | 269 | .vidioc_querycap = vidioc_querycap, |
| 270 | .vidioc_g_tuner = vidioc_g_tuner, |
| 271 | .vidioc_s_tuner = vidioc_s_tuner, |
| 272 | .vidioc_g_audio = vidioc_g_audio, |
| 273 | .vidioc_s_audio = vidioc_s_audio, |
| 274 | .vidioc_g_input = vidioc_g_input, |
| 275 | .vidioc_s_input = vidioc_s_input, |
| 276 | .vidioc_g_frequency = vidioc_g_frequency, |
| 277 | .vidioc_s_frequency = vidioc_s_frequency, |
| 278 | .vidioc_queryctrl = vidioc_queryctrl, |
| 279 | .vidioc_g_ctrl = vidioc_g_ctrl, |
| 280 | .vidioc_s_ctrl = vidioc_s_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | /* ladis: this is my card. does any other types exist? */ |
| 284 | static struct isapnp_device_id id_table[] __devinitdata = { |
| 285 | { ISAPNP_ANY_ID, ISAPNP_ANY_ID, |
| 286 | ISAPNP_VENDOR('M','F','R'), ISAPNP_FUNCTION(0xad10), 0}, |
| 287 | { ISAPNP_CARD_END, }, |
| 288 | }; |
| 289 | |
| 290 | MODULE_DEVICE_TABLE(isapnp, id_table); |
| 291 | |
Randy Dunlap | a999337 | 2008-01-23 02:39:39 -0300 | [diff] [blame] | 292 | static int __init isapnp_fmi_probe(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
| 294 | int i = 0; |
| 295 | |
| 296 | while (id_table[i].card_vendor != 0 && dev == NULL) { |
| 297 | dev = pnp_find_dev(NULL, id_table[i].vendor, |
| 298 | id_table[i].function, NULL); |
| 299 | i++; |
| 300 | } |
| 301 | |
| 302 | if (!dev) |
| 303 | return -ENODEV; |
| 304 | if (pnp_device_attach(dev) < 0) |
| 305 | return -EAGAIN; |
| 306 | if (pnp_activate_dev(dev) < 0) { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 307 | printk(KERN_ERR "radio-sf16fmi: PnP configure failed (out of resources?)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | pnp_device_detach(dev); |
| 309 | return -ENOMEM; |
| 310 | } |
| 311 | if (!pnp_port_valid(dev, 0)) { |
| 312 | pnp_device_detach(dev); |
| 313 | return -ENODEV; |
| 314 | } |
| 315 | |
| 316 | i = pnp_port_start(dev, 0); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 317 | printk(KERN_INFO "radio-sf16fmi: PnP reports card at %#x\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | return i; |
| 320 | } |
| 321 | |
| 322 | static int __init fmi_init(void) |
| 323 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 324 | struct fmi *fmi = &fmi_card; |
| 325 | struct v4l2_device *v4l2_dev = &fmi->v4l2_dev; |
| 326 | int res; |
| 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | if (io < 0) |
| 329 | io = isapnp_fmi_probe(); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 330 | strlcpy(v4l2_dev->name, "sf16fmi", sizeof(v4l2_dev->name)); |
| 331 | fmi->io = io; |
| 332 | if (fmi->io < 0) { |
| 333 | v4l2_err(v4l2_dev, "No PnP card found.\n"); |
| 334 | return fmi->io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | if (!request_region(io, 2, "radio-sf16fmi")) { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 337 | v4l2_err(v4l2_dev, "port 0x%x already in use\n", fmi->io); |
Mauro Carvalho Chehab | e08a8c9 | 2008-01-27 14:43:20 -0300 | [diff] [blame] | 338 | pnp_device_detach(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | return -EBUSY; |
| 340 | } |
| 341 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 342 | res = v4l2_device_register(NULL, v4l2_dev); |
| 343 | if (res < 0) { |
| 344 | release_region(fmi->io, 2); |
| 345 | pnp_device_detach(dev); |
| 346 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); |
| 347 | return res; |
| 348 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 349 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 350 | fmi->flags = V4L2_TUNER_CAP_LOW; |
| 351 | strlcpy(fmi->vdev.name, v4l2_dev->name, sizeof(fmi->vdev.name)); |
| 352 | fmi->vdev.v4l2_dev = v4l2_dev; |
| 353 | fmi->vdev.fops = &fmi_fops; |
| 354 | fmi->vdev.ioctl_ops = &fmi_ioctl_ops; |
| 355 | fmi->vdev.release = video_device_release_empty; |
| 356 | video_set_drvdata(&fmi->vdev, fmi); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 357 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 358 | mutex_init(&fmi->lock); |
| 359 | |
| 360 | if (video_register_device(&fmi->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { |
| 361 | v4l2_device_unregister(v4l2_dev); |
| 362 | release_region(fmi->io, 2); |
| 363 | pnp_device_detach(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | return -EINVAL; |
| 365 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 366 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 367 | v4l2_info(v4l2_dev, "card driver at 0x%x\n", fmi->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /* mute card - prevents noisy bootups */ |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 369 | fmi_mute(fmi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | return 0; |
| 371 | } |
| 372 | |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 373 | static void __exit fmi_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 375 | struct fmi *fmi = &fmi_card; |
| 376 | |
| 377 | video_unregister_device(&fmi->vdev); |
| 378 | v4l2_device_unregister(&fmi->v4l2_dev); |
| 379 | release_region(fmi->io, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | if (dev) |
| 381 | pnp_device_detach(dev); |
| 382 | } |
| 383 | |
| 384 | module_init(fmi_init); |
Hans Verkuil | c41269f | 2009-03-06 13:52:34 -0300 | [diff] [blame] | 385 | module_exit(fmi_exit); |