Skip to content

Commit 599b86f

Browse files
committed
ASoC: codec: cs42l[56,73,52]: Convert to GPIO
Merge series from "Peng Fan (OSS)" <peng.fan@oss.nxp.com>: This patchset is separate from [1], and not merging changes in one patch. So separate changes into three patches for each chip. - sort headers - Drop legacy platform support - 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. I not have platforms to test, just do the patches with my best efforts, and make build pass. [1] https://lore.kernel.org/all/20250408-asoc-gpio-v1-0-c0db9d3fd6e9@nxp.com/
2 parents ad6d689 + 5bf5bdf commit 599b86f

6 files changed

Lines changed: 150 additions & 215 deletions

File tree

include/sound/cs42l52.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

include/sound/cs42l56.h

Lines changed: 0 additions & 45 deletions
This file was deleted.

include/sound/cs42l73.h

Lines changed: 0 additions & 19 deletions
This file was deleted.

sound/soc/codecs/cs42l52.c

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,51 @@
88
* Author: Brian Austin <brian.austin@cirrus.com>
99
*/
1010

11-
#include <linux/module.h>
12-
#include <linux/moduleparam.h>
13-
#include <linux/kernel.h>
14-
#include <linux/init.h>
1511
#include <linux/delay.h>
16-
#include <linux/of_gpio.h>
17-
#include <linux/pm.h>
12+
#include <linux/gpio/consumer.h>
1813
#include <linux/i2c.h>
14+
#include <linux/init.h>
1915
#include <linux/input.h>
16+
#include <linux/kernel.h>
17+
#include <linux/module.h>
18+
#include <linux/moduleparam.h>
19+
#include <linux/pm.h>
20+
#include <linux/platform_device.h>
2021
#include <linux/regmap.h>
2122
#include <linux/slab.h>
2223
#include <linux/workqueue.h>
23-
#include <linux/platform_device.h>
2424
#include <sound/core.h>
25+
#include <sound/initval.h>
2526
#include <sound/pcm.h>
2627
#include <sound/pcm_params.h>
2728
#include <sound/soc.h>
2829
#include <sound/soc-dapm.h>
29-
#include <sound/initval.h>
3030
#include <sound/tlv.h>
31-
#include <sound/cs42l52.h>
3231
#include "cs42l52.h"
3332

3433
struct sp_config {
3534
u8 spc, format, spfs;
3635
u32 srate;
3736
};
3837

38+
struct cs42l52_platform_data {
39+
40+
/* MICBIAS Level. Check datasheet Pg48 */
41+
unsigned int micbias_lvl;
42+
43+
/* MICA mode selection Differential or Single-ended */
44+
bool mica_diff_cfg;
45+
46+
/* MICB mode selection Differential or Single-ended */
47+
bool micb_diff_cfg;
48+
49+
/* Charge Pump Freq. Check datasheet Pg73 */
50+
unsigned int chgfreq;
51+
52+
/* Reset GPIO */
53+
struct gpio_desc *reset_gpio;
54+
};
55+
3956
struct cs42l52_private {
4057
struct regmap *regmap;
4158
struct snd_soc_component *component;
@@ -1090,7 +1107,7 @@ static const struct regmap_config cs42l52_regmap = {
10901107
static int cs42l52_i2c_probe(struct i2c_client *i2c_client)
10911108
{
10921109
struct cs42l52_private *cs42l52;
1093-
struct cs42l52_platform_data *pdata = dev_get_platdata(&i2c_client->dev);
1110+
struct cs42l52_platform_data *pdata;
10941111
int ret;
10951112
unsigned int devid;
10961113
unsigned int reg;
@@ -1107,50 +1124,43 @@ static int cs42l52_i2c_probe(struct i2c_client *i2c_client)
11071124
dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret);
11081125
return ret;
11091126
}
1110-
if (pdata) {
1111-
cs42l52->pdata = *pdata;
1112-
} else {
1113-
pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata),
1114-
GFP_KERNEL);
1115-
if (!pdata)
1116-
return -ENOMEM;
1117-
1118-
if (i2c_client->dev.of_node) {
1119-
if (of_property_read_bool(i2c_client->dev.of_node,
1120-
"cirrus,mica-differential-cfg"))
1121-
pdata->mica_diff_cfg = true;
1122-
1123-
if (of_property_read_bool(i2c_client->dev.of_node,
1124-
"cirrus,micb-differential-cfg"))
1125-
pdata->micb_diff_cfg = true;
1126-
1127-
if (of_property_read_u32(i2c_client->dev.of_node,
1128-
"cirrus,micbias-lvl", &val32) >= 0)
1129-
pdata->micbias_lvl = val32;
1130-
1131-
if (of_property_read_u32(i2c_client->dev.of_node,
1132-
"cirrus,chgfreq-divisor", &val32) >= 0)
1133-
pdata->chgfreq = val32;
1134-
1135-
pdata->reset_gpio =
1136-
of_get_named_gpio(i2c_client->dev.of_node,
1137-
"cirrus,reset-gpio", 0);
1138-
}
1139-
cs42l52->pdata = *pdata;
1127+
1128+
pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), GFP_KERNEL);
1129+
if (!pdata)
1130+
return -ENOMEM;
1131+
1132+
if (i2c_client->dev.of_node) {
1133+
if (of_property_read_bool(i2c_client->dev.of_node,
1134+
"cirrus,mica-differential-cfg"))
1135+
pdata->mica_diff_cfg = true;
1136+
1137+
if (of_property_read_bool(i2c_client->dev.of_node,
1138+
"cirrus,micb-differential-cfg"))
1139+
pdata->micb_diff_cfg = true;
1140+
1141+
if (of_property_read_u32(i2c_client->dev.of_node,
1142+
"cirrus,micbias-lvl", &val32) >= 0)
1143+
pdata->micbias_lvl = val32;
1144+
1145+
if (of_property_read_u32(i2c_client->dev.of_node,
1146+
"cirrus,chgfreq-divisor", &val32) >= 0)
1147+
pdata->chgfreq = val32;
1148+
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");
11401157
}
11411158

1159+
cs42l52->pdata = *pdata;
1160+
11421161
if (cs42l52->pdata.reset_gpio) {
1143-
ret = devm_gpio_request_one(&i2c_client->dev,
1144-
cs42l52->pdata.reset_gpio,
1145-
GPIOF_OUT_INIT_HIGH,
1146-
"CS42L52 /RST");
1147-
if (ret < 0) {
1148-
dev_err(&i2c_client->dev, "Failed to request /RST %d: %d\n",
1149-
cs42l52->pdata.reset_gpio, ret);
1150-
return ret;
1151-
}
1152-
gpio_set_value_cansleep(cs42l52->pdata.reset_gpio, 0);
1153-
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);
11541164
}
11551165

11561166
i2c_set_clientdata(i2c_client, cs42l52);

sound/soc/codecs/cs42l56.c

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,64 @@
77
* Author: Brian Austin <brian.austin@cirrus.com>
88
*/
99

10-
#include <linux/module.h>
11-
#include <linux/moduleparam.h>
12-
#include <linux/kernel.h>
13-
#include <linux/init.h>
1410
#include <linux/delay.h>
15-
#include <linux/pm.h>
11+
#include <linux/gpio/consumer.h>
1612
#include <linux/i2c.h>
13+
#include <linux/init.h>
1714
#include <linux/input.h>
15+
#include <linux/kernel.h>
16+
#include <linux/module.h>
17+
#include <linux/moduleparam.h>
18+
#include <linux/of.h>
19+
#include <linux/platform_device.h>
20+
#include <linux/pm.h>
1821
#include <linux/regmap.h>
22+
#include <linux/regulator/consumer.h>
1923
#include <linux/slab.h>
2024
#include <linux/workqueue.h>
21-
#include <linux/platform_device.h>
22-
#include <linux/regulator/consumer.h>
23-
#include <linux/of.h>
24-
#include <linux/of_gpio.h>
2525
#include <sound/core.h>
26+
#include <sound/initval.h>
2627
#include <sound/pcm.h>
2728
#include <sound/pcm_params.h>
2829
#include <sound/soc.h>
2930
#include <sound/soc-dapm.h>
30-
#include <sound/initval.h>
3131
#include <sound/tlv.h>
32-
#include <sound/cs42l56.h>
3332
#include "cs42l56.h"
3433

3534
#define CS42L56_NUM_SUPPLIES 3
35+
36+
struct cs42l56_platform_data {
37+
/* GPIO for Reset */
38+
struct gpio_desc *gpio_nreset;
39+
40+
/* MICBIAS Level. Check datasheet Pg48 */
41+
unsigned int micbias_lvl;
42+
43+
/* Analog Input 1A Reference 0=Single 1=Pseudo-Differential */
44+
unsigned int ain1a_ref_cfg;
45+
46+
/* Analog Input 2A Reference 0=Single 1=Pseudo-Differential */
47+
unsigned int ain2a_ref_cfg;
48+
49+
/* Analog Input 1B Reference 0=Single 1=Pseudo-Differential */
50+
unsigned int ain1b_ref_cfg;
51+
52+
/* Analog Input 2B Reference 0=Single 1=Pseudo-Differential */
53+
unsigned int ain2b_ref_cfg;
54+
55+
/* Charge Pump Freq. Check datasheet Pg62 */
56+
unsigned int chgfreq;
57+
58+
/* HighPass Filter Right Channel Corner Frequency */
59+
unsigned int hpfb_freq;
60+
61+
/* HighPass Filter Left Channel Corner Frequency */
62+
unsigned int hpfa_freq;
63+
64+
/* Adaptive Power Control for LO/HP */
65+
unsigned int adaptive_pwr;
66+
};
67+
3668
static const char *const cs42l56_supply_names[CS42L56_NUM_SUPPLIES] = {
3769
"VA",
3870
"VCP",
@@ -1161,16 +1193,20 @@ static int cs42l56_handle_of_data(struct i2c_client *i2c_client,
11611193
if (of_property_read_u32(np, "cirrus,hpf-left-freq", &val32) >= 0)
11621194
pdata->hpfb_freq = val32;
11631195

1164-
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");
11651203

11661204
return 0;
11671205
}
11681206

11691207
static int cs42l56_i2c_probe(struct i2c_client *i2c_client)
11701208
{
11711209
struct cs42l56_private *cs42l56;
1172-
struct cs42l56_platform_data *pdata =
1173-
dev_get_platdata(&i2c_client->dev);
11741210
int ret, i;
11751211
unsigned int devid;
11761212
unsigned int alpha_rev, metal_rev;
@@ -1188,31 +1224,17 @@ static int cs42l56_i2c_probe(struct i2c_client *i2c_client)
11881224
return ret;
11891225
}
11901226

1191-
if (pdata) {
1192-
cs42l56->pdata = *pdata;
1193-
} else {
1194-
if (i2c_client->dev.of_node) {
1195-
ret = cs42l56_handle_of_data(i2c_client,
1196-
&cs42l56->pdata);
1197-
if (ret != 0)
1198-
return ret;
1199-
}
1227+
if (i2c_client->dev.of_node) {
1228+
ret = cs42l56_handle_of_data(i2c_client, &cs42l56->pdata);
1229+
if (ret != 0)
1230+
return ret;
12001231
}
12011232

12021233
if (cs42l56->pdata.gpio_nreset) {
1203-
ret = gpio_request_one(cs42l56->pdata.gpio_nreset,
1204-
GPIOF_OUT_INIT_HIGH, "CS42L56 /RST");
1205-
if (ret < 0) {
1206-
dev_err(&i2c_client->dev,
1207-
"Failed to request /RST %d: %d\n",
1208-
cs42l56->pdata.gpio_nreset, ret);
1209-
return ret;
1210-
}
1211-
gpio_set_value_cansleep(cs42l56->pdata.gpio_nreset, 0);
1212-
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);
12131236
}
12141237

1215-
12161238
i2c_set_clientdata(i2c_client, cs42l56);
12171239

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

0 commit comments

Comments
 (0)