patch-2.4.4 linux/drivers/media/radio/radio-miropcm20.c
Next file: linux/drivers/media/radio/rds-miropcm20.c
Previous file: linux/drivers/media/radio/Makefile
Back to the patch index
Back to the overall index
- Lines: 313
- Date:
Fri Apr 13 20:26:07 2001
- Orig file:
v2.4.3/linux/drivers/media/radio/radio-miropcm20.c
- Orig date:
Fri Mar 2 11:12:10 2001
diff -u --recursive --new-file v2.4.3/linux/drivers/media/radio/radio-miropcm20.c linux/drivers/media/radio/radio-miropcm20.c
@@ -2,62 +2,53 @@
* (c) 1998 Ruurd Reitsma <R.A.Reitsma@wbmt.tudelft.nl>
* Thanks to Norberto Pellici for the ACI device interface specification
* The API part is based on the radiotrack driver by M. Kirkwood
- * This driver relies on the aci mixer (drivers/sound/lowlevel/aci.c)
+ * This driver relies on the aci mixer (drivers/sound/aci.c)
* Look there for further info...
*/
-#include <linux/module.h> /* Modules */
-#include <linux/init.h> /* Initdata */
-#include <asm/uaccess.h> /* copy to/from user */
-#include <linux/videodev.h> /* kernel radio structs */
-#include "../../sound/miroaci.h" /* ACI Control by acimixer */
+/* Revision history:
+ *
+ * 1998 Ruurd Reitsma <R.A.Reitsma@wbmt.tudelft.nl>
+ * 2000-09-05 Robert Siemer <Robert.Siemer@gmx.de>
+ * removed unfinished volume control (maybe adding it later again)
+ * use OSS-mixer; added stereo control
+ */
+
+/* What ever you think about the ACI, version 0x07 is not very well!
+ * I cant get frequency, 'tuner status', 'tuner flags' or mute/mono
+ * conditions... Robert
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/videodev.h>
+#include <linux/devfs_fs_kernel.h>
+#include <asm/uaccess.h>
+
+char * aci_radio_name;
+
+#include "../../sound/aci.h"
static int users = 0;
struct pcm20_device
{
- int port;
- int curvol;
- unsigned long curfreq;
+ unsigned long freq;
int muted;
+ int stereo;
};
-/* local things */
-
-
-static void pcm20_mute(struct pcm20_device *dev)
+static int pcm20_mute(struct pcm20_device *dev, unsigned char mute)
{
-
- dev->muted = 1;
- aci_write_cmd(0xa3,0x01);
-
+ dev->muted = mute;
+ return aci_write_cmd(0xa3, mute);
}
-static int pcm20_setvol(struct pcm20_device *dev, int vol)
+static int pcm20_stereo(struct pcm20_device *dev, unsigned char stereo)
{
-
- if(vol == dev->curvol) { /* requested volume = current */
- if (dev->muted) { /* user is unmuting the card */
- dev->muted = 0;
- aci_write_cmd(0xa3,0x00); /* enable card */
- }
-
- return 0;
- }
-
- if(vol == 0) { /* volume = 0 means mute the card */
- aci_write_cmd(0x3d, 0x20);
- aci_write_cmd(0x35, 0x20);
- return 0;
- }
-
- dev->muted = 0;
- aci_write_cmd(0x3d, 32-vol); /* Right Channel */
- aci_write_cmd(0x35, 32-vol); /* Left Channel */
- dev->curvol = vol;
-
- return 0;
+ dev->stereo = stereo;
+ return aci_write_cmd(0xa4, !stereo);
}
static int pcm20_setfreq(struct pcm20_device *dev, unsigned long freq)
@@ -65,28 +56,79 @@
unsigned char freql;
unsigned char freqh;
- freq = (freq * 10) / 16;
- freql = freq & 0xff;
- freqh = freq >> 8;
+ dev->freq=freq;
+ freq /= 160;
+ if (!(aci_version==0x07 || aci_version>=0xb0))
+ freq /= 10; /* I don't know exactly which version
+ * needs this hack */
+ freql = freq & 0xff;
+ freqh = freq >> 8;
- aci_write_cmd_d(0xa7, freql, freqh); /* Tune to frequency */
+ aci_rds_cmd(RDS_RESET, 0, 0);
+ pcm20_stereo(dev, 1);
- return 0;
+ return aci_rw_cmd(0xa7, freql, freqh); /* Tune to frequency */
}
-int pcm20_getsigstr(struct pcm20_device *dev)
+static int pcm20_getflags(struct pcm20_device *dev, __u32 *flags, __u16 *signal)
{
+ /* okay, check for signal, stereo and rds here... */
+ int i;
unsigned char buf;
- aci_indexed_cmd(0xf0, 0x32, &buf);
- if ((buf & 0x80) == 0x80)
+
+ if ((i=aci_rw_cmd(0xa9, -1, -1))<0)
+ return i;
+#if DEBUG
+ printk("check_sig: 0x%x\n", i);
+#endif
+ if (i & 0x80) {
+ /* no signal from tuner */
+ *flags=0;
+ *signal=0;
+ return 0;
+ } else
+ *signal=0xffff;
+
+ if ((i=aci_rw_cmd(0xa8, -1, -1))<0)
+ return i;
+ if (i & 0x40) {
+ *flags=0;
+ } else {
+ /* stereo */
+ *flags=VIDEO_TUNER_STEREO_ON;
+ /* I cant see stereo, when forced to mono */
+ dev->stereo=1;
+ }
+
+ if ((i=aci_rds_cmd(RDS_STATUS, &buf, 1))<0)
+ return i;
+ if (buf & 1)
+ /* RDS available */
+ *flags|=VIDEO_TUNER_RDS_ON;
+ else
return 0;
- return 1; /* signal present */
+
+ if ((i=aci_rds_cmd(RDS_RXVALUE, &buf, 1))<0)
+ return i;
+#if DEBUG
+ printk("rds-signal: %d\n", buf);
+#endif
+ if (buf > 15) {
+ printk("rds-miropcm20: RX strengths unexpected high...\n");
+ buf=15;
+ }
+ /* refine signal */
+ if ((*signal=SCALE(15, 0xffff, buf))==0)
+ *signal = 1;
+
+ return 0;
}
static int pcm20_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
{
struct pcm20_device *pcm20=dev->priv;
+ int i;
switch(cmd)
{
@@ -113,11 +155,11 @@
return -EFAULT;
if(v.tuner) /* Only 1 tuner */
return -EINVAL;
- v.rangelow=(int)(87.5*16);
- v.rangehigh=(int)(108.0*16);
- v.flags=0;
+ v.rangelow=87*16000;
+ v.rangehigh=108*16000;
+ pcm20_getflags(pcm20, &v.flags, &v.signal);
+ v.flags|=VIDEO_TUNER_LOW;
v.mode=VIDEO_MODE_AUTO;
- v.signal=0xFFFF*pcm20_getsigstr(pcm20);
strcpy(v.name, "FM");
if(copy_to_user(arg,&v, sizeof(v)))
return -EFAULT;
@@ -134,20 +176,28 @@
return 0;
}
case VIDIOCGFREQ:
- if(copy_to_user(arg, &pcm20->curfreq, sizeof(pcm20->curfreq)))
+ if(copy_to_user(arg, &pcm20->freq, sizeof(pcm20->freq)))
return -EFAULT;
return 0;
case VIDIOCSFREQ:
- if(copy_from_user(&pcm20->curfreq, arg,sizeof(pcm20->curfreq)))
+ if(copy_from_user(&pcm20->freq, arg, sizeof(pcm20->freq)))
return -EFAULT;
- pcm20_setfreq(pcm20, pcm20->curfreq);
- return 0;
+ i=pcm20_setfreq(pcm20, pcm20->freq);
+#if DEBUG
+ printk("First view (setfreq): 0x%x\n", i);
+#endif
+ return i;
case VIDIOCGAUDIO:
{
struct video_audio v;
memset(&v,0, sizeof(v));
- v.flags|=VIDEO_AUDIO_MUTABLE|VIDEO_AUDIO_VOLUME;
- v.volume=pcm20->curvol * 2048;
+ v.flags=VIDEO_AUDIO_MUTABLE;
+ if (pcm20->muted)
+ v.flags|=VIDEO_AUDIO_MUTE;
+ v.mode=VIDEO_SOUND_STEREO;
+ if (pcm20->stereo)
+ v.mode|=VIDEO_SOUND_MONO;
+ /* v.step=2048; */
strcpy(v.name, "Radio");
if(copy_to_user(arg,&v, sizeof(v)))
return -EFAULT;
@@ -157,14 +207,15 @@
{
struct video_audio v;
if(copy_from_user(&v, arg, sizeof(v)))
- return -EFAULT;
+ return -EFAULT;
if(v.audio)
return -EINVAL;
- if(v.flags&VIDEO_AUDIO_MUTE)
- pcm20_mute(pcm20);
- else
- pcm20_setvol(pcm20,v.volume/2048);
+ pcm20_mute(pcm20, !!(v.flags&VIDEO_AUDIO_MUTE));
+ if(v.flags&VIDEO_SOUND_MONO)
+ pcm20_stereo(pcm20, 0);
+ if(v.flags&VIDEO_SOUND_STEREO)
+ pcm20_stereo(pcm20, 1);
return 0;
}
@@ -186,7 +237,12 @@
users--;
}
-static struct pcm20_device pcm20_unit;
+static struct pcm20_device pcm20_unit=
+{
+ freq: 87*16000,
+ muted: 1,
+ stereo: 0
+};
static struct video_device pcm20_radio=
{
@@ -197,24 +253,23 @@
open: pcm20_open,
close: pcm20_close,
ioctl: pcm20_ioctl,
+ priv: &pcm20_unit
};
static int __init pcm20_init(void)
{
-
- pcm20_radio.priv=&pcm20_unit;
-
if(video_register_device(&pcm20_radio, VFL_TYPE_RADIO)==-1)
return -EINVAL;
+ if(attach_aci_rds()<0) {
+ video_unregister_device(&pcm20_radio);
+ return -EINVAL;
+ }
+#if DEBUG
+ printk("v4l-name: %s\n", devfs_get_name(pcm20_radio.devfs_handle, 0));
+#endif
printk(KERN_INFO "Miro PCM20 radio card driver.\n");
- /* mute card - prevents noisy bootups */
-
- /* this ensures that the volume is all the way down */
-
- pcm20_unit.curvol = 0;
-
return 0;
}
@@ -225,9 +280,9 @@
static void __exit pcm20_cleanup(void)
{
+ unload_aci_rds();
video_unregister_device(&pcm20_radio);
}
module_init(pcm20_init);
module_exit(pcm20_cleanup);
-
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)