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>
27 #include "miropcm20-rds-core.h"
29 static int radio_nr = -1;
30 module_param(radio_nr, int, 0);
39 static int pcm20_mute(struct pcm20_device *dev, unsigned char mute)
42 return aci_write_cmd(ACI_SET_TUNERMUTE, mute);
45 static int pcm20_stereo(struct pcm20_device *dev, unsigned char stereo)
48 return aci_write_cmd(ACI_SET_TUNERMONO, !stereo);
51 static int pcm20_setfreq(struct pcm20_device *dev, unsigned long freq)
59 if (!(aci_version==0x07 || aci_version>=0xb0))
60 freq /= 10; /* I don't know exactly which version
65 aci_rds_cmd(RDS_RESET, NULL, 0);
68 return aci_rw_cmd(ACI_WRITE_TUNE, freql, freqh);
71 static int pcm20_getflags(struct pcm20_device *dev, __u32 *flags, __u16 *signal)
73 /* okay, check for signal, stereo and rds here... */
77 if ((i=aci_rw_cmd(ACI_READ_TUNERSTATION, -1, -1))<0)
79 pr_debug("check_sig: 0x%x\n", i);
81 /* no signal from tuner */
88 if ((i=aci_rw_cmd(ACI_READ_TUNERSTEREO, -1, -1))<0)
94 *flags=VIDEO_TUNER_STEREO_ON;
95 /* I can't see stereo, when forced to mono */
99 if ((i=aci_rds_cmd(RDS_STATUS, &buf, 1))<0)
103 *flags|=VIDEO_TUNER_RDS_ON;
107 if ((i=aci_rds_cmd(RDS_RXVALUE, &buf, 1))<0)
109 pr_debug("rds-signal: %d\n", buf);
111 printk("miropcm20-radio: RX strengths unexpected high...\n");
115 if ((*signal=SCALE(15, 0xffff, buf))==0)
121 static int pcm20_do_ioctl(struct inode *inode, struct file *file,
122 unsigned int cmd, void *arg)
124 struct video_device *dev = video_devdata(file);
125 struct pcm20_device *pcm20 = dev->priv;
132 struct video_capability *v = arg;
133 memset(v,0,sizeof(*v));
134 v->type=VID_TYPE_TUNER;
135 strcpy(v->name, "Miro PCM20");
142 struct video_tuner *v = arg;
143 if(v->tuner) /* Only 1 tuner */
145 v->rangelow=87*16000;
146 v->rangehigh=108*16000;
147 pcm20_getflags(pcm20, &v->flags, &v->signal);
148 v->flags|=VIDEO_TUNER_LOW;
149 v->mode=VIDEO_MODE_AUTO;
150 strcpy(v->name, "FM");
155 struct video_tuner *v = arg;
158 /* Only 1 tuner so no setting needed ! */
163 unsigned long *freq = arg;
169 unsigned long *freq = arg;
171 i=pcm20_setfreq(pcm20, pcm20->freq);
172 pr_debug("First view (setfreq): 0x%x\n", i);
177 struct video_audio *v = arg;
178 memset(v,0, sizeof(*v));
179 v->flags=VIDEO_AUDIO_MUTABLE;
181 v->flags|=VIDEO_AUDIO_MUTE;
182 v->mode=VIDEO_SOUND_STEREO;
184 v->mode|=VIDEO_SOUND_MONO;
186 strcpy(v->name, "Radio");
191 struct video_audio *v = arg;
195 pcm20_mute(pcm20, !!(v->flags&VIDEO_AUDIO_MUTE));
196 if(v->flags&VIDEO_SOUND_MONO)
197 pcm20_stereo(pcm20, 0);
198 if(v->flags&VIDEO_SOUND_STEREO)
199 pcm20_stereo(pcm20, 1);
208 static int pcm20_ioctl(struct inode *inode, struct file *file,
209 unsigned int cmd, unsigned long arg)
211 return video_usercopy(inode, file, cmd, arg, pcm20_do_ioctl);
214 static struct pcm20_device pcm20_unit = {
219 static const struct file_operations pcm20_fops = {
220 .owner = THIS_MODULE,
221 .open = video_exclusive_open,
222 .release = video_exclusive_release,
223 .ioctl = pcm20_ioctl,
225 .compat_ioctl = v4l_compat_ioctl32,
230 static struct video_device pcm20_radio = {
231 .owner = THIS_MODULE,
232 .name = "Miro PCM 20 radio",
233 .type = VID_TYPE_TUNER,
238 static int __init pcm20_init(void)
240 if(video_register_device(&pcm20_radio, VFL_TYPE_RADIO, radio_nr)==-1)
241 goto video_register_device;
243 if(attach_aci_rds()<0)
246 printk(KERN_INFO "Miro PCM20 radio card driver.\n");
251 video_unregister_device(&pcm20_radio);
252 video_register_device:
256 MODULE_AUTHOR("Ruurd Reitsma");
257 MODULE_DESCRIPTION("A driver for the Miro PCM20 radio card.");
258 MODULE_LICENSE("GPL");
260 static void __exit pcm20_cleanup(void)
263 video_unregister_device(&pcm20_radio);
266 module_init(pcm20_init);
267 module_exit(pcm20_cleanup);