blob: 1c3f8440a55cf113d7a9fc1850680ca0f16da869 [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 */
Geert Uytterhoeven24009822011-01-16 10:09:13 -030034#include <linux/delay.h> /* msleep */
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/io.h> /* outb, outb_p */
Hans Verkuil151c3f82009-03-06 13:45:27 -030037#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030038#include <media/v4l2-ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Hans Verkuil151c3f82009-03-06 13:45:27 -030040MODULE_AUTHOR("M.Kirkwood");
41MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
42MODULE_LICENSE("GPL");
Mauro Carvalho Chehab29834c12011-06-25 10:15:42 -030043MODULE_VERSION("0.0.3");
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -030044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#ifndef CONFIG_RADIO_RTRACK_PORT
46#define CONFIG_RADIO_RTRACK_PORT -1
47#endif
48
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030049static int io = CONFIG_RADIO_RTRACK_PORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050static int radio_nr = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Hans Verkuil151c3f82009-03-06 13:45:27 -030052module_param(io, int, 0);
53MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20f or 0x30f)");
54module_param(radio_nr, int, 0);
55
Hans Verkuil151c3f82009-03-06 13:45:27 -030056struct rtrack
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Hans Verkuil151c3f82009-03-06 13:45:27 -030058 struct v4l2_device v4l2_dev;
59 struct video_device vdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 int port;
61 int curvol;
62 unsigned long curfreq;
63 int muted;
Hans Verkuil151c3f82009-03-06 13:45:27 -030064 int io;
65 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066};
67
Hans Verkuil151c3f82009-03-06 13:45:27 -030068static struct rtrack rtrack_card;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/* local things */
71
Hans Verkuil151c3f82009-03-06 13:45:27 -030072static void rt_decvol(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Hans Verkuil151c3f82009-03-06 13:45:27 -030074 outb(0x58, rt->io); /* volume down + sigstr + on */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -020075 msleep(100);
Hans Verkuil151c3f82009-03-06 13:45:27 -030076 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077}
78
Hans Verkuil151c3f82009-03-06 13:45:27 -030079static void rt_incvol(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
Hans Verkuil151c3f82009-03-06 13:45:27 -030081 outb(0x98, rt->io); /* volume up + sigstr + on */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -020082 msleep(100);
Hans Verkuil151c3f82009-03-06 13:45:27 -030083 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Hans Verkuil151c3f82009-03-06 13:45:27 -030086static void rt_mute(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Hans Verkuil151c3f82009-03-06 13:45:27 -030088 rt->muted = 1;
89 mutex_lock(&rt->lock);
90 outb(0xd0, rt->io); /* volume steady, off */
91 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}
93
Hans Verkuil151c3f82009-03-06 13:45:27 -030094static int rt_setvol(struct rtrack *rt, int vol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
96 int i;
97
Hans Verkuil151c3f82009-03-06 13:45:27 -030098 mutex_lock(&rt->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030099
Hans Verkuil151c3f82009-03-06 13:45:27 -0300100 if (vol == rt->curvol) { /* requested volume = current */
101 if (rt->muted) { /* user is unmuting the card */
102 rt->muted = 0;
103 outb(0xd8, rt->io); /* enable card */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300104 }
Hans Verkuil151c3f82009-03-06 13:45:27 -0300105 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return 0;
107 }
108
Hans Verkuil151c3f82009-03-06 13:45:27 -0300109 if (vol == 0) { /* volume = 0 means mute the card */
110 outb(0x48, rt->io); /* volume down but still "on" */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200111 msleep(2000); /* make sure it's totally down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300112 outb(0xd0, rt->io); /* volume steady, off */
113 rt->curvol = 0; /* track the volume state! */
114 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 return 0;
116 }
117
Hans Verkuil151c3f82009-03-06 13:45:27 -0300118 rt->muted = 0;
119 if (vol > rt->curvol)
120 for (i = rt->curvol; i < vol; i++)
121 rt_incvol(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300123 for (i = rt->curvol; i > vol; i--)
124 rt_decvol(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Hans Verkuil151c3f82009-03-06 13:45:27 -0300126 rt->curvol = vol;
127 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 return 0;
129}
130
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300131/* the 128+64 on these outb's is to keep the volume stable while tuning
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 * without them, the volume _will_ creep up with each frequency change
133 * and bit 4 (+16) is to keep the signal strength meter enabled
134 */
135
Hans Verkuil151c3f82009-03-06 13:45:27 -0300136static void send_0_byte(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300138 if (rt->curvol == 0 || rt->muted) {
139 outb_p(128+64+16+ 1, rt->io); /* wr-enable + data low */
140 outb_p(128+64+16+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
142 else {
Hans Verkuil151c3f82009-03-06 13:45:27 -0300143 outb_p(128+64+16+8+ 1, rt->io); /* on + wr-enable + data low */
144 outb_p(128+64+16+8+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200146 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
Hans Verkuil151c3f82009-03-06 13:45:27 -0300149static void send_1_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+4 +1, rt->io); /* wr-enable+data high */
153 outb_p(128+64+16+4+2+1, rt->io); /* clock */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 else {
Hans Verkuil151c3f82009-03-06 13:45:27 -0300156 outb_p(128+64+16+8+4 +1, rt->io); /* on+wr-enable+data high */
157 outb_p(128+64+16+8+4+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200160 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
Hans Verkuil151c3f82009-03-06 13:45:27 -0300163static int rt_setfreq(struct rtrack *rt, unsigned long freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
165 int i;
166
Hans Verkuil151c3f82009-03-06 13:45:27 -0300167 mutex_lock(&rt->lock); /* Stop other ops interfering */
168
169 rt->curfreq = freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 /* now uses VIDEO_TUNER_LOW for fine tuning */
172
173 freq += 171200; /* Add 10.7 MHz IF */
174 freq /= 800; /* Convert to 50 kHz units */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300175
Hans Verkuil151c3f82009-03-06 13:45:27 -0300176 send_0_byte(rt); /* 0: LSB of frequency */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
179 if (freq & (1 << i))
Hans Verkuil151c3f82009-03-06 13:45:27 -0300180 send_1_byte(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300182 send_0_byte(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Hans Verkuil151c3f82009-03-06 13:45:27 -0300184 send_0_byte(rt); /* 14: test bit - always 0 */
185 send_0_byte(rt); /* 15: test bit - always 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Hans Verkuil151c3f82009-03-06 13:45:27 -0300187 send_0_byte(rt); /* 16: band data 0 - always 0 */
188 send_0_byte(rt); /* 17: band data 1 - always 0 */
189 send_0_byte(rt); /* 18: band data 2 - always 0 */
190 send_0_byte(rt); /* 19: time base - always 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Hans Verkuil151c3f82009-03-06 13:45:27 -0300192 send_0_byte(rt); /* 20: spacing (0 = 25 kHz) */
193 send_1_byte(rt); /* 21: spacing (1 = 25 kHz) */
194 send_0_byte(rt); /* 22: spacing (0 = 25 kHz) */
195 send_1_byte(rt); /* 23: AM/FM (FM = 1, always) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Hans Verkuil151c3f82009-03-06 13:45:27 -0300197 if (rt->curvol == 0 || rt->muted)
198 outb(0xd0, rt->io); /* volume steady + sigstr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300200 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300201
Hans Verkuil151c3f82009-03-06 13:45:27 -0300202 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 return 0;
205}
206
Hans Verkuil151c3f82009-03-06 13:45:27 -0300207static int rt_getsigstr(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300209 int sig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Hans Verkuil151c3f82009-03-06 13:45:27 -0300211 mutex_lock(&rt->lock);
212 if (inb(rt->io) & 2) /* bit set = no signal present */
213 sig = 0;
214 mutex_unlock(&rt->lock);
215 return sig;
216}
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -0300217
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300218static int vidioc_querycap(struct file *file, void *priv,
219 struct v4l2_capability *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300221 strlcpy(v->driver, "radio-aimslab", sizeof(v->driver));
222 strlcpy(v->card, "RadioTrack", sizeof(v->card));
Hans Verkuil151c3f82009-03-06 13:45:27 -0300223 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
Hans Verkuil151c3f82009-03-06 13:45:27 -0300224 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300225 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300228static int vidioc_g_tuner(struct file *file, void *priv,
229 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300231 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300232
233 if (v->index > 0)
234 return -EINVAL;
235
Hans Verkuil151c3f82009-03-06 13:45:27 -0300236 strlcpy(v->name, "FM", sizeof(v->name));
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300237 v->type = V4L2_TUNER_RADIO;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300238 v->rangelow = 87 * 16000;
239 v->rangehigh = 108 * 16000;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300240 v->rxsubchans = V4L2_TUNER_SUB_MONO;
241 v->capability = V4L2_TUNER_CAP_LOW;
242 v->audmode = V4L2_TUNER_MODE_MONO;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300243 v->signal = 0xffff * rt_getsigstr(rt);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300244 return 0;
245}
246
247static int vidioc_s_tuner(struct file *file, void *priv,
248 struct v4l2_tuner *v)
249{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300250 return v->index ? -EINVAL : 0;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300251}
252
253static int vidioc_s_frequency(struct file *file, void *priv,
254 struct v4l2_frequency *f)
255{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300256 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300257
Hans Verkuila3a9e282009-11-27 04:33:25 -0300258 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
259 return -EINVAL;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300260 rt_setfreq(rt, f->frequency);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300261 return 0;
262}
263
264static int vidioc_g_frequency(struct file *file, void *priv,
265 struct v4l2_frequency *f)
266{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300267 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300268
Hans Verkuila3a9e282009-11-27 04:33:25 -0300269 if (f->tuner != 0)
270 return -EINVAL;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300271 f->type = V4L2_TUNER_RADIO;
272 f->frequency = rt->curfreq;
273 return 0;
274}
275
276static int vidioc_queryctrl(struct file *file, void *priv,
277 struct v4l2_queryctrl *qc)
278{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300279 switch (qc->id) {
280 case V4L2_CID_AUDIO_MUTE:
281 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
282 case V4L2_CID_AUDIO_VOLUME:
283 return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300284 }
285 return -EINVAL;
286}
287
288static int vidioc_g_ctrl(struct file *file, void *priv,
289 struct v4l2_control *ctrl)
290{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300291 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300292
293 switch (ctrl->id) {
294 case V4L2_CID_AUDIO_MUTE:
295 ctrl->value = rt->muted;
296 return 0;
297 case V4L2_CID_AUDIO_VOLUME:
Hans Verkuil151c3f82009-03-06 13:45:27 -0300298 ctrl->value = rt->curvol;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300299 return 0;
300 }
301 return -EINVAL;
302}
303
304static int vidioc_s_ctrl(struct file *file, void *priv,
305 struct v4l2_control *ctrl)
306{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300307 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300308
309 switch (ctrl->id) {
310 case V4L2_CID_AUDIO_MUTE:
311 if (ctrl->value)
312 rt_mute(rt);
313 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300314 rt_setvol(rt, rt->curvol);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300315 return 0;
316 case V4L2_CID_AUDIO_VOLUME:
Hans Verkuil151c3f82009-03-06 13:45:27 -0300317 rt_setvol(rt, ctrl->value);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300318 return 0;
319 }
320 return -EINVAL;
321}
322
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300323static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
324{
325 *i = 0;
326 return 0;
327}
328
329static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
330{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300331 return i ? -EINVAL : 0;
332}
333
334static int vidioc_g_audio(struct file *file, void *priv,
335 struct v4l2_audio *a)
336{
337 a->index = 0;
338 strlcpy(a->name, "Radio", sizeof(a->name));
339 a->capability = V4L2_AUDCAP_STEREO;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300340 return 0;
341}
342
343static int vidioc_s_audio(struct file *file, void *priv,
344 struct v4l2_audio *a)
345{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300346 return a->index ? -EINVAL : 0;
347}
348
Hans Verkuilbec43662008-12-30 06:58:20 -0300349static const struct v4l2_file_operations rtrack_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 .owner = THIS_MODULE,
Hans Verkuil32958fd2010-11-14 09:36:23 -0300351 .unlocked_ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352};
353
Hans Verkuila3998102008-07-21 02:57:38 -0300354static const struct v4l2_ioctl_ops rtrack_ioctl_ops = {
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300355 .vidioc_querycap = vidioc_querycap,
356 .vidioc_g_tuner = vidioc_g_tuner,
357 .vidioc_s_tuner = vidioc_s_tuner,
358 .vidioc_g_audio = vidioc_g_audio,
359 .vidioc_s_audio = vidioc_s_audio,
360 .vidioc_g_input = vidioc_g_input,
361 .vidioc_s_input = vidioc_s_input,
362 .vidioc_g_frequency = vidioc_g_frequency,
363 .vidioc_s_frequency = vidioc_s_frequency,
364 .vidioc_queryctrl = vidioc_queryctrl,
365 .vidioc_g_ctrl = vidioc_g_ctrl,
366 .vidioc_s_ctrl = vidioc_s_ctrl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367};
368
369static int __init rtrack_init(void)
370{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300371 struct rtrack *rt = &rtrack_card;
372 struct v4l2_device *v4l2_dev = &rt->v4l2_dev;
373 int res;
374
375 strlcpy(v4l2_dev->name, "rtrack", sizeof(v4l2_dev->name));
376 rt->io = io;
377
378 if (rt->io == -1) {
Hans Verkuilb24c20cc2009-03-09 08:11:21 -0300379 v4l2_err(v4l2_dev, "you must set an I/O address with io=0x20f or 0x30f\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 return -EINVAL;
381 }
382
Hans Verkuil151c3f82009-03-06 13:45:27 -0300383 if (!request_region(rt->io, 2, "rtrack")) {
384 v4l2_err(v4l2_dev, "port 0x%x already in use\n", rt->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 return -EBUSY;
386 }
387
Hans Verkuil151c3f82009-03-06 13:45:27 -0300388 res = v4l2_device_register(NULL, v4l2_dev);
389 if (res < 0) {
390 release_region(rt->io, 2);
391 v4l2_err(v4l2_dev, "could not register v4l2_device\n");
392 return res;
393 }
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300394
Hans Verkuil151c3f82009-03-06 13:45:27 -0300395 strlcpy(rt->vdev.name, v4l2_dev->name, sizeof(rt->vdev.name));
396 rt->vdev.v4l2_dev = v4l2_dev;
397 rt->vdev.fops = &rtrack_fops;
398 rt->vdev.ioctl_ops = &rtrack_ioctl_ops;
399 rt->vdev.release = video_device_release_empty;
400 video_set_drvdata(&rt->vdev, rt);
401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 /* Set up the I/O locking */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300403
Hans Verkuil151c3f82009-03-06 13:45:27 -0300404 mutex_init(&rt->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300405
406 /* mute card - prevents noisy bootups */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 /* this ensures that the volume is all the way down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300409 outb(0x48, rt->io); /* volume down but still "on" */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200410 msleep(2000); /* make sure it's totally down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300411 outb(0xc0, rt->io); /* steady volume, mute card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Hans Verkuil32958fd2010-11-14 09:36:23 -0300413 if (video_register_device(&rt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
414 v4l2_device_unregister(&rt->v4l2_dev);
415 release_region(rt->io, 2);
416 return -EINVAL;
417 }
418 v4l2_info(v4l2_dev, "AIMSlab RadioTrack/RadioReveal card driver.\n");
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 return 0;
421}
422
Hans Verkuil151c3f82009-03-06 13:45:27 -0300423static void __exit rtrack_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300425 struct rtrack *rt = &rtrack_card;
426
427 video_unregister_device(&rt->vdev);
428 v4l2_device_unregister(&rt->v4l2_dev);
429 release_region(rt->io, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
432module_init(rtrack_init);
Hans Verkuil151c3f82009-03-06 13:45:27 -0300433module_exit(rtrack_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434