Import 2.1.118
[davej-history.git] / drivers / char / radio-miropcm20.c
blobffc1d1908d9964cc8686077c2a824096bef16bdc
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/lowlevel/aci.c)
6 * Look there for further info...
7 */
9 #include <linux/module.h> /* Modules */
10 #include <linux/init.h> /* Initdata */
11 #include <asm/uaccess.h> /* copy to/from user */
12 #include <linux/videodev.h> /* kernel radio structs */
13 #include <linux/config.h> /* CONFIG_RADIO_MIROPCM20 */
14 #include "../sound/lowlevel/miroaci.h" /* ACI Control by acimixer */
16 static int users = 0;
18 struct pcm20_device
20 int port;
21 int curvol;
22 unsigned long curfreq;
23 int muted;
27 /* local things */
30 static void pcm20_mute(struct pcm20_device *dev)
33 dev->muted = 1;
34 aci_write_cmd(0xa3,0x01);
38 static int pcm20_setvol(struct pcm20_device *dev, int vol)
41 if(vol == dev->curvol) { /* requested volume = current */
42 if (dev->muted) { /* user is unmuting the card */
43 dev->muted = 0;
44 aci_write_cmd(0xa3,0x00); /* enable card */
47 return 0;
50 if(vol == 0) { /* volume = 0 means mute the card */
51 aci_write_cmd(0x3d, 0x20);
52 aci_write_cmd(0x35, 0x20);
53 return 0;
56 dev->muted = 0;
57 aci_write_cmd(0x3d, 32-vol); /* Right Channel */
58 aci_write_cmd(0x35, 32-vol); /* Left Channel */
59 dev->curvol = vol;
61 return 0;
64 static int pcm20_setfreq(struct pcm20_device *dev, unsigned long freq)
66 unsigned char freql;
67 unsigned char freqh;
69 freq = (freq * 10) / 16;
70 freql = freq & 0xff;
71 freqh = freq >> 8;
74 aci_write_cmd_d(0xa7, freql, freqh); /* Tune to frequency */
76 return 0;
79 int pcm20_getsigstr(struct pcm20_device *dev)
81 unsigned char buf;
82 aci_indexed_cmd(0xf0, 0x32, &buf);
83 if ((buf & 0x80) == 0x80)
84 return 0;
85 return 1; /* signal present */
88 static int pcm20_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
90 struct pcm20_device *pcm20=dev->priv;
92 switch(cmd)
94 case VIDIOCGCAP:
96 struct video_capability v;
97 v.type=VID_TYPE_TUNER;
98 strcpy(v.name, "Miro PCM20");
99 v.channels=1;
100 v.audios=1;
101 /* No we don't do pictures */
102 v.maxwidth=0;
103 v.maxheight=0;
104 v.minwidth=0;
105 v.minheight=0;
106 if(copy_to_user(arg,&v,sizeof(v)))
107 return -EFAULT;
108 return 0;
110 case VIDIOCGTUNER:
112 struct video_tuner v;
113 if(copy_from_user(&v, arg,sizeof(v))!=0)
114 return -EFAULT;
115 if(v.tuner) /* Only 1 tuner */
116 return -EINVAL;
117 v.rangelow=(int)(87.5*16);
118 v.rangehigh=(int)(108.0*16);
119 v.flags=0;
120 v.mode=VIDEO_MODE_AUTO;
121 v.signal=0xFFFF*pcm20_getsigstr(pcm20);
122 if(copy_to_user(arg,&v, sizeof(v)))
123 return -EFAULT;
124 return 0;
126 case VIDIOCSTUNER:
128 struct video_tuner v;
129 if(copy_from_user(&v, arg, sizeof(v)))
130 return -EFAULT;
131 if(v.tuner!=0)
132 return -EINVAL;
133 /* Only 1 tuner so no setting needed ! */
134 return 0;
136 case VIDIOCGFREQ:
137 if(copy_to_user(arg, &pcm20->curfreq, sizeof(pcm20->curfreq)))
138 return -EFAULT;
139 return 0;
140 case VIDIOCSFREQ:
141 if(copy_from_user(&pcm20->curfreq, arg,sizeof(pcm20->curfreq)))
142 return -EFAULT;
143 pcm20_setfreq(pcm20, pcm20->curfreq);
144 return 0;
145 case VIDIOCGAUDIO:
147 struct video_audio v;
148 memset(&v,0, sizeof(v));
149 v.flags|=VIDEO_AUDIO_MUTABLE|VIDEO_AUDIO_VOLUME;
150 v.volume=pcm20->curvol * 2048;
151 strcpy(v.name, "Radio");
152 if(copy_to_user(arg,&v, sizeof(v)))
153 return -EFAULT;
154 return 0;
156 case VIDIOCSAUDIO:
158 struct video_audio v;
159 if(copy_from_user(&v, arg, sizeof(v)))
160 return -EFAULT;
161 if(v.audio)
162 return -EINVAL;
164 if(v.flags&VIDEO_AUDIO_MUTE)
165 pcm20_mute(pcm20);
166 else
167 pcm20_setvol(pcm20,v.volume/2048);
169 return 0;
171 default:
172 return -ENOIOCTLCMD;
176 static int pcm20_open(struct video_device *dev, int flags)
178 if(users)
179 return -EBUSY;
180 users++;
181 MOD_INC_USE_COUNT;
182 return 0;
185 static void pcm20_close(struct video_device *dev)
187 users--;
188 MOD_DEC_USE_COUNT;
191 static struct pcm20_device pcm20_unit;
193 static struct video_device pcm20_radio=
195 "Miro PCM 20 radio",
196 VID_TYPE_TUNER,
197 VID_HARDWARE_RTRACK,
198 pcm20_open,
199 pcm20_close,
200 NULL, /* Can't read (no capture ability) */
201 NULL, /* Can't write */
202 NULL, /* Can't poll */
203 pcm20_ioctl,
204 NULL,
205 NULL
208 __initfunc(int pcm20_init(struct video_init *v))
211 pcm20_radio.priv=&pcm20_unit;
213 if(video_register_device(&pcm20_radio, VFL_TYPE_RADIO)==-1)
214 return -EINVAL;
216 printk(KERN_INFO "Miro PCM20 radio card driver.\n");
218 /* mute card - prevents noisy bootups */
220 /* this ensures that the volume is all the way down */
222 pcm20_unit.curvol = 0;
224 return 0;
227 #ifdef MODULE
229 MODULE_AUTHOR("Ruurd Reitsma");
230 MODULE_DESCRIPTION("A driver for the Miro PCM20 radio card.");
232 EXPORT_NO_SYMBOLS;
234 int init_module(void)
237 return pcm20_init(NULL);
240 void cleanup_module(void)
242 video_unregister_device(&pcm20_radio);
245 #endif