7
7
* Author: Peter Ujfalusi <[email protected] >
8
8
*/
9
9
10
- #include <linux/module.h>
11
- #include <linux/errno.h>
12
10
#include <linux/device.h>
11
+ #include <linux/errno.h>
12
+ #include <linux/gpio/consumer.h>
13
13
#include <linux/i2c.h>
14
- #include <linux/gpio.h>
14
+ #include <linux/module.h>
15
+ #include <linux/of.h>
16
+ #include <linux/regmap.h>
15
17
#include <linux/regulator/consumer.h>
16
18
#include <linux/slab.h>
17
- #include <sound/tpa6130a2-plat.h>
18
19
#include <sound/soc.h>
19
20
#include <sound/tlv.h>
20
- #include <linux/of.h>
21
- #include <linux/of_gpio.h>
22
- #include <linux/regmap.h>
23
21
24
22
#include "tpa6130a2.h"
25
23
@@ -33,7 +31,7 @@ struct tpa6130a2_data {
33
31
struct device * dev ;
34
32
struct regmap * regmap ;
35
33
struct regulator * supply ;
36
- int power_gpio ;
34
+ struct gpio_desc * power_gpio ;
37
35
enum tpa_model id ;
38
36
};
39
37
@@ -49,8 +47,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
49
47
return ret ;
50
48
}
51
49
/* Power on */
52
- if (data -> power_gpio >= 0 )
53
- gpio_set_value (data -> power_gpio , 1 );
50
+ gpiod_set_value (data -> power_gpio , 1 );
54
51
55
52
/* Sync registers */
56
53
regcache_cache_only (data -> regmap , false);
@@ -59,8 +56,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
59
56
dev_err (data -> dev ,
60
57
"Failed to sync registers: %d\n" , ret );
61
58
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 );
64
60
ret2 = regulator_disable (data -> supply );
65
61
if (ret2 != 0 )
66
62
dev_err (data -> dev ,
@@ -76,8 +72,7 @@ static int tpa6130a2_power(struct tpa6130a2_data *data, bool enable)
76
72
regcache_cache_only (data -> regmap , true);
77
73
78
74
/* Power off */
79
- if (data -> power_gpio >= 0 )
80
- gpio_set_value (data -> power_gpio , 0 );
75
+ gpiod_set_value (data -> power_gpio , 0 );
81
76
82
77
ret = regulator_disable (data -> supply );
83
78
if (ret != 0 ) {
@@ -209,18 +204,10 @@ static const struct regmap_config tpa6130a2_regmap_config = {
209
204
.cache_type = REGCACHE_RBTREE ,
210
205
};
211
206
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
-
219
207
static int tpa6130a2_probe (struct i2c_client * client )
220
208
{
221
209
struct device * dev ;
222
210
struct tpa6130a2_data * data ;
223
- struct tpa6130a2_platform_data * pdata = client -> dev .platform_data ;
224
211
struct device_node * np = client -> dev .of_node ;
225
212
const char * regulator ;
226
213
unsigned int version ;
@@ -238,10 +225,13 @@ static int tpa6130a2_probe(struct i2c_client *client)
238
225
if (IS_ERR (data -> regmap ))
239
226
return PTR_ERR (data -> regmap );
240
227
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" );
245
235
} else {
246
236
dev_err (dev , "Platform data not set\n" );
247
237
dump_stack ();
@@ -252,17 +242,6 @@ static int tpa6130a2_probe(struct i2c_client *client)
252
242
253
243
data -> id = (uintptr_t )i2c_get_match_data (client );
254
244
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
-
266
245
switch (data -> id ) {
267
246
default :
268
247
dev_warn (dev , "Unknown TPA model (%d). Assuming 6130A2\n" ,
@@ -318,7 +297,6 @@ static struct i2c_driver tpa6130a2_i2c_driver = {
318
297
.of_match_table = of_match_ptr (tpa6130a2_of_match ),
319
298
},
320
299
.probe = tpa6130a2_probe ,
321
- .id_table = tpa6130a2_id ,
322
300
};
323
301
324
302
module_i2c_driver (tpa6130a2_i2c_driver );
0 commit comments