1212#include <linux/init.h>
1313#include <linux/delay.h>
1414#include <linux/pm.h>
15- #include <linux/gpio.h>
15+ #include <linux/gpio/consumer .h>
1616#include <linux/i2c.h>
1717#include <linux/regmap.h>
1818#include <linux/of.h>
19- #include <linux/of_gpio.h>
2019#include <linux/platform_device.h>
2120#include <linux/spi/spi.h>
2221#include <linux/acpi.h>
@@ -2812,8 +2811,8 @@ static int rt5640_suspend(struct snd_soc_component *component)
28122811 rt5640_reset (component );
28132812 regcache_cache_only (rt5640 -> regmap , true);
28142813 regcache_mark_dirty (rt5640 -> regmap );
2815- if (gpio_is_valid ( rt5640 -> ldo1_en ) )
2816- gpio_set_value_cansleep (rt5640 -> ldo1_en , 0 );
2814+ if (rt5640 -> ldo1_en )
2815+ gpiod_set_value_cansleep (rt5640 -> ldo1_en , 0 );
28172816
28182817 return 0 ;
28192818}
@@ -2822,8 +2821,8 @@ static int rt5640_resume(struct snd_soc_component *component)
28222821{
28232822 struct rt5640_priv * rt5640 = snd_soc_component_get_drvdata (component );
28242823
2825- if (gpio_is_valid ( rt5640 -> ldo1_en ) ) {
2826- gpio_set_value_cansleep (rt5640 -> ldo1_en , 1 );
2824+ if (rt5640 -> ldo1_en ) {
2825+ gpiod_set_value_cansleep (rt5640 -> ldo1_en , 1 );
28272826 msleep (400 );
28282827 }
28292828
@@ -2986,22 +2985,6 @@ static const struct acpi_device_id rt5640_acpi_match[] = {
29862985MODULE_DEVICE_TABLE (acpi , rt5640_acpi_match );
29872986#endif
29882987
2989- static int rt5640_parse_dt (struct rt5640_priv * rt5640 , struct device_node * np )
2990- {
2991- rt5640 -> ldo1_en = of_get_named_gpio (np , "realtek,ldo1-en-gpios" , 0 );
2992- /*
2993- * LDO1_EN is optional (it may be statically tied on the board).
2994- * -ENOENT means that the property doesn't exist, i.e. there is no
2995- * GPIO, so is not an error. Any other error code means the property
2996- * exists, but could not be parsed.
2997- */
2998- if (!gpio_is_valid (rt5640 -> ldo1_en ) &&
2999- (rt5640 -> ldo1_en != - ENOENT ))
3000- return rt5640 -> ldo1_en ;
3001-
3002- return 0 ;
3003- }
3004-
30052988static int rt5640_i2c_probe (struct i2c_client * i2c )
30062989{
30072990 struct rt5640_priv * rt5640 ;
@@ -3015,12 +2998,16 @@ static int rt5640_i2c_probe(struct i2c_client *i2c)
30152998 return - ENOMEM ;
30162999 i2c_set_clientdata (i2c , rt5640 );
30173000
3018- if (i2c -> dev .of_node ) {
3019- ret = rt5640_parse_dt (rt5640 , i2c -> dev .of_node );
3020- if (ret )
3021- return ret ;
3022- } else
3023- rt5640 -> ldo1_en = - EINVAL ;
3001+ rt5640 -> ldo1_en = devm_gpiod_get_optional (& i2c -> dev ,
3002+ "realtek,ldo1-en" ,
3003+ GPIOD_OUT_HIGH );
3004+ if (IS_ERR (rt5640 -> ldo1_en ))
3005+ return PTR_ERR (rt5640 -> ldo1_en );
3006+
3007+ if (rt5640 -> ldo1_en ) {
3008+ gpiod_set_consumer_name (rt5640 -> ldo1_en , "RT5640 LDO1_EN" );
3009+ msleep (400 );
3010+ }
30243011
30253012 rt5640 -> regmap = devm_regmap_init_i2c (i2c , & rt5640_regmap );
30263013 if (IS_ERR (rt5640 -> regmap )) {
@@ -3030,18 +3017,6 @@ static int rt5640_i2c_probe(struct i2c_client *i2c)
30303017 return ret ;
30313018 }
30323019
3033- if (gpio_is_valid (rt5640 -> ldo1_en )) {
3034- ret = devm_gpio_request_one (& i2c -> dev , rt5640 -> ldo1_en ,
3035- GPIOF_OUT_INIT_HIGH ,
3036- "RT5640 LDO1_EN" );
3037- if (ret < 0 ) {
3038- dev_err (& i2c -> dev , "Failed to request LDO1_EN %d: %d\n" ,
3039- rt5640 -> ldo1_en , ret );
3040- return ret ;
3041- }
3042- msleep (400 );
3043- }
3044-
30453020 regmap_read (rt5640 -> regmap , RT5640_VENDOR_ID2 , & val );
30463021 if (val != RT5640_DEVICE_ID ) {
30473022 dev_err (& i2c -> dev ,
0 commit comments