Skip to content

Commit

Permalink
ALSA: hda - add more NID->Control mapping
Browse files Browse the repository at this point in the history
This set of changes add missing NID values to some static control
elemenents. Also, it handles all "Capture Source" or "Input Source"
controls.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
  • Loading branch information
Jaroslav Kysela committed Dec 15, 2009
1 parent f405425 commit 5b0cb1d
Show file tree
Hide file tree
Showing 11 changed files with 415 additions and 122 deletions.
64 changes: 62 additions & 2 deletions sound/pci/hda/hda_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
#endif
list_del(&codec->list);
snd_array_free(&codec->mixers);
snd_array_free(&codec->nids);
codec->bus->caddr_tbl[codec->addr] = NULL;
if (codec->patch_ops.free)
codec->patch_ops.free(codec);
Expand Down Expand Up @@ -985,7 +986,8 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
mutex_init(&codec->control_mutex);
init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 60);
snd_array_init(&codec->mixers, sizeof(struct hda_nid_item), 32);
snd_array_init(&codec->nids, sizeof(struct hda_nid_item), 32);
snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
if (codec->bus->modelname) {
Expand Down Expand Up @@ -1706,7 +1708,7 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
EXPORT_SYMBOL_HDA(snd_hda_find_mixer_ctl);

/**
* snd_hda_ctl-add - Add a control element and assign to the codec
* snd_hda_ctl_add - Add a control element and assign to the codec
* @codec: HD-audio codec
* @nid: corresponding NID (optional)
* @kctl: the control element to assign
Expand Down Expand Up @@ -1746,6 +1748,35 @@ int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
}
EXPORT_SYMBOL_HDA(snd_hda_ctl_add);

/**
* snd_hda_add_nid - Assign a NID to a control element
* @codec: HD-audio codec
* @nid: corresponding NID (optional)
* @kctl: the control element to assign
* @index: index to kctl
*
* Add the given control element to an array inside the codec instance.
* This function is used when #snd_hda_ctl_add cannot be used for 1:1
* NID:KCTL mapping - for example "Capture Source" selector.
*/
int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
unsigned int index, hda_nid_t nid)
{
struct hda_nid_item *item;

if (nid > 0) {
item = snd_array_new(&codec->nids);
if (!item)
return -ENOMEM;
item->kctl = kctl;
item->index = index;
item->nid = nid;
return 0;
}
return -EINVAL;
}
EXPORT_SYMBOL_HDA(snd_hda_add_nid);

/**
* snd_hda_ctls_clear - Clear all controls assigned to the given codec
* @codec: HD-audio codec
Expand All @@ -1757,6 +1788,7 @@ void snd_hda_ctls_clear(struct hda_codec *codec)
for (i = 0; i < codec->mixers.used; i++)
snd_ctl_remove(codec->bus->card, items[i].kctl);
snd_array_free(&codec->mixers);
snd_array_free(&codec->nids);
}

/* pseudo device locking
Expand Down Expand Up @@ -3476,6 +3508,8 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)

for (; knew->name; knew++) {
struct snd_kcontrol *kctl;
if (knew->iface == -1) /* skip this codec private value */
continue;
kctl = snd_ctl_new1(knew, codec);
if (!kctl)
return -ENOMEM;
Expand All @@ -3496,6 +3530,32 @@ int snd_hda_add_new_ctls(struct hda_codec *codec, struct snd_kcontrol_new *knew)
}
EXPORT_SYMBOL_HDA(snd_hda_add_new_ctls);

/**
* snd_hda_add_nids - assign nids to controls from the array
* @codec: the HDA codec
* @kctl: struct snd_kcontrol
* @index: index to kctl
* @nids: the array of hda_nid_t
* @size: count of hda_nid_t items
*
* This helper function assigns NIDs in the given array to a control element.
*
* Returns 0 if successful, or a negative error code.
*/
int snd_hda_add_nids(struct hda_codec *codec, struct snd_kcontrol *kctl,
unsigned int index, hda_nid_t *nids, unsigned int size)
{
int err;

for ( ; size > 0; size--, nids++) {
err = snd_hda_add_nid(codec, kctl, index, *nids);
if (err < 0)
return err;
}
return 0;
}
EXPORT_SYMBOL_HDA(snd_hda_add_nids);

#ifdef CONFIG_SND_HDA_POWER_SAVE
static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
unsigned int power_state);
Expand Down
1 change: 1 addition & 0 deletions sound/pci/hda/hda_codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ struct hda_codec {
u32 *wcaps;

struct snd_array mixers; /* list of assigned mixer elements */
struct snd_array nids; /* list of mapped mixer elements */

struct hda_cache_rec amp_cache; /* cache for amp access */
struct hda_cache_rec cmd_cache; /* cache for other commands */
Expand Down
3 changes: 2 additions & 1 deletion sound/pci/hda/hda_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,8 @@ static int build_input_controls(struct hda_codec *codec)
}

/* create input MUX if multiple sources are available */
err = snd_hda_ctl_add(codec, 0, snd_ctl_new1(&cap_sel, codec));
err = snd_hda_ctl_add(codec, spec->adc_node->nid,
snd_ctl_new1(&cap_sel, codec));
if (err < 0)
return err;

Expand Down
5 changes: 5 additions & 0 deletions sound/pci/hda/hda_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ int snd_hda_check_board_codec_sid_config(struct hda_codec *codec,
const struct snd_pci_quirk *tbl);
int snd_hda_add_new_ctls(struct hda_codec *codec,
struct snd_kcontrol_new *knew);
int snd_hda_add_nids(struct hda_codec *codec, struct snd_kcontrol *kctl,
unsigned int index, hda_nid_t *nids, unsigned int size);

/*
* unsolicited event handler
Expand Down Expand Up @@ -466,11 +468,14 @@ int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);

struct hda_nid_item {
struct snd_kcontrol *kctl;
unsigned int index;
hda_nid_t nid;
};

int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
struct snd_kcontrol *kctl);
int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
unsigned int index, hda_nid_t nid);
void snd_hda_ctls_clear(struct hda_codec *codec);

/*
Expand Down
23 changes: 14 additions & 9 deletions sound/pci/hda/hda_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,21 @@ static const char *get_wid_type_name(unsigned int wid_value)
return "UNKNOWN Widget";
}

static void print_nid_mixers(struct snd_info_buffer *buffer,
struct hda_codec *codec, hda_nid_t nid)
static void print_nid_array(struct snd_info_buffer *buffer,
struct hda_codec *codec, hda_nid_t nid,
struct snd_array *array)
{
int i;
struct hda_nid_item *items = codec->mixers.list;
struct hda_nid_item *items = array->list, *item;
struct snd_kcontrol *kctl;
for (i = 0; i < codec->mixers.used; i++) {
if (items[i].nid == nid) {
kctl = items[i].kctl;
for (i = 0; i < array->used; i++) {
item = &items[i];
if (item->nid == nid) {
kctl = item->kctl;
snd_iprintf(buffer,
" Control: name=\"%s\", index=%i, device=%i\n",
kctl->id.name, kctl->id.index, kctl->id.device);
kctl->id.name, kctl->id.index + item->index,
kctl->id.device);
}
}
}
Expand Down Expand Up @@ -528,7 +531,8 @@ static void print_gpio(struct snd_info_buffer *buffer,
(data & (1<<i)) ? 1 : 0,
(unsol & (1<<i)) ? 1 : 0);
/* FIXME: add GPO and GPI pin information */
print_nid_mixers(buffer, codec, nid);
print_nid_array(buffer, codec, nid, &codec->mixers);
print_nid_array(buffer, codec, nid, &codec->nids);
}

static void print_codec_info(struct snd_info_entry *entry,
Expand Down Expand Up @@ -608,7 +612,8 @@ static void print_codec_info(struct snd_info_entry *entry,
snd_iprintf(buffer, " CP");
snd_iprintf(buffer, "\n");

print_nid_mixers(buffer, codec, nid);
print_nid_array(buffer, codec, nid, &codec->mixers);
print_nid_array(buffer, codec, nid, &codec->nids);
print_nid_pcms(buffer, codec, nid);

/* volume knob is a special widget that always have connection
Expand Down
31 changes: 31 additions & 0 deletions sound/pci/hda/patch_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ static struct snd_kcontrol_new ad_beep_mixer[] = {
static int ad198x_build_controls(struct hda_codec *codec)
{
struct ad198x_spec *spec = codec->spec;
struct snd_kcontrol *kctl;
unsigned int i;
int err;

Expand Down Expand Up @@ -239,6 +240,28 @@ static int ad198x_build_controls(struct hda_codec *codec)
}

ad198x_free_kctls(codec); /* no longer needed */

/* assign Capture Source enums to NID */
kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
if (!kctl)
kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
for (i = 0; kctl && i < kctl->count; i++) {
err = snd_hda_add_nids(codec, kctl, i, spec->capsrc_nids,
spec->input_mux->num_items);
if (err < 0)
return err;
}

/* assign IEC958 enums to NID */
kctl = snd_hda_find_mixer_ctl(codec,
SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source");
if (kctl) {
err = snd_hda_add_nid(codec, kctl, 0,
spec->multiout.dig_out_nid);
if (err < 0)
return err;
}

return 0;
}

Expand Down Expand Up @@ -701,6 +724,7 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "External Amplifier",
.subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
.info = ad198x_eapd_info,
.get = ad198x_eapd_get,
.put = ad198x_eapd_put,
Expand Down Expand Up @@ -808,6 +832,7 @@ static struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "Master Playback Switch",
.subdevice = HDA_SUBDEV_NID_FLAG | 0x1a,
.info = snd_hda_mixer_amp_switch_info,
.get = snd_hda_mixer_amp_switch_get,
.put = ad1986a_hp_master_sw_put,
Expand Down Expand Up @@ -1608,6 +1633,7 @@ static struct snd_kcontrol_new ad1981_hp_mixers[] = {
HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.subdevice = HDA_SUBDEV_NID_FLAG | 0x05,
.name = "Master Playback Switch",
.info = ad198x_eapd_info,
.get = ad198x_eapd_get,
Expand Down Expand Up @@ -2121,6 +2147,7 @@ static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "External Amplifier",
.subdevice = HDA_SUBDEV_NID_FLAG | 0x12,
.info = ad198x_eapd_info,
.get = ad198x_eapd_get,
.put = ad198x_eapd_put,
Expand Down Expand Up @@ -2242,6 +2269,7 @@ static struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "IEC958 Playback Source",
.subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
.info = ad1988_spdif_playback_source_info,
.get = ad1988_spdif_playback_source_get,
.put = ad1988_spdif_playback_source_put,
Expand Down Expand Up @@ -3728,6 +3756,7 @@ static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "Master Playback Switch",
.subdevice = HDA_SUBDEV_NID_FLAG | 0x21,
.info = snd_hda_mixer_amp_switch_info,
.get = snd_hda_mixer_amp_switch_get,
.put = ad1884a_mobile_master_sw_put,
Expand Down Expand Up @@ -3756,6 +3785,7 @@ static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "Master Playback Switch",
.subdevice = HDA_SUBDEV_NID_FLAG | 0x21,
.info = snd_hda_mixer_amp_switch_info,
.get = snd_hda_mixer_amp_switch_get,
.put = ad1884a_mobile_master_sw_put,
Expand Down Expand Up @@ -4097,6 +4127,7 @@ static struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
/* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
{
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.subdevice = HDA_SUBDEV_NID_FLAG | 0x21,
.name = "Master Playback Switch",
.info = snd_hda_mixer_amp_switch_info,
.get = snd_hda_mixer_amp_switch_get,
Expand Down
4 changes: 4 additions & 0 deletions sound/pci/hda/patch_cirrus.c
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,10 @@ static int build_input(struct hda_codec *codec)
err = snd_hda_ctl_add(codec, 0, kctl);
if (err < 0)
return err;
err = snd_hda_add_nids(codec, kctl, 0, spec->adc_nid,
spec->num_inputs);
if (err < 0)
return err;
}

if (spec->num_inputs > 1 && !spec->mic_detect) {
Expand Down
12 changes: 11 additions & 1 deletion sound/pci/hda/patch_cmedia.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ static struct hda_verb cmi9880_allout_init[] = {
static int cmi9880_build_controls(struct hda_codec *codec)
{
struct cmi_spec *spec = codec->spec;
int err;
struct snd_kcontrol *kctl;
int i, err;

err = snd_hda_add_new_ctls(codec, cmi9880_basic_mixer);
if (err < 0)
Expand All @@ -340,6 +341,15 @@ static int cmi9880_build_controls(struct hda_codec *codec)
if (err < 0)
return err;
}

/* assign Capture Source enums to NID */
kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
for (i = 0; kctl && i < kctl->count; i++) {
err = snd_hda_add_nids(codec, kctl, i, spec->adc_nids,
spec->input_mux->num_items);
if (err < 0)
return err;
}
return 0;
}

Expand Down
Loading

0 comments on commit 5b0cb1d

Please sign in to comment.