99
1010#include <linux/bug.h>
1111#include <linux/err.h>
12- #include <linux/gpio.h>
13- #include <linux/of_gpio.h>
12+ #include <linux/gpio/consumer.h>
1413#include <linux/slab.h>
1514#include <linux/module.h>
1615#include <linux/platform_device.h>
@@ -32,7 +31,7 @@ struct max8997_data {
3231 u8 buck1_vol [8 ];
3332 u8 buck2_vol [8 ];
3433 u8 buck5_vol [8 ];
35- int buck125_gpios [3 ];
34+ struct gpio_desc * buck125_gpiods [3 ];
3635 int buck125_gpioindex ;
3736 bool ignore_gpiodvs_side_effect ;
3837
@@ -52,9 +51,9 @@ static inline void max8997_set_gpio(struct max8997_data *max8997)
5251 int set2 = ((max8997 -> buck125_gpioindex ) >> 1 ) & 0x1 ;
5352 int set1 = ((max8997 -> buck125_gpioindex ) >> 2 ) & 0x1 ;
5453
55- gpio_set_value (max8997 -> buck125_gpios [0 ], set1 );
56- gpio_set_value (max8997 -> buck125_gpios [1 ], set2 );
57- gpio_set_value (max8997 -> buck125_gpios [2 ], set3 );
54+ gpiod_set_value (max8997 -> buck125_gpiods [0 ], set1 );
55+ gpiod_set_value (max8997 -> buck125_gpiods [1 ], set2 );
56+ gpiod_set_value (max8997 -> buck125_gpiods [2 ], set3 );
5857}
5958
6059struct voltage_map_desc {
@@ -873,31 +872,13 @@ static struct regulator_desc regulators[] = {
873872};
874873
875874#ifdef CONFIG_OF
876- static int max8997_pmic_dt_parse_dvs_gpio (struct platform_device * pdev ,
877- struct max8997_platform_data * pdata ,
878- struct device_node * pmic_np )
879- {
880- int i , gpio ;
881-
882- for (i = 0 ; i < 3 ; i ++ ) {
883- gpio = of_get_named_gpio (pmic_np ,
884- "max8997,pmic-buck125-dvs-gpios" , i );
885- if (!gpio_is_valid (gpio )) {
886- dev_err (& pdev -> dev , "invalid gpio[%d]: %d\n" , i , gpio );
887- return - EINVAL ;
888- }
889- pdata -> buck125_gpios [i ] = gpio ;
890- }
891- return 0 ;
892- }
893-
894875static int max8997_pmic_dt_parse_pdata (struct platform_device * pdev ,
895876 struct max8997_platform_data * pdata )
896877{
897878 struct max8997_dev * iodev = dev_get_drvdata (pdev -> dev .parent );
898879 struct device_node * pmic_np , * regulators_np , * reg_np ;
899880 struct max8997_regulator_data * rdata ;
900- unsigned int i , dvs_voltage_nr = 1 , ret ;
881+ unsigned int i , dvs_voltage_nr = 1 ;
901882
902883 pmic_np = iodev -> dev -> of_node ;
903884 if (!pmic_np ) {
@@ -949,10 +930,6 @@ static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,
949930
950931 if (pdata -> buck1_gpiodvs || pdata -> buck2_gpiodvs ||
951932 pdata -> buck5_gpiodvs ) {
952- ret = max8997_pmic_dt_parse_dvs_gpio (pdev , pdata , pmic_np );
953- if (ret )
954- return - EINVAL ;
955-
956933 if (of_property_read_u32 (pmic_np ,
957934 "max8997,pmic-buck125-default-dvs-idx" ,
958935 & pdata -> buck125_default_idx )) {
@@ -1039,7 +1016,6 @@ static int max8997_pmic_probe(struct platform_device *pdev)
10391016 max8997 -> buck1_gpiodvs = pdata -> buck1_gpiodvs ;
10401017 max8997 -> buck2_gpiodvs = pdata -> buck2_gpiodvs ;
10411018 max8997 -> buck5_gpiodvs = pdata -> buck5_gpiodvs ;
1042- memcpy (max8997 -> buck125_gpios , pdata -> buck125_gpios , sizeof (int ) * 3 );
10431019 max8997 -> ignore_gpiodvs_side_effect = pdata -> ignore_gpiodvs_side_effect ;
10441020
10451021 nr_dvs = (pdata -> buck1_gpiodvs || pdata -> buck2_gpiodvs ||
@@ -1110,38 +1086,27 @@ static int max8997_pmic_probe(struct platform_device *pdev)
11101086 */
11111087 if (pdata -> buck1_gpiodvs || pdata -> buck2_gpiodvs ||
11121088 pdata -> buck5_gpiodvs ) {
1089+ const char * gpio_names [3 ] = {"MAX8997 SET1" , "MAX8997 SET2" , "MAX8997 SET3" };
11131090
1114- if (!gpio_is_valid (pdata -> buck125_gpios [0 ]) ||
1115- !gpio_is_valid (pdata -> buck125_gpios [1 ]) ||
1116- !gpio_is_valid (pdata -> buck125_gpios [2 ])) {
1117- dev_err (& pdev -> dev , "GPIO NOT VALID\n" );
1118- return - EINVAL ;
1119- }
1091+ for (i = 0 ; i < 3 ; i ++ ) {
1092+ enum gpiod_flags flags ;
11201093
1121- ret = devm_gpio_request (& pdev -> dev , pdata -> buck125_gpios [0 ],
1122- "MAX8997 SET1" );
1123- if (ret )
1124- return ret ;
1125-
1126- ret = devm_gpio_request (& pdev -> dev , pdata -> buck125_gpios [1 ],
1127- "MAX8997 SET2" );
1128- if (ret )
1129- return ret ;
1130-
1131- ret = devm_gpio_request (& pdev -> dev , pdata -> buck125_gpios [2 ],
1132- "MAX8997 SET3" );
1133- if (ret )
1134- return ret ;
1135-
1136- gpio_direction_output (pdata -> buck125_gpios [0 ],
1137- (max8997 -> buck125_gpioindex >> 2 )
1138- & 0x1 ); /* SET1 */
1139- gpio_direction_output (pdata -> buck125_gpios [1 ],
1140- (max8997 -> buck125_gpioindex >> 1 )
1141- & 0x1 ); /* SET2 */
1142- gpio_direction_output (pdata -> buck125_gpios [2 ],
1143- (max8997 -> buck125_gpioindex >> 0 )
1144- & 0x1 ); /* SET3 */
1094+ if (max8997 -> buck125_gpioindex & BIT (2 - i ))
1095+ flags = GPIOD_OUT_HIGH ;
1096+ else
1097+ flags = GPIOD_OUT_LOW ;
1098+
1099+ max8997 -> buck125_gpiods [i ] = devm_gpiod_get_index (iodev -> dev ,
1100+ "max8997,pmic-buck125-dvs" ,
1101+ i ,
1102+ flags );
1103+ if (IS_ERR (max8997 -> buck125_gpiods [i ])) {
1104+ ret = PTR_ERR (max8997 -> buck125_gpiods [i ]);
1105+ return dev_err_probe (iodev -> dev , ret , "cant get GPIO %d (%d)\n" ,
1106+ i , ret );
1107+ }
1108+ gpiod_set_consumer_name (max8997 -> buck125_gpiods [i ], gpio_names [i ]);
1109+ }
11451110 }
11461111
11471112 /* DVS-GPIO disabled */
0 commit comments