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
28 #include <linux/module.h> /* Modules */
29 #include <linux/init.h> /* Initdata */
30 #include <linux/ioport.h> /* check_region, request_region */
31 #include <linux/delay.h> /* udelay */
32 #include <asm/io.h> /* outb, outb_p */
33 #include <asm/uaccess.h> /* copy to/from user */
34 #include <linux/videodev.h> /* kernel radio structs */
35 #include <linux/config.h> /* CONFIG_RADIO_ZOLTRIX_PORT */
37 #ifndef CONFIG_RADIO_ZOLTRIX_PORT
38 #define CONFIG_RADIO_ZOLTRIX_PORT -1
41 static int io
= CONFIG_RADIO_ZOLTRIX_PORT
;
47 unsigned long curfreq
;
50 struct semaphore lock
;
56 static void sleep_delay(void)
58 /* Sleep nicely for +/- 10 mS */
62 static int zol_setvol(struct zol_device
*dev
, int vol
)
72 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
77 outb(dev
->curvol
-1, io
);
84 static void zol_mute(struct zol_device
*dev
)
90 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
94 static void zol_unmute(struct zol_device
*dev
)
97 zol_setvol(dev
, dev
->curvol
);
100 static int zol_setfreq(struct zol_device
*dev
, unsigned long freq
)
102 /* tunes the radio to the desired frequency */
103 unsigned long long bitmask
, f
, m
;
104 unsigned int stereo
= dev
->stereo
;
109 m
= (freq
/ 160 - 8800) * 2;
110 f
= (unsigned long long) m
+ 0x4d1c;
112 bitmask
= 0xc480402c10080000ull
;
119 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
124 bitmask
= (bitmask
^ ((f
& 0xff) << 47) ^ ((f
& 0xff00) << 30) ^ ( stereo
<< 31));
126 if ((bitmask
& 0x8000000000000000ull
) != 0) {
143 /* termination sequence */
164 zol_setvol(dev
, dev
->curvol
);
169 /* Get signal strength */
171 int zol_getsigstr(struct zol_device
*dev
)
176 outb(0x00, io
); /* This stuff I found to do nothing */
177 outb(dev
->curvol
, io
);
190 if ((a
== 0xcf) || (a
== 0xdf) /* I found this out by playing */
191 || (a
== 0xef)) /* with a binary scanner on the card io */
196 int zol_is_stereo (struct zol_device
*dev
)
203 outb(dev
->curvol
, io
);
213 if ((x1
== x2
) && (x1
== 0xcf))
218 static int zol_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
220 struct zol_device
*zol
= dev
->priv
;
225 struct video_capability v
;
226 v
.type
= VID_TYPE_TUNER
;
227 v
.channels
= 1 + zol
->stereo
;
229 /* No we don't do pictures */
234 strcpy(v
.name
, "Zoltrix Radio");
235 if (copy_to_user(arg
, &v
, sizeof(v
)))
241 struct video_tuner v
;
242 if (copy_from_user(&v
, arg
, sizeof(v
)))
246 strcpy(v
.name
, "FM");
247 v
.rangelow
= (int) (88.0 * 16000);
248 v
.rangehigh
= (int) (108.0 * 16000);
249 v
.flags
= zol_is_stereo(zol
)
250 ? VIDEO_TUNER_STEREO_ON
: 0;
251 v
.flags
|= VIDEO_TUNER_LOW
;
252 v
.mode
= VIDEO_MODE_AUTO
;
253 v
.signal
= 0xFFFF * zol_getsigstr(zol
);
254 if (copy_to_user(arg
, &v
, sizeof(v
)))
260 struct video_tuner v
;
261 if (copy_from_user(&v
, arg
, sizeof(v
)))
265 /* Only 1 tuner so no setting needed ! */
269 if (copy_to_user(arg
, &zol
->curfreq
, sizeof(zol
->curfreq
)))
273 if (copy_from_user(&zol
->curfreq
, arg
, sizeof(zol
->curfreq
)))
275 zol_setfreq(zol
, zol
->curfreq
);
279 struct video_audio v
;
280 memset(&v
, 0, sizeof(v
));
281 v
.flags
|= VIDEO_AUDIO_MUTABLE
| VIDEO_AUDIO_VOLUME
;
282 v
.mode
!= zol_is_stereo(zol
)
283 ? VIDEO_SOUND_STEREO
: VIDEO_SOUND_MONO
;
284 v
.volume
= zol
->curvol
* 4096;
286 strcpy(v
.name
, "Zoltrix Radio");
287 if (copy_to_user(arg
, &v
, sizeof(v
)))
293 struct video_audio v
;
294 if (copy_from_user(&v
, arg
, sizeof(v
)))
299 if (v
.flags
& VIDEO_AUDIO_MUTE
)
304 zol_setvol(zol
, v
.volume
/ 4096);
307 if (v
.mode
& VIDEO_SOUND_STEREO
)
310 zol_setfreq(zol
, zol
->curfreq
);
312 if (v
.mode
& VIDEO_SOUND_MONO
)
315 zol_setfreq(zol
, zol
->curfreq
);
325 static int zol_open(struct video_device
*dev
, int flags
)
334 static void zol_close(struct video_device
*dev
)
340 static struct zol_device zoltrix_unit
;
342 static struct video_device zoltrix_radio
=
344 "Zoltrix Radio Plus",
346 VID_HARDWARE_ZOLTRIX
,
349 NULL
, /* Can't read (no capture ability) */
350 NULL
, /* Can't write */
357 static int __init
zoltrix_init(void)
360 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
363 if (check_region(io
, 2)) {
364 printk(KERN_ERR
"zoltrix: port 0x%x already in use\n", io
);
367 if ((io
!= 0x20c) && (io
!= 0x30c)) {
368 printk(KERN_ERR
"zoltrix: invalid port, try 0x20c or 0x30c\n");
371 zoltrix_radio
.priv
= &zoltrix_unit
;
373 if (video_register_device(&zoltrix_radio
, VFL_TYPE_RADIO
) == -1)
376 request_region(io
, 2, "zoltrix");
377 printk(KERN_INFO
"Zoltrix Radio Plus card driver.\n");
379 init_MUTEX(&zoltrix_unit
.lock
);
381 /* mute card - prevents noisy bootups */
383 /* this ensures that the volume is all the way down */
391 zoltrix_unit
.curvol
= 0;
392 zoltrix_unit
.stereo
= 1;
397 MODULE_AUTHOR("C.van Schaik");
398 MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
399 MODULE_PARM(io
, "i");
400 MODULE_PARM_DESC(io
, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
404 static void __exit
zoltrix_cleanup_module(void)
406 video_unregister_device(&zoltrix_radio
);
407 release_region(io
, 2);
410 module_init(zoltrix_init
);
411 module_exit(zoltrix_cleanup_module
);