From 3be141494a080a9189b51fa78154c975ad8d9806 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 20 Feb 2009 14:11:16 +0100 Subject: ALSA: hda - Add generic pincfg initialization Added the generic pincfg cache and save/restore functions. Also introduced the pin-overriding via hwdep sysfs. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_hwdep.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'sound/pci/hda/hda_hwdep.c') diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c index 4ae51dc..71039a6 100644 --- a/sound/pci/hda/hda_hwdep.c +++ b/sound/pci/hda/hda_hwdep.c @@ -109,6 +109,7 @@ static void clear_hwdep_elements(struct hda_codec *codec) for (i = 0; i < codec->hints.used; i++, head++) kfree(*head); snd_array_free(&codec->hints); + snd_array_free(&codec->override_pins); } static void hwdep_free(struct snd_hwdep *hwdep) @@ -141,6 +142,7 @@ int /*__devinit*/ snd_hda_create_hwdep(struct hda_codec *codec) snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32); snd_array_init(&codec->hints, sizeof(char *), 32); + snd_array_init(&codec->override_pins, sizeof(struct hda_pincfg), 16); return 0; } @@ -316,6 +318,67 @@ static ssize_t hints_store(struct device *dev, return count; } +static ssize_t pin_configs_show(struct hda_codec *codec, + struct snd_array *list, + char *buf) +{ + int i, len = 0; + for (i = 0; i < list->used; i++) { + struct hda_pincfg *pin = snd_array_elem(list, i); + len += sprintf(buf + len, "0x%02x 0x%08x\n", + pin->nid, pin->cfg); + } + return len; +} + +static ssize_t init_pin_configs_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct snd_hwdep *hwdep = dev_get_drvdata(dev); + struct hda_codec *codec = hwdep->private_data; + return pin_configs_show(codec, &codec->init_pins, buf); +} + +static ssize_t override_pin_configs_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct snd_hwdep *hwdep = dev_get_drvdata(dev); + struct hda_codec *codec = hwdep->private_data; + return pin_configs_show(codec, &codec->override_pins, buf); +} + +static ssize_t cur_pin_configs_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct snd_hwdep *hwdep = dev_get_drvdata(dev); + struct hda_codec *codec = hwdep->private_data; + return pin_configs_show(codec, &codec->cur_pins, buf); +} + +#define MAX_PIN_CONFIGS 32 + +static ssize_t override_pin_configs_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct snd_hwdep *hwdep = dev_get_drvdata(dev); + struct hda_codec *codec = hwdep->private_data; + int nid, cfg; + int err; + + if (sscanf(buf, "%i %i", &nid, &cfg) != 2) + return -EINVAL; + if (!nid) + return -EINVAL; + err = snd_hda_add_pincfg(codec, &codec->override_pins, nid, cfg); + if (err < 0) + return err; + return count; +} + #define CODEC_ATTR_RW(type) \ __ATTR(type, 0644, type##_show, type##_store) #define CODEC_ATTR_RO(type) \ @@ -333,6 +396,9 @@ static struct device_attribute codec_attrs[] = { CODEC_ATTR_RW(modelname), CODEC_ATTR_WO(init_verbs), CODEC_ATTR_WO(hints), + CODEC_ATTR_RO(init_pin_configs), + CODEC_ATTR_RW(override_pin_configs), + CODEC_ATTR_RO(cur_pin_configs), CODEC_ATTR_WO(reconfig), CODEC_ATTR_WO(clear), }; -- cgit v1.1 From 346ff70fdbe9093947b9494fe714c89cafcceade Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 23 Feb 2009 09:42:57 +0100 Subject: ALSA: hda - Rename {override,cur}_pin with {user,driver}_pin Rename from override_pin and cur_pin with user_pin and driver_pin, respectively, to be a bit more intuitive. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_hwdep.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'sound/pci/hda/hda_hwdep.c') diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c index 71039a6..c660383 100644 --- a/sound/pci/hda/hda_hwdep.c +++ b/sound/pci/hda/hda_hwdep.c @@ -109,7 +109,7 @@ static void clear_hwdep_elements(struct hda_codec *codec) for (i = 0; i < codec->hints.used; i++, head++) kfree(*head); snd_array_free(&codec->hints); - snd_array_free(&codec->override_pins); + snd_array_free(&codec->user_pins); } static void hwdep_free(struct snd_hwdep *hwdep) @@ -142,7 +142,7 @@ int /*__devinit*/ snd_hda_create_hwdep(struct hda_codec *codec) snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32); snd_array_init(&codec->hints, sizeof(char *), 32); - snd_array_init(&codec->override_pins, sizeof(struct hda_pincfg), 16); + snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16); return 0; } @@ -340,29 +340,29 @@ static ssize_t init_pin_configs_show(struct device *dev, return pin_configs_show(codec, &codec->init_pins, buf); } -static ssize_t override_pin_configs_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t user_pin_configs_show(struct device *dev, + struct device_attribute *attr, + char *buf) { struct snd_hwdep *hwdep = dev_get_drvdata(dev); struct hda_codec *codec = hwdep->private_data; - return pin_configs_show(codec, &codec->override_pins, buf); + return pin_configs_show(codec, &codec->user_pins, buf); } -static ssize_t cur_pin_configs_show(struct device *dev, - struct device_attribute *attr, - char *buf) +static ssize_t driver_pin_configs_show(struct device *dev, + struct device_attribute *attr, + char *buf) { struct snd_hwdep *hwdep = dev_get_drvdata(dev); struct hda_codec *codec = hwdep->private_data; - return pin_configs_show(codec, &codec->cur_pins, buf); + return pin_configs_show(codec, &codec->driver_pins, buf); } #define MAX_PIN_CONFIGS 32 -static ssize_t override_pin_configs_store(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t user_pin_configs_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) { struct snd_hwdep *hwdep = dev_get_drvdata(dev); struct hda_codec *codec = hwdep->private_data; @@ -373,7 +373,7 @@ static ssize_t override_pin_configs_store(struct device *dev, return -EINVAL; if (!nid) return -EINVAL; - err = snd_hda_add_pincfg(codec, &codec->override_pins, nid, cfg); + err = snd_hda_add_pincfg(codec, &codec->user_pins, nid, cfg); if (err < 0) return err; return count; @@ -397,8 +397,8 @@ static struct device_attribute codec_attrs[] = { CODEC_ATTR_WO(init_verbs), CODEC_ATTR_WO(hints), CODEC_ATTR_RO(init_pin_configs), - CODEC_ATTR_RW(override_pin_configs), - CODEC_ATTR_RO(cur_pin_configs), + CODEC_ATTR_RW(user_pin_configs), + CODEC_ATTR_RO(driver_pin_configs), CODEC_ATTR_WO(reconfig), CODEC_ATTR_WO(clear), }; -- cgit v1.1 From a65d629ceb4cff5e7d5edadfd6bf1f64c370a517 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 23 Feb 2009 16:57:04 +0100 Subject: ALSA: hda - Add pseudo device-locking for clear/reconfig Added the pseudo device-locking using card->shutdown flag to avoid the crash via clear/reconfig during operations. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_hwdep.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'sound/pci/hda/hda_hwdep.c') diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c index c660383..4af484b 100644 --- a/sound/pci/hda/hda_hwdep.c +++ b/sound/pci/hda/hda_hwdep.c @@ -155,7 +155,13 @@ int /*__devinit*/ snd_hda_create_hwdep(struct hda_codec *codec) static int clear_codec(struct hda_codec *codec) { - snd_hda_codec_reset(codec); + int err; + + err = snd_hda_codec_reset(codec); + if (err < 0) { + snd_printk(KERN_ERR "The codec is being used, can't free.\n"); + return err; + } clear_hwdep_elements(codec); return 0; } @@ -165,7 +171,12 @@ static int reconfig_codec(struct hda_codec *codec) int err; snd_printk(KERN_INFO "hda-codec: reconfiguring\n"); - snd_hda_codec_reset(codec); + err = snd_hda_codec_reset(codec); + if (err < 0) { + snd_printk(KERN_ERR + "The codec is being used, can't reconfigure.\n"); + return err; + } err = snd_hda_codec_configure(codec); if (err < 0) return err; -- cgit v1.1 From 43b62713f67d9f0655f3a61f5bd14d6297ddd3ce Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 2 Mar 2009 14:25:17 +0100 Subject: ALSA: hda - Add hint string helper functions Added snd_hda_get_hint() and snd_hda_get_bool_hint() helper functions to retrieve a hint value. Internally, the hint is stored in a pair of two strings, key and val. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_hwdep.c | 112 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 13 deletions(-) (limited to 'sound/pci/hda/hda_hwdep.c') diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c index 4af484b..5e554de 100644 --- a/sound/pci/hda/hda_hwdep.c +++ b/sound/pci/hda/hda_hwdep.c @@ -30,6 +30,12 @@ #include #include +/* hint string pair */ +struct hda_hint { + const char *key; + const char *val; /* contained in the same alloc as key */ +}; + /* * write/read an out-of-bound verb */ @@ -99,15 +105,15 @@ static int hda_hwdep_open(struct snd_hwdep *hw, struct file *file) static void clear_hwdep_elements(struct hda_codec *codec) { - char **head; int i; /* clear init verbs */ snd_array_free(&codec->init_verbs); /* clear hints */ - head = codec->hints.list; - for (i = 0; i < codec->hints.used; i++, head++) - kfree(*head); + for (i = 0; i < codec->hints.used; i++) { + struct hda_hint *hint = snd_array_elem(&codec->hints, i); + kfree(hint->key); /* we don't need to free hint->val */ + } snd_array_free(&codec->hints); snd_array_free(&codec->user_pins); } @@ -141,7 +147,7 @@ int /*__devinit*/ snd_hda_create_hwdep(struct hda_codec *codec) #endif snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32); - snd_array_init(&codec->hints, sizeof(char *), 32); + snd_array_init(&codec->hints, sizeof(struct hda_hint), 32); snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16); return 0; @@ -306,26 +312,81 @@ static ssize_t init_verbs_store(struct device *dev, return count; } +static struct hda_hint *get_hint(struct hda_codec *codec, const char *key) +{ + int i; + + for (i = 0; i < codec->hints.used; i++) { + struct hda_hint *hint = snd_array_elem(&codec->hints, i); + if (!strcmp(hint->key, key)) + return hint; + } + return NULL; +} + +static void remove_trail_spaces(char *str) +{ + char *p; + if (!*str) + return; + p = str + strlen(str) - 1; + for (; isspace(*p); p--) { + *p = 0; + if (p == str) + return; + } +} + +#define MAX_HINTS 1024 + static ssize_t hints_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct snd_hwdep *hwdep = dev_get_drvdata(dev); struct hda_codec *codec = hwdep->private_data; - char *p; - char **hint; + char *key, *val; + struct hda_hint *hint; - if (!*buf || isspace(*buf) || *buf == '#' || *buf == '\n') + while (isspace(*buf)) + buf++; + if (!*buf || *buf == '#' || *buf == '\n') return count; - p = kstrndup_noeol(buf, 1024); - if (!p) + if (*buf == '=') + return -EINVAL; + key = kstrndup_noeol(buf, 1024); + if (!key) return -ENOMEM; - hint = snd_array_new(&codec->hints); + /* extract key and val */ + val = strchr(key, '='); + if (!val) { + kfree(key); + return -EINVAL; + } + *val++ = 0; + while (isspace(*val)) + val++; + remove_trail_spaces(key); + remove_trail_spaces(val); + hint = get_hint(codec, key); + if (hint) { + /* replace */ + kfree(hint->key); + hint->key = key; + hint->val = val; + return count; + } + /* allocate a new hint entry */ + if (codec->hints.used >= MAX_HINTS) + hint = NULL; + else + hint = snd_array_new(&codec->hints); if (!hint) { - kfree(p); + kfree(key); return -ENOMEM; } - *hint = p; + hint->key = key; + hint->val = val; return count; } @@ -428,4 +489,29 @@ int snd_hda_hwdep_add_sysfs(struct hda_codec *codec) return 0; } +/* + * Look for hint string + */ +const char *snd_hda_get_hint(struct hda_codec *codec, const char *key) +{ + struct hda_hint *hint = get_hint(codec, key); + return hint ? hint->val : NULL; +} +EXPORT_SYMBOL_HDA(snd_hda_get_hint); + +int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key) +{ + const char *p = snd_hda_get_hint(codec, key); + if (!p || !*p) + return -ENOENT; + switch (toupper(*p)) { + case 'T': /* true */ + case 'Y': /* yes */ + case '1': + return 1; + } + return 0; +} +EXPORT_SYMBOL_HDA(snd_hda_get_bool_hint); + #endif /* CONFIG_SND_HDA_RECONFIG */ -- cgit v1.1 From ab1726f920275b52991b2eff7538ac6d313bf9a2 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 2 Mar 2009 17:09:25 +0100 Subject: ALSA: hda - Add show for init_verbs and hints sysfs entries Added the show method for init_verbs and hints hwdep sysfs entries. They show the current values. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_hwdep.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'sound/pci/hda/hda_hwdep.c') diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c index 5e554de..1e3ccc7 100644 --- a/sound/pci/hda/hda_hwdep.c +++ b/sound/pci/hda/hda_hwdep.c @@ -290,6 +290,22 @@ static ssize_t type##_store(struct device *dev, \ CODEC_ACTION_STORE(reconfig); CODEC_ACTION_STORE(clear); +static ssize_t init_verbs_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct snd_hwdep *hwdep = dev_get_drvdata(dev); + struct hda_codec *codec = hwdep->private_data; + int i, len = 0; + for (i = 0; i < codec->init_verbs.used; i++) { + struct hda_verb *v = snd_array_elem(&codec->init_verbs, i); + len += snprintf(buf + len, PAGE_SIZE - len, + "0x%02x 0x%03x 0x%04x\n", + v->nid, v->verb, v->param); + } + return len; +} + static ssize_t init_verbs_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -312,6 +328,21 @@ static ssize_t init_verbs_store(struct device *dev, return count; } +static ssize_t hints_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct snd_hwdep *hwdep = dev_get_drvdata(dev); + struct hda_codec *codec = hwdep->private_data; + int i, len = 0; + for (i = 0; i < codec->hints.used; i++) { + struct hda_hint *hint = snd_array_elem(&codec->hints, i); + len += snprintf(buf + len, PAGE_SIZE - len, + "%s = %s\n", hint->key, hint->val); + } + return len; +} + static struct hda_hint *get_hint(struct hda_codec *codec, const char *key) { int i; @@ -466,8 +497,8 @@ static struct device_attribute codec_attrs[] = { CODEC_ATTR_RO(mfg), CODEC_ATTR_RW(name), CODEC_ATTR_RW(modelname), - CODEC_ATTR_WO(init_verbs), - CODEC_ATTR_WO(hints), + CODEC_ATTR_RW(init_verbs), + CODEC_ATTR_RW(hints), CODEC_ATTR_RO(init_pin_configs), CODEC_ATTR_RW(user_pin_configs), CODEC_ATTR_RO(driver_pin_configs), -- cgit v1.1 From bb6ac72fb19c6676eb8bafa8e3b8bf970a2294a2 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 13 Mar 2009 09:02:42 +0100 Subject: ALSA: hda - power up before codec initialization Change the power state of each widget before starting the initialization work so that all verbs are executed properly. Also, keep power-up during hwdep reconfiguration. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_hwdep.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'sound/pci/hda/hda_hwdep.c') diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c index 1e3ccc7..1c57505 100644 --- a/sound/pci/hda/hda_hwdep.c +++ b/sound/pci/hda/hda_hwdep.c @@ -176,25 +176,29 @@ static int reconfig_codec(struct hda_codec *codec) { int err; + snd_hda_power_up(codec); snd_printk(KERN_INFO "hda-codec: reconfiguring\n"); err = snd_hda_codec_reset(codec); if (err < 0) { snd_printk(KERN_ERR "The codec is being used, can't reconfigure.\n"); - return err; + goto error; } err = snd_hda_codec_configure(codec); if (err < 0) - return err; + goto error; /* rebuild PCMs */ err = snd_hda_codec_build_pcms(codec); if (err < 0) - return err; + goto error; /* rebuild mixers */ err = snd_hda_codec_build_controls(codec); if (err < 0) - return err; - return snd_card_register(codec->bus->card); + goto error; + err = snd_card_register(codec->bus->card); + error: + snd_hda_power_down(codec); + return err; } /* -- cgit v1.1