aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/hda_hwdep.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-02-20 08:11:16 -0500
committerTakashi Iwai <tiwai@suse.de>2009-02-20 10:48:26 -0500
commit3be141494a080a9189b51fa78154c975ad8d9806 (patch)
tree17b62025f9616afe5938a1638195f9b1e9498f11 /sound/pci/hda/hda_hwdep.c
parentd2f57cd54a602c979e571aa337b206c88609876d (diff)
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 <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/hda_hwdep.c')
-rw-r--r--sound/pci/hda/hda_hwdep.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index 4ae51dcb81af..71039a6dec28 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)
109 for (i = 0; i < codec->hints.used; i++, head++) 109 for (i = 0; i < codec->hints.used; i++, head++)
110 kfree(*head); 110 kfree(*head);
111 snd_array_free(&codec->hints); 111 snd_array_free(&codec->hints);
112 snd_array_free(&codec->override_pins);
112} 113}
113 114
114static void hwdep_free(struct snd_hwdep *hwdep) 115static void hwdep_free(struct snd_hwdep *hwdep)
@@ -141,6 +142,7 @@ int /*__devinit*/ snd_hda_create_hwdep(struct hda_codec *codec)
141 142
142 snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32); 143 snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32);
143 snd_array_init(&codec->hints, sizeof(char *), 32); 144 snd_array_init(&codec->hints, sizeof(char *), 32);
145 snd_array_init(&codec->override_pins, sizeof(struct hda_pincfg), 16);
144 146
145 return 0; 147 return 0;
146} 148}
@@ -316,6 +318,67 @@ static ssize_t hints_store(struct device *dev,
316 return count; 318 return count;
317} 319}
318 320
321static ssize_t pin_configs_show(struct hda_codec *codec,
322 struct snd_array *list,
323 char *buf)
324{
325 int i, len = 0;
326 for (i = 0; i < list->used; i++) {
327 struct hda_pincfg *pin = snd_array_elem(list, i);
328 len += sprintf(buf + len, "0x%02x 0x%08x\n",
329 pin->nid, pin->cfg);
330 }
331 return len;
332}
333
334static ssize_t init_pin_configs_show(struct device *dev,
335 struct device_attribute *attr,
336 char *buf)
337{
338 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
339 struct hda_codec *codec = hwdep->private_data;
340 return pin_configs_show(codec, &codec->init_pins, buf);
341}
342
343static ssize_t override_pin_configs_show(struct device *dev,
344 struct device_attribute *attr,
345 char *buf)
346{
347 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
348 struct hda_codec *codec = hwdep->private_data;
349 return pin_configs_show(codec, &codec->override_pins, buf);
350}
351
352static ssize_t cur_pin_configs_show(struct device *dev,
353 struct device_attribute *attr,
354 char *buf)
355{
356 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
357 struct hda_codec *codec = hwdep->private_data;
358 return pin_configs_show(codec, &codec->cur_pins, buf);
359}
360
361#define MAX_PIN_CONFIGS 32
362
363static ssize_t override_pin_configs_store(struct device *dev,
364 struct device_attribute *attr,
365 const char *buf, size_t count)
366{
367 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
368 struct hda_codec *codec = hwdep->private_data;
369 int nid, cfg;
370 int err;
371
372 if (sscanf(buf, "%i %i", &nid, &cfg) != 2)
373 return -EINVAL;
374 if (!nid)
375 return -EINVAL;
376 err = snd_hda_add_pincfg(codec, &codec->override_pins, nid, cfg);
377 if (err < 0)
378 return err;
379 return count;
380}
381
319#define CODEC_ATTR_RW(type) \ 382#define CODEC_ATTR_RW(type) \
320 __ATTR(type, 0644, type##_show, type##_store) 383 __ATTR(type, 0644, type##_show, type##_store)
321#define CODEC_ATTR_RO(type) \ 384#define CODEC_ATTR_RO(type) \
@@ -333,6 +396,9 @@ static struct device_attribute codec_attrs[] = {
333 CODEC_ATTR_RW(modelname), 396 CODEC_ATTR_RW(modelname),
334 CODEC_ATTR_WO(init_verbs), 397 CODEC_ATTR_WO(init_verbs),
335 CODEC_ATTR_WO(hints), 398 CODEC_ATTR_WO(hints),
399 CODEC_ATTR_RO(init_pin_configs),
400 CODEC_ATTR_RW(override_pin_configs),
401 CODEC_ATTR_RO(cur_pin_configs),
336 CODEC_ATTR_WO(reconfig), 402 CODEC_ATTR_WO(reconfig),
337 CODEC_ATTR_WO(clear), 403 CODEC_ATTR_WO(clear),
338}; 404};