1 /* zoltrix radio plus driver for Linux radio support
2 * (c) 1998 C. van Schaik <carl@leg.uct.ac.za>
5 * Due to the inconsistancy 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;
49 unsigned long curfreq;
52 struct semaphore lock;
58 static void sleep_delay(void)
60 /* Sleep nicely for +/- 10 mS */
64 static int zol_setvol(struct zol_device *dev, int vol)
74 inb(io + 3); /* Zoltrix needs to be read to confirm */
79 outb(dev->curvol-1, io);
86 static void zol_mute(struct zol_device *dev)
92 inb(io + 3); /* Zoltrix needs to be read to confirm */
96 static void zol_unmute(struct zol_device *dev)
99 zol_setvol(dev, dev->curvol);
102 static int zol_setfreq(struct zol_device *dev, unsigned long freq)
104 /* tunes the radio to the desired frequency */
105 unsigned long long bitmask, f, m;
106 unsigned int stereo = dev->stereo;
111 m = (freq / 160 - 8800) * 2;
112 f = (unsigned long long) m + 0x4d1c;
114 bitmask = 0xc480402c10080000ull;
121 inb(io + 3); /* Zoltrix needs to be read to confirm */
126 bitmask = (bitmask ^ ((f & 0xff) << 47) ^ ((f & 0xff00) << 30) ^ ( stereo << 31));
128 if ((bitmask & 0x8000000000000000ull) != 0) {
145 /* termination sequence */
166 zol_setvol(dev, dev->curvol);
171 /* Get signal strength */
173 int zol_getsigstr(struct zol_device *dev)
178 outb(0x00, io); /* This stuff I found to do nothing */
179 outb(dev->curvol, io);
192 if ((a == 0xcf) || (a == 0xdf) /* I found this out by playing */
193 || (a == 0xef)) /* with a binary scanner on the card io */
198 int zol_is_stereo (struct zol_device *dev)
205 outb(dev->curvol, io);
215 if ((x1 == x2) && (x1 == 0xcf))
220 static int zol_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
222 struct zol_device *zol = dev->priv;
227 struct video_capability v;
228 v.type = VID_TYPE_TUNER;
229 v.channels = 1 + zol->stereo;
231 /* No we don't do pictures */
236 strcpy(v.name, "Zoltrix Radio");
237 if (copy_to_user(arg, &v, sizeof(v)))
243 struct video_tuner v;
244 if (copy_from_user(&v, arg, sizeof(v)))
248 strcpy(v.name, "FM");
249 v.rangelow = (int) (88.0 * 16000);
250 v.rangehigh = (int) (108.0 * 16000);
251 v.flags = zol_is_stereo(zol)
252 ? VIDEO_TUNER_STEREO_ON : 0;
253 v.flags |= VIDEO_TUNER_LOW;
254 v.mode = VIDEO_MODE_AUTO;
255 v.signal = 0xFFFF * zol_getsigstr(zol);
256 if (copy_to_user(arg, &v, sizeof(v)))
262 struct video_tuner v;
263 if (copy_from_user(&v, arg, sizeof(v)))
267 /* Only 1 tuner so no setting needed ! */
271 if (copy_to_user(arg, &zol->curfreq, sizeof(zol->curfreq)))
275 if (copy_from_user(&zol->curfreq, arg, sizeof(zol->curfreq)))
277 zol_setfreq(zol, zol->curfreq);
281 struct video_audio v;
282 memset(&v, 0, sizeof(v));
283 v.flags |= VIDEO_AUDIO_MUTABLE | VIDEO_AUDIO_VOLUME;
284 v.mode |= zol_is_stereo(zol)
285 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
286 v.volume = zol->curvol * 4096;
288 strcpy(v.name, "Zoltrix Radio");
289 if (copy_to_user(arg, &v, sizeof(v)))
295 struct video_audio v;
296 if (copy_from_user(&v, arg, sizeof(v)))
301 if (v.flags & VIDEO_AUDIO_MUTE)
306 zol_setvol(zol, v.volume / 4096);
309 if (v.mode & VIDEO_SOUND_STEREO)
312 zol_setfreq(zol, zol->curfreq);
314 if (v.mode & VIDEO_SOUND_MONO)
317 zol_setfreq(zol, zol->curfreq);
327 static int zol_open(struct video_device *dev, int flags)
335 static void zol_close(struct video_device *dev)
340 static struct zol_device zoltrix_unit;
342 static struct video_device zoltrix_radio =
345 name: "Zoltrix Radio Plus",
346 type: VID_TYPE_TUNER,
347 hardware: VID_HARDWARE_ZOLTRIX,
353 static int __init zoltrix_init(void)
356 printk(KERN_ERR "You must set an I/O address with io=0x???\n");
359 if ((io != 0x20c) && (io != 0x30c)) {
360 printk(KERN_ERR "zoltrix: invalid port, try 0x20c or 0x30c\n");
364 zoltrix_radio.priv = &zoltrix_unit;
365 if (!request_region(io, 2, "zoltrix")) {
366 printk(KERN_ERR "zoltrix: port 0x%x already in use\n", io);
370 if (video_register_device(&zoltrix_radio, VFL_TYPE_RADIO, radio_nr) == -1)
372 release_region(io, 2);
375 printk(KERN_INFO "Zoltrix Radio Plus card driver.\n");
377 init_MUTEX(&zoltrix_unit.lock);
379 /* mute card - prevents noisy bootups */
381 /* this ensures that the volume is all the way down */
389 zoltrix_unit.curvol = 0;
390 zoltrix_unit.stereo = 1;
395 MODULE_AUTHOR("C.van Schaik");
396 MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
397 MODULE_LICENSE("GPL");
399 MODULE_PARM(io, "i");
400 MODULE_PARM_DESC(io, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
401 MODULE_PARM(radio_nr, "i");
405 static void __exit zoltrix_cleanup_module(void)
407 video_unregister_device(&zoltrix_radio);
408 release_region(io, 2);
411 module_init(zoltrix_init);
412 module_exit(zoltrix_cleanup_module);