Dont touch fs_struct in drivers
[pandora-kernel.git] / sound / ppc / tumbler.c
index 8e01b55..3f8d716 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 
-#include <sound/driver.h>
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/i2c.h>
@@ -275,14 +274,20 @@ static int tumbler_put_master_volume(struct snd_kcontrol *kcontrol,
 {
        struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
        struct pmac_tumbler *mix = chip->mixer_data;
+       unsigned int vol[2];
        int change;
 
        snd_assert(mix, return -ENODEV);
-       change = mix->master_vol[0] != ucontrol->value.integer.value[0] ||
-               mix->master_vol[1] != ucontrol->value.integer.value[1];
+       vol[0] = ucontrol->value.integer.value[0];
+       vol[1] = ucontrol->value.integer.value[1];
+       if (vol[0] >= ARRAY_SIZE(master_volume_table) ||
+           vol[1] >= ARRAY_SIZE(master_volume_table))
+               return -EINVAL;
+       change = mix->master_vol[0] != vol[0] ||
+               mix->master_vol[1] != vol[1];
        if (change) {
-               mix->master_vol[0] = ucontrol->value.integer.value[0];
-               mix->master_vol[1] = ucontrol->value.integer.value[1];
+               mix->master_vol[0] = vol[0];
+               mix->master_vol[1] = vol[1];
                tumbler_set_master_volume(mix);
        }
        return change;
@@ -417,13 +422,22 @@ static int tumbler_put_drc_value(struct snd_kcontrol *kcontrol,
 {
        struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
        struct pmac_tumbler *mix;
+       unsigned int val;
        int change;
 
        if (! (mix = chip->mixer_data))
                return -ENODEV;
-       change = mix->drc_range != ucontrol->value.integer.value[0];
+       val = ucontrol->value.integer.value[0];
+       if (chip->model == PMAC_TUMBLER) {
+               if (val > TAS3001_DRC_MAX)
+                       return -EINVAL;
+       } else {
+               if (val > TAS3004_DRC_MAX)
+                       return -EINVAL;
+       }
+       change = mix->drc_range != val;
        if (change) {
-               mix->drc_range = ucontrol->value.integer.value[0];
+               mix->drc_range = val;
                if (chip->model == PMAC_TUMBLER)
                        tumbler_set_drc(mix);
                else
@@ -530,13 +544,17 @@ static int tumbler_put_mono(struct snd_kcontrol *kcontrol,
        struct tumbler_mono_vol *info = (struct tumbler_mono_vol *)kcontrol->private_value;
        struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
        struct pmac_tumbler *mix;
+       unsigned int vol;
        int change;
 
        if (! (mix = chip->mixer_data))
                return -ENODEV;
-       change = mix->mono_vol[info->index] != ucontrol->value.integer.value[0];
+       vol = ucontrol->value.integer.value[0];
+       if (vol >= info->max)
+               return -EINVAL;
+       change = mix->mono_vol[info->index] != vol;
        if (change) {
-               mix->mono_vol[info->index] = ucontrol->value.integer.value[0];
+               mix->mono_vol[info->index] = vol;
                tumbler_set_mono_volume(mix, info);
        }
        return change;
@@ -672,15 +690,21 @@ static int snapper_put_mix(struct snd_kcontrol *kcontrol,
        int idx = (int)kcontrol->private_value;
        struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
        struct pmac_tumbler *mix;
+       unsigned int vol[2];
        int change;
 
        if (! (mix = chip->mixer_data))
                return -ENODEV;
-       change = mix->mix_vol[idx][0] != ucontrol->value.integer.value[0] ||
-               mix->mix_vol[idx][1] != ucontrol->value.integer.value[1];
+       vol[0] = ucontrol->value.integer.value[0];
+       vol[1] = ucontrol->value.integer.value[1];
+       if (vol[0] >= ARRAY_SIZE(mixer_volume_table) ||
+           vol[1] >= ARRAY_SIZE(mixer_volume_table))
+               return -EINVAL;
+       change = mix->mix_vol[idx][0] != vol[0] ||
+               mix->mix_vol[idx][1] != vol[1];
        if (change) {
-               mix->mix_vol[idx][0] = ucontrol->value.integer.value[0];
-               mix->mix_vol[idx][1] = ucontrol->value.integer.value[1];
+               mix->mix_vol[idx][0] = vol[0];
+               mix->mix_vol[idx][1] = vol[1];
                snapper_set_mix_vol(mix, idx);
        }
        return change;
@@ -784,7 +808,7 @@ static int snapper_get_capture_source(struct snd_kcontrol *kcontrol,
        struct pmac_tumbler *mix = chip->mixer_data;
 
        snd_assert(mix, return -ENODEV);
-       ucontrol->value.integer.value[0] = mix->capture_source;
+       ucontrol->value.enumerated.item[0] = mix->capture_source;
        return 0;
 }
 
@@ -796,9 +820,9 @@ static int snapper_put_capture_source(struct snd_kcontrol *kcontrol,
        int change;
 
        snd_assert(mix, return -ENODEV);
-       change = ucontrol->value.integer.value[0] != mix->capture_source;
+       change = ucontrol->value.enumerated.item[0] != mix->capture_source;
        if (change) {
-               mix->capture_source = !!ucontrol->value.integer.value[0];
+               mix->capture_source = !!ucontrol->value.enumerated.item[0];
                snapper_set_capture_source(mix);
        }
        return change;
@@ -1031,32 +1055,40 @@ static irqreturn_t headphone_intr(int irq, void *devid)
 /* look for audio-gpio device */
 static struct device_node *find_audio_device(const char *name)
 {
+       struct device_node *gpiop;
        struct device_node *np;
   
-       if (! (np = find_devices("gpio")))
+       gpiop = of_find_node_by_name(NULL, "gpio");
+       if (! gpiop)
                return NULL;
   
-       for (np = np->child; np; np = np->sibling) {
+       for (np = of_get_next_child(gpiop, NULL); np;
+                       np = of_get_next_child(gpiop, np)) {
                const char *property = of_get_property(np, "audio-gpio", NULL);
                if (property && strcmp(property, name) == 0)
-                       return np;
+                       break;
        }  
-       return NULL;
+       of_node_put(gpiop);
+       return np;
 }
 
 /* look for audio-gpio device */
 static struct device_node *find_compatible_audio_device(const char *name)
 {
+       struct device_node *gpiop;
        struct device_node *np;
   
-       if (! (np = find_devices("gpio")))
+       gpiop = of_find_node_by_name(NULL, "gpio");
+       if (!gpiop)
                return NULL;
   
-       for (np = np->child; np; np = np->sibling) {
-               if (device_is_compatible(np, name))
-                       return np;
+       for (np = of_get_next_child(gpiop, NULL); np;
+                       np = of_get_next_child(gpiop, np)) {
+               if (of_device_is_compatible(np, name))
+                       break;
        }  
-       return NULL;
+       of_node_put(gpiop);
+       return np;
 }
 
 /* find an audio device and get its address */
@@ -1066,6 +1098,7 @@ static long tumbler_find_device(const char *device, const char *platform,
        struct device_node *node;
        const u32 *base;
        u32 addr;
+       long ret;
 
        if (is_compatible)
                node = find_compatible_audio_device(device);
@@ -1083,6 +1116,7 @@ static long tumbler_find_device(const char *device, const char *platform,
                if (!base) {
                        DBG("(E) cannot find address for device %s !\n", device);
                        snd_printd("cannot find address for device %s\n", device);
+                       of_node_put(node);
                        return -ENODEV;
                }
                addr = *base;
@@ -1124,7 +1158,9 @@ static long tumbler_find_device(const char *device, const char *platform,
        DBG("(I) GPIO device %s found, offset: %x, active state: %d !\n",
            device, gp->addr, gp->active_state);
 
-       return irq_of_parse_and_map(node, 0);
+       ret = irq_of_parse_and_map(node, 0);
+       of_node_put(node);
+       return ret;
 }
 
 /* reset audio */
@@ -1315,9 +1351,8 @@ int __init snd_pmac_tumbler_init(struct snd_pmac *chip)
        char *chipname;
 
 #ifdef CONFIG_KMOD
-       if (current->fs->root)
-               request_module("i2c-powermac");
-#endif /* CONFIG_KMOD */       
+       request_module("i2c-powermac");
+#endif /* CONFIG_KMOD */
 
        mix = kzalloc(sizeof(*mix), GFP_KERNEL);
        if (! mix)
@@ -1342,9 +1377,9 @@ int __init snd_pmac_tumbler_init(struct snd_pmac *chip)
                return err;
 
        /* set up TAS */
-       tas_node = find_devices("deq");
+       tas_node = of_find_node_by_name(NULL, "deq");
        if (tas_node == NULL)
-               tas_node = find_devices("codec");
+               tas_node = of_find_node_by_name(NULL, "codec");
        if (tas_node == NULL)
                return -ENODEV;
 
@@ -1355,6 +1390,7 @@ int __init snd_pmac_tumbler_init(struct snd_pmac *chip)
                mix->i2c.addr = (*paddr) >> 1;
        else
                mix->i2c.addr = TAS_I2C_ADDR;
+       of_node_put(tas_node);
 
        DBG("(I) TAS i2c address is: %x\n", mix->i2c.addr);