diff options
author | Takashi Iwai <tiwai@suse.de> | 2009-05-16 04:00:49 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2009-05-16 04:00:49 -0400 |
commit | 812a2cca295ee7f56cd1b988a0f93646285c214a (patch) | |
tree | 814133d9216d3da4707aceda00e24f3b83f8f910 /sound/pci/hda/hda_codec.c | |
parent | 2fc998907947f92b1b9113faad531d7f5a857987 (diff) |
ALSA: hda - Split codec->name to vendor and chip name strings
Split the name string in hda_codec struct to vendor_name and chip_name
strings to be stored directly from the preset name.
Since mostly only the chip name is referred in many patch_*.c, this
results in the reduction of many codes in the end.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/hda_codec.c')
-rw-r--r-- | sound/pci/hda/hda_codec.c | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index b91f6ed5cc58..77385de01744 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c | |||
@@ -623,7 +623,10 @@ static int get_codec_name(struct hda_codec *codec) | |||
623 | const struct hda_vendor_id *c; | 623 | const struct hda_vendor_id *c; |
624 | const char *vendor = NULL; | 624 | const char *vendor = NULL; |
625 | u16 vendor_id = codec->vendor_id >> 16; | 625 | u16 vendor_id = codec->vendor_id >> 16; |
626 | char tmp[16], name[32]; | 626 | char tmp[16]; |
627 | |||
628 | if (codec->vendor_name) | ||
629 | goto get_chip_name; | ||
627 | 630 | ||
628 | for (c = hda_vendor_ids; c->id; c++) { | 631 | for (c = hda_vendor_ids; c->id; c++) { |
629 | if (c->id == vendor_id) { | 632 | if (c->id == vendor_id) { |
@@ -635,14 +638,21 @@ static int get_codec_name(struct hda_codec *codec) | |||
635 | sprintf(tmp, "Generic %04x", vendor_id); | 638 | sprintf(tmp, "Generic %04x", vendor_id); |
636 | vendor = tmp; | 639 | vendor = tmp; |
637 | } | 640 | } |
641 | codec->vendor_name = kstrdup(vendor, GFP_KERNEL); | ||
642 | if (!codec->vendor_name) | ||
643 | return -ENOMEM; | ||
644 | |||
645 | get_chip_name: | ||
646 | if (codec->chip_name) | ||
647 | return 0; | ||
648 | |||
638 | if (codec->preset && codec->preset->name) | 649 | if (codec->preset && codec->preset->name) |
639 | snprintf(name, sizeof(name), "%s %s", vendor, | 650 | codec->chip_name = kstrdup(codec->preset->name, GFP_KERNEL); |
640 | codec->preset->name); | 651 | else { |
641 | else | 652 | sprintf(tmp, "ID %x", codec->vendor_id & 0xffff); |
642 | snprintf(name, sizeof(name), "%s ID %x", vendor, | 653 | codec->chip_name = kstrdup(tmp, GFP_KERNEL); |
643 | codec->vendor_id & 0xffff); | 654 | } |
644 | codec->name = kstrdup(name, GFP_KERNEL); | 655 | if (!codec->chip_name) |
645 | if (!codec->name) | ||
646 | return -ENOMEM; | 656 | return -ENOMEM; |
647 | return 0; | 657 | return 0; |
648 | } | 658 | } |
@@ -848,7 +858,8 @@ static void snd_hda_codec_free(struct hda_codec *codec) | |||
848 | module_put(codec->owner); | 858 | module_put(codec->owner); |
849 | free_hda_cache(&codec->amp_cache); | 859 | free_hda_cache(&codec->amp_cache); |
850 | free_hda_cache(&codec->cmd_cache); | 860 | free_hda_cache(&codec->cmd_cache); |
851 | kfree(codec->name); | 861 | kfree(codec->vendor_name); |
862 | kfree(codec->chip_name); | ||
852 | kfree(codec->modelname); | 863 | kfree(codec->modelname); |
853 | kfree(codec->wcaps); | 864 | kfree(codec->wcaps); |
854 | kfree(codec); | 865 | kfree(codec); |
@@ -989,15 +1000,16 @@ int snd_hda_codec_configure(struct hda_codec *codec) | |||
989 | int err; | 1000 | int err; |
990 | 1001 | ||
991 | codec->preset = find_codec_preset(codec); | 1002 | codec->preset = find_codec_preset(codec); |
992 | if (!codec->name) { | 1003 | if (!codec->vendor_name || !codec->chip_name) { |
993 | err = get_codec_name(codec); | 1004 | err = get_codec_name(codec); |
994 | if (err < 0) | 1005 | if (err < 0) |
995 | return err; | 1006 | return err; |
996 | } | 1007 | } |
997 | /* audio codec should override the mixer name */ | 1008 | /* audio codec should override the mixer name */ |
998 | if (codec->afg || !*codec->bus->card->mixername) | 1009 | if (codec->afg || !*codec->bus->card->mixername) |
999 | strlcpy(codec->bus->card->mixername, codec->name, | 1010 | snprintf(codec->bus->card->mixername, |
1000 | sizeof(codec->bus->card->mixername)); | 1011 | sizeof(codec->bus->card->mixername), |
1012 | "%s %s", codec->vendor_name, codec->chip_name); | ||
1001 | 1013 | ||
1002 | if (is_generic_config(codec)) { | 1014 | if (is_generic_config(codec)) { |
1003 | err = snd_hda_parse_generic_codec(codec); | 1015 | err = snd_hda_parse_generic_codec(codec); |