Skip to content

Commit 178c169

Browse files
MrVanbroonie
authored andcommitted
ASoC: codec: twl4030: Convert to GPIO descriptors
of_gpio.h is deprecated, update the driver to use GPIO descriptors. - Use of_property_present to check "ti,hs_extmute_gpio" to set hs_extmute - if returned value is true. - Use devm_gpiod_get_optional to get GPIO descriptor, set consumer name. - Use gpiod_set_value to configure output value. While at here - drop remove hook after switching to use devm_gpiod_get_optional - Add return value for twl4030_init_chip to propagate value to parent in case defer probe happens Checking the only user logicpd-som-lv.dtsi that uses polarity GPIO_ACTIVE_HIGH, so all should work as expected. Cc: Tony Lindgren <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Peng Fan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 5ae1bd2 commit 178c169

File tree

1 file changed

+23
-40
lines changed

1 file changed

+23
-40
lines changed

sound/soc/codecs/twl4030.c

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
*/
77

88
#include <linux/delay.h>
9-
#include <linux/gpio.h>
9+
#include <linux/gpio/consumer.h>
1010
#include <linux/i2c.h>
1111
#include <linux/init.h>
1212
#include <linux/mfd/twl.h>
1313
#include <linux/mfd/twl4030-audio.h>
1414
#include <linux/module.h>
1515
#include <linux/moduleparam.h>
1616
#include <linux/of.h>
17-
#include <linux/of_gpio.h>
1817
#include <linux/pm.h>
1918
#include <linux/platform_device.h>
2019
#include <linux/slab.h>
@@ -37,7 +36,7 @@ struct twl4030_board_params {
3736
unsigned int ramp_delay_value;
3837
unsigned int offset_cncl_path;
3938
unsigned int hs_extmute:1;
40-
int hs_extmute_gpio;
39+
struct gpio_desc *hs_extmute_gpio;
4140
};
4241

4342
/* codec private data */
@@ -211,8 +210,7 @@ twl4030_get_board_param_values(struct twl4030_board_params *board_params,
211210
if (!of_property_read_u32(node, "ti,hs_extmute", &value))
212211
board_params->hs_extmute = value;
213212

214-
board_params->hs_extmute_gpio = of_get_named_gpio(node, "ti,hs_extmute_gpio", 0);
215-
if (gpio_is_valid(board_params->hs_extmute_gpio))
213+
if (of_property_present(node, "ti,hs_extmute_gpio"))
216214
board_params->hs_extmute = 1;
217215
}
218216

@@ -240,7 +238,7 @@ twl4030_get_board_params(struct snd_soc_component *component)
240238
return board_params;
241239
}
242240

243-
static void twl4030_init_chip(struct snd_soc_component *component)
241+
static int twl4030_init_chip(struct snd_soc_component *component)
244242
{
245243
struct twl4030_board_params *board_params;
246244
struct twl4030_priv *twl4030 = snd_soc_component_get_drvdata(component);
@@ -250,24 +248,20 @@ static void twl4030_init_chip(struct snd_soc_component *component)
250248
board_params = twl4030_get_board_params(component);
251249

252250
if (board_params && board_params->hs_extmute) {
253-
if (gpio_is_valid(board_params->hs_extmute_gpio)) {
254-
int ret;
255-
256-
if (!board_params->hs_extmute_gpio)
257-
dev_warn(component->dev,
258-
"Extmute GPIO is 0 is this correct?\n");
259-
260-
ret = gpio_request_one(board_params->hs_extmute_gpio,
261-
GPIOF_OUT_INIT_LOW,
262-
"hs_extmute");
263-
if (ret) {
264-
dev_err(component->dev,
265-
"Failed to get hs_extmute GPIO\n");
266-
board_params->hs_extmute_gpio = -1;
267-
}
251+
board_params->hs_extmute_gpio = devm_gpiod_get_optional(component->dev,
252+
"ti,hs_extmute",
253+
GPIOD_OUT_LOW);
254+
if (IS_ERR(board_params->hs_extmute_gpio))
255+
return dev_err_probe(component->dev, PTR_ERR(board_params->hs_extmute_gpio),
256+
"Failed to get hs_extmute GPIO\n");
257+
258+
if (board_params->hs_extmute_gpio) {
259+
gpiod_set_consumer_name(board_params->hs_extmute_gpio, "hs_extmute");
268260
} else {
269261
u8 pin_mux;
270262

263+
dev_info(component->dev, "use TWL4030 GPIO6\n");
264+
271265
/* Set TWL4030 GPIO6 as EXTMUTE signal */
272266
twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux,
273267
TWL4030_PMBR1_REG);
@@ -295,7 +289,7 @@ static void twl4030_init_chip(struct snd_soc_component *component)
295289

296290
/* Machine dependent setup */
297291
if (!board_params)
298-
return;
292+
return 0;
299293

300294
twl4030->board_params = board_params;
301295

@@ -330,6 +324,8 @@ static void twl4030_init_chip(struct snd_soc_component *component)
330324
TWL4030_CNCL_OFFSET_START));
331325

332326
twl4030_codec_enable(component, 0);
327+
328+
return 0;
333329
}
334330

335331
static void twl4030_apll_enable(struct snd_soc_component *component, int enable)
@@ -712,8 +708,8 @@ static void headset_ramp(struct snd_soc_component *component, int ramp)
712708
/* Enable external mute control, this dramatically reduces
713709
* the pop-noise */
714710
if (board_params && board_params->hs_extmute) {
715-
if (gpio_is_valid(board_params->hs_extmute_gpio)) {
716-
gpio_set_value(board_params->hs_extmute_gpio, 1);
711+
if (board_params->hs_extmute_gpio) {
712+
gpiod_set_value(board_params->hs_extmute_gpio, 1);
717713
} else {
718714
hs_pop |= TWL4030_EXTMUTE;
719715
twl4030_write(component, TWL4030_REG_HS_POPN_SET, hs_pop);
@@ -748,8 +744,8 @@ static void headset_ramp(struct snd_soc_component *component, int ramp)
748744

749745
/* Disable external mute */
750746
if (board_params && board_params->hs_extmute) {
751-
if (gpio_is_valid(board_params->hs_extmute_gpio)) {
752-
gpio_set_value(board_params->hs_extmute_gpio, 0);
747+
if (board_params->hs_extmute_gpio) {
748+
gpiod_set_value(board_params->hs_extmute_gpio, 0);
753749
} else {
754750
hs_pop &= ~TWL4030_EXTMUTE;
755751
twl4030_write(component, TWL4030_REG_HS_POPN_SET, hs_pop);
@@ -2166,24 +2162,11 @@ static int twl4030_soc_probe(struct snd_soc_component *component)
21662162
/* Set the defaults, and power up the codec */
21672163
twl4030->sysclk = twl4030_audio_get_mclk() / 1000;
21682164

2169-
twl4030_init_chip(component);
2170-
2171-
return 0;
2172-
}
2173-
2174-
static void twl4030_soc_remove(struct snd_soc_component *component)
2175-
{
2176-
struct twl4030_priv *twl4030 = snd_soc_component_get_drvdata(component);
2177-
struct twl4030_board_params *board_params = twl4030->board_params;
2178-
2179-
if (board_params && board_params->hs_extmute &&
2180-
gpio_is_valid(board_params->hs_extmute_gpio))
2181-
gpio_free(board_params->hs_extmute_gpio);
2165+
return twl4030_init_chip(component);
21822166
}
21832167

21842168
static const struct snd_soc_component_driver soc_component_dev_twl4030 = {
21852169
.probe = twl4030_soc_probe,
2186-
.remove = twl4030_soc_remove,
21872170
.read = twl4030_read,
21882171
.write = twl4030_write,
21892172
.set_bias_level = twl4030_set_bias_level,

0 commit comments

Comments
 (0)