Commit 171c9830 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: ice1712: Simplify with snd_ctl_find_id_mixer()

Replace an open code with the new snd_ctl_find_id_mixer().
There is no functional change.

Also, add the missing NULL checks in psc724_set_jack_state() to deal
with error cases.

Link: https://lore.kernel.org/r/20230720082108.31346-7-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 5f2a937b
...@@ -408,22 +408,13 @@ static const char * const follower_vols[] = { ...@@ -408,22 +408,13 @@ static const char * const follower_vols[] = {
static static
DECLARE_TLV_DB_SCALE(juli_master_db_scale, -6350, 50, 1); DECLARE_TLV_DB_SCALE(juli_master_db_scale, -6350, 50, 1);
static struct snd_kcontrol *ctl_find(struct snd_card *card,
const char *name)
{
struct snd_ctl_elem_id sid = {0};
strscpy(sid.name, name, sizeof(sid.name));
sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
return snd_ctl_find_id(card, &sid);
}
static void add_followers(struct snd_card *card, static void add_followers(struct snd_card *card,
struct snd_kcontrol *master, struct snd_kcontrol *master,
const char * const *list) const char * const *list)
{ {
for (; *list; list++) { for (; *list; list++) {
struct snd_kcontrol *follower = ctl_find(card, *list); struct snd_kcontrol *follower =
snd_ctl_find_id_mixer(card, *list);
/* dev_dbg(card->dev, "add_followers - %s\n", *list); */ /* dev_dbg(card->dev, "add_followers - %s\n", *list); */
if (follower) { if (follower) {
/* dev_dbg(card->dev, "follower %s found\n", *list); */ /* dev_dbg(card->dev, "follower %s found\n", *list); */
......
...@@ -177,7 +177,6 @@ static bool psc724_get_master_switch(struct snd_ice1712 *ice) ...@@ -177,7 +177,6 @@ static bool psc724_get_master_switch(struct snd_ice1712 *ice)
static void psc724_set_jack_state(struct snd_ice1712 *ice, bool hp_connected) static void psc724_set_jack_state(struct snd_ice1712 *ice, bool hp_connected)
{ {
struct psc724_spec *spec = ice->spec; struct psc724_spec *spec = ice->spec;
struct snd_ctl_elem_id elem_id;
struct snd_kcontrol *kctl; struct snd_kcontrol *kctl;
u16 power = spec->wm8776.regs[WM8776_REG_PWRDOWN] & ~WM8776_PWR_HPPD; u16 power = spec->wm8776.regs[WM8776_REG_PWRDOWN] & ~WM8776_PWR_HPPD;
...@@ -187,16 +186,14 @@ static void psc724_set_jack_state(struct snd_ice1712 *ice, bool hp_connected) ...@@ -187,16 +186,14 @@ static void psc724_set_jack_state(struct snd_ice1712 *ice, bool hp_connected)
snd_wm8776_set_power(&spec->wm8776, power); snd_wm8776_set_power(&spec->wm8776, power);
spec->hp_connected = hp_connected; spec->hp_connected = hp_connected;
/* notify about master speaker mute change */ /* notify about master speaker mute change */
memset(&elem_id, 0, sizeof(elem_id)); kctl = snd_ctl_find_id_mixer(ice->card,
elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; "Master Speakers Playback Switch");
strscpy(elem_id.name, "Master Speakers Playback Switch", if (kctl)
sizeof(elem_id.name));
kctl = snd_ctl_find_id(ice->card, &elem_id);
snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
/* and headphone mute change */ /* and headphone mute change */
strscpy(elem_id.name, spec->wm8776.ctl[WM8776_CTL_HP_SW].name, kctl = snd_ctl_find_id_mixer(ice->card,
sizeof(elem_id.name)); spec->wm8776.ctl[WM8776_CTL_HP_SW].name);
kctl = snd_ctl_find_id(ice->card, &elem_id); if (kctl)
snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id); snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
} }
......
...@@ -766,21 +766,12 @@ static const char * const follower_vols[] = { ...@@ -766,21 +766,12 @@ static const char * const follower_vols[] = {
static static
DECLARE_TLV_DB_SCALE(qtet_master_db_scale, -6350, 50, 1); DECLARE_TLV_DB_SCALE(qtet_master_db_scale, -6350, 50, 1);
static struct snd_kcontrol *ctl_find(struct snd_card *card,
const char *name)
{
struct snd_ctl_elem_id sid = {0};
strscpy(sid.name, name, sizeof(sid.name));
sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
return snd_ctl_find_id(card, &sid);
}
static void add_followers(struct snd_card *card, static void add_followers(struct snd_card *card,
struct snd_kcontrol *master, const char * const *list) struct snd_kcontrol *master, const char * const *list)
{ {
for (; *list; list++) { for (; *list; list++) {
struct snd_kcontrol *follower = ctl_find(card, *list); struct snd_kcontrol *follower =
snd_ctl_find_id_mixer(card, *list);
if (follower) if (follower)
snd_ctl_add_follower(master, follower); snd_ctl_add_follower(master, follower);
} }
......
...@@ -34,13 +34,9 @@ static void snd_wm8776_activate_ctl(struct snd_wm8776 *wm, ...@@ -34,13 +34,9 @@ static void snd_wm8776_activate_ctl(struct snd_wm8776 *wm,
struct snd_card *card = wm->card; struct snd_card *card = wm->card;
struct snd_kcontrol *kctl; struct snd_kcontrol *kctl;
struct snd_kcontrol_volatile *vd; struct snd_kcontrol_volatile *vd;
struct snd_ctl_elem_id elem_id;
unsigned int index_offset; unsigned int index_offset;
memset(&elem_id, 0, sizeof(elem_id)); kctl = snd_ctl_find_id_mixer(card, ctl_name);
strscpy(elem_id.name, ctl_name, sizeof(elem_id.name));
elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
kctl = snd_ctl_find_id(card, &elem_id);
if (!kctl) if (!kctl)
return; return;
index_offset = snd_ctl_get_ioff(kctl, &kctl->id); index_offset = snd_ctl_get_ioff(kctl, &kctl->id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment