ASoC: rt712: add GPIOs for LED control
Subsystems (3)
PATCH 1/1 ASoC: rt712: add GPIOs for LED control
From: Shuming Fan <[email protected]>
Certain platforms use the RT712 GPIOs to control the microphone mute LED and speaker mute LED. This patch lets the LED subsystem to handle the GPIO control.
--- sound/soc/codecs/rt712-sdca-sdw.h | 3 + sound/soc/codecs/rt712-sdca.c | 106 ++++++++++++++++++++++++++++++ sound/soc/codecs/rt712-sdca.h | 6 +- 3 files changed, 114 insertions(+), 1 deletion(-)
sound/soc/codecs/rt712-sdca-sdw.h +3 -0
@@ -46,6 +46,9 @@ static const struct reg_default rt712_sdca_mbq_defaults[] = { { 0x5b00029, 0x3fff }, { 0x5b0002a, 0xf000 }, { 0x6100000, 0x04e4 }, + { 0x6100009, 0x0000 }, + { 0x610000a, 0x0000 }, + { 0x610000b, 0x0020 }, { 0x610000e, 0x0007 }, { 0x6100045, 0x0860 }, { 0x6100046, 0x0029 },
sound/soc/codecs/rt712-sdca.c +106 -0
118 lines not on this page · raw message
sound/soc/codecs/rt712-sdca.h +5 -1
@@ -14,6 +14,7 @@#include <linux/soundwire/sdw_type.h> #include <sound/soc.h> #include <linux/workqueue.h> +#include <linux/gpio/driver.h> struct rt712_sdca_priv {struct regmap *regmap;
@@ -45,6 +46,7 @@ struct rt712_sdca_priv {bool fu05_dapm_mute;bool fu05_mixer_l_mute;bool fu05_mixer_r_mute; +struct gpio_chip gpio_chip; };struct rt712_dmic_kctrl_priv {
@@ -114,6 +116,9 @@ struct rt712_dmic_kctrl_priv {#define RT712_HDA_LEGACY_MUX_CTL0 0x00#define RT712_HDA_LEGACY_CONFIG_CTL0 0x06#define RT712_HDA_LEGACY_RESET_CTL 0x08 +#define RT712_HDA_GPIO_EN_CTL 0x09 +#define RT712_HDA_GPIO_DIRECTION_CTL 0x0a +#define RT712_HDA_GPIO_SET_CTL 0x0b#define RT712_HDA_LEGACY_GPIO_WAKE_EN_CTL 0x0e#define RT712_DMIC_ENT_FLOAT_CTL 0x10#define RT712_DMIC_GAIN_ENT_FLOAT_CTL0 0x11
@@ -271,7 +276,6 @@ enum { RT712_CLK_FREQ_22_5792MHZ = 4, }; -int rt712_sdca_io_init (struct device *dev,struct sdw_slave *slave);int rt712_sdca_init (struct device *dev,struct regmap *regmap,struct regmap *mbq_regmap,struct sdw_slave *slave);
Signature · 1 line
2.54.0
Mark Brown
maintainerQuoted 6 lines · On Wed, Sep 16, 2026 at 05:05:13PM +0800, [email protected] wrote:
From: Shuming Fan <[email protected]>
Certain platforms use the RT712 GPIOs to control the microphone mute LED and speaker mute LED. This patch lets the LED subsystem to handle the GPIO control.
sound/soc/codecs/rt712-sdca.c +1
-0+static int rt712_sdca_gpio_request (struct gpio_chip *chip,unsigned int offset)
sound/soc/codecs/rt712-sdca.c static void rt712_sdca_clk_patch2(struct rt712_sdca_priv *rt712) · line 126
Quoted 10 lines
sound/soc/codecs/rt712-sdca.c +10
-0+{ +struct rt712_sdca_priv *rt712 =gpiochip_get_data (chip); +unsigned int gpio_pin = offset +3 ; +int ret; + +dev_dbg (&rt712->slave->dev,"%s: gpio_pin=%d\n" , __func__, gpio_pin); + + ret =pm_runtime_resume (rt712->component->dev); +if (ret <0 && ret != -EACCES ) +return ret;
This pm_runtime_resume() usage can race with autosuspend, if the autosuspend timer is about to expire it could do so before we actually update the register values so the writes won't actually happen. It's very unlikely to actually happen but the risk is there.
sound/soc/codecs/rt712-sdca.c static void rt712_sdca_clk_patch2(struct rt712_sdca_priv *rt712) · line 136
Quoted 9 lines
sound/soc/codecs/rt712-sdca.c +9
-0+/* +* Only support GPIO3 and GPIO4 for now +*/ +switch (gpio_pin) { +case 3 : +break ; +case 4 : +rt712_sdca_index_update_bits (rt712,RT712_VENDOR_HDA_CTL , +RT712_HDA_LEGACY_CONFIG_CTL0 ,0x000c ,0x0004 );
This doesn't do any locking with other regmap users and gpiolib won't hold a lock for us - since rt712_sdca_index_update_bits() is a read/modify/write cycle this could lead to corruption.
sound/soc/codecs/rt712-sdca.c static void rt712_sdca_clk_patch2(struct rt712_sdca_priv *rt712) · line 217
Quoted 12 lines
sound/soc/codecs/rt712-sdca.c +12
-0+static void rt712_sdca_gpio_init (struct rt712_sdca_priv *rt712) +{ +int ret; + + rt712->gpio_chip = rt712_sdca_template_chip; + rt712->gpio_chip.parent = &rt712->slave->dev; + rt712->gpio_chip.fwnode =dev_fwnode (&rt712->slave->dev); + + ret =devm_gpiochip_add_data (&rt712->slave->dev, &rt712->gpio_chip, rt712); +if (ret !=0 ) +dev_err (&rt712->slave->dev,"Failed to add GPIOs: %d\n" , ret); +}
The gpiolib usage either needs to be conditional on gpiolib or we need the driver to depend on it. Either is fine.
sound/soc/codecs/rt712-sdca.c static int rt712_sdca_probe(struct snd_soc_component *component) · line 1212
Quoted 10 lines
sound/soc/codecs/rt712-sdca.c +3
-0@@ -1101,6 +1204,9 @@ static int rt712_sdca_probe(struct snd_soc_component *component) rt712_sdca_spk_dapm_routes, ARRAY_SIZE(rt712_sdca_spk_dapm_routes)); } +/* initialize GPIOs */ +rt712_sdca_gpio_init (rt712); +if (!rt712->first_hw_init)return 0 ;
This will happen every time the card binds and uses devm, I'd expect it to happen when the SoundWire device binds rather than during ASoC level initialisation. We don't want to continually register and unregister the GPIOs.
sound/soc/codecs/rt712-sdca.h enum { · line 281
Quoted 8 lines
sound/soc/codecs/rt712-sdca.h +0
-1@@ -271,7 +276,6 @@ enum { RT712_CLK_FREQ_22_5792MHZ = 4, }; -int rt712_sdca_io_init (struct device *dev,struct sdw_slave *slave);int rt712_sdca_init (struct device *dev,struct regmap *regmap,struct regmap *mbq_regmap,struct sdw_slave *slave);
Unrelated whitespace change.
Quoted 11 lines
sound/soc/codecs/rt712-sdca.c static void rt712_sdca_clk_patch2(struct rt712_sdca_priv *rt712) · line 126
Quoted 6 lines
sound/soc/codecs/rt712-sdca.c +6
-0+dev_dbg (&rt712->slave->dev,"%s: gpio_pin=%d\n" , __func__, +gpio_pin); + + ret =pm_runtime_resume (rt712->component->dev); +if (ret <0 && ret != -EACCES ) +return ret;This
pm_runtime_resume()usage can race with autosuspend, if the autosuspend timer is about to expire it could do so before we actually update the register values so the writes won't actually happen. It's very unlikely to actually happen but the risk is there.
Thanks for review.
I will use pm_runtime_resume_and_get() instead.
Quoted 10 lines
sound/soc/codecs/rt712-sdca.c static void rt712_sdca_clk_patch2(struct rt712_sdca_priv *rt712) · line 136
Quoted 6 lines
sound/soc/codecs/rt712-sdca.c +6
-0+switch (gpio_pin) { +case 3 : +break ; +case 4 : +rt712_sdca_index_update_bits (rt712,RT712_VENDOR_HDA_CTL , +RT712_HDA_LEGACY_CONFIG_CTL0 ,0x000c ,0x0004 );This doesn't do any locking with other regmap users and gpiolib won't hold a lock for us - since
rt712_sdca_index_update_bits()is a read/modify/write cycle this could lead to corruption.
Sure. May I add a lock in the callback instead of only locking rt712_sdca_index_update_bits()? I will send v2 afterward.
Quoted 9 lines
sound/soc/codecs/rt712-sdca.c static void rt712_sdca_clk_patch2(struct rt712_sdca_priv *rt712)
Quoted 8 lines
sound/soc/codecs/rt712-sdca.c +8
-0+static void rt712_sdca_gpio_init (struct rt712_sdca_priv *rt712) { +int ret; + + rt712->gpio_chip = rt712_sdca_template_chip; + rt712->gpio_chip.parent = &rt712->slave->dev; + rt712->gpio_chip.fwnode =dev_fwnode (&rt712->slave->dev); + + ret = devm_gpiochip_add_data(&rt712->slave->dev, &rt712->gpio_chip,rt712);
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (ret != 0) + dev_err(&rt712->slave->dev, "Failed to add GPIOs: %d\n", ret); }The gpiolib usage either needs to be conditional on gpiolib or we need the driver to depend on it. Either is fine.
Add the 'IS_ENABLED(CONFIG_GPIOLIB)' check before calling rt712_sdca_gpio_init().
Quoted 11 lines
sound/soc/codecs/rt712-sdca.c static int rt712_sdca_probe(struct snd_soc_component *component) · line 1211
Quoted 7 lines
sound/soc/codecs/rt712-sdca.c +3
-0+/* initialize GPIOs */ +rt712_sdca_gpio_init (rt712); +if (!rt712->first_hw_init)return 0 ;This will happen every time the card binds and uses devm, I'd expect it to happen when the SoundWire device binds rather than during ASoC level initialisation. We don't want to continually register and unregister the GPIOs.
Will move to sdw_driver.probe().
Quoted 10 lines
sound/soc/codecs/rt712-sdca.h enum { · line 281
Quoted 8 lines
sound/soc/codecs/rt712-sdca.h +0
-1@@ -271,7 +276,6 @@ enum { RT712_CLK_FREQ_22_5792MHZ = 4, }; -int rt712_sdca_io_init (struct device *dev,struct sdw_slave *slave);int rt712_sdca_init (struct device *dev,struct regmap *regmap,struct regmap *mbq_regmap,struct sdw_slave *slave);Unrelated whitespace change.
Wil fix
Mark Brown
maintainerQuoted 8 lines · Shuming [范書銘]
Quoted 6 lines
sound/soc/codecs/rt712-sdca.c static void rt712_sdca_clk_patch2(struct rt712_sdca_priv *rt712) · line 136
Quoted 2 lines
sound/soc/codecs/rt712-sdca.c +2
-0+rt712_sdca_index_update_bits (rt712,RT712_VENDOR_HDA_CTL , +RT712_HDA_LEGACY_CONFIG_CTL0 ,0x000c ,0x0004 );This doesn't do any locking with other regmap users and gpiolib won't hold a lock for us - since
rt712_sdca_index_update_bits()is a read/modify/write cycle this could lead to corruption.Sure. May I add a lock in the callback instead of only locking
rt712_sdca_index_update_bits()?
That sounds pluasible.