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> /* request_region */
32 #include <linux/delay.h> /* udelay, msleep */
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
;
54 static int zol_setvol(struct zol_device
*dev
, int vol
)
64 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
69 outb(dev
->curvol
-1, io
);
76 static void zol_mute(struct zol_device
*dev
)
82 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
86 static void zol_unmute(struct zol_device
*dev
)
89 zol_setvol(dev
, dev
->curvol
);
92 static int zol_setfreq(struct zol_device
*dev
, unsigned long freq
)
94 /* tunes the radio to the desired frequency */
95 unsigned long long bitmask
, f
, m
;
96 unsigned int stereo
= dev
->stereo
;
101 m
= (freq
/ 160 - 8800) * 2;
102 f
= (unsigned long long) m
+ 0x4d1c;
104 bitmask
= 0xc480402c10080000ull
;
111 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
116 bitmask
= (bitmask
^ ((f
& 0xff) << 47) ^ ((f
& 0xff00) << 30) ^ ( stereo
<< 31));
118 if ((bitmask
& 0x8000000000000000ull
) != 0) {
135 /* termination sequence */
156 zol_setvol(dev
, dev
->curvol
);
161 /* Get signal strength */
163 static int zol_getsigstr(struct zol_device
*dev
)
168 outb(0x00, io
); /* This stuff I found to do nothing */
169 outb(dev
->curvol
, io
);
181 if ((a
== 0xcf) || (a
== 0xdf) /* I found this out by playing */
182 || (a
== 0xef)) /* with a binary scanner on the card io */
187 static int zol_is_stereo (struct zol_device
*dev
)
194 outb(dev
->curvol
, io
);
203 if ((x1
== x2
) && (x1
== 0xcf))
208 static int zol_do_ioctl(struct inode
*inode
, struct file
*file
,
209 unsigned int cmd
, void *arg
)
211 struct video_device
*dev
= video_devdata(file
);
212 struct zol_device
*zol
= dev
->priv
;
217 struct video_capability
*v
= arg
;
219 memset(v
,0,sizeof(*v
));
220 v
->type
= VID_TYPE_TUNER
;
221 v
->channels
= 1 + zol
->stereo
;
223 strcpy(v
->name
, "Zoltrix Radio");
228 struct video_tuner
*v
= arg
;
231 strcpy(v
->name
, "FM");
232 v
->rangelow
= (int) (88.0 * 16000);
233 v
->rangehigh
= (int) (108.0 * 16000);
234 v
->flags
= zol_is_stereo(zol
)
235 ? VIDEO_TUNER_STEREO_ON
: 0;
236 v
->flags
|= VIDEO_TUNER_LOW
;
237 v
->mode
= VIDEO_MODE_AUTO
;
238 v
->signal
= 0xFFFF * zol_getsigstr(zol
);
243 struct video_tuner
*v
= arg
;
246 /* Only 1 tuner so no setting needed ! */
251 unsigned long *freq
= arg
;
252 *freq
= zol
->curfreq
;
257 unsigned long *freq
= arg
;
258 zol
->curfreq
= *freq
;
259 zol_setfreq(zol
, zol
->curfreq
);
264 struct video_audio
*v
= arg
;
265 memset(v
, 0, sizeof(*v
));
266 v
->flags
|= VIDEO_AUDIO_MUTABLE
| VIDEO_AUDIO_VOLUME
;
267 v
->mode
|= zol_is_stereo(zol
)
268 ? VIDEO_SOUND_STEREO
: VIDEO_SOUND_MONO
;
269 v
->volume
= zol
->curvol
* 4096;
271 strcpy(v
->name
, "Zoltrix Radio");
276 struct video_audio
*v
= arg
;
280 if (v
->flags
& VIDEO_AUDIO_MUTE
)
284 zol_setvol(zol
, v
->volume
/ 4096);
287 if (v
->mode
& VIDEO_SOUND_STEREO
) {
289 zol_setfreq(zol
, zol
->curfreq
);
291 if (v
->mode
& VIDEO_SOUND_MONO
) {
293 zol_setfreq(zol
, zol
->curfreq
);
302 static int zol_ioctl(struct inode
*inode
, struct file
*file
,
303 unsigned int cmd
, unsigned long arg
)
305 return video_usercopy(inode
, file
, cmd
, arg
, zol_do_ioctl
);
308 static struct zol_device zoltrix_unit
;
310 static struct file_operations zoltrix_fops
=
312 .owner
= THIS_MODULE
,
313 .open
= video_exclusive_open
,
314 .release
= video_exclusive_release
,
319 static struct video_device zoltrix_radio
=
321 .owner
= THIS_MODULE
,
322 .name
= "Zoltrix Radio Plus",
323 .type
= VID_TYPE_TUNER
,
324 .hardware
= VID_HARDWARE_ZOLTRIX
,
325 .fops
= &zoltrix_fops
,
328 static int __init
zoltrix_init(void)
331 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
334 if ((io
!= 0x20c) && (io
!= 0x30c)) {
335 printk(KERN_ERR
"zoltrix: invalid port, try 0x20c or 0x30c\n");
339 zoltrix_radio
.priv
= &zoltrix_unit
;
340 if (!request_region(io
, 2, "zoltrix")) {
341 printk(KERN_ERR
"zoltrix: port 0x%x already in use\n", io
);
345 if (video_register_device(&zoltrix_radio
, VFL_TYPE_RADIO
, radio_nr
) == -1)
347 release_region(io
, 2);
350 printk(KERN_INFO
"Zoltrix Radio Plus card driver.\n");
352 init_MUTEX(&zoltrix_unit
.lock
);
354 /* mute card - prevents noisy bootups */
356 /* this ensures that the volume is all the way down */
363 zoltrix_unit
.curvol
= 0;
364 zoltrix_unit
.stereo
= 1;
369 MODULE_AUTHOR("C.van Schaik");
370 MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
371 MODULE_LICENSE("GPL");
373 module_param(io
, int, 0);
374 MODULE_PARM_DESC(io
, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
375 module_param(radio_nr
, int, 0);
377 static void __exit
zoltrix_cleanup_module(void)
379 video_unregister_device(&zoltrix_radio
);
380 release_region(io
, 2);
383 module_init(zoltrix_init
);
384 module_exit(zoltrix_cleanup_module
);