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
;
55 static void sleep_delay(void)
57 /* Sleep nicely for +/- 10 mS */
61 static int zol_setvol(struct zol_device
*dev
, int vol
)
70 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
74 outb(dev
->curvol
-1, io
);
81 static void zol_mute(struct zol_device
*dev
)
86 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
89 static void zol_unmute(struct zol_device
*dev
)
92 zol_setvol(dev
, dev
->curvol
);
95 static int zol_setfreq(struct zol_device
*dev
, unsigned long freq
)
97 /* tunes the radio to the desired frequency */
98 unsigned long long bitmask
, f
, m
;
99 unsigned int stereo
= dev
->stereo
;
104 m
= (freq
/ 160 - 8800) * 2;
105 f
= (unsigned long long) m
+ 0x4d1c;
107 bitmask
= 0xc480402c10080000ull
;
112 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
117 bitmask
= (bitmask
^ ((f
& 0xff) << 47) ^ ((f
& 0xff00) << 30) ^ ( stereo
<< 31));
119 if ((bitmask
& 0x8000000000000000ull
) != 0) {
136 /* termination sequence */
151 zol_setvol(dev
, dev
->curvol
);
155 /* Get signal strength */
157 int zol_getsigstr(struct zol_device
*dev
)
161 outb(0x00, io
); /* This stuff I found to do nothing */
162 outb(dev
->curvol
, io
);
173 if ((a
== 0xcf) || (a
== 0xdf) /* I found this out by playing */
174 || (a
== 0xef)) /* with a binary scanner on the card io */
179 int zol_is_stereo (struct zol_device
*dev
)
184 outb(dev
->curvol
, io
);
192 if ((x1
== x2
) && (x1
== 0xcf))
197 static int zol_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
199 struct zol_device
*zol
= dev
->priv
;
204 struct video_capability v
;
205 v
.type
= VID_TYPE_TUNER
;
206 v
.channels
= 1 + zol
->stereo
;
208 /* No we don't do pictures */
213 strcpy(v
.name
, "Zoltrix Radio");
214 if (copy_to_user(arg
, &v
, sizeof(v
)))
220 struct video_tuner v
;
221 if (copy_from_user(&v
, arg
, sizeof(v
)))
225 strcpy(v
.name
, "FM");
226 v
.rangelow
= (int) (88.0 * 16000);
227 v
.rangehigh
= (int) (108.0 * 16000);
228 v
.flags
= zol_is_stereo(zol
)
229 ? VIDEO_TUNER_STEREO_ON
: 0;
230 v
.flags
|= VIDEO_TUNER_LOW
;
231 v
.mode
= VIDEO_MODE_AUTO
;
232 v
.signal
= 0xFFFF * zol_getsigstr(zol
);
233 if (copy_to_user(arg
, &v
, sizeof(v
)))
239 struct video_tuner v
;
240 if (copy_from_user(&v
, arg
, sizeof(v
)))
244 /* Only 1 tuner so no setting needed ! */
248 if (copy_to_user(arg
, &zol
->curfreq
, sizeof(zol
->curfreq
)))
252 if (copy_from_user(&zol
->curfreq
, arg
, sizeof(zol
->curfreq
)))
254 zol_setfreq(zol
, zol
->curfreq
);
258 struct video_audio v
;
259 memset(&v
, 0, sizeof(v
));
260 v
.flags
|= VIDEO_AUDIO_MUTABLE
| VIDEO_AUDIO_VOLUME
;
261 v
.mode
!= zol_is_stereo(zol
)
262 ? VIDEO_SOUND_STEREO
: VIDEO_SOUND_MONO
;
263 v
.volume
= zol
->curvol
* 4096;
265 strcpy(v
.name
, "Zoltrix Radio");
266 if (copy_to_user(arg
, &v
, sizeof(v
)))
272 struct video_audio v
;
273 if (copy_from_user(&v
, arg
, sizeof(v
)))
278 if (v
.flags
& VIDEO_AUDIO_MUTE
)
283 zol_setvol(zol
, v
.volume
/ 4096);
286 if (v
.mode
& VIDEO_SOUND_STEREO
)
289 zol_setfreq(zol
, zol
->curfreq
);
291 if (v
.mode
& VIDEO_SOUND_MONO
)
294 zol_setfreq(zol
, zol
->curfreq
);
304 static int zol_open(struct video_device
*dev
, int flags
)
313 static void zol_close(struct video_device
*dev
)
319 static struct zol_device zoltrix_unit
;
321 static struct video_device zoltrix_radio
=
323 "Zoltrix Radio Plus",
325 VID_HARDWARE_ZOLTRIX
,
328 NULL
, /* Can't read (no capture ability) */
329 NULL
, /* Can't write */
336 __initfunc(int zoltrix_init(struct video_init
*v
))
338 if (check_region(io
, 2)) {
339 printk(KERN_ERR
"zoltrix: port 0x%x already in use\n", io
);
342 if ((io
!= 0x20c) && (io
!= 0x30c)) {
343 printk(KERN_ERR
"zoltrix: invalid port, try 0x20c or 0x30c\n");
346 zoltrix_radio
.priv
= &zoltrix_unit
;
348 if (video_register_device(&zoltrix_radio
, VFL_TYPE_RADIO
) == -1)
351 request_region(io
, 2, "zoltrix");
352 printk(KERN_INFO
"Zoltrix Radio Plus card driver.\n");
354 /* mute card - prevents noisy bootups */
356 /* this ensures that the volume is all the way down */
364 zoltrix_unit
.curvol
= 0;
365 zoltrix_unit
.stereo
= 1;
372 MODULE_AUTHOR("C.van Schaik");
373 MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
374 MODULE_PARM(io
, "i");
375 MODULE_PARM_DESC(io
, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
379 int init_module(void)
382 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
385 return zoltrix_init(NULL
);
388 void cleanup_module(void)
390 video_unregister_device(&zoltrix_radio
);
391 release_region(io
, 2);