Commit | Line | Data |
---|---|---|
fdcfd4e7 HV |
1 | /* |
2 | * Miro PCM20 radio driver for Linux radio support | |
8366fc39 KH |
3 | * (c) 1998 Ruurd Reitsma <R.A.Reitsma@wbmt.tudelft.nl> |
4 | * Thanks to Norberto Pellici for the ACI device interface specification | |
5 | * The API part is based on the radiotrack driver by M. Kirkwood | |
6 | * This driver relies on the aci mixer provided by the snd-miro | |
7 | * ALSA driver. | |
8 | * Look there for further info... | |
fdcfd4e7 HV |
9 | * |
10 | * From the original miro RDS sources: | |
11 | * | |
12 | * (c) 2001 Robert Siemer <Robert.Siemer@gmx.de> | |
13 | * | |
14 | * Many thanks to Fred Seidel <seidel@metabox.de>, the | |
15 | * designer of the RDS decoder hardware. With his help | |
16 | * I was able to code this driver. | |
17 | * Thanks also to Norberto Pellicci, Dominic Mounteney | |
18 | * <DMounteney@pinnaclesys.com> and www.teleauskunft.de | |
19 | * for good hints on finding Fred. It was somewhat hard | |
20 | * to locate him here in Germany... [: | |
21 | * | |
22 | * This code has been reintroduced and converted to use | |
23 | * the new V4L2 RDS API by: | |
24 | * | |
25 | * Hans Verkuil <hans.verkuil@cisco.com> | |
8366fc39 KH |
26 | */ |
27 | ||
28 | #include <linux/module.h> | |
29 | #include <linux/init.h> | |
fdcfd4e7 | 30 | #include <linux/delay.h> |
8366fc39 | 31 | #include <linux/videodev2.h> |
fdcfd4e7 | 32 | #include <linux/kthread.h> |
8366fc39 KH |
33 | #include <media/v4l2-device.h> |
34 | #include <media/v4l2-ioctl.h> | |
7f51a610 | 35 | #include <media/v4l2-ctrls.h> |
f7c096f7 HV |
36 | #include <media/v4l2-fh.h> |
37 | #include <media/v4l2-event.h> | |
8366fc39 KH |
38 | #include <sound/aci.h> |
39 | ||
fdcfd4e7 HV |
40 | #define RDS_DATASHIFT 2 /* Bit 2 */ |
41 | #define RDS_DATAMASK (1 << RDS_DATASHIFT) | |
42 | #define RDS_BUSYMASK 0x10 /* Bit 4 */ | |
43 | #define RDS_CLOCKMASK 0x08 /* Bit 3 */ | |
44 | #define RDS_DATA(x) (((x) >> RDS_DATASHIFT) & 1) | |
45 | ||
46 | #define RDS_STATUS 0x01 | |
47 | #define RDS_STATIONNAME 0x02 | |
48 | #define RDS_TEXT 0x03 | |
49 | #define RDS_ALTFREQ 0x04 | |
50 | #define RDS_TIMEDATE 0x05 | |
51 | #define RDS_PI_CODE 0x06 | |
52 | #define RDS_PTYTATP 0x07 | |
53 | #define RDS_RESET 0x08 | |
54 | #define RDS_RXVALUE 0x09 | |
55 | ||
8366fc39 KH |
56 | static int radio_nr = -1; |
57 | module_param(radio_nr, int, 0); | |
58 | MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)"); | |
59 | ||
8366fc39 KH |
60 | struct pcm20 { |
61 | struct v4l2_device v4l2_dev; | |
62 | struct video_device vdev; | |
7f51a610 | 63 | struct v4l2_ctrl_handler ctrl_handler; |
fdcfd4e7 HV |
64 | struct v4l2_ctrl *rds_pty; |
65 | struct v4l2_ctrl *rds_ps_name; | |
66 | struct v4l2_ctrl *rds_radio_test; | |
67 | struct v4l2_ctrl *rds_ta; | |
68 | struct v4l2_ctrl *rds_tp; | |
69 | struct v4l2_ctrl *rds_ms; | |
70 | /* thread for periodic RDS status checking */ | |
71 | struct task_struct *kthread; | |
8366fc39 | 72 | unsigned long freq; |
f5e7cc4a | 73 | u32 audmode; |
8366fc39 | 74 | struct snd_miro_aci *aci; |
32958fdd | 75 | struct mutex lock; |
8366fc39 KH |
76 | }; |
77 | ||
78 | static struct pcm20 pcm20_card = { | |
f5e7cc4a HV |
79 | .freq = 87 * 16000, |
80 | .audmode = V4L2_TUNER_MODE_STEREO, | |
8366fc39 KH |
81 | }; |
82 | ||
fdcfd4e7 HV |
83 | |
84 | static int rds_waitread(struct snd_miro_aci *aci) | |
85 | { | |
86 | u8 byte; | |
87 | int i = 2000; | |
88 | ||
89 | do { | |
90 | byte = inb(aci->aci_port + ACI_REG_RDS); | |
91 | i--; | |
92 | } while ((byte & RDS_BUSYMASK) && i); | |
93 | ||
94 | /* | |
95 | * It's magic, but without this the data that you read later on | |
96 | * is unreliable and full of bit errors. With this 1 usec delay | |
97 | * everything is fine. | |
98 | */ | |
99 | udelay(1); | |
100 | return i ? byte : -1; | |
101 | } | |
102 | ||
103 | static int rds_rawwrite(struct snd_miro_aci *aci, u8 byte) | |
104 | { | |
105 | if (rds_waitread(aci) >= 0) { | |
106 | outb(byte, aci->aci_port + ACI_REG_RDS); | |
107 | return 0; | |
108 | } | |
109 | return -1; | |
110 | } | |
111 | ||
112 | static int rds_write(struct snd_miro_aci *aci, u8 byte) | |
113 | { | |
114 | u8 sendbuffer[8]; | |
115 | int i; | |
116 | ||
117 | for (i = 7; i >= 0; i--) | |
118 | sendbuffer[7 - i] = (byte & (1 << i)) ? RDS_DATAMASK : 0; | |
119 | sendbuffer[0] |= RDS_CLOCKMASK; | |
120 | ||
121 | for (i = 0; i < 8; i++) | |
122 | rds_rawwrite(aci, sendbuffer[i]); | |
123 | return 0; | |
124 | } | |
125 | ||
126 | static int rds_readcycle_nowait(struct snd_miro_aci *aci) | |
127 | { | |
128 | outb(0, aci->aci_port + ACI_REG_RDS); | |
129 | return rds_waitread(aci); | |
130 | } | |
131 | ||
132 | static int rds_readcycle(struct snd_miro_aci *aci) | |
133 | { | |
134 | if (rds_rawwrite(aci, 0) < 0) | |
135 | return -1; | |
136 | return rds_waitread(aci); | |
137 | } | |
138 | ||
139 | static int rds_ack(struct snd_miro_aci *aci) | |
140 | { | |
141 | int i = rds_readcycle(aci); | |
142 | ||
143 | if (i < 0) | |
144 | return -1; | |
145 | if (i & RDS_DATAMASK) | |
146 | return 0; /* ACK */ | |
147 | return 1; /* NACK */ | |
148 | } | |
149 | ||
150 | static int rds_cmd(struct snd_miro_aci *aci, u8 cmd, u8 databuffer[], u8 datasize) | |
151 | { | |
152 | int i, j; | |
153 | ||
154 | rds_write(aci, cmd); | |
155 | ||
156 | /* RDS_RESET doesn't need further processing */ | |
157 | if (cmd == RDS_RESET) | |
158 | return 0; | |
159 | if (rds_ack(aci)) | |
160 | return -EIO; | |
161 | if (datasize == 0) | |
162 | return 0; | |
163 | ||
164 | /* to be able to use rds_readcycle_nowait() | |
165 | I have to waitread() here */ | |
166 | if (rds_waitread(aci) < 0) | |
167 | return -1; | |
168 | ||
169 | memset(databuffer, 0, datasize); | |
170 | ||
171 | for (i = 0; i < 8 * datasize; i++) { | |
172 | j = rds_readcycle_nowait(aci); | |
173 | if (j < 0) | |
174 | return -EIO; | |
175 | databuffer[i / 8] |= RDS_DATA(j) << (7 - (i % 8)); | |
176 | } | |
177 | return 0; | |
178 | } | |
179 | ||
8366fc39 KH |
180 | static int pcm20_setfreq(struct pcm20 *dev, unsigned long freq) |
181 | { | |
182 | unsigned char freql; | |
183 | unsigned char freqh; | |
184 | struct snd_miro_aci *aci = dev->aci; | |
185 | ||
8366fc39 KH |
186 | freq /= 160; |
187 | if (!(aci->aci_version == 0x07 || aci->aci_version >= 0xb0)) | |
188 | freq /= 10; /* I don't know exactly which version | |
189 | * needs this hack */ | |
190 | freql = freq & 0xff; | |
191 | freqh = freq >> 8; | |
192 | ||
fdcfd4e7 | 193 | rds_cmd(aci, RDS_RESET, 0, 0); |
8366fc39 KH |
194 | return snd_aci_cmd(aci, ACI_WRITE_TUNE, freql, freqh); |
195 | } | |
196 | ||
8366fc39 KH |
197 | static int vidioc_querycap(struct file *file, void *priv, |
198 | struct v4l2_capability *v) | |
199 | { | |
f122d9a8 HV |
200 | struct pcm20 *dev = video_drvdata(file); |
201 | ||
8366fc39 KH |
202 | strlcpy(v->driver, "Miro PCM20", sizeof(v->driver)); |
203 | strlcpy(v->card, "Miro PCM20", sizeof(v->card)); | |
f122d9a8 | 204 | snprintf(v->bus_info, sizeof(v->bus_info), "ISA:%s", dev->v4l2_dev.name); |
fdcfd4e7 | 205 | v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO | V4L2_CAP_RDS_CAPTURE; |
f122d9a8 | 206 | v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS; |
8366fc39 KH |
207 | return 0; |
208 | } | |
209 | ||
fdcfd4e7 HV |
210 | static bool sanitize(char *p, int size) |
211 | { | |
212 | int i; | |
213 | bool ret = true; | |
214 | ||
215 | for (i = 0; i < size; i++) { | |
216 | if (p[i] < 32 || p[i] >= 128) { | |
217 | p[i] = ' '; | |
218 | ret = false; | |
219 | } | |
220 | } | |
221 | return ret; | |
222 | } | |
223 | ||
8366fc39 KH |
224 | static int vidioc_g_tuner(struct file *file, void *priv, |
225 | struct v4l2_tuner *v) | |
226 | { | |
f5e7cc4a | 227 | struct pcm20 *dev = video_drvdata(file); |
9bbc5820 | 228 | int res; |
fdcfd4e7 | 229 | u8 buf; |
f5e7cc4a HV |
230 | |
231 | if (v->index) | |
8366fc39 KH |
232 | return -EINVAL; |
233 | strlcpy(v->name, "FM", sizeof(v->name)); | |
234 | v->type = V4L2_TUNER_RADIO; | |
235 | v->rangelow = 87*16000; | |
236 | v->rangehigh = 108*16000; | |
9bbc5820 HV |
237 | res = snd_aci_cmd(dev->aci, ACI_READ_TUNERSTATION, -1, -1); |
238 | v->signal = (res & 0x80) ? 0 : 0xffff; | |
239 | /* Note: stereo detection does not work if the audio is muted, | |
240 | it will default to mono in that case. */ | |
241 | res = snd_aci_cmd(dev->aci, ACI_READ_TUNERSTEREO, -1, -1); | |
242 | v->rxsubchans = (res & 0x40) ? V4L2_TUNER_SUB_MONO : | |
243 | V4L2_TUNER_SUB_STEREO; | |
fdcfd4e7 HV |
244 | v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO | |
245 | V4L2_TUNER_CAP_RDS | V4L2_TUNER_CAP_RDS_CONTROLS; | |
f5e7cc4a | 246 | v->audmode = dev->audmode; |
fdcfd4e7 HV |
247 | res = rds_cmd(dev->aci, RDS_RXVALUE, &buf, 1); |
248 | if (res >= 0 && buf) | |
249 | v->rxsubchans |= V4L2_TUNER_SUB_RDS; | |
8366fc39 KH |
250 | return 0; |
251 | } | |
252 | ||
253 | static int vidioc_s_tuner(struct file *file, void *priv, | |
2f73c7c5 | 254 | const struct v4l2_tuner *v) |
8366fc39 | 255 | { |
f5e7cc4a HV |
256 | struct pcm20 *dev = video_drvdata(file); |
257 | ||
258 | if (v->index) | |
259 | return -EINVAL; | |
260 | if (v->audmode > V4L2_TUNER_MODE_STEREO) | |
2f73c7c5 HV |
261 | dev->audmode = V4L2_TUNER_MODE_STEREO; |
262 | else | |
263 | dev->audmode = v->audmode; | |
f5e7cc4a | 264 | snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO, |
2f73c7c5 | 265 | dev->audmode == V4L2_TUNER_MODE_MONO, -1); |
f5e7cc4a | 266 | return 0; |
8366fc39 KH |
267 | } |
268 | ||
269 | static int vidioc_g_frequency(struct file *file, void *priv, | |
270 | struct v4l2_frequency *f) | |
271 | { | |
272 | struct pcm20 *dev = video_drvdata(file); | |
273 | ||
274 | if (f->tuner != 0) | |
275 | return -EINVAL; | |
276 | ||
277 | f->type = V4L2_TUNER_RADIO; | |
278 | f->frequency = dev->freq; | |
279 | return 0; | |
280 | } | |
281 | ||
282 | ||
283 | static int vidioc_s_frequency(struct file *file, void *priv, | |
b530a447 | 284 | const struct v4l2_frequency *f) |
8366fc39 KH |
285 | { |
286 | struct pcm20 *dev = video_drvdata(file); | |
287 | ||
288 | if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO) | |
289 | return -EINVAL; | |
290 | ||
b530a447 | 291 | dev->freq = clamp_t(u32, f->frequency, 87 * 16000U, 108 * 16000U); |
f5e7cc4a | 292 | pcm20_setfreq(dev, dev->freq); |
8366fc39 KH |
293 | return 0; |
294 | } | |
295 | ||
7f51a610 | 296 | static int pcm20_s_ctrl(struct v4l2_ctrl *ctrl) |
8366fc39 | 297 | { |
7f51a610 | 298 | struct pcm20 *dev = container_of(ctrl->handler, struct pcm20, ctrl_handler); |
8366fc39 KH |
299 | |
300 | switch (ctrl->id) { | |
301 | case V4L2_CID_AUDIO_MUTE: | |
f5e7cc4a | 302 | snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, ctrl->val, -1); |
7f51a610 | 303 | return 0; |
8366fc39 | 304 | } |
7f51a610 | 305 | return -EINVAL; |
8366fc39 KH |
306 | } |
307 | ||
fdcfd4e7 HV |
308 | static int pcm20_thread(void *data) |
309 | { | |
310 | struct pcm20 *dev = data; | |
311 | const unsigned no_rds_start_counter = 5; | |
312 | const unsigned sleep_msecs = 2000; | |
313 | unsigned no_rds_counter = no_rds_start_counter; | |
314 | ||
315 | for (;;) { | |
316 | char text_buffer[66]; | |
317 | u8 buf; | |
318 | int res; | |
319 | ||
320 | msleep_interruptible(sleep_msecs); | |
321 | ||
322 | if (kthread_should_stop()) | |
323 | break; | |
324 | ||
325 | res = rds_cmd(dev->aci, RDS_RXVALUE, &buf, 1); | |
326 | if (res) | |
327 | continue; | |
328 | if (buf == 0) { | |
329 | if (no_rds_counter == 0) | |
330 | continue; | |
331 | no_rds_counter--; | |
332 | if (no_rds_counter) | |
333 | continue; | |
334 | ||
335 | /* | |
336 | * No RDS seen for no_rds_start_counter * sleep_msecs | |
337 | * milliseconds, clear all RDS controls to their | |
338 | * default values. | |
339 | */ | |
340 | v4l2_ctrl_s_ctrl_string(dev->rds_ps_name, ""); | |
341 | v4l2_ctrl_s_ctrl(dev->rds_ms, 1); | |
342 | v4l2_ctrl_s_ctrl(dev->rds_ta, 0); | |
343 | v4l2_ctrl_s_ctrl(dev->rds_tp, 0); | |
344 | v4l2_ctrl_s_ctrl(dev->rds_pty, 0); | |
345 | v4l2_ctrl_s_ctrl_string(dev->rds_radio_test, ""); | |
346 | continue; | |
347 | } | |
348 | no_rds_counter = no_rds_start_counter; | |
349 | ||
350 | res = rds_cmd(dev->aci, RDS_STATUS, &buf, 1); | |
351 | if (res) | |
352 | continue; | |
353 | if ((buf >> 3) & 1) { | |
354 | res = rds_cmd(dev->aci, RDS_STATIONNAME, text_buffer, 8); | |
355 | text_buffer[8] = 0; | |
356 | if (!res && sanitize(text_buffer, 8)) | |
357 | v4l2_ctrl_s_ctrl_string(dev->rds_ps_name, text_buffer); | |
358 | } | |
359 | if ((buf >> 6) & 1) { | |
360 | u8 pty; | |
361 | ||
362 | res = rds_cmd(dev->aci, RDS_PTYTATP, &pty, 1); | |
363 | if (!res) { | |
364 | v4l2_ctrl_s_ctrl(dev->rds_ms, !!(pty & 0x01)); | |
365 | v4l2_ctrl_s_ctrl(dev->rds_ta, !!(pty & 0x02)); | |
366 | v4l2_ctrl_s_ctrl(dev->rds_tp, !!(pty & 0x80)); | |
367 | v4l2_ctrl_s_ctrl(dev->rds_pty, (pty >> 2) & 0x1f); | |
368 | } | |
369 | } | |
370 | if ((buf >> 4) & 1) { | |
371 | res = rds_cmd(dev->aci, RDS_TEXT, text_buffer, 65); | |
372 | text_buffer[65] = 0; | |
373 | if (!res && sanitize(text_buffer + 1, 64)) | |
374 | v4l2_ctrl_s_ctrl_string(dev->rds_radio_test, text_buffer + 1); | |
375 | } | |
376 | } | |
377 | return 0; | |
378 | } | |
379 | ||
380 | static int pcm20_open(struct file *file) | |
381 | { | |
382 | struct pcm20 *dev = video_drvdata(file); | |
383 | int res = v4l2_fh_open(file); | |
384 | ||
385 | if (!res && v4l2_fh_is_singular_file(file) && | |
386 | IS_ERR_OR_NULL(dev->kthread)) { | |
387 | dev->kthread = kthread_run(pcm20_thread, dev, "%s", | |
388 | dev->v4l2_dev.name); | |
389 | if (IS_ERR(dev->kthread)) { | |
390 | v4l2_err(&dev->v4l2_dev, "kernel_thread() failed\n"); | |
391 | v4l2_fh_release(file); | |
392 | return PTR_ERR(dev->kthread); | |
393 | } | |
394 | } | |
395 | return res; | |
396 | } | |
397 | ||
398 | static int pcm20_release(struct file *file) | |
399 | { | |
400 | struct pcm20 *dev = video_drvdata(file); | |
401 | ||
402 | if (v4l2_fh_is_singular_file(file) && !IS_ERR_OR_NULL(dev->kthread)) { | |
403 | kthread_stop(dev->kthread); | |
404 | dev->kthread = NULL; | |
405 | } | |
406 | return v4l2_fh_release(file); | |
407 | } | |
408 | ||
409 | static const struct v4l2_file_operations pcm20_fops = { | |
410 | .owner = THIS_MODULE, | |
411 | .open = pcm20_open, | |
412 | .poll = v4l2_ctrl_poll, | |
413 | .release = pcm20_release, | |
414 | .unlocked_ioctl = video_ioctl2, | |
415 | }; | |
416 | ||
8366fc39 KH |
417 | static const struct v4l2_ioctl_ops pcm20_ioctl_ops = { |
418 | .vidioc_querycap = vidioc_querycap, | |
419 | .vidioc_g_tuner = vidioc_g_tuner, | |
420 | .vidioc_s_tuner = vidioc_s_tuner, | |
421 | .vidioc_g_frequency = vidioc_g_frequency, | |
422 | .vidioc_s_frequency = vidioc_s_frequency, | |
f7c096f7 HV |
423 | .vidioc_log_status = v4l2_ctrl_log_status, |
424 | .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, | |
425 | .vidioc_unsubscribe_event = v4l2_event_unsubscribe, | |
7f51a610 HV |
426 | }; |
427 | ||
428 | static const struct v4l2_ctrl_ops pcm20_ctrl_ops = { | |
429 | .s_ctrl = pcm20_s_ctrl, | |
8366fc39 KH |
430 | }; |
431 | ||
432 | static int __init pcm20_init(void) | |
433 | { | |
434 | struct pcm20 *dev = &pcm20_card; | |
435 | struct v4l2_device *v4l2_dev = &dev->v4l2_dev; | |
7f51a610 | 436 | struct v4l2_ctrl_handler *hdl; |
8366fc39 KH |
437 | int res; |
438 | ||
439 | dev->aci = snd_aci_get_aci(); | |
440 | if (dev->aci == NULL) { | |
441 | v4l2_err(v4l2_dev, | |
442 | "you must load the snd-miro driver first!\n"); | |
443 | return -ENODEV; | |
444 | } | |
f122d9a8 | 445 | strlcpy(v4l2_dev->name, "radio-miropcm20", sizeof(v4l2_dev->name)); |
32958fdd | 446 | mutex_init(&dev->lock); |
8366fc39 KH |
447 | |
448 | res = v4l2_device_register(NULL, v4l2_dev); | |
449 | if (res < 0) { | |
450 | v4l2_err(v4l2_dev, "could not register v4l2_device\n"); | |
451 | return -EINVAL; | |
452 | } | |
453 | ||
7f51a610 | 454 | hdl = &dev->ctrl_handler; |
fdcfd4e7 | 455 | v4l2_ctrl_handler_init(hdl, 7); |
7f51a610 HV |
456 | v4l2_ctrl_new_std(hdl, &pcm20_ctrl_ops, |
457 | V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1); | |
fdcfd4e7 HV |
458 | dev->rds_pty = v4l2_ctrl_new_std(hdl, NULL, |
459 | V4L2_CID_RDS_RX_PTY, 0, 0x1f, 1, 0); | |
460 | dev->rds_ps_name = v4l2_ctrl_new_std(hdl, NULL, | |
461 | V4L2_CID_RDS_RX_PS_NAME, 0, 8, 8, 0); | |
462 | dev->rds_radio_test = v4l2_ctrl_new_std(hdl, NULL, | |
463 | V4L2_CID_RDS_RX_RADIO_TEXT, 0, 64, 64, 0); | |
464 | dev->rds_ta = v4l2_ctrl_new_std(hdl, NULL, | |
465 | V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT, 0, 1, 1, 0); | |
466 | dev->rds_tp = v4l2_ctrl_new_std(hdl, NULL, | |
467 | V4L2_CID_RDS_RX_TRAFFIC_PROGRAM, 0, 1, 1, 0); | |
468 | dev->rds_ms = v4l2_ctrl_new_std(hdl, NULL, | |
469 | V4L2_CID_RDS_RX_MUSIC_SPEECH, 0, 1, 1, 1); | |
7f51a610 HV |
470 | v4l2_dev->ctrl_handler = hdl; |
471 | if (hdl->error) { | |
472 | res = hdl->error; | |
473 | v4l2_err(v4l2_dev, "Could not register control\n"); | |
474 | goto err_hdl; | |
475 | } | |
8366fc39 KH |
476 | strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name)); |
477 | dev->vdev.v4l2_dev = v4l2_dev; | |
478 | dev->vdev.fops = &pcm20_fops; | |
479 | dev->vdev.ioctl_ops = &pcm20_ioctl_ops; | |
480 | dev->vdev.release = video_device_release_empty; | |
32958fdd | 481 | dev->vdev.lock = &dev->lock; |
8366fc39 | 482 | video_set_drvdata(&dev->vdev, dev); |
f5e7cc4a HV |
483 | snd_aci_cmd(dev->aci, ACI_SET_TUNERMONO, |
484 | dev->audmode == V4L2_TUNER_MODE_MONO, -1); | |
485 | pcm20_setfreq(dev, dev->freq); | |
8366fc39 KH |
486 | |
487 | if (video_register_device(&dev->vdev, VFL_TYPE_RADIO, radio_nr) < 0) | |
7f51a610 | 488 | goto err_hdl; |
8366fc39 KH |
489 | |
490 | v4l2_info(v4l2_dev, "Mirosound PCM20 Radio tuner\n"); | |
491 | return 0; | |
7f51a610 HV |
492 | err_hdl: |
493 | v4l2_ctrl_handler_free(hdl); | |
8366fc39 KH |
494 | v4l2_device_unregister(v4l2_dev); |
495 | return -EINVAL; | |
496 | } | |
497 | ||
498 | MODULE_AUTHOR("Ruurd Reitsma, Krzysztof Helt"); | |
499 | MODULE_DESCRIPTION("A driver for the Miro PCM20 radio card."); | |
500 | MODULE_LICENSE("GPL"); | |
501 | ||
502 | static void __exit pcm20_cleanup(void) | |
503 | { | |
504 | struct pcm20 *dev = &pcm20_card; | |
505 | ||
506 | video_unregister_device(&dev->vdev); | |
f5e7cc4a | 507 | snd_aci_cmd(dev->aci, ACI_SET_TUNERMUTE, 1, -1); |
7f51a610 | 508 | v4l2_ctrl_handler_free(&dev->ctrl_handler); |
8366fc39 KH |
509 | v4l2_device_unregister(&dev->v4l2_dev); |
510 | } | |
511 | ||
512 | module_init(pcm20_init); | |
513 | module_exit(pcm20_cleanup); |