Skip to content

Commit 0bb92e4

Browse files
MrVanbroonie
authored andcommitted
ASoC: codec: cs42l56: 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 nreset value is first output HIGH, then LOW, then HIGH. Checking the datasheet, nreset is should be held low after power on, when nreset is high, it starts to work. Since the driver has been here for quite long time and no complain on the nreset flow, still follow original flow when using GPIOD descriptors. Commit 944004e ("gpiolib: of: add a quirk for reset line for Cirrus CS42L56 codec") added quirks, so the gpio request API will work as before. Per datasheet, the DTS polarity should be GPIOD_ACTIVE_LOW. The binding example use value 0(GPIOD_ACTIVE_HIGH) which seems wrong. There is no in-tree DTS has the device, so all should be fine. Signed-off-by: Peng Fan <peng.fan@nxp.com> Link: https://patch.msgid.link/20250506-csl42x-v3-3-e9496db544c4@nxp.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 86f6e47 commit 0bb92e4

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

sound/soc/codecs/cs42l56.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
*/
99

1010
#include <linux/delay.h>
11+
#include <linux/gpio/consumer.h>
1112
#include <linux/i2c.h>
1213
#include <linux/init.h>
1314
#include <linux/input.h>
1415
#include <linux/kernel.h>
1516
#include <linux/module.h>
1617
#include <linux/moduleparam.h>
1718
#include <linux/of.h>
18-
#include <linux/of_gpio.h>
1919
#include <linux/platform_device.h>
2020
#include <linux/pm.h>
2121
#include <linux/regmap.h>
@@ -35,7 +35,7 @@
3535

3636
struct cs42l56_platform_data {
3737
/* GPIO for Reset */
38-
unsigned int gpio_nreset;
38+
struct gpio_desc *gpio_nreset;
3939

4040
/* MICBIAS Level. Check datasheet Pg48 */
4141
unsigned int micbias_lvl;
@@ -1193,7 +1193,13 @@ static int cs42l56_handle_of_data(struct i2c_client *i2c_client,
11931193
if (of_property_read_u32(np, "cirrus,hpf-left-freq", &val32) >= 0)
11941194
pdata->hpfb_freq = val32;
11951195

1196-
pdata->gpio_nreset = of_get_named_gpio(np, "cirrus,gpio-nreset", 0);
1196+
pdata->gpio_nreset = devm_gpiod_get_optional(&i2c_client->dev, "cirrus,gpio-nreset",
1197+
GPIOD_OUT_LOW);
1198+
1199+
if (IS_ERR(pdata->gpio_nreset))
1200+
return PTR_ERR(pdata->gpio_nreset);
1201+
1202+
gpiod_set_consumer_name(pdata->gpio_nreset, "CS42L56 /RST");
11971203

11981204
return 0;
11991205
}
@@ -1225,19 +1231,10 @@ static int cs42l56_i2c_probe(struct i2c_client *i2c_client)
12251231
}
12261232

12271233
if (cs42l56->pdata.gpio_nreset) {
1228-
ret = gpio_request_one(cs42l56->pdata.gpio_nreset,
1229-
GPIOF_OUT_INIT_HIGH, "CS42L56 /RST");
1230-
if (ret < 0) {
1231-
dev_err(&i2c_client->dev,
1232-
"Failed to request /RST %d: %d\n",
1233-
cs42l56->pdata.gpio_nreset, ret);
1234-
return ret;
1235-
}
1236-
gpio_set_value_cansleep(cs42l56->pdata.gpio_nreset, 0);
1237-
gpio_set_value_cansleep(cs42l56->pdata.gpio_nreset, 1);
1234+
gpiod_set_value_cansleep(cs42l56->pdata.gpio_nreset, 1);
1235+
gpiod_set_value_cansleep(cs42l56->pdata.gpio_nreset, 0);
12381236
}
12391237

1240-
12411238
i2c_set_clientdata(i2c_client, cs42l56);
12421239

12431240
for (i = 0; i < ARRAY_SIZE(cs42l56->supplies); i++)

0 commit comments

Comments
 (0)