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 "../../../sound/oss/aci.h"
26 #include "miropcm20-rds-core.h"
28 static int radio_nr = -1;
29 module_param(radio_nr, int, 0);
38 static int pcm20_mute(struct pcm20_device *dev, unsigned char mute)
41 return aci_write_cmd(ACI_SET_TUNERMUTE, mute);
44 static int pcm20_stereo(struct pcm20_device *dev, unsigned char stereo)
47 return aci_write_cmd(ACI_SET_TUNERMONO, !stereo);
50 static int pcm20_setfreq(struct pcm20_device *dev, unsigned long freq)
58 if (!(aci_version==0x07 || aci_version>=0xb0))
59 freq /= 10; /* I don't know exactly which version
64 aci_rds_cmd(RDS_RESET, NULL, 0);
67 return aci_rw_cmd(ACI_WRITE_TUNE, freql, freqh);
70 static int pcm20_getflags(struct pcm20_device *dev, __u32 *flags, __u16 *signal)
72 /* okay, check for signal, stereo and rds here... */
76 if ((i=aci_rw_cmd(ACI_READ_TUNERSTATION, -1, -1))<0)
78 pr_debug("check_sig: 0x%x\n", i);
80 /* no signal from tuner */
87 if ((i=aci_rw_cmd(ACI_READ_TUNERSTEREO, -1, -1))<0)
93 *flags=VIDEO_TUNER_STEREO_ON;
94 /* I can't see stereo, when forced to mono */
98 if ((i=aci_rds_cmd(RDS_STATUS, &buf, 1))<0)
102 *flags|=VIDEO_TUNER_RDS_ON;
106 if ((i=aci_rds_cmd(RDS_RXVALUE, &buf, 1))<0)
108 pr_debug("rds-signal: %d\n", buf);
110 printk("miropcm20-radio: RX strengths unexpected high...\n");
114 if ((*signal=SCALE(15, 0xffff, buf))==0)
120 static int pcm20_do_ioctl(struct inode *inode, struct file *file,
121 unsigned int cmd, void *arg)
123 struct video_device *dev = video_devdata(file);
124 struct pcm20_device *pcm20 = dev->priv;
131 struct video_capability *v = arg;
132 memset(v,0,sizeof(*v));
133 v->type=VID_TYPE_TUNER;
134 strcpy(v->name, "Miro PCM20");
141 struct video_tuner *v = arg;
142 if(v->tuner) /* Only 1 tuner */
144 v->rangelow=87*16000;
145 v->rangehigh=108*16000;
146 pcm20_getflags(pcm20, &v->flags, &v->signal);
147 v->flags|=VIDEO_TUNER_LOW;
148 v->mode=VIDEO_MODE_AUTO;
149 strcpy(v->name, "FM");
154 struct video_tuner *v = arg;
157 /* Only 1 tuner so no setting needed ! */
162 unsigned long *freq = arg;
168 unsigned long *freq = arg;
170 i=pcm20_setfreq(pcm20, pcm20->freq);
171 pr_debug("First view (setfreq): 0x%x\n", i);
176 struct video_audio *v = arg;
177 memset(v,0, sizeof(*v));
178 v->flags=VIDEO_AUDIO_MUTABLE;
180 v->flags|=VIDEO_AUDIO_MUTE;
181 v->mode=VIDEO_SOUND_STEREO;
183 v->mode|=VIDEO_SOUND_MONO;
185 strcpy(v->name, "Radio");
190 struct video_audio *v = arg;
194 pcm20_mute(pcm20, !!(v->flags&VIDEO_AUDIO_MUTE));
195 if(v->flags&VIDEO_SOUND_MONO)
196 pcm20_stereo(pcm20, 0);
197 if(v->flags&VIDEO_SOUND_STEREO)
198 pcm20_stereo(pcm20, 1);
207 static int pcm20_ioctl(struct inode *inode, struct file *file,
208 unsigned int cmd, unsigned long arg)
210 return video_usercopy(inode, file, cmd, arg, pcm20_do_ioctl);
213 static struct pcm20_device pcm20_unit = {
218 static struct file_operations pcm20_fops = {
219 .owner = THIS_MODULE,
220 .open = video_exclusive_open,
221 .release = video_exclusive_release,
222 .ioctl = pcm20_ioctl,
223 .compat_ioctl = v4l_compat_ioctl32,
227 static struct video_device pcm20_radio = {
228 .owner = THIS_MODULE,
229 .name = "Miro PCM 20 radio",
230 .type = VID_TYPE_TUNER,
231 .hardware = VID_HARDWARE_RTRACK,
236 static int __init pcm20_init(void)
238 if(video_register_device(&pcm20_radio, VFL_TYPE_RADIO, radio_nr)==-1)
239 goto video_register_device;
241 if(attach_aci_rds()<0)
244 printk(KERN_INFO "Miro PCM20 radio card driver.\n");
249 video_unregister_device(&pcm20_radio);
250 video_register_device:
254 MODULE_AUTHOR("Ruurd Reitsma");
255 MODULE_DESCRIPTION("A driver for the Miro PCM20 radio card.");
256 MODULE_LICENSE("GPL");
258 static void __exit pcm20_cleanup(void)
261 video_unregister_device(&pcm20_radio);
264 module_init(pcm20_init);
265 module_exit(pcm20_cleanup);