Commit 2e42b089 authored by Takashi Iwai's avatar Takashi Iwai Committed by Greg Kroah-Hartman

staging: bcm2835-audio: Simplify kctl creation helpers

Just a minor code refactoring and adding some const prefix.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Tested-by: default avatarStefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8cc64ae7
...@@ -97,40 +97,34 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol, ...@@ -97,40 +97,34 @@ static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1); static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
static struct snd_kcontrol_new snd_bcm2835_ctl[] = { static const struct snd_kcontrol_new snd_bcm2835_ctl[] = {
{ {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Playback Volume", .name = "PCM Playback Volume",
.index = 0,
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
.private_value = PCM_PLAYBACK_VOLUME, .private_value = PCM_PLAYBACK_VOLUME,
.info = snd_bcm2835_ctl_info, .info = snd_bcm2835_ctl_info,
.get = snd_bcm2835_ctl_get, .get = snd_bcm2835_ctl_get,
.put = snd_bcm2835_ctl_put, .put = snd_bcm2835_ctl_put,
.count = 1,
.tlv = {.p = snd_bcm2835_db_scale} .tlv = {.p = snd_bcm2835_db_scale}
}, },
{ {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Playback Switch", .name = "PCM Playback Switch",
.index = 0,
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.private_value = PCM_PLAYBACK_MUTE, .private_value = PCM_PLAYBACK_MUTE,
.info = snd_bcm2835_ctl_info, .info = snd_bcm2835_ctl_info,
.get = snd_bcm2835_ctl_get, .get = snd_bcm2835_ctl_get,
.put = snd_bcm2835_ctl_put, .put = snd_bcm2835_ctl_put,
.count = 1,
}, },
{ {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "PCM Playback Route", .name = "PCM Playback Route",
.index = 0,
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
.private_value = PCM_PLAYBACK_DEVICE, .private_value = PCM_PLAYBACK_DEVICE,
.info = snd_bcm2835_ctl_info, .info = snd_bcm2835_ctl_info,
.get = snd_bcm2835_ctl_get, .get = snd_bcm2835_ctl_get,
.put = snd_bcm2835_ctl_put, .put = snd_bcm2835_ctl_put,
.count = 1,
}, },
}; };
...@@ -196,7 +190,7 @@ static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol, ...@@ -196,7 +190,7 @@ static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
return 0; return 0;
} }
static struct snd_kcontrol_new snd_bcm2835_spdif[] = { static const struct snd_kcontrol_new snd_bcm2835_spdif[] = {
{ {
.iface = SNDRV_CTL_ELEM_IFACE_PCM, .iface = SNDRV_CTL_ELEM_IFACE_PCM,
.name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
...@@ -213,28 +207,32 @@ static struct snd_kcontrol_new snd_bcm2835_spdif[] = { ...@@ -213,28 +207,32 @@ static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
}, },
}; };
int snd_bcm2835_new_ctl(struct bcm2835_chip *chip) static int create_ctls(struct bcm2835_chip *chip, size_t size,
const struct snd_kcontrol_new *kctls)
{ {
int err; int i, err;
unsigned int idx;
strcpy(chip->card->mixername, "Broadcom Mixer"); for (i = 0; i < size; i++) {
for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) { err = snd_ctl_add(chip->card, snd_ctl_new1(&kctls[i], chip));
err = snd_ctl_add(chip->card,
snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
if (err < 0)
return err;
}
for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
err = snd_ctl_add(chip->card,
snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
if (err < 0) if (err < 0)
return err; return err;
} }
return 0; return 0;
} }
static struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = { int snd_bcm2835_new_ctl(struct bcm2835_chip *chip)
{
int err;
strcpy(chip->card->mixername, "Broadcom Mixer");
err = create_ctls(chip, ARRAY_SIZE(snd_bcm2835_ctl), snd_bcm2835_ctl);
if (err < 0)
return err;
return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_spdif),
snd_bcm2835_spdif);
}
static const struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = {
{ {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "Headphone Playback Volume", .name = "Headphone Playback Volume",
...@@ -263,21 +261,12 @@ static struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = { ...@@ -263,21 +261,12 @@ static struct snd_kcontrol_new snd_bcm2835_headphones_ctl[] = {
int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip) int snd_bcm2835_new_headphones_ctl(struct bcm2835_chip *chip)
{ {
int err;
unsigned int idx;
strcpy(chip->card->mixername, "Broadcom Mixer"); strcpy(chip->card->mixername, "Broadcom Mixer");
for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_headphones_ctl); idx++) { return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_headphones_ctl),
err = snd_ctl_add(chip->card, snd_bcm2835_headphones_ctl);
snd_ctl_new1(&snd_bcm2835_headphones_ctl[idx],
chip));
if (err)
return err;
}
return 0;
} }
static struct snd_kcontrol_new snd_bcm2835_hdmi[] = { static const struct snd_kcontrol_new snd_bcm2835_hdmi[] = {
{ {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.name = "HDMI Playback Volume", .name = "HDMI Playback Volume",
...@@ -306,16 +295,8 @@ static struct snd_kcontrol_new snd_bcm2835_hdmi[] = { ...@@ -306,16 +295,8 @@ static struct snd_kcontrol_new snd_bcm2835_hdmi[] = {
int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip) int snd_bcm2835_new_hdmi_ctl(struct bcm2835_chip *chip)
{ {
int err;
unsigned int idx;
strcpy(chip->card->mixername, "Broadcom Mixer"); strcpy(chip->card->mixername, "Broadcom Mixer");
for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_hdmi); idx++) { return create_ctls(chip, ARRAY_SIZE(snd_bcm2835_hdmi),
err = snd_ctl_add(chip->card, snd_bcm2835_hdmi);
snd_ctl_new1(&snd_bcm2835_hdmi[idx], chip));
if (err)
return err;
}
return 0;
} }
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