aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/radio/radio-aimslab.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2009-03-06 11:45:27 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:43:12 -0400
commit151c3f82529844c39ad52fe8d877dd2ffe06c70d (patch)
tree3327b459736e9954d460d43d0007ba3e9703f88c /drivers/media/radio/radio-aimslab.c
parentf9996c95623d63de6f5957512976137bbac729f0 (diff)
V4L/DVB (10880): radio-aimslab: convert to v4l2_device.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/radio/radio-aimslab.c')
-rw-r--r--drivers/media/radio/radio-aimslab.c348
1 files changed, 167 insertions, 181 deletions
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index bfa13b8b3043..ee204fdc4157 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -32,14 +32,16 @@
32#include <linux/init.h> /* Initdata */ 32#include <linux/init.h> /* Initdata */
33#include <linux/ioport.h> /* request_region */ 33#include <linux/ioport.h> /* request_region */
34#include <linux/delay.h> /* udelay */ 34#include <linux/delay.h> /* udelay */
35#include <asm/io.h> /* outb, outb_p */
36#include <asm/uaccess.h> /* copy to/from user */
37#include <linux/videodev2.h> /* kernel radio structs */ 35#include <linux/videodev2.h> /* kernel radio structs */
38#include <media/v4l2-common.h> 36#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>
39#include <media/v4l2-ioctl.h> 40#include <media/v4l2-ioctl.h>
40 41
41#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 42MODULE_AUTHOR("M.Kirkwood");
42#define RADIO_VERSION KERNEL_VERSION(0,0,2) 43MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
44MODULE_LICENSE("GPL");
43 45
44#ifndef CONFIG_RADIO_RTRACK_PORT 46#ifndef CONFIG_RADIO_RTRACK_PORT
45#define CONFIG_RADIO_RTRACK_PORT -1 47#define CONFIG_RADIO_RTRACK_PORT -1
@@ -47,86 +49,95 @@
47 49
48static int io = CONFIG_RADIO_RTRACK_PORT; 50static int io = CONFIG_RADIO_RTRACK_PORT;
49static int radio_nr = -1; 51static int radio_nr = -1;
50static struct mutex lock;
51 52
52struct rt_device 53module_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
53{ 60{
54 unsigned long in_use; 61 struct v4l2_device v4l2_dev;
62 struct video_device vdev;
55 int port; 63 int port;
56 int curvol; 64 int curvol;
57 unsigned long curfreq; 65 unsigned long curfreq;
58 int muted; 66 int muted;
67 int io;
68 struct mutex lock;
59}; 69};
60 70
71static struct rtrack rtrack_card;
61 72
62/* local things */ 73/* local things */
63 74
64static void sleep_delay(long n) 75static void sleep_delay(long n)
65{ 76{
66 /* Sleep nicely for 'n' uS */ 77 /* Sleep nicely for 'n' uS */
67 int d=n/msecs_to_jiffies(1000); 78 int d = n / msecs_to_jiffies(1000);
68 if(!d) 79 if (!d)
69 udelay(n); 80 udelay(n);
70 else 81 else
71 msleep(jiffies_to_msecs(d)); 82 msleep(jiffies_to_msecs(d));
72} 83}
73 84
74static void rt_decvol(void) 85static void rt_decvol(struct rtrack *rt)
75{ 86{
76 outb(0x58, io); /* volume down + sigstr + on */ 87 outb(0x58, rt->io); /* volume down + sigstr + on */
77 sleep_delay(100000); 88 sleep_delay(100000);
78 outb(0xd8, io); /* volume steady + sigstr + on */ 89 outb(0xd8, rt->io); /* volume steady + sigstr + on */
79} 90}
80 91
81static void rt_incvol(void) 92static void rt_incvol(struct rtrack *rt)
82{ 93{
83 outb(0x98, io); /* volume up + sigstr + on */ 94 outb(0x98, rt->io); /* volume up + sigstr + on */
84 sleep_delay(100000); 95 sleep_delay(100000);
85 outb(0xd8, io); /* volume steady + sigstr + on */ 96 outb(0xd8, rt->io); /* volume steady + sigstr + on */
86} 97}
87 98
88static void rt_mute(struct rt_device *dev) 99static void rt_mute(struct rtrack *rt)
89{ 100{
90 dev->muted = 1; 101 rt->muted = 1;
91 mutex_lock(&lock); 102 mutex_lock(&rt->lock);
92 outb(0xd0, io); /* volume steady, off */ 103 outb(0xd0, rt->io); /* volume steady, off */
93 mutex_unlock(&lock); 104 mutex_unlock(&rt->lock);
94} 105}
95 106
96static int rt_setvol(struct rt_device *dev, int vol) 107static int rt_setvol(struct rtrack *rt, int vol)
97{ 108{
98 int i; 109 int i;
99 110
100 mutex_lock(&lock); 111 mutex_lock(&rt->lock);
101 112
102 if(vol == dev->curvol) { /* requested volume = current */ 113 if (vol == rt->curvol) { /* requested volume = current */
103 if (dev->muted) { /* user is unmuting the card */ 114 if (rt->muted) { /* user is unmuting the card */
104 dev->muted = 0; 115 rt->muted = 0;
105 outb (0xd8, io); /* enable card */ 116 outb(0xd8, rt->io); /* enable card */
106 } 117 }
107 mutex_unlock(&lock); 118 mutex_unlock(&rt->lock);
108 return 0; 119 return 0;
109 } 120 }
110 121
111 if(vol == 0) { /* volume = 0 means mute the card */ 122 if (vol == 0) { /* volume = 0 means mute the card */
112 outb(0x48, io); /* volume down but still "on" */ 123 outb(0x48, rt->io); /* volume down but still "on" */
113 sleep_delay(2000000); /* make sure it's totally down */ 124 sleep_delay(2000000); /* make sure it's totally down */
114 outb(0xd0, io); /* volume steady, off */ 125 outb(0xd0, rt->io); /* volume steady, off */
115 dev->curvol = 0; /* track the volume state! */ 126 rt->curvol = 0; /* track the volume state! */
116 mutex_unlock(&lock); 127 mutex_unlock(&rt->lock);
117 return 0; 128 return 0;
118 } 129 }
119 130
120 dev->muted = 0; 131 rt->muted = 0;
121 if(vol > dev->curvol) 132 if (vol > rt->curvol)
122 for(i = dev->curvol; i < vol; i++) 133 for (i = rt->curvol; i < vol; i++)
123 rt_incvol(); 134 rt_incvol(rt);
124 else 135 else
125 for(i = dev->curvol; i > vol; i--) 136 for (i = rt->curvol; i > vol; i--)
126 rt_decvol(); 137 rt_decvol(rt);
127 138
128 dev->curvol = vol; 139 rt->curvol = vol;
129 mutex_unlock(&lock); 140 mutex_unlock(&rt->lock);
130 return 0; 141 return 0;
131} 142}
132 143
@@ -135,155 +146,137 @@ static int rt_setvol(struct rt_device *dev, int vol)
135 * and bit 4 (+16) is to keep the signal strength meter enabled 146 * and bit 4 (+16) is to keep the signal strength meter enabled
136 */ 147 */
137 148
138static void send_0_byte(int port, struct rt_device *dev) 149static void send_0_byte(struct rtrack *rt)
139{ 150{
140 if ((dev->curvol == 0) || (dev->muted)) { 151 if (rt->curvol == 0 || rt->muted) {
141 outb_p(128+64+16+ 1, port); /* wr-enable + data low */ 152 outb_p(128+64+16+ 1, rt->io); /* wr-enable + data low */
142 outb_p(128+64+16+2+1, port); /* clock */ 153 outb_p(128+64+16+2+1, rt->io); /* clock */
143 } 154 }
144 else { 155 else {
145 outb_p(128+64+16+8+ 1, port); /* on + wr-enable + data low */ 156 outb_p(128+64+16+8+ 1, rt->io); /* on + wr-enable + data low */
146 outb_p(128+64+16+8+2+1, port); /* clock */ 157 outb_p(128+64+16+8+2+1, rt->io); /* clock */
147 } 158 }
148 sleep_delay(1000); 159 sleep_delay(1000);
149} 160}
150 161
151static void send_1_byte(int port, struct rt_device *dev) 162static void send_1_byte(struct rtrack *rt)
152{ 163{
153 if ((dev->curvol == 0) || (dev->muted)) { 164 if (rt->curvol == 0 || rt->muted) {
154 outb_p(128+64+16+4 +1, port); /* wr-enable+data high */ 165 outb_p(128+64+16+4 +1, rt->io); /* wr-enable+data high */
155 outb_p(128+64+16+4+2+1, port); /* clock */ 166 outb_p(128+64+16+4+2+1, rt->io); /* clock */
156 } 167 }
157 else { 168 else {
158 outb_p(128+64+16+8+4 +1, port); /* on+wr-enable+data high */ 169 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, port); /* clock */ 170 outb_p(128+64+16+8+4+2+1, rt->io); /* clock */
160 } 171 }
161 172
162 sleep_delay(1000); 173 sleep_delay(1000);
163} 174}
164 175
165static int rt_setfreq(struct rt_device *dev, unsigned long freq) 176static int rt_setfreq(struct rtrack *rt, unsigned long freq)
166{ 177{
167 int i; 178 int i;
168 179
169 /* adapted from radio-aztech.c */ 180 mutex_lock(&rt->lock); /* Stop other ops interfering */
181
182 rt->curfreq = freq;
170 183
171 /* now uses VIDEO_TUNER_LOW for fine tuning */ 184 /* now uses VIDEO_TUNER_LOW for fine tuning */
172 185
173 freq += 171200; /* Add 10.7 MHz IF */ 186 freq += 171200; /* Add 10.7 MHz IF */
174 freq /= 800; /* Convert to 50 kHz units */ 187 freq /= 800; /* Convert to 50 kHz units */
175 188
176 mutex_lock(&lock); /* Stop other ops interfering */ 189 send_0_byte(rt); /* 0: LSB of frequency */
177
178 send_0_byte (io, dev); /* 0: LSB of frequency */
179 190
180 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */ 191 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
181 if (freq & (1 << i)) 192 if (freq & (1 << i))
182 send_1_byte (io, dev); 193 send_1_byte(rt);
183 else 194 else
184 send_0_byte (io, dev); 195 send_0_byte(rt);
185 196
186 send_0_byte (io, dev); /* 14: test bit - always 0 */ 197 send_0_byte(rt); /* 14: test bit - always 0 */
187 send_0_byte (io, dev); /* 15: test bit - always 0 */ 198 send_0_byte(rt); /* 15: test bit - always 0 */
188 199
189 send_0_byte (io, dev); /* 16: band data 0 - always 0 */ 200 send_0_byte(rt); /* 16: band data 0 - always 0 */
190 send_0_byte (io, dev); /* 17: band data 1 - always 0 */ 201 send_0_byte(rt); /* 17: band data 1 - always 0 */
191 send_0_byte (io, dev); /* 18: band data 2 - always 0 */ 202 send_0_byte(rt); /* 18: band data 2 - always 0 */
192 send_0_byte (io, dev); /* 19: time base - always 0 */ 203 send_0_byte(rt); /* 19: time base - always 0 */
193 204
194 send_0_byte (io, dev); /* 20: spacing (0 = 25 kHz) */ 205 send_0_byte(rt); /* 20: spacing (0 = 25 kHz) */
195 send_1_byte (io, dev); /* 21: spacing (1 = 25 kHz) */ 206 send_1_byte(rt); /* 21: spacing (1 = 25 kHz) */
196 send_0_byte (io, dev); /* 22: spacing (0 = 25 kHz) */ 207 send_0_byte(rt); /* 22: spacing (0 = 25 kHz) */
197 send_1_byte (io, dev); /* 23: AM/FM (FM = 1, always) */ 208 send_1_byte(rt); /* 23: AM/FM (FM = 1, always) */
198 209
199 if ((dev->curvol == 0) || (dev->muted)) 210 if (rt->curvol == 0 || rt->muted)
200 outb (0xd0, io); /* volume steady + sigstr */ 211 outb(0xd0, rt->io); /* volume steady + sigstr */
201 else 212 else
202 outb (0xd8, io); /* volume steady + sigstr + on */ 213 outb(0xd8, rt->io); /* volume steady + sigstr + on */
203 214
204 mutex_unlock(&lock); 215 mutex_unlock(&rt->lock);
205 216
206 return 0; 217 return 0;
207} 218}
208 219
209static int rt_getsigstr(struct rt_device *dev) 220static int rt_getsigstr(struct rtrack *rt)
210{ 221{
211 if (inb(io) & 2) /* bit set = no signal present */ 222 int sig = 1;
212 return 0;
213 return 1; /* signal present */
214}
215 223
216static struct v4l2_queryctrl radio_qctrl[] = { 224 mutex_lock(&rt->lock);
217 { 225 if (inb(rt->io) & 2) /* bit set = no signal present */
218 .id = V4L2_CID_AUDIO_MUTE, 226 sig = 0;
219 .name = "Mute", 227 mutex_unlock(&rt->lock);
220 .minimum = 0, 228 return sig;
221 .maximum = 1, 229}
222 .default_value = 1,
223 .type = V4L2_CTRL_TYPE_BOOLEAN,
224 },{
225 .id = V4L2_CID_AUDIO_VOLUME,
226 .name = "Volume",
227 .minimum = 0,
228 .maximum = 0xff,
229 .step = 1,
230 .default_value = 0xff,
231 .type = V4L2_CTRL_TYPE_INTEGER,
232 }
233};
234 230
235static int vidioc_querycap(struct file *file, void *priv, 231static int vidioc_querycap(struct file *file, void *priv,
236 struct v4l2_capability *v) 232 struct v4l2_capability *v)
237{ 233{
238 strlcpy(v->driver, "radio-aimslab", sizeof(v->driver)); 234 strlcpy(v->driver, "radio-aimslab", sizeof(v->driver));
239 strlcpy(v->card, "RadioTrack", sizeof(v->card)); 235 strlcpy(v->card, "RadioTrack", sizeof(v->card));
240 sprintf(v->bus_info, "ISA"); 236 strlcpy(v->bus_info, "ISA", sizeof(v->bus_info));
241 v->version = RADIO_VERSION; 237 v->version = RADIO_VERSION;
242 v->capabilities = V4L2_CAP_TUNER; 238 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
243 return 0; 239 return 0;
244} 240}
245 241
246static int vidioc_g_tuner(struct file *file, void *priv, 242static int vidioc_g_tuner(struct file *file, void *priv,
247 struct v4l2_tuner *v) 243 struct v4l2_tuner *v)
248{ 244{
249 struct rt_device *rt = video_drvdata(file); 245 struct rtrack *rt = video_drvdata(file);
250 246
251 if (v->index > 0) 247 if (v->index > 0)
252 return -EINVAL; 248 return -EINVAL;
253 249
254 strcpy(v->name, "FM"); 250 strlcpy(v->name, "FM", sizeof(v->name));
255 v->type = V4L2_TUNER_RADIO; 251 v->type = V4L2_TUNER_RADIO;
256 v->rangelow = (87*16000); 252 v->rangelow = 87 * 16000;
257 v->rangehigh = (108*16000); 253 v->rangehigh = 108 * 16000;
258 v->rxsubchans = V4L2_TUNER_SUB_MONO; 254 v->rxsubchans = V4L2_TUNER_SUB_MONO;
259 v->capability = V4L2_TUNER_CAP_LOW; 255 v->capability = V4L2_TUNER_CAP_LOW;
260 v->audmode = V4L2_TUNER_MODE_MONO; 256 v->audmode = V4L2_TUNER_MODE_MONO;
261 v->signal = 0xffff*rt_getsigstr(rt); 257 v->signal = 0xffff * rt_getsigstr(rt);
262 return 0; 258 return 0;
263} 259}
264 260
265static int vidioc_s_tuner(struct file *file, void *priv, 261static int vidioc_s_tuner(struct file *file, void *priv,
266 struct v4l2_tuner *v) 262 struct v4l2_tuner *v)
267{ 263{
268 if (v->index > 0) 264 return v->index ? -EINVAL : 0;
269 return -EINVAL;
270 return 0;
271} 265}
272 266
273static int vidioc_s_frequency(struct file *file, void *priv, 267static int vidioc_s_frequency(struct file *file, void *priv,
274 struct v4l2_frequency *f) 268 struct v4l2_frequency *f)
275{ 269{
276 struct rt_device *rt = video_drvdata(file); 270 struct rtrack *rt = video_drvdata(file);
277 271
278 rt->curfreq = f->frequency; 272 rt_setfreq(rt, f->frequency);
279 rt_setfreq(rt, rt->curfreq);
280 return 0; 273 return 0;
281} 274}
282 275
283static int vidioc_g_frequency(struct file *file, void *priv, 276static int vidioc_g_frequency(struct file *file, void *priv,
284 struct v4l2_frequency *f) 277 struct v4l2_frequency *f)
285{ 278{
286 struct rt_device *rt = video_drvdata(file); 279 struct rtrack *rt = video_drvdata(file);
287 280
288 f->type = V4L2_TUNER_RADIO; 281 f->type = V4L2_TUNER_RADIO;
289 f->frequency = rt->curfreq; 282 f->frequency = rt->curfreq;
@@ -293,14 +286,11 @@ static int vidioc_g_frequency(struct file *file, void *priv,
293static int vidioc_queryctrl(struct file *file, void *priv, 286static int vidioc_queryctrl(struct file *file, void *priv,
294 struct v4l2_queryctrl *qc) 287 struct v4l2_queryctrl *qc)
295{ 288{
296 int i; 289 switch (qc->id) {
297 290 case V4L2_CID_AUDIO_MUTE:
298 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 291 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
299 if (qc->id && qc->id == radio_qctrl[i].id) { 292 case V4L2_CID_AUDIO_VOLUME:
300 memcpy(qc, &(radio_qctrl[i]), 293 return v4l2_ctrl_query_fill(qc, 0, 0xff, 1, 0xff);
301 sizeof(*qc));
302 return 0;
303 }
304 } 294 }
305 return -EINVAL; 295 return -EINVAL;
306} 296}
@@ -308,14 +298,14 @@ static int vidioc_queryctrl(struct file *file, void *priv,
308static int vidioc_g_ctrl(struct file *file, void *priv, 298static int vidioc_g_ctrl(struct file *file, void *priv,
309 struct v4l2_control *ctrl) 299 struct v4l2_control *ctrl)
310{ 300{
311 struct rt_device *rt = video_drvdata(file); 301 struct rtrack *rt = video_drvdata(file);
312 302
313 switch (ctrl->id) { 303 switch (ctrl->id) {
314 case V4L2_CID_AUDIO_MUTE: 304 case V4L2_CID_AUDIO_MUTE:
315 ctrl->value = rt->muted; 305 ctrl->value = rt->muted;
316 return 0; 306 return 0;
317 case V4L2_CID_AUDIO_VOLUME: 307 case V4L2_CID_AUDIO_VOLUME:
318 ctrl->value = rt->curvol * 6554; 308 ctrl->value = rt->curvol;
319 return 0; 309 return 0;
320 } 310 }
321 return -EINVAL; 311 return -EINVAL;
@@ -324,33 +314,22 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
324static int vidioc_s_ctrl(struct file *file, void *priv, 314static int vidioc_s_ctrl(struct file *file, void *priv,
325 struct v4l2_control *ctrl) 315 struct v4l2_control *ctrl)
326{ 316{
327 struct rt_device *rt = video_drvdata(file); 317 struct rtrack *rt = video_drvdata(file);
328 318
329 switch (ctrl->id) { 319 switch (ctrl->id) {
330 case V4L2_CID_AUDIO_MUTE: 320 case V4L2_CID_AUDIO_MUTE:
331 if (ctrl->value) 321 if (ctrl->value)
332 rt_mute(rt); 322 rt_mute(rt);
333 else 323 else
334 rt_setvol(rt,rt->curvol); 324 rt_setvol(rt, rt->curvol);
335 return 0; 325 return 0;
336 case V4L2_CID_AUDIO_VOLUME: 326 case V4L2_CID_AUDIO_VOLUME:
337 rt_setvol(rt,ctrl->value); 327 rt_setvol(rt, ctrl->value);
338 return 0; 328 return 0;
339 } 329 }
340 return -EINVAL; 330 return -EINVAL;
341} 331}
342 332
343static int vidioc_g_audio (struct file *file, void *priv,
344 struct v4l2_audio *a)
345{
346 if (a->index > 1)
347 return -EINVAL;
348
349 strcpy(a->name, "Radio");
350 a->capability = V4L2_AUDCAP_STEREO;
351 return 0;
352}
353
354static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i) 333static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
355{ 334{
356 *i = 0; 335 *i = 0;
@@ -359,36 +338,38 @@ static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
359 338
360static int vidioc_s_input(struct file *filp, void *priv, unsigned int i) 339static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
361{ 340{
362 if (i != 0) 341 return i ? -EINVAL : 0;
363 return -EINVAL;
364 return 0;
365} 342}
366 343
367static int vidioc_s_audio(struct file *file, void *priv, 344static int vidioc_g_audio(struct file *file, void *priv,
368 struct v4l2_audio *a) 345 struct v4l2_audio *a)
369{ 346{
370 if (a->index != 0) 347 a->index = 0;
371 return -EINVAL; 348 strlcpy(a->name, "Radio", sizeof(a->name));
349 a->capability = V4L2_AUDCAP_STEREO;
372 return 0; 350 return 0;
373} 351}
374 352
375static struct rt_device rtrack_unit; 353static int vidioc_s_audio(struct file *file, void *priv,
354 struct v4l2_audio *a)
355{
356 return a->index ? -EINVAL : 0;
357}
376 358
377static int rtrack_exclusive_open(struct file *file) 359static int rtrack_open(struct file *file)
378{ 360{
379 return test_and_set_bit(0, &rtrack_unit.in_use) ? -EBUSY : 0; 361 return 0;
380} 362}
381 363
382static int rtrack_exclusive_release(struct file *file) 364static int rtrack_release(struct file *file)
383{ 365{
384 clear_bit(0, &rtrack_unit.in_use);
385 return 0; 366 return 0;
386} 367}
387 368
388static const struct v4l2_file_operations rtrack_fops = { 369static const struct v4l2_file_operations rtrack_fops = {
389 .owner = THIS_MODULE, 370 .owner = THIS_MODULE,
390 .open = rtrack_exclusive_open, 371 .open = rtrack_open,
391 .release = rtrack_exclusive_release, 372 .release = rtrack_release,
392 .ioctl = video_ioctl2, 373 .ioctl = video_ioctl2,
393}; 374};
394 375
@@ -407,64 +388,69 @@ static const struct v4l2_ioctl_ops rtrack_ioctl_ops = {
407 .vidioc_s_ctrl = vidioc_s_ctrl, 388 .vidioc_s_ctrl = vidioc_s_ctrl,
408}; 389};
409 390
410static struct video_device rtrack_radio = {
411 .name = "RadioTrack radio",
412 .fops = &rtrack_fops,
413 .ioctl_ops = &rtrack_ioctl_ops,
414 .release = video_device_release_empty,
415};
416
417static int __init rtrack_init(void) 391static int __init rtrack_init(void)
418{ 392{
419 if(io==-1) 393 struct rtrack *rt = &rtrack_card;
420 { 394 struct v4l2_device *v4l2_dev = &rt->v4l2_dev;
421 printk(KERN_ERR "You must set an I/O address with io=0x???\n"); 395 int res;
396
397 strlcpy(v4l2_dev->name, "rtrack", sizeof(v4l2_dev->name));
398 rt->io = io;
399
400 if (rt->io == -1) {
401 v4l2_err(v4l2_dev, "you must set an I/O address with io=0x???\n");
422 return -EINVAL; 402 return -EINVAL;
423 } 403 }
424 404
425 if (!request_region(io, 2, "rtrack")) 405 if (!request_region(rt->io, 2, "rtrack")) {
426 { 406 v4l2_err(v4l2_dev, "port 0x%x already in use\n", rt->io);
427 printk(KERN_ERR "rtrack: port 0x%x already in use\n", io);
428 return -EBUSY; 407 return -EBUSY;
429 } 408 }
430 409
431 video_set_drvdata(&rtrack_radio, &rtrack_unit); 410 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 }
432 416
433 if (video_register_device(&rtrack_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 417 strlcpy(rt->vdev.name, v4l2_dev->name, sizeof(rt->vdev.name));
434 release_region(io, 2); 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);
435 return -EINVAL; 427 return -EINVAL;
436 } 428 }
437 printk(KERN_INFO "AIMSlab RadioTrack/RadioReveal card driver.\n"); 429 v4l2_info(v4l2_dev, "AIMSlab RadioTrack/RadioReveal card driver.\n");
438 430
439 /* Set up the I/O locking */ 431 /* Set up the I/O locking */
440 432
441 mutex_init(&lock); 433 mutex_init(&rt->lock);
442 434
443 /* mute card - prevents noisy bootups */ 435 /* mute card - prevents noisy bootups */
444 436
445 /* this ensures that the volume is all the way down */ 437 /* this ensures that the volume is all the way down */
446 outb(0x48, io); /* volume down but still "on" */ 438 outb(0x48, rt->io); /* volume down but still "on" */
447 sleep_delay(2000000); /* make sure it's totally down */ 439 sleep_delay(2000000); /* make sure it's totally down */
448 outb(0xc0, io); /* steady volume, mute card */ 440 outb(0xc0, rt->io); /* steady volume, mute card */
449 rtrack_unit.curvol = 0;
450 441
451 return 0; 442 return 0;
452} 443}
453 444
454MODULE_AUTHOR("M.Kirkwood"); 445static void __exit rtrack_exit(void)
455MODULE_DESCRIPTION("A driver for the RadioTrack/RadioReveal radio card.");
456MODULE_LICENSE("GPL");
457
458module_param(io, int, 0);
459MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20f or 0x30f)");
460module_param(radio_nr, int, 0);
461
462static void __exit cleanup_rtrack_module(void)
463{ 446{
464 video_unregister_device(&rtrack_radio); 447 struct rtrack *rt = &rtrack_card;
465 release_region(io,2); 448
449 video_unregister_device(&rt->vdev);
450 v4l2_device_unregister(&rt->v4l2_dev);
451 release_region(rt->io, 2);
466} 452}
467 453
468module_init(rtrack_init); 454module_init(rtrack_init);
469module_exit(cleanup_rtrack_module); 455module_exit(rtrack_exit);
470 456