V4L/DVB (8433): Fix macro name at z0194a.h
[deliverable/linux.git] / drivers / media / radio / radio-rtrack2.c
CommitLineData
1da177e4 1/* RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff
4286c6f6 2 *
1da177e4
LT
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 *
f8c559f8 9 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
1da177e4
LT
10 */
11
12#include <linux/module.h> /* Modules */
13#include <linux/init.h> /* Initdata */
fb911ee8 14#include <linux/ioport.h> /* request_region */
1da177e4
LT
15#include <linux/delay.h> /* udelay */
16#include <asm/io.h> /* outb, outb_p */
17#include <asm/uaccess.h> /* copy to/from user */
f8c559f8 18#include <linux/videodev2.h> /* kernel radio structs */
5e87efa3 19#include <media/v4l2-common.h>
1da177e4
LT
20#include <linux/spinlock.h>
21
f8c559f8
MCC
22#include <linux/version.h> /* for KERNEL_VERSION MACRO */
23#define RADIO_VERSION KERNEL_VERSION(0,0,2)
24
25static struct v4l2_queryctrl radio_qctrl[] = {
26 {
27 .id = V4L2_CID_AUDIO_MUTE,
28 .name = "Mute",
29 .minimum = 0,
30 .maximum = 1,
31 .default_value = 1,
32 .type = V4L2_CTRL_TYPE_BOOLEAN,
33 },{
34 .id = V4L2_CID_AUDIO_VOLUME,
35 .name = "Volume",
36 .minimum = 0,
37 .maximum = 65535,
38 .step = 65535,
39 .default_value = 0xff,
40 .type = V4L2_CTRL_TYPE_INTEGER,
41 }
42};
43
1da177e4
LT
44#ifndef CONFIG_RADIO_RTRACK2_PORT
45#define CONFIG_RADIO_RTRACK2_PORT -1
46#endif
47
4286c6f6 48static int io = CONFIG_RADIO_RTRACK2_PORT;
1da177e4
LT
49static int radio_nr = -1;
50static spinlock_t lock;
51
52struct rt_device
53{
54 int port;
55 unsigned long curfreq;
56 int muted;
57};
58
59
60/* local things */
61
62static void rt_mute(struct rt_device *dev)
63{
4286c6f6 64 if(dev->muted)
1da177e4
LT
65 return;
66 spin_lock(&lock);
67 outb(1, io);
68 spin_unlock(&lock);
69 dev->muted = 1;
70}
71
72static void rt_unmute(struct rt_device *dev)
73{
74 if(dev->muted == 0)
75 return;
76 spin_lock(&lock);
77 outb(0, io);
78 spin_unlock(&lock);
79 dev->muted = 0;
80}
81
82static void zero(void)
83{
4286c6f6 84 outb_p(1, io);
1da177e4
LT
85 outb_p(3, io);
86 outb_p(1, io);
87}
88
89static void one(void)
90{
4286c6f6 91 outb_p(5, io);
1da177e4
LT
92 outb_p(7, io);
93 outb_p(5, io);
94}
95
96static int rt_setfreq(struct rt_device *dev, unsigned long freq)
97{
98 int i;
99
100 freq = freq / 200 + 856;
4286c6f6 101
1da177e4
LT
102 spin_lock(&lock);
103
104 outb_p(0xc8, io);
105 outb_p(0xc9, io);
106 outb_p(0xc9, io);
107
108 for (i = 0; i < 10; i++)
109 zero ();
110
111 for (i = 14; i >= 0; i--)
112 if (freq & (1 << i))
113 one ();
114 else
115 zero ();
116
117 outb_p(0xc8, io);
118 if (!dev->muted)
119 outb_p(0, io);
4286c6f6 120
1da177e4
LT
121 spin_unlock(&lock);
122 return 0;
123}
124
25f30389
DL
125static int vidioc_querycap(struct file *file, void *priv,
126 struct v4l2_capability *v)
127{
128 strlcpy(v->driver, "radio-rtrack2", sizeof(v->driver));
129 strlcpy(v->card, "RadioTrack II", sizeof(v->card));
130 sprintf(v->bus_info, "ISA");
131 v->version = RADIO_VERSION;
132 v->capabilities = V4L2_CAP_TUNER;
133 return 0;
134}
135
136static int vidioc_s_tuner(struct file *file, void *priv,
137 struct v4l2_tuner *v)
138{
139 if (v->index > 0)
140 return -EINVAL;
141
142 return 0;
143}
144
1da177e4
LT
145static int rt_getsigstr(struct rt_device *dev)
146{
147 if (inb(io) & 2) /* bit set = no signal present */
148 return 0;
149 return 1; /* signal present */
150}
151
25f30389
DL
152static int vidioc_g_tuner(struct file *file, void *priv,
153 struct v4l2_tuner *v)
1da177e4
LT
154{
155 struct video_device *dev = video_devdata(file);
25f30389
DL
156 struct rt_device *rt = dev->priv;
157
158 if (v->index > 0)
159 return -EINVAL;
160
161 strcpy(v->name, "FM");
162 v->type = V4L2_TUNER_RADIO;
163 v->rangelow = (88*16000);
164 v->rangehigh = (108*16000);
165 v->rxsubchans = V4L2_TUNER_SUB_MONO;
166 v->capability = V4L2_TUNER_CAP_LOW;
167 v->audmode = V4L2_TUNER_MODE_MONO;
168 v->signal = 0xFFFF*rt_getsigstr(rt);
169 return 0;
170}
f8c559f8 171
25f30389
DL
172static int vidioc_s_frequency(struct file *file, void *priv,
173 struct v4l2_frequency *f)
174{
175 struct video_device *dev = video_devdata(file);
176 struct rt_device *rt = dev->priv;
f8c559f8 177
25f30389
DL
178 rt->curfreq = f->frequency;
179 rt_setfreq(rt, rt->curfreq);
180 return 0;
181}
f8c559f8 182
25f30389
DL
183static int vidioc_g_frequency(struct file *file, void *priv,
184 struct v4l2_frequency *f)
185{
186 struct video_device *dev = video_devdata(file);
187 struct rt_device *rt = dev->priv;
f8c559f8 188
25f30389
DL
189 f->type = V4L2_TUNER_RADIO;
190 f->frequency = rt->curfreq;
191 return 0;
192}
f8c559f8 193
25f30389
DL
194static int vidioc_queryctrl(struct file *file, void *priv,
195 struct v4l2_queryctrl *qc)
196{
197 int i;
f8c559f8 198
25f30389
DL
199 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
200 if (qc->id && qc->id == radio_qctrl[i].id) {
201 memcpy(qc, &(radio_qctrl[i]),
202 sizeof(*qc));
1da177e4
LT
203 return 0;
204 }
25f30389
DL
205 }
206 return -EINVAL;
207}
f8c559f8 208
25f30389
DL
209static int vidioc_g_ctrl(struct file *file, void *priv,
210 struct v4l2_control *ctrl)
211{
212 struct video_device *dev = video_devdata(file);
213 struct rt_device *rt = dev->priv;
f8c559f8 214
25f30389
DL
215 switch (ctrl->id) {
216 case V4L2_CID_AUDIO_MUTE:
217 ctrl->value = rt->muted;
218 return 0;
219 case V4L2_CID_AUDIO_VOLUME:
220 if (rt->muted)
221 ctrl->value = 0;
222 else
223 ctrl->value = 65535;
224 return 0;
1da177e4 225 }
25f30389 226 return -EINVAL;
1da177e4
LT
227}
228
25f30389
DL
229static int vidioc_s_ctrl(struct file *file, void *priv,
230 struct v4l2_control *ctrl)
1da177e4 231{
25f30389
DL
232 struct video_device *dev = video_devdata(file);
233 struct rt_device *rt = dev->priv;
234
235 switch (ctrl->id) {
236 case V4L2_CID_AUDIO_MUTE:
237 if (ctrl->value)
238 rt_mute(rt);
239 else
240 rt_unmute(rt);
241 return 0;
242 case V4L2_CID_AUDIO_VOLUME:
243 if (ctrl->value)
244 rt_unmute(rt);
245 else
246 rt_mute(rt);
247 return 0;
248 }
249 return -EINVAL;
1da177e4
LT
250}
251
8b811cf0
DL
252static int vidioc_g_audio(struct file *file, void *priv,
253 struct v4l2_audio *a)
254{
255 if (a->index > 1)
256 return -EINVAL;
257
258 strcpy(a->name, "Radio");
259 a->capability = V4L2_AUDCAP_STEREO;
260 return 0;
261}
262
263static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
264{
265 *i = 0;
266 return 0;
267}
268
269static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
270{
271 if (i != 0)
272 return -EINVAL;
273 return 0;
274}
275
276static int vidioc_s_audio(struct file *file, void *priv,
277 struct v4l2_audio *a)
278{
279 if (a->index != 0)
280 return -EINVAL;
281 return 0;
282}
283
1da177e4
LT
284static struct rt_device rtrack2_unit;
285
fa027c2a 286static const struct file_operations rtrack2_fops = {
1da177e4
LT
287 .owner = THIS_MODULE,
288 .open = video_exclusive_open,
289 .release = video_exclusive_release,
25f30389 290 .ioctl = video_ioctl2,
078ff795 291#ifdef CONFIG_COMPAT
0d0fbf81 292 .compat_ioctl = v4l_compat_ioctl32,
078ff795 293#endif
1da177e4
LT
294 .llseek = no_llseek,
295};
296
297static struct video_device rtrack2_radio=
298{
299 .owner = THIS_MODULE,
300 .name = "RadioTrack II radio",
301 .type = VID_TYPE_TUNER,
1da177e4 302 .fops = &rtrack2_fops,
25f30389
DL
303 .vidioc_querycap = vidioc_querycap,
304 .vidioc_g_tuner = vidioc_g_tuner,
305 .vidioc_s_tuner = vidioc_s_tuner,
306 .vidioc_g_frequency = vidioc_g_frequency,
307 .vidioc_s_frequency = vidioc_s_frequency,
308 .vidioc_queryctrl = vidioc_queryctrl,
309 .vidioc_g_ctrl = vidioc_g_ctrl,
310 .vidioc_s_ctrl = vidioc_s_ctrl,
8b811cf0
DL
311 .vidioc_g_audio = vidioc_g_audio,
312 .vidioc_s_audio = vidioc_s_audio,
313 .vidioc_g_input = vidioc_g_input,
314 .vidioc_s_input = vidioc_s_input,
1da177e4
LT
315};
316
317static int __init rtrack2_init(void)
318{
319 if(io==-1)
320 {
321 printk(KERN_ERR "You must set an I/O address with io=0x20c or io=0x30c\n");
322 return -EINVAL;
323 }
4286c6f6 324 if (!request_region(io, 4, "rtrack2"))
1da177e4
LT
325 {
326 printk(KERN_ERR "rtrack2: port 0x%x already in use\n", io);
327 return -EBUSY;
328 }
329
330 rtrack2_radio.priv=&rtrack2_unit;
331
4286c6f6 332 spin_lock_init(&lock);
1da177e4
LT
333 if(video_register_device(&rtrack2_radio, VFL_TYPE_RADIO, radio_nr)==-1)
334 {
335 release_region(io, 4);
336 return -EINVAL;
337 }
4286c6f6 338
1da177e4
LT
339 printk(KERN_INFO "AIMSlab Radiotrack II card driver.\n");
340
4286c6f6 341 /* mute card - prevents noisy bootups */
1da177e4
LT
342 outb(1, io);
343 rtrack2_unit.muted = 1;
344
345 return 0;
346}
347
348MODULE_AUTHOR("Ben Pfaff");
349MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
350MODULE_LICENSE("GPL");
351
352module_param(io, int, 0);
353MODULE_PARM_DESC(io, "I/O address of the RadioTrack card (0x20c or 0x30c)");
354module_param(radio_nr, int, 0);
355
356static void __exit rtrack2_cleanup_module(void)
357{
358 video_unregister_device(&rtrack2_radio);
359 release_region(io,4);
360}
361
362module_init(rtrack2_init);
363module_exit(rtrack2_cleanup_module);
364
365/*
366 Local variables:
367 compile-command: "mmake"
368 End:
369*/
This page took 0.467252 seconds and 5 git commands to generate.