1 /* zoltrix radio plus driver for Linux radio support
2 * (c) 1998 C. van Schaik <carl@leg.uct.ac.za>
5 * Due to the inconsistency in reading from the signal flags
6 * it is difficult to get an accurate tuned signal.
8 * It seems that the card is not linear to 0 volume. It cuts off
9 * at a low volume, and it is not possible (at least I have not found)
10 * to get fine volume control over the low volume range.
12 * Some code derived from code by Romolo Manfredini
15 * 1999-05-06 - (C. van Schaik)
16 * - Make signal strength and stereo scans
17 * kinder to cpu while in delay
18 * 1999-01-05 - (C. van Schaik)
19 * - Changed tuning to 1/160Mhz accuracy
20 * - Added stereo support
21 * (card defaults to stereo)
22 * (can explicitly force mono on the card)
23 * (can detect if station is in stereo)
24 * - Added unmute function
25 * - Reworked ioctl functions
26 * 2002-07-15 - Fix Stereo typo
28 * 2006-07-24 - Converted to V4L2 API
29 * by Mauro Carvalho Chehab <mchehab@infradead.org>
32 #include <linux/module.h> /* Modules */
33 #include <linux/init.h> /* Initdata */
34 #include <linux/ioport.h> /* request_region */
35 #include <linux/delay.h> /* udelay, msleep */
36 #include <asm/io.h> /* outb, outb_p */
37 #include <asm/uaccess.h> /* copy to/from user */
38 #include <linux/videodev2.h> /* kernel radio structs */
39 #include <media/v4l2-common.h>
41 #include <linux/version.h> /* for KERNEL_VERSION MACRO */
42 #define RADIO_VERSION KERNEL_VERSION(0,0,2)
44 static struct v4l2_queryctrl radio_qctrl
[] = {
46 .id
= V4L2_CID_AUDIO_MUTE
,
51 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
53 .id
= V4L2_CID_AUDIO_VOLUME
,
58 .default_value
= 0xff,
59 .type
= V4L2_CTRL_TYPE_INTEGER
,
63 #ifndef CONFIG_RADIO_ZOLTRIX_PORT
64 #define CONFIG_RADIO_ZOLTRIX_PORT -1
67 static int io
= CONFIG_RADIO_ZOLTRIX_PORT
;
68 static int radio_nr
= -1;
73 unsigned long curfreq
;
79 static int zol_setvol(struct zol_device
*dev
, int vol
)
85 mutex_lock(&dev
->lock
);
89 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
90 mutex_unlock(&dev
->lock
);
94 outb(dev
->curvol
-1, io
);
97 mutex_unlock(&dev
->lock
);
101 static void zol_mute(struct zol_device
*dev
)
104 mutex_lock(&dev
->lock
);
107 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
108 mutex_unlock(&dev
->lock
);
111 static void zol_unmute(struct zol_device
*dev
)
114 zol_setvol(dev
, dev
->curvol
);
117 static int zol_setfreq(struct zol_device
*dev
, unsigned long freq
)
119 /* tunes the radio to the desired frequency */
120 unsigned long long bitmask
, f
, m
;
121 unsigned int stereo
= dev
->stereo
;
126 m
= (freq
/ 160 - 8800) * 2;
127 f
= (unsigned long long) m
+ 0x4d1c;
129 bitmask
= 0xc480402c10080000ull
;
132 mutex_lock(&dev
->lock
);
136 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
141 bitmask
= (bitmask
^ ((f
& 0xff) << 47) ^ ((f
& 0xff00) << 30) ^ ( stereo
<< 31));
143 if ((bitmask
& 0x8000000000000000ull
) != 0) {
160 /* termination sequence */
177 mutex_unlock(&dev
->lock
);
181 zol_setvol(dev
, dev
->curvol
);
186 /* Get signal strength */
188 static int zol_getsigstr(struct zol_device
*dev
)
192 mutex_lock(&dev
->lock
);
193 outb(0x00, io
); /* This stuff I found to do nothing */
194 outb(dev
->curvol
, io
);
201 mutex_unlock(&dev
->lock
);
206 if ((a
== 0xcf) || (a
== 0xdf) /* I found this out by playing */
207 || (a
== 0xef)) /* with a binary scanner on the card io */
212 static int zol_is_stereo (struct zol_device
*dev
)
216 mutex_lock(&dev
->lock
);
219 outb(dev
->curvol
, io
);
226 mutex_unlock(&dev
->lock
);
228 if ((x1
== x2
) && (x1
== 0xcf))
233 static int vidioc_querycap(struct file
*file
, void *priv
,
234 struct v4l2_capability
*v
)
236 strlcpy(v
->driver
, "radio-zoltrix", sizeof(v
->driver
));
237 strlcpy(v
->card
, "Zoltrix Radio", sizeof(v
->card
));
238 sprintf(v
->bus_info
, "ISA");
239 v
->version
= RADIO_VERSION
;
240 v
->capabilities
= V4L2_CAP_TUNER
;
244 static int vidioc_g_tuner(struct file
*file
, void *priv
,
245 struct v4l2_tuner
*v
)
247 struct video_device
*dev
= video_devdata(file
);
248 struct zol_device
*zol
= dev
->priv
;
253 strcpy(v
->name
, "FM");
254 v
->type
= V4L2_TUNER_RADIO
;
255 v
->rangelow
= (88*16000);
256 v
->rangehigh
= (108*16000);
257 v
->rxsubchans
= V4L2_TUNER_SUB_MONO
|V4L2_TUNER_SUB_STEREO
;
258 v
->capability
= V4L2_TUNER_CAP_LOW
;
259 if (zol_is_stereo(zol
))
260 v
->audmode
= V4L2_TUNER_MODE_STEREO
;
262 v
->audmode
= V4L2_TUNER_MODE_MONO
;
263 v
->signal
= 0xFFFF*zol_getsigstr(zol
);
267 static int vidioc_s_tuner(struct file
*file
, void *priv
,
268 struct v4l2_tuner
*v
)
275 static int vidioc_s_frequency(struct file
*file
, void *priv
,
276 struct v4l2_frequency
*f
)
278 struct video_device
*dev
= video_devdata(file
);
279 struct zol_device
*zol
= dev
->priv
;
281 zol
->curfreq
= f
->frequency
;
282 zol_setfreq(zol
, zol
->curfreq
);
286 static int vidioc_g_frequency(struct file
*file
, void *priv
,
287 struct v4l2_frequency
*f
)
289 struct video_device
*dev
= video_devdata(file
);
290 struct zol_device
*zol
= dev
->priv
;
292 f
->type
= V4L2_TUNER_RADIO
;
293 f
->frequency
= zol
->curfreq
;
297 static int vidioc_queryctrl(struct file
*file
, void *priv
,
298 struct v4l2_queryctrl
*qc
)
302 for (i
= 0; i
< ARRAY_SIZE(radio_qctrl
); i
++) {
303 if (qc
->id
&& qc
->id
== radio_qctrl
[i
].id
) {
304 memcpy(qc
, &(radio_qctrl
[i
]),
312 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
313 struct v4l2_control
*ctrl
)
315 struct video_device
*dev
= video_devdata(file
);
316 struct zol_device
*zol
= dev
->priv
;
319 case V4L2_CID_AUDIO_MUTE
:
320 ctrl
->value
= zol
->muted
;
322 case V4L2_CID_AUDIO_VOLUME
:
323 ctrl
->value
= zol
->curvol
* 4096;
329 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
330 struct v4l2_control
*ctrl
)
332 struct video_device
*dev
= video_devdata(file
);
333 struct zol_device
*zol
= dev
->priv
;
336 case V4L2_CID_AUDIO_MUTE
:
341 zol_setvol(zol
,zol
->curvol
);
344 case V4L2_CID_AUDIO_VOLUME
:
345 zol_setvol(zol
,ctrl
->value
/4096);
349 zol_setfreq(zol
, zol
->curfreq
);
351 /* FIXME: Implement stereo/mono switch on V4L2 */
352 if (v
->mode
& VIDEO_SOUND_STEREO
) {
354 zol_setfreq(zol
, zol
->curfreq
);
356 if (v
->mode
& VIDEO_SOUND_MONO
) {
358 zol_setfreq(zol
, zol
->curfreq
);
364 static int vidioc_g_audio(struct file
*file
, void *priv
,
365 struct v4l2_audio
*a
)
370 strcpy(a
->name
, "Radio");
371 a
->capability
= V4L2_AUDCAP_STEREO
;
375 static int vidioc_g_input(struct file
*filp
, void *priv
, unsigned int *i
)
381 static int vidioc_s_input(struct file
*filp
, void *priv
, unsigned int i
)
388 static int vidioc_s_audio(struct file
*file
, void *priv
,
389 struct v4l2_audio
*a
)
396 static struct zol_device zoltrix_unit
;
398 static const struct file_operations zoltrix_fops
=
400 .owner
= THIS_MODULE
,
401 .open
= video_exclusive_open
,
402 .release
= video_exclusive_release
,
403 .ioctl
= video_ioctl2
,
404 .compat_ioctl
= v4l_compat_ioctl32
,
408 static struct video_device zoltrix_radio
=
410 .owner
= THIS_MODULE
,
411 .name
= "Zoltrix Radio Plus",
412 .type
= VID_TYPE_TUNER
,
414 .fops
= &zoltrix_fops
,
415 .vidioc_querycap
= vidioc_querycap
,
416 .vidioc_g_tuner
= vidioc_g_tuner
,
417 .vidioc_s_tuner
= vidioc_s_tuner
,
418 .vidioc_g_audio
= vidioc_g_audio
,
419 .vidioc_s_audio
= vidioc_s_audio
,
420 .vidioc_g_input
= vidioc_g_input
,
421 .vidioc_s_input
= vidioc_s_input
,
422 .vidioc_g_frequency
= vidioc_g_frequency
,
423 .vidioc_s_frequency
= vidioc_s_frequency
,
424 .vidioc_queryctrl
= vidioc_queryctrl
,
425 .vidioc_g_ctrl
= vidioc_g_ctrl
,
426 .vidioc_s_ctrl
= vidioc_s_ctrl
,
429 static int __init
zoltrix_init(void)
432 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
435 if ((io
!= 0x20c) && (io
!= 0x30c)) {
436 printk(KERN_ERR
"zoltrix: invalid port, try 0x20c or 0x30c\n");
440 zoltrix_radio
.priv
= &zoltrix_unit
;
441 if (!request_region(io
, 2, "zoltrix")) {
442 printk(KERN_ERR
"zoltrix: port 0x%x already in use\n", io
);
446 if (video_register_device(&zoltrix_radio
, VFL_TYPE_RADIO
, radio_nr
) == -1)
448 release_region(io
, 2);
451 printk(KERN_INFO
"Zoltrix Radio Plus card driver.\n");
453 mutex_init(&zoltrix_unit
.lock
);
455 /* mute card - prevents noisy bootups */
457 /* this ensures that the volume is all the way down */
464 zoltrix_unit
.curvol
= 0;
465 zoltrix_unit
.stereo
= 1;
470 MODULE_AUTHOR("C.van Schaik");
471 MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
472 MODULE_LICENSE("GPL");
474 module_param(io
, int, 0);
475 MODULE_PARM_DESC(io
, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
476 module_param(radio_nr
, int, 0);
478 static void __exit
zoltrix_cleanup_module(void)
480 video_unregister_device(&zoltrix_radio
);
481 release_region(io
, 2);
484 module_init(zoltrix_init
);
485 module_exit(zoltrix_cleanup_module
);