Skip to content

Commit 5bf5bdf

Browse files
MrVanbroonie
authored andcommitted
ASoC: codec: cs42l52: Convert to GPIO descriptors
of_gpio.h is deprecated, update the driver to use GPIO descriptors. - Use devm_gpiod_get_optional to get GPIO descriptor with default polarity GPIOD_OUT_LOW, set consumer name. - Use gpiod_set_value_cansleep to configure output value. Checking the current driver using legacy GPIO API, the reset value is first output HIGH, then LOW, then HIGH. Checking the datasheet, the device remains in Power-down state until RESET pin is brought high. Since the driver has been here for quite long time and no complain on the reset flow, still follow original flow when using GPIOD descriptors. Per datasheet, the DTS polarity should be GPIOD_ACTIVE_LOW. The binding example use value 0(GPIOD_ACTIVE_HIGH) which seems wrong. And the binding use reset-gpio as example, not same as driver using "cirrus,reset-gpio", and there is no in-tree DTS has the device, so all should be fine with this patch. Signed-off-by: Peng Fan <peng.fan@nxp.com> Link: https://patch.msgid.link/20250506-csl42x-v3-9-e9496db544c4@nxp.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 772c036 commit 5bf5bdf

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

sound/soc/codecs/cs42l52.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
*/
1010

1111
#include <linux/delay.h>
12+
#include <linux/gpio/consumer.h>
1213
#include <linux/i2c.h>
1314
#include <linux/init.h>
1415
#include <linux/input.h>
1516
#include <linux/kernel.h>
1617
#include <linux/module.h>
1718
#include <linux/moduleparam.h>
18-
#include <linux/of_gpio.h>
1919
#include <linux/pm.h>
2020
#include <linux/platform_device.h>
2121
#include <linux/regmap.h>
@@ -50,7 +50,7 @@ struct cs42l52_platform_data {
5050
unsigned int chgfreq;
5151

5252
/* Reset GPIO */
53-
unsigned int reset_gpio;
53+
struct gpio_desc *reset_gpio;
5454
};
5555

5656
struct cs42l52_private {
@@ -1146,25 +1146,21 @@ static int cs42l52_i2c_probe(struct i2c_client *i2c_client)
11461146
"cirrus,chgfreq-divisor", &val32) >= 0)
11471147
pdata->chgfreq = val32;
11481148

1149-
pdata->reset_gpio =
1150-
of_get_named_gpio(i2c_client->dev.of_node,
1151-
"cirrus,reset-gpio", 0);
1149+
pdata->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev,
1150+
"cirrus,reset",
1151+
GPIOD_OUT_LOW);
1152+
1153+
if (IS_ERR(pdata->reset_gpio))
1154+
return PTR_ERR(pdata->reset_gpio);
1155+
1156+
gpiod_set_consumer_name(pdata->reset_gpio, "CS42L52 /RST");
11521157
}
11531158

11541159
cs42l52->pdata = *pdata;
11551160

11561161
if (cs42l52->pdata.reset_gpio) {
1157-
ret = devm_gpio_request_one(&i2c_client->dev,
1158-
cs42l52->pdata.reset_gpio,
1159-
GPIOF_OUT_INIT_HIGH,
1160-
"CS42L52 /RST");
1161-
if (ret < 0) {
1162-
dev_err(&i2c_client->dev, "Failed to request /RST %d: %d\n",
1163-
cs42l52->pdata.reset_gpio, ret);
1164-
return ret;
1165-
}
1166-
gpio_set_value_cansleep(cs42l52->pdata.reset_gpio, 0);
1167-
gpio_set_value_cansleep(cs42l52->pdata.reset_gpio, 1);
1162+
gpiod_set_value_cansleep(cs42l52->pdata.reset_gpio, 1);
1163+
gpiod_set_value_cansleep(cs42l52->pdata.reset_gpio, 0);
11681164
}
11691165

11701166
i2c_set_clientdata(i2c_client, cs42l52);

0 commit comments

Comments
 (0)