77 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
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-
219207static 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
324302module_i2c_driver (tpa6130a2_i2c_driver );
0 commit comments