[TG3]: Add tagged status support.
[linux-2.6/verdex.git] / drivers / media / radio / miropcm20-radio.c
blobc2ebe8754a9569bf326430a08920e3a096a2aa07
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...
7 */
9 /* Revision history:
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);
31 struct pcm20_device {
32 unsigned long freq;
33 int muted;
34 int stereo;
38 static int pcm20_mute(struct pcm20_device *dev, unsigned char mute)
40 dev->muted = mute;
41 return aci_write_cmd(ACI_SET_TUNERMUTE, mute);
44 static int pcm20_stereo(struct pcm20_device *dev, unsigned char stereo)
46 dev->stereo = stereo;
47 return aci_write_cmd(ACI_SET_TUNERMONO, !stereo);
50 static int pcm20_setfreq(struct pcm20_device *dev, unsigned long freq)
52 unsigned char freql;
53 unsigned char freqh;
55 dev->freq=freq;
57 freq /= 160;
58 if (!(aci_version==0x07 || aci_version>=0xb0))
59 freq /= 10; /* I don't know exactly which version
60 * needs this hack */
61 freql = freq & 0xff;
62 freqh = freq >> 8;
64 aci_rds_cmd(RDS_RESET, NULL, 0);
65 pcm20_stereo(dev, 1);
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... */
73 int i;
74 unsigned char buf;
76 if ((i=aci_rw_cmd(ACI_READ_TUNERSTATION, -1, -1))<0)
77 return i;
78 pr_debug("check_sig: 0x%x\n", i);
79 if (i & 0x80) {
80 /* no signal from tuner */
81 *flags=0;
82 *signal=0;
83 return 0;
84 } else
85 *signal=0xffff;
87 if ((i=aci_rw_cmd(ACI_READ_TUNERSTEREO, -1, -1))<0)
88 return i;
89 if (i & 0x40) {
90 *flags=0;
91 } else {
92 /* stereo */
93 *flags=VIDEO_TUNER_STEREO_ON;
94 /* I can't see stereo, when forced to mono */
95 dev->stereo=1;
98 if ((i=aci_rds_cmd(RDS_STATUS, &buf, 1))<0)
99 return i;
100 if (buf & 1)
101 /* RDS available */
102 *flags|=VIDEO_TUNER_RDS_ON;
103 else
104 return 0;
106 if ((i=aci_rds_cmd(RDS_RXVALUE, &buf, 1))<0)
107 return i;
108 pr_debug("rds-signal: %d\n", buf);
109 if (buf > 15) {
110 printk("miropcm20-radio: RX strengths unexpected high...\n");
111 buf=15;
113 /* refine signal */
114 if ((*signal=SCALE(15, 0xffff, buf))==0)
115 *signal = 1;
117 return 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;
125 int i;
127 switch(cmd)
129 case VIDIOCGCAP:
131 struct video_capability *v = arg;
132 memset(v,0,sizeof(*v));
133 v->type=VID_TYPE_TUNER;
134 strcpy(v->name, "Miro PCM20");
135 v->channels=1;
136 v->audios=1;
137 return 0;
139 case VIDIOCGTUNER:
141 struct video_tuner *v = arg;
142 if(v->tuner) /* Only 1 tuner */
143 return -EINVAL;
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");
150 return 0;
152 case VIDIOCSTUNER:
154 struct video_tuner *v = arg;
155 if(v->tuner!=0)
156 return -EINVAL;
157 /* Only 1 tuner so no setting needed ! */
158 return 0;
160 case VIDIOCGFREQ:
162 unsigned long *freq = arg;
163 *freq = pcm20->freq;
164 return 0;
166 case VIDIOCSFREQ:
168 unsigned long *freq = arg;
169 pcm20->freq = *freq;
170 i=pcm20_setfreq(pcm20, pcm20->freq);
171 pr_debug("First view (setfreq): 0x%x\n", i);
172 return i;
174 case VIDIOCGAUDIO:
176 struct video_audio *v = arg;
177 memset(v,0, sizeof(*v));
178 v->flags=VIDEO_AUDIO_MUTABLE;
179 if (pcm20->muted)
180 v->flags|=VIDEO_AUDIO_MUTE;
181 v->mode=VIDEO_SOUND_STEREO;
182 if (pcm20->stereo)
183 v->mode|=VIDEO_SOUND_MONO;
184 /* v->step=2048; */
185 strcpy(v->name, "Radio");
186 return 0;
188 case VIDIOCSAUDIO:
190 struct video_audio *v = arg;
191 if(v->audio)
192 return -EINVAL;
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);
200 return 0;
202 default:
203 return -ENOIOCTLCMD;
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 = {
214 .freq = 87*16000,
215 .muted = 1,
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 .llseek = no_llseek,
226 static struct video_device pcm20_radio = {
227 .owner = THIS_MODULE,
228 .name = "Miro PCM 20 radio",
229 .type = VID_TYPE_TUNER,
230 .hardware = VID_HARDWARE_RTRACK,
231 .fops = &pcm20_fops,
232 .priv = &pcm20_unit
235 static int __init pcm20_init(void)
237 if(video_register_device(&pcm20_radio, VFL_TYPE_RADIO, radio_nr)==-1)
238 goto video_register_device;
240 if(attach_aci_rds()<0)
241 goto attach_aci_rds;
243 printk(KERN_INFO "Miro PCM20 radio card driver.\n");
245 return 0;
247 attach_aci_rds:
248 video_unregister_device(&pcm20_radio);
249 video_register_device:
250 return -EINVAL;
253 MODULE_AUTHOR("Ruurd Reitsma");
254 MODULE_DESCRIPTION("A driver for the Miro PCM20 radio card.");
255 MODULE_LICENSE("GPL");
257 static void __exit pcm20_cleanup(void)
259 unload_aci_rds();
260 video_unregister_device(&pcm20_radio);
263 module_init(pcm20_init);
264 module_exit(pcm20_cleanup);