fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / sound / ppc / daca.c
index 0b48286..57202b0 100644 (file)
 #include <sound/driver.h>
 #include <linux/init.h>
 #include <linux/i2c.h>
-#include <linux/i2c-dev.h>
 #include <linux/kmod.h>
 #include <linux/slab.h>
 #include <sound/core.h>
 #include "pmac.h"
 
-#define chip_t pmac_t
-
 /* i2c address */
 #define DACA_I2C_ADDR  0x4d
 
 #define DACA_VOL_MAX   0x38
 
 
-typedef struct pmac_daca_t {
-       pmac_keywest_t i2c;
+struct pmac_daca {
+       struct pmac_keywest i2c;
        int left_vol, right_vol;
        unsigned int deemphasis : 1;
        unsigned int amp_on : 1;
-} pmac_daca_t;
+};
 
 
 /*
  * initialize / detect DACA
  */
-static int daca_init_client(pmac_keywest_t *i2c)
+static int daca_init_client(struct pmac_keywest *i2c)
 {
        unsigned short wdata = 0x00;
        /* SR: no swap, 1bit delay, 32-48kHz */
        /* GCFG: power amp inverted, DAC on */
-       if (snd_pmac_keywest_write_byte(i2c, DACA_REG_SR, 0x08) < 0 ||
-           snd_pmac_keywest_write_byte(i2c, DACA_REG_GCFG, 0x05) < 0)
+       if (i2c_smbus_write_byte_data(i2c->client, DACA_REG_SR, 0x08) < 0 ||
+           i2c_smbus_write_byte_data(i2c->client, DACA_REG_GCFG, 0x05) < 0)
                return -EINVAL;
-       return snd_pmac_keywest_write(i2c, DACA_REG_AVOL, 2, (unsigned char*)&wdata);
+       return i2c_smbus_write_block_data(i2c->client, DACA_REG_AVOL,
+                                         2, (unsigned char*)&wdata);
 }
 
 /*
  * update volume
  */
-static int daca_set_volume(pmac_daca_t *mix)
+static int daca_set_volume(struct pmac_daca *mix)
 {
        unsigned char data[2];
   
@@ -83,16 +81,18 @@ static int daca_set_volume(pmac_daca_t *mix)
        else
                data[1] = mix->right_vol;
        data[1] |= mix->deemphasis ? 0x40 : 0;
-       if (snd_pmac_keywest_write(&mix->i2c, DACA_REG_AVOL, 2, data) < 0) {
-               snd_printk("failed to set volume \n");  
-               return -EINVAL; 
+       if (i2c_smbus_write_block_data(mix->i2c.client, DACA_REG_AVOL,
+                                      2, data) < 0) {
+               snd_printk("failed to set volume \n");
+               return -EINVAL;
        }
        return 0;
 }
 
 
 /* deemphasis switch */
-static int daca_info_deemphasis(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
+static int daca_info_deemphasis(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
        uinfo->count = 1;
@@ -101,20 +101,22 @@ static int daca_info_deemphasis(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *u
        return 0;
 }
 
-static int daca_get_deemphasis(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int daca_get_deemphasis(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
 {
-       pmac_t *chip = snd_kcontrol_chip(kcontrol);
-       pmac_daca_t *mix;
+       struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
+       struct pmac_daca *mix;
        if (! (mix = chip->mixer_data))
                return -ENODEV;
        ucontrol->value.integer.value[0] = mix->deemphasis ? 1 : 0;
        return 0;
 }
 
-static int daca_put_deemphasis(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int daca_put_deemphasis(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
 {
-       pmac_t *chip = snd_kcontrol_chip(kcontrol);
-       pmac_daca_t *mix;
+       struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
+       struct pmac_daca *mix;
        int change;
 
        if (! (mix = chip->mixer_data))
@@ -128,7 +130,8 @@ static int daca_put_deemphasis(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u
 }
 
 /* output volume */
-static int daca_info_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
+static int daca_info_volume(struct snd_kcontrol *kcontrol,
+                           struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
        uinfo->count = 2;
@@ -137,10 +140,11 @@ static int daca_info_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo
        return 0;
 }
 
-static int daca_get_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int daca_get_volume(struct snd_kcontrol *kcontrol,
+                          struct snd_ctl_elem_value *ucontrol)
 {
-       pmac_t *chip = snd_kcontrol_chip(kcontrol);
-       pmac_daca_t *mix;
+       struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
+       struct pmac_daca *mix;
        if (! (mix = chip->mixer_data))
                return -ENODEV;
        ucontrol->value.integer.value[0] = mix->left_vol;
@@ -148,10 +152,11 @@ static int daca_get_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucont
        return 0;
 }
 
-static int daca_put_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int daca_put_volume(struct snd_kcontrol *kcontrol,
+                          struct snd_ctl_elem_value *ucontrol)
 {
-       pmac_t *chip = snd_kcontrol_chip(kcontrol);
-       pmac_daca_t *mix;
+       struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
+       struct pmac_daca *mix;
        int change;
 
        if (! (mix = chip->mixer_data))
@@ -169,20 +174,22 @@ static int daca_put_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucont
 /* amplifier switch */
 #define daca_info_amp  daca_info_deemphasis
 
-static int daca_get_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int daca_get_amp(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_value *ucontrol)
 {
-       pmac_t *chip = snd_kcontrol_chip(kcontrol);
-       pmac_daca_t *mix;
+       struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
+       struct pmac_daca *mix;
        if (! (mix = chip->mixer_data))
                return -ENODEV;
        ucontrol->value.integer.value[0] = mix->amp_on ? 1 : 0;
        return 0;
 }
 
-static int daca_put_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int daca_put_amp(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_value *ucontrol)
 {
-       pmac_t *chip = snd_kcontrol_chip(kcontrol);
-       pmac_daca_t *mix;
+       struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
+       struct pmac_daca *mix;
        int change;
 
        if (! (mix = chip->mixer_data))
@@ -190,13 +197,13 @@ static int daca_put_amp(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol
        change = mix->amp_on != ucontrol->value.integer.value[0];
        if (change) {
                mix->amp_on = ucontrol->value.integer.value[0];
-               snd_pmac_keywest_write_byte(&mix->i2c, DACA_REG_GCFG,
-                                           mix->amp_on ? 0x05 : 0x04);
+               i2c_smbus_write_byte_data(mix->i2c.client, DACA_REG_GCFG,
+                                         mix->amp_on ? 0x05 : 0x04);
        }
        return change;
 }
 
-static snd_kcontrol_new_t daca_mixers[] = {
+static struct snd_kcontrol_new daca_mixers[] = {
        { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
          .name = "Deemphasis Switch",
          .info = daca_info_deemphasis,
@@ -217,24 +224,22 @@ static snd_kcontrol_new_t daca_mixers[] = {
        },
 };
 
-#define num_controls(ary) (sizeof(ary) / sizeof(snd_kcontrol_new_t))
-
 
-#ifdef CONFIG_PMAC_PBOOK
-static void daca_resume(pmac_t *chip)
+#ifdef CONFIG_PM
+static void daca_resume(struct snd_pmac *chip)
 {
-       pmac_daca_t *mix = chip->mixer_data;
-       snd_pmac_keywest_write_byte(&mix->i2c, DACA_REG_SR, 0x08);
-       snd_pmac_keywest_write_byte(&mix->i2c, DACA_REG_GCFG,
-                                   mix->amp_on ? 0x05 : 0x04);
+       struct pmac_daca *mix = chip->mixer_data;
+       i2c_smbus_write_byte_data(mix->i2c.client, DACA_REG_SR, 0x08);
+       i2c_smbus_write_byte_data(mix->i2c.client, DACA_REG_GCFG,
+                                 mix->amp_on ? 0x05 : 0x04);
        daca_set_volume(mix);
 }
-#endif /* CONFIG_PMAC_PBOOK */
+#endif /* CONFIG_PM */
 
 
-static void daca_cleanup(pmac_t *chip)
+static void daca_cleanup(struct snd_pmac *chip)
 {
-       pmac_daca_t *mix = chip->mixer_data;
+       struct pmac_daca *mix = chip->mixer_data;
        if (! mix)
                return;
        snd_pmac_keywest_cleanup(&mix->i2c);
@@ -243,20 +248,19 @@ static void daca_cleanup(pmac_t *chip)
 }
 
 /* exported */
-int __init snd_pmac_daca_init(pmac_t *chip)
+int __init snd_pmac_daca_init(struct snd_pmac *chip)
 {
        int i, err;
-       pmac_daca_t *mix;
+       struct pmac_daca *mix;
 
 #ifdef CONFIG_KMOD
        if (current->fs->root)
-               request_module("i2c-keywest");
+               request_module("i2c-powermac");
 #endif /* CONFIG_KMOD */       
 
-       mix = kmalloc(sizeof(*mix), GFP_KERNEL);
+       mix = kzalloc(sizeof(*mix), GFP_KERNEL);
        if (! mix)
                return -ENOMEM;
-       memset(mix, 0, sizeof(*mix));
        chip->mixer_data = mix;
        chip->mixer_free = daca_cleanup;
        mix->amp_on = 1; /* default on */
@@ -272,12 +276,12 @@ int __init snd_pmac_daca_init(pmac_t *chip)
         */
        strcpy(chip->card->mixername, "PowerMac DACA");
 
-       for (i = 0; i < num_controls(daca_mixers); i++) {
+       for (i = 0; i < ARRAY_SIZE(daca_mixers); i++) {
                if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&daca_mixers[i], chip))) < 0)
                        return err;
        }
 
-#ifdef CONFIG_PMAC_PBOOK
+#ifdef CONFIG_PM
        chip->resume = daca_resume;
 #endif