blob: 6cc5d130fbc84b3251a995499da96c504b8d59cf [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 */
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -030034#include <linux/videodev2.h> /* kernel radio structs */
Hans Verkuil151c3f82009-03-06 13:45:27 -030035#include <linux/version.h> /* for KERNEL_VERSION MACRO */
36#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 Chehab46ff2c72006-08-08 09:10:01 -030043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#ifndef CONFIG_RADIO_RTRACK_PORT
45#define CONFIG_RADIO_RTRACK_PORT -1
46#endif
47
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -030048static int io = CONFIG_RADIO_RTRACK_PORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static int radio_nr = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Hans Verkuil151c3f82009-03-06 13:45:27 -030051module_param(io, int, 0);
52MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20f or 0x30f)");
53module_param(radio_nr, int, 0);
54
55#define RADIO_VERSION KERNEL_VERSION(0, 0, 2)
56
57struct rtrack
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
Hans Verkuil151c3f82009-03-06 13:45:27 -030059 struct v4l2_device v4l2_dev;
60 struct video_device vdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 int port;
62 int curvol;
63 unsigned long curfreq;
64 int muted;
Hans Verkuil151c3f82009-03-06 13:45:27 -030065 int io;
66 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067};
68
Hans Verkuil151c3f82009-03-06 13:45:27 -030069static struct rtrack rtrack_card;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/* local things */
72
Hans Verkuil151c3f82009-03-06 13:45:27 -030073static void rt_decvol(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Hans Verkuil151c3f82009-03-06 13:45:27 -030075 outb(0x58, rt->io); /* volume down + sigstr + on */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -020076 msleep(100);
Hans Verkuil151c3f82009-03-06 13:45:27 -030077 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
Hans Verkuil151c3f82009-03-06 13:45:27 -030080static void rt_incvol(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Hans Verkuil151c3f82009-03-06 13:45:27 -030082 outb(0x98, rt->io); /* volume up + sigstr + on */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -020083 msleep(100);
Hans Verkuil151c3f82009-03-06 13:45:27 -030084 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
Hans Verkuil151c3f82009-03-06 13:45:27 -030087static void rt_mute(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Hans Verkuil151c3f82009-03-06 13:45:27 -030089 rt->muted = 1;
90 mutex_lock(&rt->lock);
91 outb(0xd0, rt->io); /* volume steady, off */
92 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093}
94
Hans Verkuil151c3f82009-03-06 13:45:27 -030095static int rt_setvol(struct rtrack *rt, int vol)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
97 int i;
98
Hans Verkuil151c3f82009-03-06 13:45:27 -030099 mutex_lock(&rt->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300100
Hans Verkuil151c3f82009-03-06 13:45:27 -0300101 if (vol == rt->curvol) { /* requested volume = current */
102 if (rt->muted) { /* user is unmuting the card */
103 rt->muted = 0;
104 outb(0xd8, rt->io); /* enable card */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300105 }
Hans Verkuil151c3f82009-03-06 13:45:27 -0300106 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 return 0;
108 }
109
Hans Verkuil151c3f82009-03-06 13:45:27 -0300110 if (vol == 0) { /* volume = 0 means mute the card */
111 outb(0x48, rt->io); /* volume down but still "on" */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200112 msleep(2000); /* make sure it's totally down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300113 outb(0xd0, rt->io); /* volume steady, off */
114 rt->curvol = 0; /* track the volume state! */
115 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return 0;
117 }
118
Hans Verkuil151c3f82009-03-06 13:45:27 -0300119 rt->muted = 0;
120 if (vol > rt->curvol)
121 for (i = rt->curvol; i < vol; i++)
122 rt_incvol(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300124 for (i = rt->curvol; i > vol; i--)
125 rt_decvol(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Hans Verkuil151c3f82009-03-06 13:45:27 -0300127 rt->curvol = vol;
128 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return 0;
130}
131
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300132/* the 128+64 on these outb's is to keep the volume stable while tuning
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 * without them, the volume _will_ creep up with each frequency change
134 * and bit 4 (+16) is to keep the signal strength meter enabled
135 */
136
Hans Verkuil151c3f82009-03-06 13:45:27 -0300137static void send_0_byte(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300139 if (rt->curvol == 0 || rt->muted) {
140 outb_p(128+64+16+ 1, rt->io); /* wr-enable + data low */
141 outb_p(128+64+16+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 }
143 else {
Hans Verkuil151c3f82009-03-06 13:45:27 -0300144 outb_p(128+64+16+8+ 1, rt->io); /* on + wr-enable + data low */
145 outb_p(128+64+16+8+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200147 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148}
149
Hans Verkuil151c3f82009-03-06 13:45:27 -0300150static void send_1_byte(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300152 if (rt->curvol == 0 || rt->muted) {
153 outb_p(128+64+16+4 +1, rt->io); /* wr-enable+data high */
154 outb_p(128+64+16+4+2+1, rt->io); /* clock */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300155 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 else {
Hans Verkuil151c3f82009-03-06 13:45:27 -0300157 outb_p(128+64+16+8+4 +1, rt->io); /* on+wr-enable+data high */
158 outb_p(128+64+16+8+4+2+1, rt->io); /* clock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200161 msleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
Hans Verkuil151c3f82009-03-06 13:45:27 -0300164static int rt_setfreq(struct rtrack *rt, unsigned long freq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
166 int i;
167
Hans Verkuil151c3f82009-03-06 13:45:27 -0300168 mutex_lock(&rt->lock); /* Stop other ops interfering */
169
170 rt->curfreq = freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 /* now uses VIDEO_TUNER_LOW for fine tuning */
173
174 freq += 171200; /* Add 10.7 MHz IF */
175 freq /= 800; /* Convert to 50 kHz units */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300176
Hans Verkuil151c3f82009-03-06 13:45:27 -0300177 send_0_byte(rt); /* 0: LSB of frequency */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
180 if (freq & (1 << i))
Hans Verkuil151c3f82009-03-06 13:45:27 -0300181 send_1_byte(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300183 send_0_byte(rt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Hans Verkuil151c3f82009-03-06 13:45:27 -0300185 send_0_byte(rt); /* 14: test bit - always 0 */
186 send_0_byte(rt); /* 15: test bit - always 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Hans Verkuil151c3f82009-03-06 13:45:27 -0300188 send_0_byte(rt); /* 16: band data 0 - always 0 */
189 send_0_byte(rt); /* 17: band data 1 - always 0 */
190 send_0_byte(rt); /* 18: band data 2 - always 0 */
191 send_0_byte(rt); /* 19: time base - always 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Hans Verkuil151c3f82009-03-06 13:45:27 -0300193 send_0_byte(rt); /* 20: spacing (0 = 25 kHz) */
194 send_1_byte(rt); /* 21: spacing (1 = 25 kHz) */
195 send_0_byte(rt); /* 22: spacing (0 = 25 kHz) */
196 send_1_byte(rt); /* 23: AM/FM (FM = 1, always) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Hans Verkuil151c3f82009-03-06 13:45:27 -0300198 if (rt->curvol == 0 || rt->muted)
199 outb(0xd0, rt->io); /* volume steady + sigstr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300201 outb(0xd8, rt->io); /* volume steady + sigstr + on */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300202
Hans Verkuil151c3f82009-03-06 13:45:27 -0300203 mutex_unlock(&rt->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 return 0;
206}
207
Hans Verkuil151c3f82009-03-06 13:45:27 -0300208static int rt_getsigstr(struct rtrack *rt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300210 int sig = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Hans Verkuil151c3f82009-03-06 13:45:27 -0300212 mutex_lock(&rt->lock);
213 if (inb(rt->io) & 2) /* bit set = no signal present */
214 sig = 0;
215 mutex_unlock(&rt->lock);
216 return sig;
217}
Mauro Carvalho Chehab46ff2c72006-08-08 09:10:01 -0300218
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300219static int vidioc_querycap(struct file *file, void *priv,
220 struct v4l2_capability *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300222 strlcpy(v->driver, "radio-aimslab", sizeof(v->driver));
223 strlcpy(v->card, "RadioTrack", sizeof(v->card));
Hans Verkuil151c3f82009-03-06 13:45:27 -0300224 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300225 v->version = RADIO_VERSION;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300226 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300227 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
229
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300230static int vidioc_g_tuner(struct file *file, void *priv,
231 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300233 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300234
235 if (v->index > 0)
236 return -EINVAL;
237
Hans Verkuil151c3f82009-03-06 13:45:27 -0300238 strlcpy(v->name, "FM", sizeof(v->name));
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300239 v->type = V4L2_TUNER_RADIO;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300240 v->rangelow = 87 * 16000;
241 v->rangehigh = 108 * 16000;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300242 v->rxsubchans = V4L2_TUNER_SUB_MONO;
243 v->capability = V4L2_TUNER_CAP_LOW;
244 v->audmode = V4L2_TUNER_MODE_MONO;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300245 v->signal = 0xffff * rt_getsigstr(rt);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300246 return 0;
247}
248
249static int vidioc_s_tuner(struct file *file, void *priv,
250 struct v4l2_tuner *v)
251{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300252 return v->index ? -EINVAL : 0;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300253}
254
255static int vidioc_s_frequency(struct file *file, void *priv,
256 struct v4l2_frequency *f)
257{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300258 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300259
Hans Verkuila3a9e282009-11-27 04:33:25 -0300260 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
261 return -EINVAL;
Hans Verkuil151c3f82009-03-06 13:45:27 -0300262 rt_setfreq(rt, f->frequency);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300263 return 0;
264}
265
266static int vidioc_g_frequency(struct file *file, void *priv,
267 struct v4l2_frequency *f)
268{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300269 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300270
Hans Verkuila3a9e282009-11-27 04:33:25 -0300271 if (f->tuner != 0)
272 return -EINVAL;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300273 f->type = V4L2_TUNER_RADIO;
274 f->frequency = rt->curfreq;
275 return 0;
276}
277
278static int vidioc_queryctrl(struct file *file, void *priv,
279 struct v4l2_queryctrl *qc)
280{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300281 switch (qc->id) {
282 case V4L2_CID_AUDIO_MUTE:
283 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
284 case V4L2_CID_AUDIO_VOLUME:
285 return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300286 }
287 return -EINVAL;
288}
289
290static int vidioc_g_ctrl(struct file *file, void *priv,
291 struct v4l2_control *ctrl)
292{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300293 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300294
295 switch (ctrl->id) {
296 case V4L2_CID_AUDIO_MUTE:
297 ctrl->value = rt->muted;
298 return 0;
299 case V4L2_CID_AUDIO_VOLUME:
Hans Verkuil151c3f82009-03-06 13:45:27 -0300300 ctrl->value = rt->curvol;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300301 return 0;
302 }
303 return -EINVAL;
304}
305
306static int vidioc_s_ctrl(struct file *file, void *priv,
307 struct v4l2_control *ctrl)
308{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300309 struct rtrack *rt = video_drvdata(file);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300310
311 switch (ctrl->id) {
312 case V4L2_CID_AUDIO_MUTE:
313 if (ctrl->value)
314 rt_mute(rt);
315 else
Hans Verkuil151c3f82009-03-06 13:45:27 -0300316 rt_setvol(rt, rt->curvol);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300317 return 0;
318 case V4L2_CID_AUDIO_VOLUME:
Hans Verkuil151c3f82009-03-06 13:45:27 -0300319 rt_setvol(rt, ctrl->value);
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300320 return 0;
321 }
322 return -EINVAL;
323}
324
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300325static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
326{
327 *i = 0;
328 return 0;
329}
330
331static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
332{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300333 return i ? -EINVAL : 0;
334}
335
336static int vidioc_g_audio(struct file *file, void *priv,
337 struct v4l2_audio *a)
338{
339 a->index = 0;
340 strlcpy(a->name, "Radio", sizeof(a->name));
341 a->capability = V4L2_AUDCAP_STEREO;
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300342 return 0;
343}
344
345static int vidioc_s_audio(struct file *file, void *priv,
346 struct v4l2_audio *a)
347{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300348 return a->index ? -EINVAL : 0;
349}
350
Hans Verkuilbec43662008-12-30 06:58:20 -0300351static const struct v4l2_file_operations rtrack_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 .owner = THIS_MODULE,
Hans Verkuil32958fd2010-11-14 09:36:23 -0300353 .unlocked_ioctl = video_ioctl2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354};
355
Hans Verkuila3998102008-07-21 02:57:38 -0300356static const struct v4l2_ioctl_ops rtrack_ioctl_ops = {
Douglas Landgraf385e8d82007-04-25 00:14:36 -0300357 .vidioc_querycap = vidioc_querycap,
358 .vidioc_g_tuner = vidioc_g_tuner,
359 .vidioc_s_tuner = vidioc_s_tuner,
360 .vidioc_g_audio = vidioc_g_audio,
361 .vidioc_s_audio = vidioc_s_audio,
362 .vidioc_g_input = vidioc_g_input,
363 .vidioc_s_input = vidioc_s_input,
364 .vidioc_g_frequency = vidioc_g_frequency,
365 .vidioc_s_frequency = vidioc_s_frequency,
366 .vidioc_queryctrl = vidioc_queryctrl,
367 .vidioc_g_ctrl = vidioc_g_ctrl,
368 .vidioc_s_ctrl = vidioc_s_ctrl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369};
370
371static int __init rtrack_init(void)
372{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300373 struct rtrack *rt = &rtrack_card;
374 struct v4l2_device *v4l2_dev = &rt->v4l2_dev;
375 int res;
376
377 strlcpy(v4l2_dev->name, "rtrack", sizeof(v4l2_dev->name));
378 rt->io = io;
379
380 if (rt->io == -1) {
Hans Verkuilb24c20cc2009-03-09 08:11:21 -0300381 v4l2_err(v4l2_dev, "you must set an I/O address with io=0x20f or 0x30f\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 return -EINVAL;
383 }
384
Hans Verkuil151c3f82009-03-06 13:45:27 -0300385 if (!request_region(rt->io, 2, "rtrack")) {
386 v4l2_err(v4l2_dev, "port 0x%x already in use\n", rt->io);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 return -EBUSY;
388 }
389
Hans Verkuil151c3f82009-03-06 13:45:27 -0300390 res = v4l2_device_register(NULL, v4l2_dev);
391 if (res < 0) {
392 release_region(rt->io, 2);
393 v4l2_err(v4l2_dev, "could not register v4l2_device\n");
394 return res;
395 }
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300396
Hans Verkuil151c3f82009-03-06 13:45:27 -0300397 strlcpy(rt->vdev.name, v4l2_dev->name, sizeof(rt->vdev.name));
398 rt->vdev.v4l2_dev = v4l2_dev;
399 rt->vdev.fops = &rtrack_fops;
400 rt->vdev.ioctl_ops = &rtrack_ioctl_ops;
401 rt->vdev.release = video_device_release_empty;
402 video_set_drvdata(&rt->vdev, rt);
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 /* Set up the I/O locking */
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300405
Hans Verkuil151c3f82009-03-06 13:45:27 -0300406 mutex_init(&rt->lock);
Mauro Carvalho Chehab4286c6f2006-04-08 16:06:16 -0300407
408 /* mute card - prevents noisy bootups */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
410 /* this ensures that the volume is all the way down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300411 outb(0x48, rt->io); /* volume down but still "on" */
Mauro Carvalho Chehabe3c92212011-01-06 08:16:04 -0200412 msleep(2000); /* make sure it's totally down */
Hans Verkuil151c3f82009-03-06 13:45:27 -0300413 outb(0xc0, rt->io); /* steady volume, mute card */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Hans Verkuil32958fd2010-11-14 09:36:23 -0300415 if (video_register_device(&rt->vdev, VFL_TYPE_RADIO, radio_nr) < 0) {
416 v4l2_device_unregister(&rt->v4l2_dev);
417 release_region(rt->io, 2);
418 return -EINVAL;
419 }
420 v4l2_info(v4l2_dev, "AIMSlab RadioTrack/RadioReveal card driver.\n");
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 return 0;
423}
424
Hans Verkuil151c3f82009-03-06 13:45:27 -0300425static void __exit rtrack_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426{
Hans Verkuil151c3f82009-03-06 13:45:27 -0300427 struct rtrack *rt = &rtrack_card;
428
429 video_unregister_device(&rt->vdev);
430 v4l2_device_unregister(&rt->v4l2_dev);
431 release_region(rt->io, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
434module_init(rtrack_init);
Hans Verkuil151c3f82009-03-06 13:45:27 -0300435module_exit(rtrack_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436