blob: 4ce10dbeadd861c587ad274ccdd09e784b9a729e [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/version.h> /* for KERNEL_VERSION MACRO */
37#include <linux/io.h> /* outb, outb_p */
Hans Verkuil151c3f82009-03-06 13:45:27 -030038#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030039#include <media/v4l2-ioctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Hans Verkuil151c3f82009-03-06 13:45:27 -030041MODULE_AUTHOR("M.Kirkwood");
42MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
43MODULE_LICENSE("GPL");
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
56#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
57
58struct rtrack
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Hans Verkuil151c3f82009-03-06 13:45:27 -030060 struct v4l2_device v4l2_dev;
61 struct video_device vdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 int port;
63 int curvol;
64 unsigned long curfreq;
65 int muted;
Hans Verkuil151c3f82009-03-06 13:45:27 -030066 int io;
67 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068};
69
Hans Verkuil151c3f82009-03-06 13:45:27 -030070static struct rtrack rtrack_card;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72/* local things */
73
Hans Verkuil151c3f82009-03-06 13:45:27 -030074static void rt_decvol(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Hans Verkuil151c3f82009-03-06 13:45:27 -030076 outb(0x58, rt->io); /* volume down + sigstr + on */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -020077 msleep(100);
Hans Verkuil151c3f82009-03-06 13:45:27 -030078 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Hans Verkuil151c3f82009-03-06 13:45:27 -030081static void rt_incvol(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Hans Verkuil151c3f82009-03-06 13:45:27 -030083 outb(0x98, rt->io); /* volume up + sigstr + on */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -020084 msleep(100);
Hans Verkuil151c3f82009-03-06 13:45:27 -030085 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Hans Verkuil151c3f82009-03-06 13:45:27 -030088static void rt_mute(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Hans Verkuil151c3f82009-03-06 13:45:27 -030090 rt->muted = 1;
91 mutex_lock(&rt->lock);
92 outb(0xd0, rt->io); /* volume steady, off */
93 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
Hans Verkuil151c3f82009-03-06 13:45:27 -030096static int rt_setvol(struct rtrack *rt, int vol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 int i;
99
Hans Verkuil151c3f82009-03-06 13:45:27 -0300100 mutex_lock(&rt->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300101
Hans Verkuil151c3f82009-03-06 13:45:27 -0300102 if (vol == rt->curvol) { /* requested volume = current */
103 if (rt->muted) { /* user is unmuting the card */
104 rt->muted = 0;
105 outb(0xd8, rt->io); /* enable card */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300106 }
Hans Verkuil151c3f82009-03-06 13:45:27 -0300107 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 return 0;
109 }
110
Hans Verkuil151c3f82009-03-06 13:45:27 -0300111 if (vol == 0) { /* volume = 0 means mute the card */
112 outb(0x48, rt->io); /* volume down but still "on" */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200113 msleep(2000); /* make sure it's totally down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300114 outb(0xd0, rt->io); /* volume steady, off */
115 rt->curvol = 0; /* track the volume state! */
116 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 return 0;
118 }
119
Hans Verkuil151c3f82009-03-06 13:45:27 -0300120 rt->muted = 0;
121 if (vol > rt->curvol)
122 for (i = rt->curvol; i < vol; i++)
123 rt_incvol(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300125 for (i = rt->curvol; i > vol; i--)
126 rt_decvol(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Hans Verkuil151c3f82009-03-06 13:45:27 -0300128 rt->curvol = vol;
129 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return 0;
131}
132
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300133/* the 128+64 on these outb's is to keep the volume stable while tuning
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 * without them, the volume _will_ creep up with each frequency change
135 * and bit 4 (+16) is to keep the signal strength meter enabled
136 */
137
Hans Verkuil151c3f82009-03-06 13:45:27 -0300138static void send_0_byte(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300140 if (rt->curvol == 0 || rt->muted) {
141 outb_p(128+64+16+ 1, rt->io); /* wr-enable + data low */
142 outb_p(128+64+16+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144 else {
Hans Verkuil151c3f82009-03-06 13:45:27 -0300145 outb_p(128+64+16+8+ 1, rt->io); /* on + wr-enable + data low */
146 outb_p(128+64+16+8+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 }
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200148 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
Hans Verkuil151c3f82009-03-06 13:45:27 -0300151static void send_1_byte(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300153 if (rt->curvol == 0 || rt->muted) {
154 outb_p(128+64+16+4 +1, rt->io); /* wr-enable+data high */
155 outb_p(128+64+16+4+2+1, rt->io); /* clock */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 else {
Hans Verkuil151c3f82009-03-06 13:45:27 -0300158 outb_p(128+64+16+8+4 +1, rt->io); /* on+wr-enable+data high */
159 outb_p(128+64+16+8+4+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 }
161
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200162 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
Hans Verkuil151c3f82009-03-06 13:45:27 -0300165static int rt_setfreq(struct rtrack *rt, unsigned long freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
167 int i;
168
Hans Verkuil151c3f82009-03-06 13:45:27 -0300169 mutex_lock(&rt->lock); /* Stop other ops interfering */
170
171 rt->curfreq = freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /* now uses VIDEO_TUNER_LOW for fine tuning */
174
175 freq += 171200; /* Add 10.7 MHz IF */
176 freq /= 800; /* Convert to 50 kHz units */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300177
Hans Verkuil151c3f82009-03-06 13:45:27 -0300178 send_0_byte(rt); /* 0: LSB of frequency */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
181 if (freq & (1 << i))
Hans Verkuil151c3f82009-03-06 13:45:27 -0300182 send_1_byte(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300184 send_0_byte(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Hans Verkuil151c3f82009-03-06 13:45:27 -0300186 send_0_byte(rt); /* 14: test bit - always 0 */
187 send_0_byte(rt); /* 15: test bit - always 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Hans Verkuil151c3f82009-03-06 13:45:27 -0300189 send_0_byte(rt); /* 16: band data 0 - always 0 */
190 send_0_byte(rt); /* 17: band data 1 - always 0 */
191 send_0_byte(rt); /* 18: band data 2 - always 0 */
192 send_0_byte(rt); /* 19: time base - always 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Hans Verkuil151c3f82009-03-06 13:45:27 -0300194 send_0_byte(rt); /* 20: spacing (0 = 25 kHz) */
195 send_1_byte(rt); /* 21: spacing (1 = 25 kHz) */
196 send_0_byte(rt); /* 22: spacing (0 = 25 kHz) */
197 send_1_byte(rt); /* 23: AM/FM (FM = 1, always) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Hans Verkuil151c3f82009-03-06 13:45:27 -0300199 if (rt->curvol == 0 || rt->muted)
200 outb(0xd0, rt->io); /* volume steady + sigstr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300202 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300203
Hans Verkuil151c3f82009-03-06 13:45:27 -0300204 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 return 0;
207}
208
Hans Verkuil151c3f82009-03-06 13:45:27 -0300209static int rt_getsigstr(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300211 int sig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Hans Verkuil151c3f82009-03-06 13:45:27 -0300213 mutex_lock(&rt->lock);
214 if (inb(rt->io) & 2) /* bit set = no signal present */
215 sig = 0;
216 mutex_unlock(&rt->lock);
217 return sig;
218}
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -0300219
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300220static int vidioc_querycap(struct file *file, void *priv,
221 struct v4l2_capability *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300223 strlcpy(v->driver, "radio-aimslab", sizeof(v->driver));
224 strlcpy(v->card, "RadioTrack", sizeof(v->card));
Hans Verkuil151c3f82009-03-06 13:45:27 -0300225 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300226 v->version = RADIO_VERSION;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300227 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300228 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300231static int vidioc_g_tuner(struct file *file, void *priv,
232 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300234 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300235
236 if (v->index > 0)
237 return -EINVAL;
238
Hans Verkuil151c3f82009-03-06 13:45:27 -0300239 strlcpy(v->name, "FM", sizeof(v->name));
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300240 v->type = V4L2_TUNER_RADIO;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300241 v->rangelow = 87 * 16000;
242 v->rangehigh = 108 * 16000;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300243 v->rxsubchans = V4L2_TUNER_SUB_MONO;
244 v->capability = V4L2_TUNER_CAP_LOW;
245 v->audmode = V4L2_TUNER_MODE_MONO;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300246 v->signal = 0xffff * rt_getsigstr(rt);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300247 return 0;
248}
249
250static int vidioc_s_tuner(struct file *file, void *priv,
251 struct v4l2_tuner *v)
252{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300253 return v->index ? -EINVAL : 0;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300254}
255
256static int vidioc_s_frequency(struct file *file, void *priv,
257 struct v4l2_frequency *f)
258{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300259 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300260
Hans Verkuila3a9e282009-11-27 04:33:25 -0300261 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
262 return -EINVAL;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300263 rt_setfreq(rt, f->frequency);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300264 return 0;
265}
266
267static int vidioc_g_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 Verkuila3a9e282009-11-27 04:33:25 -0300272 if (f->tuner != 0)
273 return -EINVAL;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300274 f->type = V4L2_TUNER_RADIO;
275 f->frequency = rt->curfreq;
276 return 0;
277}
278
279static int vidioc_queryctrl(struct file *file, void *priv,
280 struct v4l2_queryctrl *qc)
281{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300282 switch (qc->id) {
283 case V4L2_CID_AUDIO_MUTE:
284 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
285 case V4L2_CID_AUDIO_VOLUME:
286 return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300287 }
288 return -EINVAL;
289}
290
291static int vidioc_g_ctrl(struct file *file, void *priv,
292 struct v4l2_control *ctrl)
293{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300294 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300295
296 switch (ctrl->id) {
297 case V4L2_CID_AUDIO_MUTE:
298 ctrl->value = rt->muted;
299 return 0;
300 case V4L2_CID_AUDIO_VOLUME:
Hans Verkuil151c3f82009-03-06 13:45:27 -0300301 ctrl->value = rt->curvol;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300302 return 0;
303 }
304 return -EINVAL;
305}
306
307static int vidioc_s_ctrl(struct file *file, void *priv,
308 struct v4l2_control *ctrl)
309{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300310 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300311
312 switch (ctrl->id) {
313 case V4L2_CID_AUDIO_MUTE:
314 if (ctrl->value)
315 rt_mute(rt);
316 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300317 rt_setvol(rt, rt->curvol);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300318 return 0;
319 case V4L2_CID_AUDIO_VOLUME:
Hans Verkuil151c3f82009-03-06 13:45:27 -0300320 rt_setvol(rt, ctrl->value);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300321 return 0;
322 }
323 return -EINVAL;
324}
325
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300326static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
327{
328 *i = 0;
329 return 0;
330}
331
332static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
333{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300334 return i ? -EINVAL : 0;
335}
336
337static int vidioc_g_audio(struct file *file, void *priv,
338 struct v4l2_audio *a)
339{
340 a->index = 0;
341 strlcpy(a->name, "Radio", sizeof(a->name));
342 a->capability = V4L2_AUDCAP_STEREO;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300343 return 0;
344}
345
346static int vidioc_s_audio(struct file *file, void *priv,
347 struct v4l2_audio *a)
348{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300349 return a->index ? -EINVAL : 0;
350}
351
Hans Verkuilbec43662008-12-30 06:58:20 -0300352static const struct v4l2_file_operations rtrack_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 .owner = THIS_MODULE,
Hans Verkuil32958fd2010-11-14 09:36:23 -0300354 .unlocked_ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355};
356
Hans Verkuila3998102008-07-21 02:57:38 -0300357static const struct v4l2_ioctl_ops rtrack_ioctl_ops = {
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300358 .vidioc_querycap = vidioc_querycap,
359 .vidioc_g_tuner = vidioc_g_tuner,
360 .vidioc_s_tuner = vidioc_s_tuner,
361 .vidioc_g_audio = vidioc_g_audio,
362 .vidioc_s_audio = vidioc_s_audio,
363 .vidioc_g_input = vidioc_g_input,
364 .vidioc_s_input = vidioc_s_input,
365 .vidioc_g_frequency = vidioc_g_frequency,
366 .vidioc_s_frequency = vidioc_s_frequency,
367 .vidioc_queryctrl = vidioc_queryctrl,
368 .vidioc_g_ctrl = vidioc_g_ctrl,
369 .vidioc_s_ctrl = vidioc_s_ctrl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370};
371
372static int __init rtrack_init(void)
373{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300374 struct rtrack *rt = &rtrack_card;
375 struct v4l2_device *v4l2_dev = &rt->v4l2_dev;
376 int res;
377
378 strlcpy(v4l2_dev->name, "rtrack", sizeof(v4l2_dev->name));
379 rt->io = io;
380
381 if (rt->io == -1) {
Hans Verkuilb24c20cc2009-03-09 08:11:21 -0300382 v4l2_err(v4l2_dev, "you must set an I/O address with io=0x20f or 0x30f\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 return -EINVAL;
384 }
385
Hans Verkuil151c3f82009-03-06 13:45:27 -0300386 if (!request_region(rt->io, 2, "rtrack")) {
387 v4l2_err(v4l2_dev, "port 0x%x already in use\n", rt->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 return -EBUSY;
389 }
390
Hans Verkuil151c3f82009-03-06 13:45:27 -0300391 res = v4l2_device_register(NULL, v4l2_dev);
392 if (res < 0) {
393 release_region(rt->io, 2);
394 v4l2_err(v4l2_dev, "could not register v4l2_device\n");
395 return res;
396 }
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300397
Hans Verkuil151c3f82009-03-06 13:45:27 -0300398 strlcpy(rt->vdev.name, v4l2_dev->name, sizeof(rt->vdev.name));
399 rt->vdev.v4l2_dev = v4l2_dev;
400 rt->vdev.fops = &rtrack_fops;
401 rt->vdev.ioctl_ops = &rtrack_ioctl_ops;
402 rt->vdev.release = video_device_release_empty;
403 video_set_drvdata(&rt->vdev, rt);
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 /* Set up the I/O locking */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300406
Hans Verkuil151c3f82009-03-06 13:45:27 -0300407 mutex_init(&rt->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300408
409 /* mute card - prevents noisy bootups */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
411 /* this ensures that the volume is all the way down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300412 outb(0x48, rt->io); /* volume down but still "on" */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200413 msleep(2000); /* make sure it's totally down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300414 outb(0xc0, rt->io); /* steady volume, mute card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Hans Verkuil32958fd2010-11-14 09:36:23 -0300416 if (video_register_device(&rt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
417 v4l2_device_unregister(&rt->v4l2_dev);
418 release_region(rt->io, 2);
419 return -EINVAL;
420 }
421 v4l2_info(v4l2_dev, "AIMSlab RadioTrack/RadioReveal card driver.\n");
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 return 0;
424}
425
Hans Verkuil151c3f82009-03-06 13:45:27 -0300426static void __exit rtrack_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300428 struct rtrack *rt = &rtrack_card;
429
430 video_unregister_device(&rt->vdev);
431 v4l2_device_unregister(&rt->v4l2_dev);
432 release_region(rt->io, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
434
435module_init(rtrack_init);
Hans Verkuil151c3f82009-03-06 13:45:27 -0300436module_exit(rtrack_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437