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...
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 */
22 unsigned long curfreq
;
30 static void pcm20_mute(struct pcm20_device
*dev
)
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 */
44 aci_write_cmd(0xa3,0x00); /* enable card */
50 if(vol
== 0) { /* volume = 0 means mute the card */
51 aci_write_cmd(0x3d, 0x20);
52 aci_write_cmd(0x35, 0x20);
57 aci_write_cmd(0x3d, 32-vol
); /* Right Channel */
58 aci_write_cmd(0x35, 32-vol
); /* Left Channel */
64 static int pcm20_setfreq(struct pcm20_device
*dev
, unsigned long freq
)
69 freq
= (freq
* 10) / 16;
74 aci_write_cmd_d(0xa7, freql
, freqh
); /* Tune to frequency */
79 int pcm20_getsigstr(struct pcm20_device
*dev
)
82 aci_indexed_cmd(0xf0, 0x32, &buf
);
83 if ((buf
& 0x80) == 0x80)
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
;
96 struct video_capability v
;
97 v
.type
=VID_TYPE_TUNER
;
98 strcpy(v
.name
, "Miro PCM20");
101 /* No we don't do pictures */
106 if(copy_to_user(arg
,&v
,sizeof(v
)))
112 struct video_tuner v
;
113 if(copy_from_user(&v
, arg
,sizeof(v
))!=0)
115 if(v
.tuner
) /* Only 1 tuner */
117 v
.rangelow
=(int)(87.5*16);
118 v
.rangehigh
=(int)(108.0*16);
120 v
.mode
=VIDEO_MODE_AUTO
;
121 v
.signal
=0xFFFF*pcm20_getsigstr(pcm20
);
122 if(copy_to_user(arg
,&v
, sizeof(v
)))
128 struct video_tuner v
;
129 if(copy_from_user(&v
, arg
, sizeof(v
)))
133 /* Only 1 tuner so no setting needed ! */
137 if(copy_to_user(arg
, &pcm20
->curfreq
, sizeof(pcm20
->curfreq
)))
141 if(copy_from_user(&pcm20
->curfreq
, arg
,sizeof(pcm20
->curfreq
)))
143 pcm20_setfreq(pcm20
, pcm20
->curfreq
);
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
)))
158 struct video_audio v
;
159 if(copy_from_user(&v
, arg
, sizeof(v
)))
164 if(v
.flags
&VIDEO_AUDIO_MUTE
)
167 pcm20_setvol(pcm20
,v
.volume
/2048);
176 static int pcm20_open(struct video_device
*dev
, int flags
)
185 static void pcm20_close(struct video_device
*dev
)
191 static struct pcm20_device pcm20_unit
;
193 static struct video_device pcm20_radio
=
200 NULL
, /* Can't read (no capture ability) */
201 NULL
, /* Can't write */
202 NULL
, /* Can't poll */
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)
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;
229 MODULE_AUTHOR("Ruurd Reitsma");
230 MODULE_DESCRIPTION("A driver for the Miro PCM20 radio card.");
234 int init_module(void)
237 return pcm20_init(NULL
);
240 void cleanup_module(void)
242 video_unregister_device(&pcm20_radio
);