Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 2 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood |
Alan Cox | d9b0144 | 2008-10-27 15:13:47 -0300 | [diff] [blame] | 4 | * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org> |
| 6 | * |
| 7 | * TODO: Allow for more than one of these foolish entities :-) |
| 8 | * |
Mauro Carvalho Chehab | f8c559f | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 9 | * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> /* Modules */ |
| 13 | #include <linux/init.h> /* Initdata */ |
Peter Osterlund | fb911ee | 2005-09-13 01:25:15 -0700 | [diff] [blame] | 14 | #include <linux/ioport.h> /* request_region */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/delay.h> /* udelay */ |
Mauro Carvalho Chehab | f8c559f | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 16 | #include <linux/videodev2.h> /* kernel radio structs */ |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 17 | #include <linux/mutex.h> |
Mauro Carvalho Chehab | f8c559f | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 18 | #include <linux/version.h> /* for KERNEL_VERSION MACRO */ |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 19 | #include <linux/io.h> /* outb, outb_p */ |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 20 | #include <media/v4l2-device.h> |
| 21 | #include <media/v4l2-ioctl.h> |
Mauro Carvalho Chehab | f8c559f | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 22 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 23 | MODULE_AUTHOR("Ben Pfaff"); |
| 24 | MODULE_DESCRIPTION("A driver for the RadioTrack II radio card."); |
| 25 | MODULE_LICENSE("GPL"); |
Mauro Carvalho Chehab | f8c559f | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #ifndef CONFIG_RADIO_RTRACK2_PORT |
| 28 | #define CONFIG_RADIO_RTRACK2_PORT -1 |
| 29 | #endif |
| 30 | |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 31 | static int io = CONFIG_RADIO_RTRACK2_PORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | static int radio_nr = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 34 | module_param(io, int, 0); |
| 35 | MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20c or 0x30c)"); |
| 36 | module_param(radio_nr, int, 0); |
| 37 | |
| 38 | #define RADIO_VERSION KERNEL_VERSION(0, 0, 2) |
| 39 | |
| 40 | struct rtrack2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 42 | struct v4l2_device v4l2_dev; |
| 43 | struct video_device vdev; |
| 44 | int io; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | unsigned long curfreq; |
| 46 | int muted; |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 47 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 50 | static struct rtrack2 rtrack2_card; |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /* local things */ |
| 54 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 55 | static void rt_mute(struct rtrack2 *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 57 | if (dev->muted) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | return; |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 59 | mutex_lock(&dev->lock); |
| 60 | outb(1, dev->io); |
| 61 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | dev->muted = 1; |
| 63 | } |
| 64 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 65 | static void rt_unmute(struct rtrack2 *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
| 67 | if(dev->muted == 0) |
| 68 | return; |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 69 | mutex_lock(&dev->lock); |
| 70 | outb(0, dev->io); |
| 71 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | dev->muted = 0; |
| 73 | } |
| 74 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 75 | static void zero(struct rtrack2 *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 77 | outb_p(1, dev->io); |
| 78 | outb_p(3, dev->io); |
| 79 | outb_p(1, dev->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 82 | static void one(struct rtrack2 *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 84 | outb_p(5, dev->io); |
| 85 | outb_p(7, dev->io); |
| 86 | outb_p(5, dev->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 89 | static int rt_setfreq(struct rtrack2 *dev, unsigned long freq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
| 91 | int i; |
| 92 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 93 | mutex_lock(&dev->lock); |
| 94 | dev->curfreq = freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | freq = freq / 200 + 856; |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 96 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 97 | outb_p(0xc8, dev->io); |
| 98 | outb_p(0xc9, dev->io); |
| 99 | outb_p(0xc9, dev->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | for (i = 0; i < 10; i++) |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 102 | zero(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | for (i = 14; i >= 0; i--) |
| 105 | if (freq & (1 << i)) |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 106 | one(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | else |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 108 | zero(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 110 | outb_p(0xc8, dev->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | if (!dev->muted) |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 112 | outb_p(0, dev->io); |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 113 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 114 | mutex_unlock(&dev->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 118 | static int vidioc_querycap(struct file *file, void *priv, |
| 119 | struct v4l2_capability *v) |
| 120 | { |
| 121 | strlcpy(v->driver, "radio-rtrack2", sizeof(v->driver)); |
| 122 | strlcpy(v->card, "RadioTrack II", sizeof(v->card)); |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 123 | strlcpy(v->bus_info, "ISA", sizeof(v->bus_info)); |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 124 | v->version = RADIO_VERSION; |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 125 | v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static int vidioc_s_tuner(struct file *file, void *priv, |
| 130 | struct v4l2_tuner *v) |
| 131 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 132 | return v->index ? -EINVAL : 0; |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 133 | } |
| 134 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 135 | static int rt_getsigstr(struct rtrack2 *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 137 | int sig = 1; |
| 138 | |
| 139 | mutex_lock(&dev->lock); |
| 140 | if (inb(dev->io) & 2) /* bit set = no signal present */ |
| 141 | sig = 0; |
| 142 | mutex_unlock(&dev->lock); |
| 143 | return sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 146 | static int vidioc_g_tuner(struct file *file, void *priv, |
| 147 | struct v4l2_tuner *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 149 | struct rtrack2 *rt = video_drvdata(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 151 | if (v->index > 0) |
| 152 | return -EINVAL; |
Mauro Carvalho Chehab | f8c559f | 2006-08-08 09:10:02 -0300 | [diff] [blame] | 153 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 154 | strlcpy(v->name, "FM", sizeof(v->name)); |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 155 | v->type = V4L2_TUNER_RADIO; |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 156 | v->rangelow = 88 * 16000; |
| 157 | v->rangehigh = 108 * 16000; |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 158 | v->rxsubchans = V4L2_TUNER_SUB_MONO; |
| 159 | v->capability = V4L2_TUNER_CAP_LOW; |
| 160 | v->audmode = V4L2_TUNER_MODE_MONO; |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 161 | v->signal = 0xFFFF * rt_getsigstr(rt); |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 162 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 165 | static int vidioc_s_frequency(struct file *file, void *priv, |
| 166 | struct v4l2_frequency *f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 168 | struct rtrack2 *rt = video_drvdata(file); |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -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; |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 172 | rt_setfreq(rt, f->frequency); |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | static int vidioc_g_frequency(struct file *file, void *priv, |
| 177 | struct v4l2_frequency *f) |
| 178 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 179 | struct rtrack2 *rt = video_drvdata(file); |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 180 | |
Hans Verkuil | a3a9e28 | 2009-11-27 04:33:25 -0300 | [diff] [blame] | 181 | if (f->tuner != 0) |
| 182 | return -EINVAL; |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 183 | f->type = V4L2_TUNER_RADIO; |
| 184 | f->frequency = rt->curfreq; |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | static int vidioc_queryctrl(struct file *file, void *priv, |
| 189 | struct v4l2_queryctrl *qc) |
| 190 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 191 | switch (qc->id) { |
| 192 | case V4L2_CID_AUDIO_MUTE: |
| 193 | return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1); |
| 194 | case V4L2_CID_AUDIO_VOLUME: |
| 195 | return v4l2_ctrl_query_fill(qc, 0, 65535, 65535, 65535); |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 196 | } |
| 197 | return -EINVAL; |
| 198 | } |
| 199 | |
| 200 | static int vidioc_g_ctrl(struct file *file, void *priv, |
| 201 | struct v4l2_control *ctrl) |
| 202 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 203 | struct rtrack2 *rt = video_drvdata(file); |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 204 | |
| 205 | switch (ctrl->id) { |
| 206 | case V4L2_CID_AUDIO_MUTE: |
| 207 | ctrl->value = rt->muted; |
| 208 | return 0; |
| 209 | case V4L2_CID_AUDIO_VOLUME: |
| 210 | if (rt->muted) |
| 211 | ctrl->value = 0; |
| 212 | else |
| 213 | ctrl->value = 65535; |
| 214 | return 0; |
| 215 | } |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | |
| 219 | static int vidioc_s_ctrl(struct file *file, void *priv, |
| 220 | struct v4l2_control *ctrl) |
| 221 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 222 | struct rtrack2 *rt = video_drvdata(file); |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 223 | |
| 224 | switch (ctrl->id) { |
| 225 | case V4L2_CID_AUDIO_MUTE: |
| 226 | if (ctrl->value) |
| 227 | rt_mute(rt); |
| 228 | else |
| 229 | rt_unmute(rt); |
| 230 | return 0; |
| 231 | case V4L2_CID_AUDIO_VOLUME: |
| 232 | if (ctrl->value) |
| 233 | rt_unmute(rt); |
| 234 | else |
| 235 | rt_mute(rt); |
| 236 | return 0; |
| 237 | } |
| 238 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Douglas Landgraf | 8b811cf | 2007-04-20 06:37:36 -0300 | [diff] [blame] | 241 | static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) |
| 242 | { |
| 243 | *i = 0; |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) |
| 248 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 249 | return i ? -EINVAL : 0; |
| 250 | } |
| 251 | |
| 252 | static int vidioc_g_audio(struct file *file, void *priv, |
| 253 | struct v4l2_audio *a) |
| 254 | { |
| 255 | a->index = 0; |
| 256 | strlcpy(a->name, "Radio", sizeof(a->name)); |
| 257 | a->capability = V4L2_AUDCAP_STEREO; |
Douglas Landgraf | 8b811cf | 2007-04-20 06:37:36 -0300 | [diff] [blame] | 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | static int vidioc_s_audio(struct file *file, void *priv, |
| 262 | struct v4l2_audio *a) |
| 263 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 264 | return a->index ? -EINVAL : 0; |
| 265 | } |
| 266 | |
Hans Verkuil | bec4366 | 2008-12-30 06:58:20 -0300 | [diff] [blame] | 267 | static const struct v4l2_file_operations rtrack2_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | .owner = THIS_MODULE, |
Hans Verkuil | 32958fd | 2010-11-14 09:36:23 -0300 | [diff] [blame] | 269 | .unlocked_ioctl = video_ioctl2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
Hans Verkuil | a399810 | 2008-07-21 02:57:38 -0300 | [diff] [blame] | 272 | static const struct v4l2_ioctl_ops rtrack2_ioctl_ops = { |
Douglas Landgraf | 25f3038 | 2007-04-19 16:42:25 -0300 | [diff] [blame] | 273 | .vidioc_querycap = vidioc_querycap, |
| 274 | .vidioc_g_tuner = vidioc_g_tuner, |
| 275 | .vidioc_s_tuner = vidioc_s_tuner, |
| 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, |
Douglas Landgraf | 8b811cf | 2007-04-20 06:37:36 -0300 | [diff] [blame] | 281 | .vidioc_g_audio = vidioc_g_audio, |
| 282 | .vidioc_s_audio = vidioc_s_audio, |
| 283 | .vidioc_g_input = vidioc_g_input, |
| 284 | .vidioc_s_input = vidioc_s_input, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | static int __init rtrack2_init(void) |
| 288 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 289 | struct rtrack2 *dev = &rtrack2_card; |
| 290 | struct v4l2_device *v4l2_dev = &dev->v4l2_dev; |
| 291 | int res; |
| 292 | |
| 293 | strlcpy(v4l2_dev->name, "rtrack2", sizeof(v4l2_dev->name)); |
| 294 | dev->io = io; |
| 295 | if (dev->io == -1) { |
| 296 | v4l2_err(v4l2_dev, "You must set an I/O address with io=0x20c or io=0x30c\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | return -EINVAL; |
| 298 | } |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 299 | if (!request_region(dev->io, 4, "rtrack2")) { |
| 300 | v4l2_err(v4l2_dev, "port 0x%x already in use\n", dev->io); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | return -EBUSY; |
| 302 | } |
| 303 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 304 | res = v4l2_device_register(NULL, v4l2_dev); |
| 305 | if (res < 0) { |
| 306 | release_region(dev->io, 4); |
| 307 | v4l2_err(v4l2_dev, "Could not register v4l2_device\n"); |
| 308 | return res; |
| 309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 311 | strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name)); |
| 312 | dev->vdev.v4l2_dev = v4l2_dev; |
| 313 | dev->vdev.fops = &rtrack2_fops; |
| 314 | dev->vdev.ioctl_ops = &rtrack2_ioctl_ops; |
| 315 | dev->vdev.release = video_device_release_empty; |
| 316 | video_set_drvdata(&dev->vdev, dev); |
| 317 | |
Hans Verkuil | 32958fd | 2010-11-14 09:36:23 -0300 | [diff] [blame] | 318 | /* mute card - prevents noisy bootups */ |
| 319 | outb(1, dev->io); |
| 320 | dev->muted = 1; |
| 321 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 322 | mutex_init(&dev->lock); |
| 323 | if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) { |
| 324 | v4l2_device_unregister(v4l2_dev); |
| 325 | release_region(dev->io, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | return -EINVAL; |
| 327 | } |
Mauro Carvalho Chehab | 4286c6f | 2006-04-08 16:06:16 -0300 | [diff] [blame] | 328 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 329 | v4l2_info(v4l2_dev, "AIMSlab Radiotrack II card driver.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | return 0; |
| 332 | } |
| 333 | |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 334 | static void __exit rtrack2_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 336 | struct rtrack2 *dev = &rtrack2_card; |
| 337 | |
| 338 | video_unregister_device(&dev->vdev); |
| 339 | v4l2_device_unregister(&dev->v4l2_dev); |
| 340 | release_region(dev->io, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | module_init(rtrack2_init); |
Hans Verkuil | 922c78e | 2009-03-06 13:52:06 -0300 | [diff] [blame] | 344 | module_exit(rtrack2_exit); |