[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / media / radio / radio-rtrack2.c
blobc00245d4d24900a59d90eb1e3ab54aaa51eca2b2
1 /* RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff
2 *
3 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
4 * Converted to new API by Alan Cox <Alan.Cox@linux.org>
5 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
7 * TODO: Allow for more than one of these foolish entities :-)
9 */
11 #include <linux/module.h> /* Modules */
12 #include <linux/init.h> /* Initdata */
13 #include <linux/ioport.h> /* check_region, request_region */
14 #include <linux/delay.h> /* udelay */
15 #include <asm/io.h> /* outb, outb_p */
16 #include <asm/uaccess.h> /* copy to/from user */
17 #include <linux/videodev.h> /* kernel radio structs */
18 #include <linux/config.h> /* CONFIG_RADIO_RTRACK2_PORT */
19 #include <linux/spinlock.h>
21 #ifndef CONFIG_RADIO_RTRACK2_PORT
22 #define CONFIG_RADIO_RTRACK2_PORT -1
23 #endif
25 static int io = CONFIG_RADIO_RTRACK2_PORT;
26 static int radio_nr = -1;
27 static spinlock_t lock;
29 struct rt_device
31 int port;
32 unsigned long curfreq;
33 int muted;
37 /* local things */
39 static void rt_mute(struct rt_device *dev)
41 if(dev->muted)
42 return;
43 spin_lock(&lock);
44 outb(1, io);
45 spin_unlock(&lock);
46 dev->muted = 1;
49 static void rt_unmute(struct rt_device *dev)
51 if(dev->muted == 0)
52 return;
53 spin_lock(&lock);
54 outb(0, io);
55 spin_unlock(&lock);
56 dev->muted = 0;
59 static void zero(void)
61 outb_p(1, io);
62 outb_p(3, io);
63 outb_p(1, io);
66 static void one(void)
68 outb_p(5, io);
69 outb_p(7, io);
70 outb_p(5, io);
73 static int rt_setfreq(struct rt_device *dev, unsigned long freq)
75 int i;
77 freq = freq / 200 + 856;
79 spin_lock(&lock);
81 outb_p(0xc8, io);
82 outb_p(0xc9, io);
83 outb_p(0xc9, io);
85 for (i = 0; i < 10; i++)
86 zero ();
88 for (i = 14; i >= 0; i--)
89 if (freq & (1 << i))
90 one ();
91 else
92 zero ();
94 outb_p(0xc8, io);
95 if (!dev->muted)
96 outb_p(0, io);
98 spin_unlock(&lock);
99 return 0;
102 static int rt_getsigstr(struct rt_device *dev)
104 if (inb(io) & 2) /* bit set = no signal present */
105 return 0;
106 return 1; /* signal present */
109 static int rt_do_ioctl(struct inode *inode, struct file *file,
110 unsigned int cmd, void *arg)
112 struct video_device *dev = video_devdata(file);
113 struct rt_device *rt=dev->priv;
115 switch(cmd)
117 case VIDIOCGCAP:
119 struct video_capability *v = arg;
120 memset(v,0,sizeof(*v));
121 v->type=VID_TYPE_TUNER;
122 v->channels=1;
123 v->audios=1;
124 strcpy(v->name, "RadioTrack II");
125 return 0;
127 case VIDIOCGTUNER:
129 struct video_tuner *v = arg;
130 if(v->tuner) /* Only 1 tuner */
131 return -EINVAL;
132 v->rangelow=88*16000;
133 v->rangehigh=108*16000;
134 v->flags=VIDEO_TUNER_LOW;
135 v->mode=VIDEO_MODE_AUTO;
136 v->signal=0xFFFF*rt_getsigstr(rt);
137 strcpy(v->name, "FM");
138 return 0;
140 case VIDIOCSTUNER:
142 struct video_tuner *v = arg;
143 if(v->tuner!=0)
144 return -EINVAL;
145 /* Only 1 tuner so no setting needed ! */
146 return 0;
148 case VIDIOCGFREQ:
150 unsigned long *freq = arg;
151 *freq = rt->curfreq;
152 return 0;
154 case VIDIOCSFREQ:
156 unsigned long *freq = arg;
157 rt->curfreq = *freq;
158 rt_setfreq(rt, rt->curfreq);
159 return 0;
161 case VIDIOCGAUDIO:
163 struct video_audio *v = arg;
164 memset(v,0, sizeof(*v));
165 v->flags|=VIDEO_AUDIO_MUTABLE;
166 v->volume=1;
167 v->step=65535;
168 strcpy(v->name, "Radio");
169 return 0;
171 case VIDIOCSAUDIO:
173 struct video_audio *v = arg;
174 if(v->audio)
175 return -EINVAL;
177 if(v->flags&VIDEO_AUDIO_MUTE)
178 rt_mute(rt);
179 else
180 rt_unmute(rt);
182 return 0;
184 default:
185 return -ENOIOCTLCMD;
189 static int rt_ioctl(struct inode *inode, struct file *file,
190 unsigned int cmd, unsigned long arg)
192 return video_usercopy(inode, file, cmd, arg, rt_do_ioctl);
195 static struct rt_device rtrack2_unit;
197 static struct file_operations rtrack2_fops = {
198 .owner = THIS_MODULE,
199 .open = video_exclusive_open,
200 .release = video_exclusive_release,
201 .ioctl = rt_ioctl,
202 .llseek = no_llseek,
205 static struct video_device rtrack2_radio=
207 .owner = THIS_MODULE,
208 .name = "RadioTrack II radio",
209 .type = VID_TYPE_TUNER,
210 .hardware = VID_HARDWARE_RTRACK2,
211 .fops = &rtrack2_fops,
214 static int __init rtrack2_init(void)
216 if(io==-1)
218 printk(KERN_ERR "You must set an I/O address with io=0x20c or io=0x30c\n");
219 return -EINVAL;
221 if (!request_region(io, 4, "rtrack2"))
223 printk(KERN_ERR "rtrack2: port 0x%x already in use\n", io);
224 return -EBUSY;
227 rtrack2_radio.priv=&rtrack2_unit;
229 spin_lock_init(&lock);
230 if(video_register_device(&rtrack2_radio, VFL_TYPE_RADIO, radio_nr)==-1)
232 release_region(io, 4);
233 return -EINVAL;
236 printk(KERN_INFO "AIMSlab Radiotrack II card driver.\n");
238 /* mute card - prevents noisy bootups */
239 outb(1, io);
240 rtrack2_unit.muted = 1;
242 return 0;
245 MODULE_AUTHOR("Ben Pfaff");
246 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
247 MODULE_LICENSE("GPL");
249 module_param(io, int, 0);
250 MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20c or 0x30c)");
251 module_param(radio_nr, int, 0);
253 static void __exit rtrack2_cleanup_module(void)
255 video_unregister_device(&rtrack2_radio);
256 release_region(io,4);
259 module_init(rtrack2_init);
260 module_exit(rtrack2_cleanup_module);
263 Local variables:
264 compile-command: "mmake"
265 End: