1 /* RadioTrack II driver for Linux radio support (C) 1998 Ben Pfaff
3 * Based on RadioTrack I/RadioReveal (C) 1997 M. Kirkwood
4 * Converted to new API by Alan Cox <alan@lxorguk.ukuu.org.uk>
5 * Various bugfixes and enhancements by Russell Kroll <rkroll@exploits.org>
7 * TODO: Allow for more than one of these foolish entities :-)
9 * Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
12 #include <linux/module.h> /* Modules */
13 #include <linux/init.h> /* Initdata */
14 #include <linux/ioport.h> /* request_region */
15 #include <linux/delay.h> /* udelay */
16 #include <linux/videodev2.h> /* kernel radio structs */
17 #include <linux/mutex.h>
18 #include <linux/io.h> /* outb, outb_p */
19 #include <media/v4l2-device.h>
20 #include <media/v4l2-ioctl.h>
22 MODULE_AUTHOR("Ben Pfaff");
23 MODULE_DESCRIPTION("A driver for the RadioTrack II radio card.");
24 MODULE_LICENSE("GPL");
25 MODULE_VERSION("0.0.3");
27 #ifndef CONFIG_RADIO_RTRACK2_PORT
28 #define CONFIG_RADIO_RTRACK2_PORT -1
31 static int io
= CONFIG_RADIO_RTRACK2_PORT
;
32 static int radio_nr
= -1;
34 module_param(io
, int, 0);
35 MODULE_PARM_DESC(io
, "I/O address of the RadioTrack card (0x20c or 0x30c)");
36 module_param(radio_nr
, int, 0);
40 struct v4l2_device v4l2_dev
;
41 struct video_device vdev
;
43 unsigned long curfreq
;
48 static struct rtrack2 rtrack2_card
;
53 static void rt_mute(struct rtrack2
*dev
)
57 mutex_lock(&dev
->lock
);
59 mutex_unlock(&dev
->lock
);
63 static void rt_unmute(struct rtrack2
*dev
)
67 mutex_lock(&dev
->lock
);
69 mutex_unlock(&dev
->lock
);
73 static void zero(struct rtrack2
*dev
)
80 static void one(struct rtrack2
*dev
)
87 static int rt_setfreq(struct rtrack2
*dev
, unsigned long freq
)
91 mutex_lock(&dev
->lock
);
93 freq
= freq
/ 200 + 856;
95 outb_p(0xc8, dev
->io
);
96 outb_p(0xc9, dev
->io
);
97 outb_p(0xc9, dev
->io
);
99 for (i
= 0; i
< 10; i
++)
102 for (i
= 14; i
>= 0; i
--)
108 outb_p(0xc8, dev
->io
);
112 mutex_unlock(&dev
->lock
);
116 static int vidioc_querycap(struct file
*file
, void *priv
,
117 struct v4l2_capability
*v
)
119 strlcpy(v
->driver
, "radio-rtrack2", sizeof(v
->driver
));
120 strlcpy(v
->card
, "RadioTrack II", sizeof(v
->card
));
121 strlcpy(v
->bus_info
, "ISA", sizeof(v
->bus_info
));
122 v
->capabilities
= V4L2_CAP_TUNER
| V4L2_CAP_RADIO
;
126 static int vidioc_s_tuner(struct file
*file
, void *priv
,
127 struct v4l2_tuner
*v
)
129 return v
->index
? -EINVAL
: 0;
132 static int rt_getsigstr(struct rtrack2
*dev
)
136 mutex_lock(&dev
->lock
);
137 if (inb(dev
->io
) & 2) /* bit set = no signal present */
139 mutex_unlock(&dev
->lock
);
143 static int vidioc_g_tuner(struct file
*file
, void *priv
,
144 struct v4l2_tuner
*v
)
146 struct rtrack2
*rt
= video_drvdata(file
);
151 strlcpy(v
->name
, "FM", sizeof(v
->name
));
152 v
->type
= V4L2_TUNER_RADIO
;
153 v
->rangelow
= 88 * 16000;
154 v
->rangehigh
= 108 * 16000;
155 v
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
156 v
->capability
= V4L2_TUNER_CAP_LOW
;
157 v
->audmode
= V4L2_TUNER_MODE_MONO
;
158 v
->signal
= 0xFFFF * rt_getsigstr(rt
);
162 static int vidioc_s_frequency(struct file
*file
, void *priv
,
163 struct v4l2_frequency
*f
)
165 struct rtrack2
*rt
= video_drvdata(file
);
167 if (f
->tuner
!= 0 || f
->type
!= V4L2_TUNER_RADIO
)
169 rt_setfreq(rt
, f
->frequency
);
173 static int vidioc_g_frequency(struct file
*file
, void *priv
,
174 struct v4l2_frequency
*f
)
176 struct rtrack2
*rt
= video_drvdata(file
);
180 f
->type
= V4L2_TUNER_RADIO
;
181 f
->frequency
= rt
->curfreq
;
185 static int vidioc_queryctrl(struct file
*file
, void *priv
,
186 struct v4l2_queryctrl
*qc
)
189 case V4L2_CID_AUDIO_MUTE
:
190 return v4l2_ctrl_query_fill(qc
, 0, 1, 1, 1);
191 case V4L2_CID_AUDIO_VOLUME
:
192 return v4l2_ctrl_query_fill(qc
, 0, 65535, 65535, 65535);
197 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
198 struct v4l2_control
*ctrl
)
200 struct rtrack2
*rt
= video_drvdata(file
);
203 case V4L2_CID_AUDIO_MUTE
:
204 ctrl
->value
= rt
->muted
;
206 case V4L2_CID_AUDIO_VOLUME
:
216 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
217 struct v4l2_control
*ctrl
)
219 struct rtrack2
*rt
= video_drvdata(file
);
222 case V4L2_CID_AUDIO_MUTE
:
228 case V4L2_CID_AUDIO_VOLUME
:
238 static int vidioc_g_input(struct file
*filp
, void *priv
, unsigned int *i
)
244 static int vidioc_s_input(struct file
*filp
, void *priv
, unsigned int i
)
246 return i
? -EINVAL
: 0;
249 static int vidioc_g_audio(struct file
*file
, void *priv
,
250 struct v4l2_audio
*a
)
253 strlcpy(a
->name
, "Radio", sizeof(a
->name
));
254 a
->capability
= V4L2_AUDCAP_STEREO
;
258 static int vidioc_s_audio(struct file
*file
, void *priv
,
259 struct v4l2_audio
*a
)
261 return a
->index
? -EINVAL
: 0;
264 static const struct v4l2_file_operations rtrack2_fops
= {
265 .owner
= THIS_MODULE
,
266 .unlocked_ioctl
= video_ioctl2
,
269 static const struct v4l2_ioctl_ops rtrack2_ioctl_ops
= {
270 .vidioc_querycap
= vidioc_querycap
,
271 .vidioc_g_tuner
= vidioc_g_tuner
,
272 .vidioc_s_tuner
= vidioc_s_tuner
,
273 .vidioc_g_frequency
= vidioc_g_frequency
,
274 .vidioc_s_frequency
= vidioc_s_frequency
,
275 .vidioc_queryctrl
= vidioc_queryctrl
,
276 .vidioc_g_ctrl
= vidioc_g_ctrl
,
277 .vidioc_s_ctrl
= vidioc_s_ctrl
,
278 .vidioc_g_audio
= vidioc_g_audio
,
279 .vidioc_s_audio
= vidioc_s_audio
,
280 .vidioc_g_input
= vidioc_g_input
,
281 .vidioc_s_input
= vidioc_s_input
,
284 static int __init
rtrack2_init(void)
286 struct rtrack2
*dev
= &rtrack2_card
;
287 struct v4l2_device
*v4l2_dev
= &dev
->v4l2_dev
;
290 strlcpy(v4l2_dev
->name
, "rtrack2", sizeof(v4l2_dev
->name
));
293 v4l2_err(v4l2_dev
, "You must set an I/O address with io=0x20c or io=0x30c\n");
296 if (!request_region(dev
->io
, 4, "rtrack2")) {
297 v4l2_err(v4l2_dev
, "port 0x%x already in use\n", dev
->io
);
301 res
= v4l2_device_register(NULL
, v4l2_dev
);
303 release_region(dev
->io
, 4);
304 v4l2_err(v4l2_dev
, "Could not register v4l2_device\n");
308 strlcpy(dev
->vdev
.name
, v4l2_dev
->name
, sizeof(dev
->vdev
.name
));
309 dev
->vdev
.v4l2_dev
= v4l2_dev
;
310 dev
->vdev
.fops
= &rtrack2_fops
;
311 dev
->vdev
.ioctl_ops
= &rtrack2_ioctl_ops
;
312 dev
->vdev
.release
= video_device_release_empty
;
313 video_set_drvdata(&dev
->vdev
, dev
);
315 /* mute card - prevents noisy bootups */
319 mutex_init(&dev
->lock
);
320 if (video_register_device(&dev
->vdev
, VFL_TYPE_RADIO
, radio_nr
) < 0) {
321 v4l2_device_unregister(v4l2_dev
);
322 release_region(dev
->io
, 4);
326 v4l2_info(v4l2_dev
, "AIMSlab Radiotrack II card driver.\n");
331 static void __exit
rtrack2_exit(void)
333 struct rtrack2
*dev
= &rtrack2_card
;
335 video_unregister_device(&dev
->vdev
);
336 v4l2_device_unregister(&dev
->v4l2_dev
);
337 release_region(dev
->io
, 4);
340 module_init(rtrack2_init
);
341 module_exit(rtrack2_exit
);