Merge branch 'next'
[cascardo/linux.git] / sound / i2c / other / tea575x-tuner.c
index 4c2fd14..c13a178 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *   ALSA driver for TEA5757/5759 Philips AM/FM radio tuner chips
  *
- *     Copyright (c) 2004 Jaroslav Kysela <perex@suse.cz>
+ *     Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz>
  *
  *
  *   This program is free software; you can redistribute it and/or modify
@@ -20,7 +20,6 @@
  *
  */      
 
-#include <sound/driver.h>
 #include <asm/io.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
@@ -28,7 +27,7 @@
 #include <sound/core.h>
 #include <sound/tea575x-tuner.h>
 
-MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
 MODULE_DESCRIPTION("Routines for control of TEA5757/5759 Philips AM/FM radio tuner chips");
 MODULE_LICENSE("GPL");
 
@@ -88,8 +87,7 @@ static void snd_tea575x_set_freq(struct snd_tea575x *tea)
 static int snd_tea575x_ioctl(struct inode *inode, struct file *file,
                             unsigned int cmd, unsigned long data)
 {
-       struct video_device *dev = video_devdata(file);
-       struct snd_tea575x *tea = video_get_drvdata(dev);
+       struct snd_tea575x *tea = video_drvdata(file);
        void __user *arg = (void __user *)data;
        
        switch(cmd) {
@@ -159,6 +157,10 @@ static int snd_tea575x_ioctl(struct inode *inode, struct file *file,
                        struct video_audio v;
                        if(copy_from_user(&v, arg, sizeof(v))) 
                                return -EFAULT; 
+                       if (tea->ops->mute)
+                               tea->ops->mute(tea,
+                                              (v.flags &
+                                               VIDEO_AUDIO_MUTE) ? 1 : 0);
                        if(v.audio) 
                                return -EINVAL;
                        return 0;
@@ -172,6 +174,21 @@ static void snd_tea575x_release(struct video_device *vfd)
 {
 }
 
+static int snd_tea575x_exclusive_open(struct inode *inode, struct file *file)
+{
+       struct snd_tea575x *tea = video_drvdata(file);
+
+       return test_and_set_bit(0, &tea->in_use) ? -EBUSY : 0;
+}
+
+static int snd_tea575x_exclusive_release(struct inode *inode, struct file *file)
+{
+       struct snd_tea575x *tea = video_drvdata(file);
+
+       clear_bit(0, &tea->in_use);
+       return 0;
+}
+
 /*
  * initialize all the tea575x chips
  */
@@ -186,16 +203,14 @@ void snd_tea575x_init(struct snd_tea575x *tea)
        }
 
        memset(&tea->vd, 0, sizeof(tea->vd));
-       tea->vd.owner = tea->card->module;
        strcpy(tea->vd.name, tea->tea5759 ? "TEA5759 radio" : "TEA5757 radio");
-       tea->vd.type = VID_TYPE_TUNER;
-       tea->vd.hardware = VID_HARDWARE_RTRACK; /* FIXME: assign new number */
        tea->vd.release = snd_tea575x_release;
        video_set_drvdata(&tea->vd, tea);
        tea->vd.fops = &tea->fops;
+       tea->in_use = 0;
        tea->fops.owner = tea->card->module;
-       tea->fops.open = video_exclusive_open;
-       tea->fops.release = video_exclusive_release;
+       tea->fops.open = snd_tea575x_exclusive_open;
+       tea->fops.release = snd_tea575x_exclusive_release;
        tea->fops.ioctl = snd_tea575x_ioctl;
        if (video_register_device(&tea->vd, VFL_TYPE_RADIO, tea->dev_nr - 1) < 0) {
                snd_printk(KERN_ERR "unable to register tea575x tuner\n");
@@ -207,6 +222,10 @@ void snd_tea575x_init(struct snd_tea575x *tea)
        tea->freq = 90500 * 16;         /* 90.5Mhz default */
 
        snd_tea575x_set_freq(tea);
+
+       /* mute on init */
+       if (tea->ops->mute)
+               tea->ops->mute(tea, 1);
 }
 
 void snd_tea575x_exit(struct snd_tea575x *tea)