1 /* Miro PCM20 radio driver for Linux radio support
2 * (c) 1998 Ruurd Reitsma <R.A.Reitsma@wbmt.tudelft.nl>
3 * Thanks to Norberto Pellici for the ACI device interface specification
4 * The API part is based on the radiotrack driver by M. Kirkwood
5 * This driver relies on the aci mixer (drivers/sound/aci.c)
6 * Look there for further info...
11 * 1998 Ruurd Reitsma <R.A.Reitsma@wbmt.tudelft.nl>
12 * 2000-09-05 Robert Siemer <Robert.Siemer@gmx.de>
13 * removed unfinished volume control (maybe adding it later again)
14 * use OSS-mixer; added stereo control
17 /* What ever you think about the ACI, version 0x07 is not very well!
18 * I can't get frequency, 'tuner status', 'tuner flags' or mute/mono
19 * conditions... Robert
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/videodev.h>
25 #include <media/v4l2-common.h>
26 #include <media/v4l2-ioctl.h>
28 #include "miropcm20-rds-core.h"
30 static int radio_nr = -1;
31 module_param(radio_nr, int, 0);
40 static int pcm20_mute(struct pcm20_device *dev, unsigned char mute)
43 return aci_write_cmd(ACI_SET_TUNERMUTE, mute);
46 static int pcm20_stereo(struct pcm20_device *dev, unsigned char stereo)
49 return aci_write_cmd(ACI_SET_TUNERMONO, !stereo);
52 static int pcm20_setfreq(struct pcm20_device *dev, unsigned long freq)
60 if (!(aci_version==0x07 || aci_version>=0xb0))
61 freq /= 10; /* I don't know exactly which version
66 aci_rds_cmd(RDS_RESET, NULL, 0);
69 return aci_rw_cmd(ACI_WRITE_TUNE, freql, freqh);
72 static int pcm20_getflags(struct pcm20_device *dev, __u32 *flags, __u16 *signal)
74 /* okay, check for signal, stereo and rds here... */
78 if ((i=aci_rw_cmd(ACI_READ_TUNERSTATION, -1, -1))<0)
80 pr_debug("check_sig: 0x%x\n", i);
82 /* no signal from tuner */
89 if ((i=aci_rw_cmd(ACI_READ_TUNERSTEREO, -1, -1))<0)
95 *flags=VIDEO_TUNER_STEREO_ON;
96 /* I can't see stereo, when forced to mono */
100 if ((i=aci_rds_cmd(RDS_STATUS, &buf, 1))<0)
104 *flags|=VIDEO_TUNER_RDS_ON;
108 if ((i=aci_rds_cmd(RDS_RXVALUE, &buf, 1))<0)
110 pr_debug("rds-signal: %d\n", buf);
112 printk("miropcm20-radio: RX strengths unexpected high...\n");
116 if ((*signal=SCALE(15, 0xffff, buf))==0)
122 static int pcm20_do_ioctl(struct inode *inode, struct file *file,
123 unsigned int cmd, void *arg)
125 struct video_device *dev = video_devdata(file);
126 struct pcm20_device *pcm20 = dev->priv;
133 struct video_capability *v = arg;
134 memset(v,0,sizeof(*v));
135 v->type=VID_TYPE_TUNER;
136 strcpy(v->name, "Miro PCM20");
143 struct video_tuner *v = arg;
144 if(v->tuner) /* Only 1 tuner */
146 v->rangelow=87*16000;
147 v->rangehigh=108*16000;
148 pcm20_getflags(pcm20, &v->flags, &v->signal);
149 v->flags|=VIDEO_TUNER_LOW;
150 v->mode=VIDEO_MODE_AUTO;
151 strcpy(v->name, "FM");
156 struct video_tuner *v = arg;
159 /* Only 1 tuner so no setting needed ! */
164 unsigned long *freq = arg;
170 unsigned long *freq = arg;
172 i=pcm20_setfreq(pcm20, pcm20->freq);
173 pr_debug("First view (setfreq): 0x%x\n", i);
178 struct video_audio *v = arg;
179 memset(v,0, sizeof(*v));
180 v->flags=VIDEO_AUDIO_MUTABLE;
182 v->flags|=VIDEO_AUDIO_MUTE;
183 v->mode=VIDEO_SOUND_STEREO;
185 v->mode|=VIDEO_SOUND_MONO;
187 strcpy(v->name, "Radio");
192 struct video_audio *v = arg;
196 pcm20_mute(pcm20, !!(v->flags&VIDEO_AUDIO_MUTE));
197 if(v->flags&VIDEO_SOUND_MONO)
198 pcm20_stereo(pcm20, 0);
199 if(v->flags&VIDEO_SOUND_STEREO)
200 pcm20_stereo(pcm20, 1);
209 static int pcm20_ioctl(struct inode *inode, struct file *file,
210 unsigned int cmd, unsigned long arg)
212 return video_usercopy(inode, file, cmd, arg, pcm20_do_ioctl);
215 static struct pcm20_device pcm20_unit = {
220 static const struct file_operations pcm20_fops = {
221 .owner = THIS_MODULE,
222 .open = video_exclusive_open,
223 .release = video_exclusive_release,
224 .ioctl = pcm20_ioctl,
226 .compat_ioctl = v4l_compat_ioctl32,
231 static struct video_device pcm20_radio = {
232 .name = "Miro PCM 20 radio",
237 static int __init pcm20_init(void)
239 if(video_register_device(&pcm20_radio, VFL_TYPE_RADIO, radio_nr)==-1)
240 goto video_register_device;
242 if(attach_aci_rds()<0)
245 printk(KERN_INFO "Miro PCM20 radio card driver.\n");
250 video_unregister_device(&pcm20_radio);
251 video_register_device:
255 MODULE_AUTHOR("Ruurd Reitsma");
256 MODULE_DESCRIPTION("A driver for the Miro PCM20 radio card.");
257 MODULE_LICENSE("GPL");
259 static void __exit pcm20_cleanup(void)
262 video_unregister_device(&pcm20_radio);
265 module_init(pcm20_init);
266 module_exit(pcm20_cleanup);