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
29 #include <linux/module.h> /* Modules */
30 #include <linux/init.h> /* Initdata */
31 #include <linux/ioport.h> /* check_region, request_region */
32 #include <linux/delay.h> /* udelay */
33 #include <asm/io.h> /* outb, outb_p */
34 #include <asm/uaccess.h> /* copy to/from user */
35 #include <linux/videodev.h> /* kernel radio structs */
36 #include <linux/config.h> /* CONFIG_RADIO_ZOLTRIX_PORT */
38 #ifndef CONFIG_RADIO_ZOLTRIX_PORT
39 #define CONFIG_RADIO_ZOLTRIX_PORT -1
42 static int io = CONFIG_RADIO_ZOLTRIX_PORT;
43 static int radio_nr = -1;
48 unsigned long curfreq;
51 struct semaphore lock;
57 static void sleep_delay(void)
59 /* Sleep nicely for +/- 10 mS */
63 static int zol_setvol(struct zol_device *dev, int vol)
73 inb(io + 3); /* Zoltrix needs to be read to confirm */
78 outb(dev->curvol-1, io);
85 static void zol_mute(struct zol_device *dev)
91 inb(io + 3); /* Zoltrix needs to be read to confirm */
95 static void zol_unmute(struct zol_device *dev)
98 zol_setvol(dev, dev->curvol);
101 static int zol_setfreq(struct zol_device *dev, unsigned long freq)
103 /* tunes the radio to the desired frequency */
104 unsigned long long bitmask, f, m;
105 unsigned int stereo = dev->stereo;
110 m = (freq / 160 - 8800) * 2;
111 f = (unsigned long long) m + 0x4d1c;
113 bitmask = 0xc480402c10080000ull;
120 inb(io + 3); /* Zoltrix needs to be read to confirm */
125 bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ ( stereo << 31));
127 if ((bitmask & 0x8000000000000000ull) != 0) {
144 /* termination sequence */
165 zol_setvol(dev, dev->curvol);
170 /* Get signal strength */
172 int zol_getsigstr(struct zol_device *dev)
177 outb(0x00, io); /* This stuff I found to do nothing */
178 outb(dev->curvol, io);
191 if ((a == 0xcf) || (a == 0xdf) /* I found this out by playing */
192 || (a == 0xef)) /* with a binary scanner on the card io */
197 int zol_is_stereo (struct zol_device *dev)
204 outb(dev->curvol, io);
214 if ((x1 == x2) && (x1 == 0xcf))
219 static int zol_do_ioctl(struct inode *inode, struct file *file,
220 unsigned int cmd, void *arg)
222 struct video_device *dev = video_devdata(file);
223 struct zol_device *zol = dev->priv;
228 struct video_capability *v = arg;
230 memset(v,0,sizeof(*v));
231 v->type = VID_TYPE_TUNER;
232 v->channels = 1 + zol->stereo;
234 strcpy(v->name, "Zoltrix Radio");
239 struct video_tuner *v = arg;
242 strcpy(v->name, "FM");
243 v->rangelow = (int) (88.0 * 16000);
244 v->rangehigh = (int) (108.0 * 16000);
245 v->flags = zol_is_stereo(zol)
246 ? VIDEO_TUNER_STEREO_ON : 0;
247 v->flags |= VIDEO_TUNER_LOW;
248 v->mode = VIDEO_MODE_AUTO;
249 v->signal = 0xFFFF * zol_getsigstr(zol);
254 struct video_tuner *v = arg;
257 /* Only 1 tuner so no setting needed ! */
262 unsigned long *freq = arg;
263 *freq = zol->curfreq;
268 unsigned long *freq = arg;
269 zol->curfreq = *freq;
270 zol_setfreq(zol, zol->curfreq);
275 struct video_audio *v = arg;
276 memset(v, 0, sizeof(*v));
277 v->flags |= VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME;
278 v->mode |= zol_is_stereo(zol)
279 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
280 v->volume = zol->curvol * 4096;
282 strcpy(v->name, "Zoltrix Radio");
287 struct video_audio *v = arg;
291 if (v->flags & VIDEO_AUDIO_MUTE)
295 zol_setvol(zol, v->volume / 4096);
298 if (v->mode & VIDEO_SOUND_STEREO) {
300 zol_setfreq(zol, zol->curfreq);
302 if (v->mode & VIDEO_SOUND_MONO) {
304 zol_setfreq(zol, zol->curfreq);
313 static int zol_ioctl(struct inode *inode, struct file *file,
314 unsigned int cmd, unsigned long arg)
316 return video_usercopy(inode, file, cmd, arg, zol_do_ioctl);
319 static struct zol_device zoltrix_unit;
321 static struct file_operations zoltrix_fops =
323 .owner = THIS_MODULE,
324 .open = video_exclusive_open,
325 .release = video_exclusive_release,
330 static struct video_device zoltrix_radio =
332 .owner = THIS_MODULE,
333 .name = "Zoltrix Radio Plus",
334 .type = VID_TYPE_TUNER,
335 .hardware = VID_HARDWARE_ZOLTRIX,
336 .fops = &zoltrix_fops,
339 static int __init zoltrix_init(void)
342 printk(KERN_ERR "You must set an I/O address with io=0x???\n");
345 if ((io != 0x20c) && (io != 0x30c)) {
346 printk(KERN_ERR "zoltrix: invalid port, try 0x20c or 0x30c\n");
350 zoltrix_radio.priv = &zoltrix_unit;
351 if (!request_region(io, 2, "zoltrix")) {
352 printk(KERN_ERR "zoltrix: port 0x%x already in use\n", io);
356 if (video_register_device(&zoltrix_radio, VFL_TYPE_RADIO, radio_nr) == -1)
358 release_region(io, 2);
361 printk(KERN_INFO "Zoltrix Radio Plus card driver.\n");
363 init_MUTEX(&zoltrix_unit.lock);
365 /* mute card - prevents noisy bootups */
367 /* this ensures that the volume is all the way down */
375 zoltrix_unit.curvol = 0;
376 zoltrix_unit.stereo = 1;
381 MODULE_AUTHOR("C.van Schaik");
382 MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
383 MODULE_LICENSE("GPL");
385 MODULE_PARM(io, "i");
386 MODULE_PARM_DESC(io, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
387 MODULE_PARM(radio_nr, "i");
389 static void __exit zoltrix_cleanup_module(void)
391 video_unregister_device(&zoltrix_radio);
392 release_region(io, 2);
395 module_init(zoltrix_init);
396 module_exit(zoltrix_cleanup_module);