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 * There seems to be a problem with the volume setting that I must still
10 * It seems that the card has is not linear to 0 volume. It cuts off
11 * at a low frequency, and it is not possible (at least I have not found)
12 * to get fine volume control over the low volume range.
14 * Some code derived from code by Frans Brinkman
16 * 1999-01-05 - (C. van Schaik)
17 * - Changed tuning to 1/160Mhz accuracy
18 * - Added stereo support
19 * (card defaults to stereo)
20 * (can explicitly force mono on the card)
21 * (can detect if station is in stereo)
22 * - Added unmute function
23 * - Reworked ioctl functions
26 #include <linux/module.h> /* Modules */
27 #include <linux/init.h> /* Initdata */
28 #include <linux/ioport.h> /* check_region, request_region */
29 #include <linux/delay.h> /* udelay */
30 #include <asm/io.h> /* outb, outb_p */
31 #include <asm/uaccess.h> /* copy to/from user */
32 #include <linux/videodev.h> /* kernel radio structs */
33 #include <linux/config.h> /* CONFIG_RADIO_ZOLTRIX_PORT */
35 #ifndef CONFIG_RADIO_ZOLTRIX_PORT
36 #define CONFIG_RADIO_ZOLTRIX_PORT -1
39 static int io
= CONFIG_RADIO_ZOLTRIX_PORT
;
45 unsigned long curfreq
;
53 static void sleep_delay(long n
)
55 /* Sleep nicely for 'n' uS */
56 int d
= n
/ (1000000 / HZ
);
61 unsigned long x
= jiffies
;
62 while ((jiffies
- x
) <= d
)
67 static int zol_setvol(struct zol_device
*dev
, int vol
)
76 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
80 outb(dev
->curvol
-1, io
);
87 static void zol_mute(struct zol_device
*dev
)
92 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
;
118 inb(io
+ 3); /* Zoltrix needs to be read to confirm */
123 bitmask
= (bitmask
^ ((f
& 0xff) << 47) ^ ((f
& 0xff00) << 30) ^ ( stereo
<< 31));
125 if ((bitmask
& 0x8000000000000000ull
) != 0) {
142 /* termination sequence */
157 zol_setvol(dev
, dev
->curvol
);
161 /* Get signal strength */
163 int zol_getsigstr(struct zol_device
*dev
)
167 outb(0x00, io
); /* This stuff I found to do nothing */
168 outb(dev
->curvol
, io
);
178 if ((a
== 0xcf) || (a
== 0xdf) /* I found this out by playing */
179 || (a
== 0xef)) /* with a binary scanner on the card io */
184 int zol_is_stereo (struct zol_device
*dev
)
189 outb(dev
->curvol
, io
);
196 if ((x1
== x2
) && (x1
== 0xcf))
201 static int zol_ioctl(struct video_device
*dev
, unsigned int cmd
, void *arg
)
203 struct zol_device
*zol
= dev
->priv
;
208 struct video_capability v
;
209 v
.type
= VID_TYPE_TUNER
;
210 v
.channels
= 1 + zol
->stereo
;
212 /* No we don't do pictures */
217 strcpy(v
.name
, "Zoltrix Radio");
218 if (copy_to_user(arg
, &v
, sizeof(v
)))
224 struct video_tuner v
;
226 if (copy_from_user(&v, arg, sizeof(v)))
232 strcpy(v
.name
, "Zoltrix Radio");
233 v
.rangelow
= (int) (88.0 * 16000);
234 v
.rangehigh
= (int) (108.0 * 16000);
235 v
.flags
= zol_is_stereo(zol
)
236 ? VIDEO_TUNER_STEREO_ON
: 0;
237 v
.flags
|= VIDEO_TUNER_LOW
;
238 v
.mode
= VIDEO_MODE_AUTO
;
239 v
.signal
= 0xFFFF * zol_getsigstr(zol
);
240 if (copy_to_user(arg
, &v
, sizeof(v
)))
246 struct video_tuner v
;
247 if (copy_from_user(&v
, arg
, sizeof(v
)))
251 /* Only 1 tuner so no setting needed ! */
255 if (copy_to_user(arg
, &zol
->curfreq
, sizeof(zol
->curfreq
)))
259 if (copy_from_user(&zol
->curfreq
, arg
, sizeof(zol
->curfreq
)))
261 zol_setfreq(zol
, zol
->curfreq
);
265 struct video_audio v
;
266 memset(&v
, 0, sizeof(v
));
267 v
.flags
|= VIDEO_AUDIO_MUTABLE
| VIDEO_AUDIO_VOLUME
;
268 v
.mode
!= zol_is_stereo(zol
)
269 ? VIDEO_SOUND_STEREO
: VIDEO_SOUND_MONO
;
270 v
.volume
= zol
->curvol
* 4096;
272 strcpy(v
.name
, "Zoltrix Radio");
273 if (copy_to_user(arg
, &v
, sizeof(v
)))
279 struct video_audio v
;
280 if (copy_from_user(&v
, arg
, sizeof(v
)))
285 if (v
.flags
& VIDEO_AUDIO_MUTE
)
290 if (v
.flags
& VIDEO_AUDIO_VOLUME
)
291 zol_setvol(zol
, v
.volume
/ 4096);
293 if (v
.mode
& VIDEO_SOUND_STEREO
)
296 zol_setfreq(zol
, zol
->curfreq
);
298 if (v
.mode
& VIDEO_SOUND_MONO
)
301 zol_setfreq(zol
, zol
->curfreq
);
311 static int zol_open(struct video_device
*dev
, int flags
)
320 static void zol_close(struct video_device
*dev
)
326 static struct zol_device zoltrix_unit
;
328 static struct video_device zoltrix_radio
=
330 "Zoltrix Radio Plus",
332 VID_HARDWARE_ZOLTRIX
,
335 NULL
, /* Can't read (no capture ability) */
336 NULL
, /* Can't write */
343 __initfunc(int zoltrix_init(struct video_init
*v
))
345 if (check_region(io
, 2)) {
346 printk(KERN_ERR
"zoltrix: port 0x%x already in use\n", io
);
349 if ((io
!= 0x20c) && (io
!= 0x30c)) {
350 printk(KERN_ERR
"zoltrix: invalid port, try 0x20c or 0x30c\n");
353 zoltrix_radio
.priv
= &zoltrix_unit
;
355 if (video_register_device(&zoltrix_radio
, VFL_TYPE_RADIO
) == -1)
358 request_region(io
, 2, "zoltrix");
359 printk(KERN_INFO
"Zoltrix Radio Plus card driver.\n");
361 /* mute card - prevents noisy bootups */
363 /* this ensures that the volume is all the way down */
370 zoltrix_unit
.curvol
= 0;
371 zoltrix_unit
.stereo
= 1;
378 MODULE_AUTHOR("C.van Schaik");
379 MODULE_DESCRIPTION("A driver for the Zoltrix Radio Plus.");
380 MODULE_PARM(io
, "i");
381 MODULE_PARM_DESC(io
, "I/O address of the Zoltrix Radio Plus (0x20c or 0x30c)");
385 int init_module(void)
388 printk(KERN_ERR
"You must set an I/O address with io=0x???\n");
391 return zoltrix_init(NULL
);
394 void cleanup_module(void)
396 video_unregister_device(&zoltrix_radio
);
397 release_region(io
, 2);