Merge branch 'fix/hda' into topic/hda
[safe/jmp/linux-2.6] / sound / pci / hda / patch_si3054.c
index c41fb9a..f419ee8 100644 (file)
@@ -3,7 +3,7 @@
  *
  * HD audio interface patch for Silicon Labs 3054/5 modem codec
  *
- * Copyright (c) 2005 Sasha Khapyorsky <sashak@smlink.com>
+ * Copyright (c) 2005 Sasha Khapyorsky <sashak@alsa-project.org>
  *                    Takashi Iwai <tiwai@suse.de>
  *
  *
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
-#include <sound/driver.h>
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
-#include <linux/pci.h>
 #include <sound/core.h>
 #include "hda_codec.h"
 #include "hda_local.h"
 
-
 /* si3054 verbs */
 #define SI3054_VERB_READ_NODE  0x900
 #define SI3054_VERB_WRITE_NODE 0x100
@@ -79,6 +76,8 @@
 /* si3054 codec registers (nodes) access macros */
 #define GET_REG(codec,reg) (snd_hda_codec_read(codec,reg,0,SI3054_VERB_READ_NODE,0))
 #define SET_REG(codec,reg,val) (snd_hda_codec_write(codec,reg,0,SI3054_VERB_WRITE_NODE,val))
+#define SET_REG_CACHE(codec,reg,val) \
+       snd_hda_codec_write_cache(codec,reg,0,SI3054_VERB_WRITE_NODE,val)
 
 
 struct si3054_spec {
@@ -95,18 +94,10 @@ struct si3054_spec {
 #define PRIVATE_REG(val) ((val>>16)&0xffff)
 #define PRIVATE_MASK(val) (val&0xffff)
 
-static int si3054_switch_info(snd_kcontrol_t *kcontrol,
-                              snd_ctl_elem_info_t *uinfo)
-{
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = 1;
-       return 0;
-}
+#define si3054_switch_info     snd_ctl_boolean_mono_info
 
-static int si3054_switch_get(snd_kcontrol_t *kcontrol,
-                              snd_ctl_elem_value_t *uvalue)
+static int si3054_switch_get(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *uvalue)
 {
        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
        u16 reg  = PRIVATE_REG(kcontrol->private_value);
@@ -115,22 +106,23 @@ static int si3054_switch_get(snd_kcontrol_t *kcontrol,
        return 0;
 }
 
-static int si3054_switch_put(snd_kcontrol_t *kcontrol,
-                              snd_ctl_elem_value_t *uvalue)
+static int si3054_switch_put(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *uvalue)
 {
        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
        u16 reg  = PRIVATE_REG(kcontrol->private_value);
        u16 mask = PRIVATE_MASK(kcontrol->private_value);
        if (uvalue->value.integer.value[0])
-               SET_REG(codec, reg, (GET_REG(codec, reg)) | mask);
+               SET_REG_CACHE(codec, reg, (GET_REG(codec, reg)) | mask);
        else
-               SET_REG(codec, reg, (GET_REG(codec, reg)) & ~mask);
+               SET_REG_CACHE(codec, reg, (GET_REG(codec, reg)) & ~mask);
        return 0;
 }
 
 #define SI3054_KCONTROL(kname,reg,mask) { \
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
        .name = kname, \
+       .subdevice = HDA_SUBDEV_NID_FLAG | reg, \
        .info = si3054_switch_info, \
        .get  = si3054_switch_get, \
        .put  = si3054_switch_put, \
@@ -138,7 +130,7 @@ static int si3054_switch_put(snd_kcontrol_t *kcontrol,
 }
                
 
-static snd_kcontrol_new_t si3054_modem_mixer[] = {
+static struct snd_kcontrol_new si3054_modem_mixer[] = {
        SI3054_KCONTROL("Off-hook Switch", SI3054_GPIO_CONTROL, SI3054_GPIO_OH),
        SI3054_KCONTROL("Caller ID Switch", SI3054_GPIO_CONTROL, SI3054_GPIO_CID),
        {}
@@ -158,7 +150,7 @@ static int si3054_pcm_prepare(struct hda_pcm_stream *hinfo,
                              struct hda_codec *codec,
                              unsigned int stream_tag,
                              unsigned int format,
-                             snd_pcm_substream_t *substream)
+                             struct snd_pcm_substream *substream)
 {
        u16 val;
 
@@ -175,10 +167,10 @@ static int si3054_pcm_prepare(struct hda_pcm_stream *hinfo,
 
 static int si3054_pcm_open(struct hda_pcm_stream *hinfo,
                           struct hda_codec *codec,
-                           snd_pcm_substream_t *substream)
+                           struct snd_pcm_substream *substream)
 {
        static unsigned int rates[] = { 8000, 9600, 16000 };
-       static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
+       static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
                .count = ARRAY_SIZE(rates),
                .list = rates,
                .mask = 0,
@@ -214,7 +206,7 @@ static int si3054_build_pcms(struct hda_codec *codec)
        info->name = "Si3054 Modem";
        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm;
        info->stream[SNDRV_PCM_STREAM_CAPTURE]  = si3054_pcm;
-       info->is_modem = 1;
+       info->pcm_type = HDA_PCM_TYPE_MODEM;
        return 0;
 }
 
@@ -243,7 +235,8 @@ static int si3054_init(struct hda_codec *codec)
 
        if((val&SI3054_MEI_READY) != SI3054_MEI_READY) {
                snd_printk(KERN_ERR "si3054: cannot initialize. EXT MID = %04x\n", val);
-               return -EACCES;
+               /* let's pray that this is no fatal error */
+               /* return -EACCES; */
        }
 
        SET_REG(codec, SI3054_GPIO_POLARITY, 0xffff);
@@ -275,15 +268,11 @@ static struct hda_codec_ops si3054_patch_ops = {
        .build_pcms = si3054_build_pcms,
        .init = si3054_init,
        .free = si3054_free,
-#ifdef CONFIG_PM
-       //.suspend = si3054_suspend,
-       .resume = si3054_init,
-#endif
 };
 
 static int patch_si3054(struct hda_codec *codec)
 {
-       struct si3054_spec *spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
+       struct si3054_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
        if (spec == NULL)
                return -ENOMEM;
        codec->spec = spec;
@@ -294,8 +283,53 @@ static int patch_si3054(struct hda_codec *codec)
 /*
  * patch entries
  */
-struct hda_codec_preset snd_hda_preset_si3054[] = {
+static struct hda_codec_preset snd_hda_preset_si3054[] = {
+       { .id = 0x163c3055, .name = "Si3054", .patch = patch_si3054 },
        { .id = 0x163c3155, .name = "Si3054", .patch = patch_si3054 },
+       { .id = 0x11c13026, .name = "Si3054", .patch = patch_si3054 },
+       { .id = 0x11c13055, .name = "Si3054", .patch = patch_si3054 },
+       { .id = 0x11c13155, .name = "Si3054", .patch = patch_si3054 },
+       { .id = 0x10573055, .name = "Si3054", .patch = patch_si3054 },
+       { .id = 0x10573057, .name = "Si3054", .patch = patch_si3054 },
+       { .id = 0x10573155, .name = "Si3054", .patch = patch_si3054 },
+       /* VIA HDA on Clevo m540 */
+       { .id = 0x11063288, .name = "Si3054", .patch = patch_si3054 },
+       /* Asus A8J Modem (SM56) */
+       { .id = 0x15433155, .name = "Si3054", .patch = patch_si3054 },
+       /* LG LW20 modem */
+       { .id = 0x18540018, .name = "Si3054", .patch = patch_si3054 },
        {}
 };
 
+MODULE_ALIAS("snd-hda-codec-id:163c3055");
+MODULE_ALIAS("snd-hda-codec-id:163c3155");
+MODULE_ALIAS("snd-hda-codec-id:11c13026");
+MODULE_ALIAS("snd-hda-codec-id:11c13055");
+MODULE_ALIAS("snd-hda-codec-id:11c13155");
+MODULE_ALIAS("snd-hda-codec-id:10573055");
+MODULE_ALIAS("snd-hda-codec-id:10573057");
+MODULE_ALIAS("snd-hda-codec-id:10573155");
+MODULE_ALIAS("snd-hda-codec-id:11063288");
+MODULE_ALIAS("snd-hda-codec-id:15433155");
+MODULE_ALIAS("snd-hda-codec-id:18540018");
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Si3054 HD-audio modem codec");
+
+static struct hda_codec_preset_list si3054_list = {
+       .preset = snd_hda_preset_si3054,
+       .owner = THIS_MODULE,
+};
+
+static int __init patch_si3054_init(void)
+{
+       return snd_hda_add_codec_preset(&si3054_list);
+}
+
+static void __exit patch_si3054_exit(void)
+{
+       snd_hda_delete_codec_preset(&si3054_list);
+}
+
+module_init(patch_si3054_init)
+module_exit(patch_si3054_exit)