Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: gpio-charger: Convert to GPIO descriptors

This converts the GPIO charger to use exclusively GPIO
descriptors, moving the two remaining platforms passing
global GPIO numbers over to using a GPIO descriptor table.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Linus Walleij and committed by
Sebastian Reichel
17529bcf 9123e3a7

+23 -35
+10 -2
arch/arm/mach-pxa/tosa.c
··· 369 369 /* 370 370 * Tosa AC IN 371 371 */ 372 + static struct gpiod_lookup_table tosa_power_gpiod_table = { 373 + .dev_id = "gpio-charger", 374 + .table = { 375 + GPIO_LOOKUP("gpio-pxa", TOSA_GPIO_AC_IN, 376 + NULL, GPIO_ACTIVE_LOW), 377 + { }, 378 + }, 379 + }; 380 + 372 381 static char *tosa_ac_supplied_to[] = { 373 382 "main-battery", 374 383 "backup-battery", ··· 387 378 static struct gpio_charger_platform_data tosa_power_data = { 388 379 .name = "charger", 389 380 .type = POWER_SUPPLY_TYPE_MAINS, 390 - .gpio = TOSA_GPIO_AC_IN, 391 - .gpio_active_low = 1, 392 381 .supplied_to = tosa_ac_supplied_to, 393 382 .num_supplicants = ARRAY_SIZE(tosa_ac_supplied_to), 394 383 }; ··· 958 951 clk_add_alias("CLK_CK3P6MI", tc6393xb_device.name, "GPIO11_CLK", NULL); 959 952 960 953 gpiod_add_lookup_table(&tosa_udc_gpiod_table); 954 + gpiod_add_lookup_table(&tosa_power_gpiod_table); 961 955 platform_add_devices(devices, ARRAY_SIZE(devices)); 962 956 } 963 957
+12 -2
arch/arm/mach-sa1100/collie.c
··· 30 30 #include <linux/gpio_keys.h> 31 31 #include <linux/input.h> 32 32 #include <linux/gpio.h> 33 + #include <linux/gpio/machine.h> 33 34 #include <linux/power/gpio-charger.h> 34 35 35 36 #include <video/sa1100fb.h> ··· 132 131 /* 133 132 * Collie AC IN 134 133 */ 134 + static struct gpiod_lookup_table collie_power_gpiod_table = { 135 + .dev_id = "gpio-charger", 136 + .table = { 137 + GPIO_LOOKUP("gpio", COLLIE_GPIO_AC_IN, 138 + NULL, GPIO_ACTIVE_HIGH), 139 + { }, 140 + }, 141 + }; 142 + 135 143 static char *collie_ac_supplied_to[] = { 136 144 "main-battery", 137 145 "backup-battery", 138 146 }; 139 147 140 - 141 148 static struct gpio_charger_platform_data collie_power_data = { 142 149 .name = "charger", 143 150 .type = POWER_SUPPLY_TYPE_MAINS, 144 - .gpio = COLLIE_GPIO_AC_IN, 145 151 .supplied_to = collie_ac_supplied_to, 146 152 .num_supplicants = ARRAY_SIZE(collie_ac_supplied_to), 147 153 }; ··· 393 385 394 386 395 387 platform_scoop_config = &collie_pcmcia_config; 388 + 389 + gpiod_add_lookup_table(&collie_power_gpiod_table); 396 390 397 391 ret = platform_add_devices(devices, ARRAY_SIZE(devices)); 398 392 if (ret) {
+1 -25
drivers/power/supply/gpio-charger.c
··· 5 5 */ 6 6 7 7 #include <linux/device.h> 8 - #include <linux/gpio.h> /* For legacy platform data */ 9 8 #include <linux/init.h> 10 9 #include <linux/interrupt.h> 11 10 #include <linux/kernel.h> ··· 130 131 struct power_supply_desc *charger_desc; 131 132 struct gpio_desc *charge_status; 132 133 int charge_status_irq; 133 - unsigned long flags; 134 134 int ret; 135 135 int num_props = 0; 136 136 ··· 147 149 * boardfile descriptor tables. It's good to try this first. 148 150 */ 149 151 gpio_charger->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN); 150 - 151 - /* 152 - * Fallback to legacy platform data method, if no GPIO is specified 153 - * using boardfile descriptor tables. 154 - */ 155 - if (!gpio_charger->gpiod && pdata) { 156 - /* Non-DT: use legacy GPIO numbers */ 157 - if (!gpio_is_valid(pdata->gpio)) { 158 - dev_err(dev, "Invalid gpio pin in pdata\n"); 159 - return -EINVAL; 160 - } 161 - flags = GPIOF_IN; 162 - if (pdata->gpio_active_low) 163 - flags |= GPIOF_ACTIVE_LOW; 164 - ret = devm_gpio_request_one(dev, pdata->gpio, flags, 165 - dev_name(dev)); 166 - if (ret) { 167 - dev_err(dev, "Failed to request gpio pin: %d\n", ret); 168 - return ret; 169 - } 170 - /* Then convert this to gpiod for now */ 171 - gpio_charger->gpiod = gpio_to_desc(pdata->gpio); 172 - } else if (IS_ERR(gpio_charger->gpiod)) { 152 + if (IS_ERR(gpio_charger->gpiod)) { 173 153 /* Just try again if this happens */ 174 154 if (PTR_ERR(gpio_charger->gpiod) == -EPROBE_DEFER) 175 155 return -EPROBE_DEFER;
-6
include/linux/power/gpio-charger.h
··· 13 13 * struct gpio_charger_platform_data - platform_data for gpio_charger devices 14 14 * @name: Name for the chargers power_supply device 15 15 * @type: Type of the charger 16 - * @gpio: GPIO which is used to indicate the chargers status 17 - * @gpio_active_low: Should be set to 1 if the GPIO is active low otherwise 0 18 16 * @supplied_to: Array of battery names to which this chargers supplies power 19 17 * @num_supplicants: Number of entries in the supplied_to array 20 18 */ 21 19 struct gpio_charger_platform_data { 22 20 const char *name; 23 21 enum power_supply_type type; 24 - 25 - int gpio; 26 - int gpio_active_low; 27 - 28 22 char **supplied_to; 29 23 size_t num_supplicants; 30 24 };