From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Shenghao Ding <shenghao-ding@ti.com>, Kevin Lu <kevin-lu@ti.com>,
Baojun Xu <baojun.xu@ti.com>, Sen Wang <sen@ti.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/7] ASoC: tlv320aic32x4: consolidate programming functions
Date: Sat, 25 Jul 2026 18:05:13 -0700 [thread overview]
Message-ID: <20260726010519.117805-3-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20260726010519.117805-1-dmitry.torokhov@gmail.com>
Consolidate setting up of GPIO functions instead of repeating almost
the same code block 5 times.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
sound/soc/codecs/tlv320aic32x4.c | 90 ++++++++++++--------------------
1 file changed, 33 insertions(+), 57 deletions(-)
diff --git a/sound/soc/codecs/tlv320aic32x4.c b/sound/soc/codecs/tlv320aic32x4.c
index 87b155599e94..6b3ddb89f692 100644
--- a/sound/soc/codecs/tlv320aic32x4.c
+++ b/sound/soc/codecs/tlv320aic32x4.c
@@ -222,25 +222,31 @@ static int aic32x4_set_mfp5_gpio(struct snd_kcontrol *kcontrol,
return 0;
};
-static const struct snd_kcontrol_new aic32x4_mfp1[] = {
- SOC_SINGLE_BOOL_EXT("MFP1 GPIO", 0, aic32x4_get_mfp1_gpio, NULL),
-};
-
-static const struct snd_kcontrol_new aic32x4_mfp2[] = {
- SOC_SINGLE_BOOL_EXT("MFP2 GPIO", 0, NULL, aic32x4_set_mfp2_gpio),
-};
-
-static const struct snd_kcontrol_new aic32x4_mfp3[] = {
- SOC_SINGLE_BOOL_EXT("MFP3 GPIO", 0, aic32x4_get_mfp3_gpio, NULL),
-};
-
-static const struct snd_kcontrol_new aic32x4_mfp4[] = {
- SOC_SINGLE_BOOL_EXT("MFP4 GPIO", 0, NULL, aic32x4_set_mfp4_gpio),
-};
-
-static const struct snd_kcontrol_new aic32x4_mfp5[] = {
- SOC_SINGLE_BOOL_EXT("MFP5 GPIO", 0, aic32x4_get_mfp5_gpio,
- aic32x4_set_mfp5_gpio),
+static const struct {
+ unsigned int reg;
+ struct snd_kcontrol_new ctrl;
+} aic32x4_mfp_cfg[] = {
+ {
+ .reg = AIC32X4_DINCTL,
+ .ctrl = SOC_SINGLE_BOOL_EXT("MFP1 GPIO", 0, aic32x4_get_mfp1_gpio, NULL),
+ },
+ {
+ .reg = AIC32X4_DOUTCTL,
+ .ctrl = SOC_SINGLE_BOOL_EXT("MFP2 GPIO", 0, NULL, aic32x4_set_mfp2_gpio),
+ },
+ {
+ .reg = AIC32X4_SCLKCTL,
+ .ctrl = SOC_SINGLE_BOOL_EXT("MFP3 GPIO", 0, aic32x4_get_mfp3_gpio, NULL),
+ },
+ {
+ .reg = AIC32X4_MISOCTL,
+ .ctrl = SOC_SINGLE_BOOL_EXT("MFP4 GPIO", 0, NULL, aic32x4_set_mfp4_gpio),
+ },
+ {
+ .reg = AIC32X4_GPIOCTL,
+ .ctrl = SOC_SINGLE_BOOL_EXT("MFP5 GPIO", 0, aic32x4_get_mfp5_gpio,
+ aic32x4_set_mfp5_gpio),
+ },
};
/* 0dB min, 0.5dB steps */
@@ -955,44 +961,14 @@ static void aic32x4_setup_gpios(struct snd_soc_component *component)
struct aic32x4_priv *aic32x4 = snd_soc_component_get_drvdata(component);
/* setup GPIO functions */
- /* MFP1 */
- if (aic32x4->gpio_func[0] != AIC32X4_MFPX_DEFAULT_VALUE) {
- snd_soc_component_write(component, AIC32X4_DINCTL,
- aic32x4->gpio_func[0]);
- snd_soc_add_component_controls(component, aic32x4_mfp1,
- ARRAY_SIZE(aic32x4_mfp1));
- }
-
- /* MFP2 */
- if (aic32x4->gpio_func[1] != AIC32X4_MFPX_DEFAULT_VALUE) {
- snd_soc_component_write(component, AIC32X4_DOUTCTL,
- aic32x4->gpio_func[1]);
- snd_soc_add_component_controls(component, aic32x4_mfp2,
- ARRAY_SIZE(aic32x4_mfp2));
- }
-
- /* MFP3 */
- if (aic32x4->gpio_func[2] != AIC32X4_MFPX_DEFAULT_VALUE) {
- snd_soc_component_write(component, AIC32X4_SCLKCTL,
- aic32x4->gpio_func[2]);
- snd_soc_add_component_controls(component, aic32x4_mfp3,
- ARRAY_SIZE(aic32x4_mfp3));
- }
-
- /* MFP4 */
- if (aic32x4->gpio_func[3] != AIC32X4_MFPX_DEFAULT_VALUE) {
- snd_soc_component_write(component, AIC32X4_MISOCTL,
- aic32x4->gpio_func[3]);
- snd_soc_add_component_controls(component, aic32x4_mfp4,
- ARRAY_SIZE(aic32x4_mfp4));
- }
-
- /* MFP5 */
- if (aic32x4->gpio_func[4] != AIC32X4_MFPX_DEFAULT_VALUE) {
- snd_soc_component_write(component, AIC32X4_GPIOCTL,
- aic32x4->gpio_func[4]);
- snd_soc_add_component_controls(component, aic32x4_mfp5,
- ARRAY_SIZE(aic32x4_mfp5));
+ BUILD_BUG_ON(ARRAY_SIZE(aic32x4->gpio_func) != ARRAY_SIZE(aic32x4_mfp_cfg));
+ for (int i = 0; i < ARRAY_SIZE(aic32x4->gpio_func); i++) {
+ if (aic32x4->gpio_func[i] == AIC32X4_MFPX_DEFAULT_VALUE)
+ continue;
+
+ snd_soc_component_write(component, aic32x4_mfp_cfg[i].reg,
+ aic32x4->gpio_func[i]);
+ snd_soc_add_component_controls(component, &aic32x4_mfp_cfg[i].ctrl, 1);
}
}
--
2.55.0.229.g6434b31f56-goog
next prev parent reply other threads:[~2026-07-26 1:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-26 1:05 [PATCH 1/7] ASoC: tlv320aic32x4: remove global header with platform data Dmitry Torokhov
2026-07-26 1:05 ` [PATCH 2/7] ASoC: tlv320aic32x4: do not allocate gpio config separately Dmitry Torokhov
2026-07-26 1:05 ` Dmitry Torokhov [this message]
2026-07-26 1:05 ` [PATCH 4/7] ASoC: tlv320aic32x4: move regmap_config into i2c and spi drivers Dmitry Torokhov
2026-07-26 1:05 ` [PATCH 5/7] ASoC: tlv320aic32x4: do not make clocks bulk data static Dmitry Torokhov
2026-07-26 1:05 ` [PATCH 6/7] ASoC: tlv320aic32x4: factor out rate configuration helper Dmitry Torokhov
2026-07-26 1:05 ` [PATCH 7/7] ASoC: tlv320aic32x4: clean up driver code formatting and logging Dmitry Torokhov
2026-07-29 23:18 ` [PATCH 1/7] ASoC: tlv320aic32x4: remove global header with platform data Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260726010519.117805-3-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=baojun.xu@ti.com \
--cc=broonie@kernel.org \
--cc=kevin-lu@ti.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=sen@ti.com \
--cc=shenghao-ding@ti.com \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®