1 /* radio-aztech.c - Aztech radio card driver for Linux 2.2
3 * Adapted to support the Video for Linux API by
4 * Russell Kroll <rkroll@exploits.org>. Based on original tuner code by:
8 * Jason Lewis (jlewis@twilight.vtc.vsc.edu)
9 * Scott McGrath (smcgrath@twilight.vtc.vsc.edu)
10 * William McGrath (wmcgrath@twilight.vtc.vsc.edu)
12 * The basis for this code may be found at http://bigbang.vtc.vsc.edu/fmradio/
13 * along with more information on the card itself.
16 * 1999-02-24 Russell Kroll <rkroll@exploits.org>
17 * Fine tuning/VIDEO_TUNER_LOW
18 * Range expanded to 87-108 MHz (from 87.9-107.8)
20 * Notable changes from the original source:
21 * - includes stripped down to the essentials
22 * - for loops used as delays replaced with udelay()
23 * - #defines removed, changed to static values
24 * - tuning structure changed - no more character arrays, other changes
27 #include <linux/module.h> /* Modules */
28 #include <linux/init.h> /* Initdata */
29 #include <linux/ioport.h> /* request_region */
30 #include <linux/delay.h> /* udelay */
31 #include <asm/io.h> /* outb, outb_p */
32 #include <asm/uaccess.h> /* copy to/from user */
33 #include <linux/videodev.h> /* kernel radio structs */
34 #include <media/v4l2-common.h>
35 #include <linux/config.h> /* CONFIG_RADIO_AZTECH_PORT */
37 /* acceptable ports: 0x350 (JP3 shorted), 0x358 (JP3 open) */
39 #ifndef CONFIG_RADIO_AZTECH_PORT
40 #define CONFIG_RADIO_AZTECH_PORT -1
43 static int io = CONFIG_RADIO_AZTECH_PORT;
44 static int radio_nr = -1;
45 static int radio_wait_time = 1000;
46 static struct mutex lock;
51 unsigned long curfreq;
55 static int volconvert(int level)
57 level>>=14; /* Map 16bits down to 2 bit */
60 /* convert to card-friendly values */
72 return 0; /* Quieten gcc */
75 static void send_0_byte (struct az_device *dev)
77 udelay(radio_wait_time);
78 outb_p(2+volconvert(dev->curvol), io);
79 outb_p(64+2+volconvert(dev->curvol), io);
82 static void send_1_byte (struct az_device *dev)
84 udelay (radio_wait_time);
85 outb_p(128+2+volconvert(dev->curvol), io);
86 outb_p(128+64+2+volconvert(dev->curvol), io);
89 static int az_setvol(struct az_device *dev, int vol)
92 outb (volconvert(vol), io);
97 /* thanks to Michael Dwyer for giving me a dose of clues in
98 * the signal strength department..
100 * This card has a stereo bit - bit 0 set = mono, not set = stereo
101 * It also has a "signal" bit - bit 1 set = bad signal, not set = good
105 static int az_getsigstr(struct az_device *dev)
107 if (inb(io) & 2) /* bit set = no signal present */
109 return 1; /* signal present */
112 static int az_getstereo(struct az_device *dev)
114 if (inb(io) & 1) /* bit set = mono */
116 return 1; /* stereo */
119 static int az_setfreq(struct az_device *dev, unsigned long frequency)
123 frequency += 171200; /* Add 10.7 MHz IF */
124 frequency /= 800; /* Convert to 50 kHz units */
128 send_0_byte (dev); /* 0: LSB of frequency */
130 for (i = 0; i < 13; i++) /* : frequency bits (1-13) */
131 if (frequency & (1 << i))
136 send_0_byte (dev); /* 14: test bit - always 0 */
137 send_0_byte (dev); /* 15: test bit - always 0 */
138 send_0_byte (dev); /* 16: band data 0 - always 0 */
139 if (dev->stereo) /* 17: stereo (1 to enable) */
144 send_1_byte (dev); /* 18: band data 1 - unknown */
145 send_0_byte (dev); /* 19: time base - always 0 */
146 send_0_byte (dev); /* 20: spacing (0 = 25 kHz) */
147 send_1_byte (dev); /* 21: spacing (1 = 25 kHz) */
148 send_0_byte (dev); /* 22: spacing (0 = 25 kHz) */
149 send_1_byte (dev); /* 23: AM/FM (FM = 1, always) */
151 /* latch frequency */
153 udelay (radio_wait_time);
154 outb_p(128+64+volconvert(dev->curvol), io);
161 static int az_do_ioctl(struct inode *inode, struct file *file,
162 unsigned int cmd, void *arg)
164 struct video_device *dev = video_devdata(file);
165 struct az_device *az = dev->priv;
171 struct video_capability *v = arg;
172 memset(v,0,sizeof(*v));
173 v->type=VID_TYPE_TUNER;
176 strcpy(v->name, "Aztech Radio");
181 struct video_tuner *v = arg;
182 if(v->tuner) /* Only 1 tuner */
184 v->rangelow=(87*16000);
185 v->rangehigh=(108*16000);
186 v->flags=VIDEO_TUNER_LOW;
187 v->mode=VIDEO_MODE_AUTO;
188 v->signal=0xFFFF*az_getsigstr(az);
190 v->flags|=VIDEO_TUNER_STEREO_ON;
191 strcpy(v->name, "FM");
196 struct video_tuner *v = arg;
203 unsigned long *freq = arg;
209 unsigned long *freq = arg;
211 az_setfreq(az, az->curfreq);
216 struct video_audio *v = arg;
217 memset(v,0, sizeof(*v));
218 v->flags|=VIDEO_AUDIO_MUTABLE|VIDEO_AUDIO_VOLUME;
220 v->mode=VIDEO_SOUND_STEREO;
222 v->mode=VIDEO_SOUND_MONO;
223 v->volume=az->curvol;
225 strcpy(v->name, "Radio");
230 struct video_audio *v = arg;
233 az->curvol=v->volume;
235 az->stereo=(v->mode&VIDEO_SOUND_STEREO)?1:0;
236 if(v->flags&VIDEO_AUDIO_MUTE)
239 az_setvol(az,az->curvol);
247 static int az_ioctl(struct inode *inode, struct file *file,
248 unsigned int cmd, unsigned long arg)
250 return video_usercopy(inode, file, cmd, arg, az_do_ioctl);
253 static struct az_device aztech_unit;
255 static struct file_operations aztech_fops = {
256 .owner = THIS_MODULE,
257 .open = video_exclusive_open,
258 .release = video_exclusive_release,
260 .compat_ioctl = v4l_compat_ioctl32,
264 static struct video_device aztech_radio=
266 .owner = THIS_MODULE,
267 .name = "Aztech radio",
268 .type = VID_TYPE_TUNER,
269 .hardware = VID_HARDWARE_AZTECH,
270 .fops = &aztech_fops,
273 static int __init aztech_init(void)
277 printk(KERN_ERR "You must set an I/O address with io=0x???\n");
281 if (!request_region(io, 2, "aztech"))
283 printk(KERN_ERR "aztech: port 0x%x already in use\n", io);
288 aztech_radio.priv=&aztech_unit;
290 if(video_register_device(&aztech_radio, VFL_TYPE_RADIO, radio_nr)==-1)
292 release_region(io,2);
296 printk(KERN_INFO "Aztech radio card driver v1.00/19990224 rkroll@exploits.org\n");
297 /* mute card - prevents noisy bootups */
302 MODULE_AUTHOR("Russell Kroll, Quay Lu, Donald Song, Jason Lewis, Scott McGrath, William McGrath");
303 MODULE_DESCRIPTION("A driver for the Aztech radio card.");
304 MODULE_LICENSE("GPL");
306 module_param(io, int, 0);
307 module_param(radio_nr, int, 0);
308 MODULE_PARM_DESC(io, "I/O address of the Aztech card (0x350 or 0x358)");
310 static void __exit aztech_cleanup(void)
312 video_unregister_device(&aztech_radio);
313 release_region(io,2);
316 module_init(aztech_init);
317 module_exit(aztech_cleanup);