blob: a99227f7a9da8e05bb549260dfd279ea9bc5852d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* radiotrack (radioreveal) driver for Linux radio support
2 * (c) 1997 M. Kirkwood
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -03003 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
Alan Coxd9b01442008-10-27 15:13:47 -03004 * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
6 *
7 * History:
8 * 1999-02-24 Russell Kroll <rkroll@exploits.org>
9 * Fine tuning/VIDEO_TUNER_LOW
10 * Frequency range expanded to start at 87 MHz
11 *
12 * TODO: Allow for more than one of these foolish entities :-)
13 *
14 * Notes on the hardware (reverse engineered from other peoples'
15 * reverse engineering of AIMS' code :-)
16 *
17 * Frequency control is done digitally -- ie out(port,encodefreq(95.8));
18 *
19 * The signal strength query is unsurprisingly inaccurate. And it seems
20 * to indicate that (on my card, at least) the frequency setting isn't
21 * too great. (I have to tune up .025MHz from what the freq should be
22 * to get a report that the thing is tuned.)
23 *
24 * Volume control is (ugh) analogue:
25 * out(port, start_increasing_volume);
26 * wait(a_wee_while);
27 * out(port, stop_changing_the_volume);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030028 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 */
30
31#include <linux/module.h> /* Modules */
32#include <linux/init.h> /* Initdata */
Peter Osterlundfb911ee2005-09-13 01:25:15 -070033#include <linux/ioport.h> /* request_region */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/delay.h> /* udelay */
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -030035#include <linux/videodev2.h> /* kernel radio structs */
Hans Verkuil151c3f82009-03-06 13:45:27 -030036#include <linux/version.h> /* for KERNEL_VERSION MACRO */
37#include <linux/io.h> /* outb, outb_p */
38#include <linux/uaccess.h> /* copy to/from user */
39#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030040#include <media/v4l2-ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Hans Verkuil151c3f82009-03-06 13:45:27 -030042MODULE_AUTHOR("M.Kirkwood");
43MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
44MODULE_LICENSE("GPL");
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -030045
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#ifndef CONFIG_RADIO_RTRACK_PORT
47#define CONFIG_RADIO_RTRACK_PORT -1
48#endif
49
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030050static int io = CONFIG_RADIO_RTRACK_PORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static int radio_nr = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Hans Verkuil151c3f82009-03-06 13:45:27 -030053module_param(io, int, 0);
54MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20f or 0x30f)");
55module_param(radio_nr, int, 0);
56
57#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
58
59struct rtrack
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Hans Verkuil151c3f82009-03-06 13:45:27 -030061 struct v4l2_device v4l2_dev;
62 struct video_device vdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 int port;
64 int curvol;
65 unsigned long curfreq;
66 int muted;
Hans Verkuil151c3f82009-03-06 13:45:27 -030067 int io;
68 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069};
70
Hans Verkuil151c3f82009-03-06 13:45:27 -030071static struct rtrack rtrack_card;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73/* local things */
74
75static void sleep_delay(long n)
76{
77 /* Sleep nicely for 'n' uS */
Hans Verkuil151c3f82009-03-06 13:45:27 -030078 int d = n / msecs_to_jiffies(1000);
79 if (!d)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 udelay(n);
81 else
82 msleep(jiffies_to_msecs(d));
83}
84
Hans Verkuil151c3f82009-03-06 13:45:27 -030085static void rt_decvol(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Hans Verkuil151c3f82009-03-06 13:45:27 -030087 outb(0x58, rt->io); /* volume down + sigstr + on */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 sleep_delay(100000);
Hans Verkuil151c3f82009-03-06 13:45:27 -030089 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Hans Verkuil151c3f82009-03-06 13:45:27 -030092static void rt_incvol(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Hans Verkuil151c3f82009-03-06 13:45:27 -030094 outb(0x98, rt->io); /* volume up + sigstr + on */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 sleep_delay(100000);
Hans Verkuil151c3f82009-03-06 13:45:27 -030096 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Hans Verkuil151c3f82009-03-06 13:45:27 -030099static void rt_mute(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300101 rt->muted = 1;
102 mutex_lock(&rt->lock);
103 outb(0xd0, rt->io); /* volume steady, off */
104 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105}
106
Hans Verkuil151c3f82009-03-06 13:45:27 -0300107static int rt_setvol(struct rtrack *rt, int vol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109 int i;
110
Hans Verkuil151c3f82009-03-06 13:45:27 -0300111 mutex_lock(&rt->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300112
Hans Verkuil151c3f82009-03-06 13:45:27 -0300113 if (vol == rt->curvol) { /* requested volume = current */
114 if (rt->muted) { /* user is unmuting the card */
115 rt->muted = 0;
116 outb(0xd8, rt->io); /* enable card */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300117 }
Hans Verkuil151c3f82009-03-06 13:45:27 -0300118 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 return 0;
120 }
121
Hans Verkuil151c3f82009-03-06 13:45:27 -0300122 if (vol == 0) { /* volume = 0 means mute the card */
123 outb(0x48, rt->io); /* volume down but still "on" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 sleep_delay(2000000); /* make sure it's totally down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300125 outb(0xd0, rt->io); /* volume steady, off */
126 rt->curvol = 0; /* track the volume state! */
127 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 return 0;
129 }
130
Hans Verkuil151c3f82009-03-06 13:45:27 -0300131 rt->muted = 0;
132 if (vol > rt->curvol)
133 for (i = rt->curvol; i < vol; i++)
134 rt_incvol(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300136 for (i = rt->curvol; i > vol; i--)
137 rt_decvol(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Hans Verkuil151c3f82009-03-06 13:45:27 -0300139 rt->curvol = vol;
140 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return 0;
142}
143
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300144/* the 128+64 on these outb's is to keep the volume stable while tuning
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 * without them, the volume _will_ creep up with each frequency change
146 * and bit 4 (+16) is to keep the signal strength meter enabled
147 */
148
Hans Verkuil151c3f82009-03-06 13:45:27 -0300149static void send_0_byte(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300151 if (rt->curvol == 0 || rt->muted) {
152 outb_p(128+64+16+ 1, rt->io); /* wr-enable + data low */
153 outb_p(128+64+16+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155 else {
Hans Verkuil151c3f82009-03-06 13:45:27 -0300156 outb_p(128+64+16+8+ 1, rt->io); /* on + wr-enable + data low */
157 outb_p(128+64+16+8+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300159 sleep_delay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
161
Hans Verkuil151c3f82009-03-06 13:45:27 -0300162static void send_1_byte(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300164 if (rt->curvol == 0 || rt->muted) {
165 outb_p(128+64+16+4 +1, rt->io); /* wr-enable+data high */
166 outb_p(128+64+16+4+2+1, rt->io); /* clock */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300167 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 else {
Hans Verkuil151c3f82009-03-06 13:45:27 -0300169 outb_p(128+64+16+8+4 +1, rt->io); /* on+wr-enable+data high */
170 outb_p(128+64+16+8+4+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300173 sleep_delay(1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
Hans Verkuil151c3f82009-03-06 13:45:27 -0300176static int rt_setfreq(struct rtrack *rt, unsigned long freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177{
178 int i;
179
Hans Verkuil151c3f82009-03-06 13:45:27 -0300180 mutex_lock(&rt->lock); /* Stop other ops interfering */
181
182 rt->curfreq = freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 /* now uses VIDEO_TUNER_LOW for fine tuning */
185
186 freq += 171200; /* Add 10.7 MHz IF */
187 freq /= 800; /* Convert to 50 kHz units */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300188
Hans Verkuil151c3f82009-03-06 13:45:27 -0300189 send_0_byte(rt); /* 0: LSB of frequency */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
192 if (freq & (1 << i))
Hans Verkuil151c3f82009-03-06 13:45:27 -0300193 send_1_byte(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300195 send_0_byte(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Hans Verkuil151c3f82009-03-06 13:45:27 -0300197 send_0_byte(rt); /* 14: test bit - always 0 */
198 send_0_byte(rt); /* 15: test bit - always 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Hans Verkuil151c3f82009-03-06 13:45:27 -0300200 send_0_byte(rt); /* 16: band data 0 - always 0 */
201 send_0_byte(rt); /* 17: band data 1 - always 0 */
202 send_0_byte(rt); /* 18: band data 2 - always 0 */
203 send_0_byte(rt); /* 19: time base - always 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Hans Verkuil151c3f82009-03-06 13:45:27 -0300205 send_0_byte(rt); /* 20: spacing (0 = 25 kHz) */
206 send_1_byte(rt); /* 21: spacing (1 = 25 kHz) */
207 send_0_byte(rt); /* 22: spacing (0 = 25 kHz) */
208 send_1_byte(rt); /* 23: AM/FM (FM = 1, always) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Hans Verkuil151c3f82009-03-06 13:45:27 -0300210 if (rt->curvol == 0 || rt->muted)
211 outb(0xd0, rt->io); /* volume steady + sigstr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300213 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300214
Hans Verkuil151c3f82009-03-06 13:45:27 -0300215 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 return 0;
218}
219
Hans Verkuil151c3f82009-03-06 13:45:27 -0300220static int rt_getsigstr(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300222 int sig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Hans Verkuil151c3f82009-03-06 13:45:27 -0300224 mutex_lock(&rt->lock);
225 if (inb(rt->io) & 2) /* bit set = no signal present */
226 sig = 0;
227 mutex_unlock(&rt->lock);
228 return sig;
229}
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -0300230
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300231static int vidioc_querycap(struct file *file, void *priv,
232 struct v4l2_capability *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300234 strlcpy(v->driver, "radio-aimslab", sizeof(v->driver));
235 strlcpy(v->card, "RadioTrack", sizeof(v->card));
Hans Verkuil151c3f82009-03-06 13:45:27 -0300236 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300237 v->version = RADIO_VERSION;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300238 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300239 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
241
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300242static int vidioc_g_tuner(struct file *file, void *priv,
243 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300245 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300246
247 if (v->index > 0)
248 return -EINVAL;
249
Hans Verkuil151c3f82009-03-06 13:45:27 -0300250 strlcpy(v->name, "FM", sizeof(v->name));
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300251 v->type = V4L2_TUNER_RADIO;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300252 v->rangelow = 87 * 16000;
253 v->rangehigh = 108 * 16000;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300254 v->rxsubchans = V4L2_TUNER_SUB_MONO;
255 v->capability = V4L2_TUNER_CAP_LOW;
256 v->audmode = V4L2_TUNER_MODE_MONO;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300257 v->signal = 0xffff * rt_getsigstr(rt);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300258 return 0;
259}
260
261static int vidioc_s_tuner(struct file *file, void *priv,
262 struct v4l2_tuner *v)
263{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300264 return v->index ? -EINVAL : 0;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300265}
266
267static int vidioc_s_frequency(struct file *file, void *priv,
268 struct v4l2_frequency *f)
269{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300270 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300271
Hans Verkuil151c3f82009-03-06 13:45:27 -0300272 rt_setfreq(rt, f->frequency);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300273 return 0;
274}
275
276static int vidioc_g_frequency(struct file *file, void *priv,
277 struct v4l2_frequency *f)
278{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300279 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300280
281 f->type = V4L2_TUNER_RADIO;
282 f->frequency = rt->curfreq;
283 return 0;
284}
285
286static int vidioc_queryctrl(struct file *file, void *priv,
287 struct v4l2_queryctrl *qc)
288{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300289 switch (qc->id) {
290 case V4L2_CID_AUDIO_MUTE:
291 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
292 case V4L2_CID_AUDIO_VOLUME:
293 return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300294 }
295 return -EINVAL;
296}
297
298static int vidioc_g_ctrl(struct file *file, void *priv,
299 struct v4l2_control *ctrl)
300{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300301 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300302
303 switch (ctrl->id) {
304 case V4L2_CID_AUDIO_MUTE:
305 ctrl->value = rt->muted;
306 return 0;
307 case V4L2_CID_AUDIO_VOLUME:
Hans Verkuil151c3f82009-03-06 13:45:27 -0300308 ctrl->value = rt->curvol;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300309 return 0;
310 }
311 return -EINVAL;
312}
313
314static int vidioc_s_ctrl(struct file *file, void *priv,
315 struct v4l2_control *ctrl)
316{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300317 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300318
319 switch (ctrl->id) {
320 case V4L2_CID_AUDIO_MUTE:
321 if (ctrl->value)
322 rt_mute(rt);
323 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300324 rt_setvol(rt, rt->curvol);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300325 return 0;
326 case V4L2_CID_AUDIO_VOLUME:
Hans Verkuil151c3f82009-03-06 13:45:27 -0300327 rt_setvol(rt, ctrl->value);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300328 return 0;
329 }
330 return -EINVAL;
331}
332
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300333static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
334{
335 *i = 0;
336 return 0;
337}
338
339static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
340{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300341 return i ? -EINVAL : 0;
342}
343
344static int vidioc_g_audio(struct file *file, void *priv,
345 struct v4l2_audio *a)
346{
347 a->index = 0;
348 strlcpy(a->name, "Radio", sizeof(a->name));
349 a->capability = V4L2_AUDCAP_STEREO;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300350 return 0;
351}
352
353static int vidioc_s_audio(struct file *file, void *priv,
354 struct v4l2_audio *a)
355{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300356 return a->index ? -EINVAL : 0;
357}
358
359static int rtrack_open(struct file *file)
360{
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300361 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
Hans Verkuil151c3f82009-03-06 13:45:27 -0300364static int rtrack_release(struct file *file)
Hans Verkuil3ca685a2008-08-23 04:49:13 -0300365{
Hans Verkuil3ca685a2008-08-23 04:49:13 -0300366 return 0;
367}
368
Hans Verkuilbec43662008-12-30 06:58:20 -0300369static const struct v4l2_file_operations rtrack_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 .owner = THIS_MODULE,
Hans Verkuil151c3f82009-03-06 13:45:27 -0300371 .open = rtrack_open,
372 .release = rtrack_release,
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300373 .ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374};
375
Hans Verkuila3998102008-07-21 02:57:38 -0300376static const struct v4l2_ioctl_ops rtrack_ioctl_ops = {
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300377 .vidioc_querycap = vidioc_querycap,
378 .vidioc_g_tuner = vidioc_g_tuner,
379 .vidioc_s_tuner = vidioc_s_tuner,
380 .vidioc_g_audio = vidioc_g_audio,
381 .vidioc_s_audio = vidioc_s_audio,
382 .vidioc_g_input = vidioc_g_input,
383 .vidioc_s_input = vidioc_s_input,
384 .vidioc_g_frequency = vidioc_g_frequency,
385 .vidioc_s_frequency = vidioc_s_frequency,
386 .vidioc_queryctrl = vidioc_queryctrl,
387 .vidioc_g_ctrl = vidioc_g_ctrl,
388 .vidioc_s_ctrl = vidioc_s_ctrl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389};
390
391static int __init rtrack_init(void)
392{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300393 struct rtrack *rt = &rtrack_card;
394 struct v4l2_device *v4l2_dev = &rt->v4l2_dev;
395 int res;
396
397 strlcpy(v4l2_dev->name, "rtrack", sizeof(v4l2_dev->name));
398 rt->io = io;
399
400 if (rt->io == -1) {
Hans Verkuilb24c20cc2009-03-09 08:11:21 -0300401 v4l2_err(v4l2_dev, "you must set an I/O address with io=0x20f or 0x30f\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 return -EINVAL;
403 }
404
Hans Verkuil151c3f82009-03-06 13:45:27 -0300405 if (!request_region(rt->io, 2, "rtrack")) {
406 v4l2_err(v4l2_dev, "port 0x%x already in use\n", rt->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return -EBUSY;
408 }
409
Hans Verkuil151c3f82009-03-06 13:45:27 -0300410 res = v4l2_device_register(NULL, v4l2_dev);
411 if (res < 0) {
412 release_region(rt->io, 2);
413 v4l2_err(v4l2_dev, "could not register v4l2_device\n");
414 return res;
415 }
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300416
Hans Verkuil151c3f82009-03-06 13:45:27 -0300417 strlcpy(rt->vdev.name, v4l2_dev->name, sizeof(rt->vdev.name));
418 rt->vdev.v4l2_dev = v4l2_dev;
419 rt->vdev.fops = &rtrack_fops;
420 rt->vdev.ioctl_ops = &rtrack_ioctl_ops;
421 rt->vdev.release = video_device_release_empty;
422 video_set_drvdata(&rt->vdev, rt);
423
424 if (video_register_device(&rt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
425 v4l2_device_unregister(&rt->v4l2_dev);
426 release_region(rt->io, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 return -EINVAL;
428 }
Hans Verkuil151c3f82009-03-06 13:45:27 -0300429 v4l2_info(v4l2_dev, "AIMSlab RadioTrack/RadioReveal card driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 /* Set up the I/O locking */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300432
Hans Verkuil151c3f82009-03-06 13:45:27 -0300433 mutex_init(&rt->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300434
435 /* mute card - prevents noisy bootups */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 /* this ensures that the volume is all the way down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300438 outb(0x48, rt->io); /* volume down but still "on" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 sleep_delay(2000000); /* make sure it's totally down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300440 outb(0xc0, rt->io); /* steady volume, mute card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 return 0;
443}
444
Hans Verkuil151c3f82009-03-06 13:45:27 -0300445static void __exit rtrack_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300447 struct rtrack *rt = &rtrack_card;
448
449 video_unregister_device(&rt->vdev);
450 v4l2_device_unregister(&rt->v4l2_dev);
451 release_region(rt->io, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
454module_init(rtrack_init);
Hans Verkuil151c3f82009-03-06 13:45:27 -0300455module_exit(rtrack_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456