V4L/DVB (4068): Removed all references to kernel stuff from videodev.h and videodev2.h
[deliverable/linux.git] / drivers / media / radio / radio-rtrack2.c
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>
6 *
7 * TODO: Allow for more than one of these foolish entities :-)
8 *
9 */
10
11 #include <linux/module.h> /* Modules */
12 #include <linux/init.h> /* Initdata */
13 #include <linux/ioport.h> /* 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 <media/v4l2-common.h>
19 #include <linux/config.h> /* CONFIG_RADIO_RTRACK2_PORT */
20 #include <linux/spinlock.h>
21
22 #ifndef CONFIG_RADIO_RTRACK2_PORT
23 #define CONFIG_RADIO_RTRACK2_PORT -1
24 #endif
25
26 static int io = CONFIG_RADIO_RTRACK2_PORT;
27 static int radio_nr = -1;
28 static spinlock_t lock;
29
30 struct rt_device
31 {
32 int port;
33 unsigned long curfreq;
34 int muted;
35 };
36
37
38 /* local things */
39
40 static void rt_mute(struct rt_device *dev)
41 {
42 if(dev->muted)
43 return;
44 spin_lock(&lock);
45 outb(1, io);
46 spin_unlock(&lock);
47 dev->muted = 1;
48 }
49
50 static void rt_unmute(struct rt_device *dev)
51 {
52 if(dev->muted == 0)
53 return;
54 spin_lock(&lock);
55 outb(0, io);
56 spin_unlock(&lock);
57 dev->muted = 0;
58 }
59
60 static void zero(void)
61 {
62 outb_p(1, io);
63 outb_p(3, io);
64 outb_p(1, io);
65 }
66
67 static void one(void)
68 {
69 outb_p(5, io);
70 outb_p(7, io);
71 outb_p(5, io);
72 }
73
74 static int rt_setfreq(struct rt_device *dev, unsigned long freq)
75 {
76 int i;
77
78 freq = freq / 200 + 856;
79
80 spin_lock(&lock);
81
82 outb_p(0xc8, io);
83 outb_p(0xc9, io);
84 outb_p(0xc9, io);
85
86 for (i = 0; i < 10; i++)
87 zero ();
88
89 for (i = 14; i >= 0; i--)
90 if (freq & (1 << i))
91 one ();
92 else
93 zero ();
94
95 outb_p(0xc8, io);
96 if (!dev->muted)
97 outb_p(0, io);
98
99 spin_unlock(&lock);
100 return 0;
101 }
102
103 static int rt_getsigstr(struct rt_device *dev)
104 {
105 if (inb(io) & 2) /* bit set = no signal present */
106 return 0;
107 return 1; /* signal present */
108 }
109
110 static int rt_do_ioctl(struct inode *inode, struct file *file,
111 unsigned int cmd, void *arg)
112 {
113 struct video_device *dev = video_devdata(file);
114 struct rt_device *rt=dev->priv;
115
116 switch(cmd)
117 {
118 case VIDIOCGCAP:
119 {
120 struct video_capability *v = arg;
121 memset(v,0,sizeof(*v));
122 v->type=VID_TYPE_TUNER;
123 v->channels=1;
124 v->audios=1;
125 strcpy(v->name, "RadioTrack II");
126 return 0;
127 }
128 case VIDIOCGTUNER:
129 {
130 struct video_tuner *v = arg;
131 if(v->tuner) /* Only 1 tuner */
132 return -EINVAL;
133 v->rangelow=88*16000;
134 v->rangehigh=108*16000;
135 v->flags=VIDEO_TUNER_LOW;
136 v->mode=VIDEO_MODE_AUTO;
137 v->signal=0xFFFF*rt_getsigstr(rt);
138 strcpy(v->name, "FM");
139 return 0;
140 }
141 case VIDIOCSTUNER:
142 {
143 struct video_tuner *v = arg;
144 if(v->tuner!=0)
145 return -EINVAL;
146 /* Only 1 tuner so no setting needed ! */
147 return 0;
148 }
149 case VIDIOCGFREQ:
150 {
151 unsigned long *freq = arg;
152 *freq = rt->curfreq;
153 return 0;
154 }
155 case VIDIOCSFREQ:
156 {
157 unsigned long *freq = arg;
158 rt->curfreq = *freq;
159 rt_setfreq(rt, rt->curfreq);
160 return 0;
161 }
162 case VIDIOCGAUDIO:
163 {
164 struct video_audio *v = arg;
165 memset(v,0, sizeof(*v));
166 v->flags|=VIDEO_AUDIO_MUTABLE;
167 v->volume=1;
168 v->step=65535;
169 strcpy(v->name, "Radio");
170 return 0;
171 }
172 case VIDIOCSAUDIO:
173 {
174 struct video_audio *v = arg;
175 if(v->audio)
176 return -EINVAL;
177
178 if(v->flags&VIDEO_AUDIO_MUTE)
179 rt_mute(rt);
180 else
181 rt_unmute(rt);
182
183 return 0;
184 }
185 default:
186 return -ENOIOCTLCMD;
187 }
188 }
189
190 static int rt_ioctl(struct inode *inode, struct file *file,
191 unsigned int cmd, unsigned long arg)
192 {
193 return video_usercopy(inode, file, cmd, arg, rt_do_ioctl);
194 }
195
196 static struct rt_device rtrack2_unit;
197
198 static struct file_operations rtrack2_fops = {
199 .owner = THIS_MODULE,
200 .open = video_exclusive_open,
201 .release = video_exclusive_release,
202 .ioctl = rt_ioctl,
203 .compat_ioctl = v4l_compat_ioctl32,
204 .llseek = no_llseek,
205 };
206
207 static struct video_device rtrack2_radio=
208 {
209 .owner = THIS_MODULE,
210 .name = "RadioTrack II radio",
211 .type = VID_TYPE_TUNER,
212 .hardware = VID_HARDWARE_RTRACK2,
213 .fops = &rtrack2_fops,
214 };
215
216 static int __init rtrack2_init(void)
217 {
218 if(io==-1)
219 {
220 printk(KERN_ERR "You must set an I/O address with io=0x20c or io=0x30c\n");
221 return -EINVAL;
222 }
223 if (!request_region(io, 4, "rtrack2"))
224 {
225 printk(KERN_ERR "rtrack2: port 0x%x already in use\n", io);
226 return -EBUSY;
227 }
228
229 rtrack2_radio.priv=&rtrack2_unit;
230
231 spin_lock_init(&lock);
232 if(video_register_device(&rtrack2_radio, VFL_TYPE_RADIO, radio_nr)==-1)
233 {
234 release_region(io, 4);
235 return -EINVAL;
236 }
237
238 printk(KERN_INFO "AIMSlab Radiotrack II card driver.\n");
239
240 /* mute card - prevents noisy bootups */
241 outb(1, io);
242 rtrack2_unit.muted = 1;
243
244 return 0;
245 }
246
247 MODULE_AUTHOR("Ben Pfaff");
248 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
249 MODULE_LICENSE("GPL");
250
251 module_param(io, int, 0);
252 MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20c or 0x30c)");
253 module_param(radio_nr, int, 0);
254
255 static void __exit rtrack2_cleanup_module(void)
256 {
257 video_unregister_device(&rtrack2_radio);
258 release_region(io,4);
259 }
260
261 module_init(rtrack2_init);
262 module_exit(rtrack2_cleanup_module);
263
264 /*
265 Local variables:
266 compile-command: "mmake"
267 End:
268 */
This page took 0.039922 seconds and 6 git commands to generate.