Skip to content

Commit c27c313

Browse files
committed
ASoC: codec: tpa6130a2: Convert to GPIO descriptors
Merge series from "Peng Fan (OSS)" <[email protected]>: Per Mark's comments in [1], each driver in one patchset and not merge the changes to one driver in one patch, so worked out three patches. - Sort the included headers. - Drop sound/tpa6130a2-plat.h because no user is creating the device using platform data - Covert to GPIO descriptors Checking the DTS polarity, all users are using GPIOD_ACTIVE_HIGH. so all should work as expected with this patch. I not have hardware to test, just my best effort to do this. [1] https://lore.kernel.org/all/[email protected]/
2 parents b009011 + f198b6b commit c27c313

File tree

3 files changed

+16
-56
lines changed

3 files changed

+16
-56
lines changed

MAINTAINERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23896,7 +23896,6 @@ F: Documentation/devicetree/bindings/sound/ti,tlv320*.yaml
2389623896
F: Documentation/devicetree/bindings/sound/ti,tlv320adcx140.yaml
2389723897
F: include/sound/tas2*.h
2389823898
F: include/sound/tlv320*.h
23899-
F: include/sound/tpa6130a2-plat.h
2390023899
F: sound/pci/hda/tas2781_hda_i2c.c
2390123900
F: sound/soc/codecs/pcm1681.c
2390223901
F: sound/soc/codecs/pcm1789*.*

include/sound/tpa6130a2-plat.h

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

sound/soc/codecs/tpa6130a2.c

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@
77
* Author: Peter Ujfalusi <[email protected]>
88
*/
99

10-
#include <linux/module.h>
11-
#include <linux/errno.h>
1210
#include <linux/device.h>
11+
#include <linux/errno.h>
12+
#include <linux/gpio/consumer.h>
1313
#include <linux/i2c.h>
14-
#include <linux/gpio.h>
14+
#include <linux/module.h>
15+
#include <linux/of.h>
16+
#include <linux/regmap.h>
1517
#include <linux/regulator/consumer.h>
1618
#include <linux/slab.h>
17-
#include <sound/tpa6130a2-plat.h>
1819
#include <sound/soc.h>
1920
#include <sound/tlv.h>
20-
#include <linux/of.h>
21-
#include <linux/of_gpio.h>
22-
#include <linux/regmap.h>
2321

2422
#include "tpa6130a2.h"
2523

@@ -33,7 +31,7 @@ struct tpa6130a2_data {
3331
struct device *dev;
3432
struct regmap *regmap;
3533
struct regulator *supply;
36-
int power_gpio;
34+
struct gpio_desc *power_gpio;
3735
enum tpa_model id;
3836
};
3937

@@ -49,8 +47,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
4947
return ret;
5048
}
5149
/* Power on */
52-
if (data->power_gpio >= 0)
53-
gpio_set_value(data->power_gpio, 1);
50+
gpiod_set_value(data->power_gpio, 1);
5451

5552
/* Sync registers */
5653
regcache_cache_only(data->regmap, false);
@@ -59,8 +56,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
5956
dev_err(data->dev,
6057
"Failed to sync registers: %d\n", ret);
6158
regcache_cache_only(data->regmap, true);
62-
if (data->power_gpio >= 0)
63-
gpio_set_value(data->power_gpio, 0);
59+
gpiod_set_value(data->power_gpio, 0);
6460
ret2 = regulator_disable(data->supply);
6561
if (ret2 != 0)
6662
dev_err(data->dev,
@@ -76,8 +72,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
7672
regcache_cache_only(data->regmap, true);
7773

7874
/* Power off */
79-
if (data->power_gpio >= 0)
80-
gpio_set_value(data->power_gpio, 0);
75+
gpiod_set_value(data->power_gpio, 0);
8176

8277
ret = regulator_disable(data->supply);
8378
if (ret != 0) {
@@ -209,18 +204,10 @@ static const struct regmap_config tpa6130a2_regmap_config = {
209204
.cache_type = REGCACHE_RBTREE,
210205
};
211206

212-
static const struct i2c_device_id tpa6130a2_id[] = {
213-
{ "tpa6130a2", TPA6130A2 },
214-
{ "tpa6140a2", TPA6140A2 },
215-
{ }
216-
};
217-
MODULE_DEVICE_TABLE(i2c, tpa6130a2_id);
218-
219207
static int tpa6130a2_probe(struct i2c_client *client)
220208
{
221209
struct device *dev;
222210
struct tpa6130a2_data *data;
223-
struct tpa6130a2_platform_data *pdata = client->dev.platform_data;
224211
struct device_node *np = client->dev.of_node;
225212
const char *regulator;
226213
unsigned int version;
@@ -238,10 +225,13 @@ static int tpa6130a2_probe(struct i2c_client *client)
238225
if (IS_ERR(data->regmap))
239226
return PTR_ERR(data->regmap);
240227

241-
if (pdata) {
242-
data->power_gpio = pdata->power_gpio;
243-
} else if (np) {
244-
data->power_gpio = of_get_named_gpio(np, "power-gpio", 0);
228+
if (np) {
229+
data->power_gpio = devm_gpiod_get_optional(dev, "power", GPIOD_OUT_LOW);
230+
if (IS_ERR(data->power_gpio)) {
231+
return dev_err_probe(dev, PTR_ERR(data->power_gpio),
232+
"Failed to request power GPIO\n");
233+
}
234+
gpiod_set_consumer_name(data->power_gpio, "tpa6130a2 enable");
245235
} else {
246236
dev_err(dev, "Platform data not set\n");
247237
dump_stack();
@@ -252,17 +242,6 @@ static int tpa6130a2_probe(struct i2c_client *client)
252242

253243
data->id = (uintptr_t)i2c_get_match_data(client);
254244

255-
if (data->power_gpio >= 0) {
256-
ret = devm_gpio_request(dev, data->power_gpio,
257-
"tpa6130a2 enable");
258-
if (ret < 0) {
259-
dev_err(dev, "Failed to request power GPIO (%d)\n",
260-
data->power_gpio);
261-
return ret;
262-
}
263-
gpio_direction_output(data->power_gpio, 0);
264-
}
265-
266245
switch (data->id) {
267246
default:
268247
dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
@@ -318,7 +297,6 @@ static struct i2c_driver tpa6130a2_i2c_driver = {
318297
.of_match_table = of_match_ptr(tpa6130a2_of_match),
319298
},
320299
.probe = tpa6130a2_probe,
321-
.id_table = tpa6130a2_id,
322300
};
323301

324302
module_i2c_driver(tpa6130a2_i2c_driver);

0 commit comments

Comments
 (0)