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