Commit 17529bcf authored by Linus Walleij's avatar Linus Walleij Committed by Sebastian Reichel

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: default avatarLinus Walleij <linus.walleij@linaro.org>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 9123e3a7
...@@ -369,6 +369,15 @@ static struct pxaficp_platform_data tosa_ficp_platform_data = { ...@@ -369,6 +369,15 @@ static struct pxaficp_platform_data tosa_ficp_platform_data = {
/* /*
* Tosa AC IN * Tosa AC IN
*/ */
static struct gpiod_lookup_table tosa_power_gpiod_table = {
.dev_id = "gpio-charger",
.table = {
GPIO_LOOKUP("gpio-pxa", TOSA_GPIO_AC_IN,
NULL, GPIO_ACTIVE_LOW),
{ },
},
};
static char *tosa_ac_supplied_to[] = { static char *tosa_ac_supplied_to[] = {
"main-battery", "main-battery",
"backup-battery", "backup-battery",
...@@ -378,8 +387,6 @@ static char *tosa_ac_supplied_to[] = { ...@@ -378,8 +387,6 @@ static char *tosa_ac_supplied_to[] = {
static struct gpio_charger_platform_data tosa_power_data = { static struct gpio_charger_platform_data tosa_power_data = {
.name = "charger", .name = "charger",
.type = POWER_SUPPLY_TYPE_MAINS, .type = POWER_SUPPLY_TYPE_MAINS,
.gpio = TOSA_GPIO_AC_IN,
.gpio_active_low = 1,
.supplied_to = tosa_ac_supplied_to, .supplied_to = tosa_ac_supplied_to,
.num_supplicants = ARRAY_SIZE(tosa_ac_supplied_to), .num_supplicants = ARRAY_SIZE(tosa_ac_supplied_to),
}; };
...@@ -951,6 +958,7 @@ static void __init tosa_init(void) ...@@ -951,6 +958,7 @@ static void __init tosa_init(void)
clk_add_alias("CLK_CK3P6MI", tc6393xb_device.name, "GPIO11_CLK", NULL); clk_add_alias("CLK_CK3P6MI", tc6393xb_device.name, "GPIO11_CLK", NULL);
gpiod_add_lookup_table(&tosa_udc_gpiod_table); gpiod_add_lookup_table(&tosa_udc_gpiod_table);
gpiod_add_lookup_table(&tosa_power_gpiod_table);
platform_add_devices(devices, ARRAY_SIZE(devices)); platform_add_devices(devices, ARRAY_SIZE(devices));
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <linux/gpio_keys.h> #include <linux/gpio_keys.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/gpio/machine.h>
#include <linux/power/gpio-charger.h> #include <linux/power/gpio-charger.h>
#include <video/sa1100fb.h> #include <video/sa1100fb.h>
...@@ -131,16 +132,23 @@ static struct irda_platform_data collie_ir_data = { ...@@ -131,16 +132,23 @@ static struct irda_platform_data collie_ir_data = {
/* /*
* Collie AC IN * Collie AC IN
*/ */
static struct gpiod_lookup_table collie_power_gpiod_table = {
.dev_id = "gpio-charger",
.table = {
GPIO_LOOKUP("gpio", COLLIE_GPIO_AC_IN,
NULL, GPIO_ACTIVE_HIGH),
{ },
},
};
static char *collie_ac_supplied_to[] = { static char *collie_ac_supplied_to[] = {
"main-battery", "main-battery",
"backup-battery", "backup-battery",
}; };
static struct gpio_charger_platform_data collie_power_data = { static struct gpio_charger_platform_data collie_power_data = {
.name = "charger", .name = "charger",
.type = POWER_SUPPLY_TYPE_MAINS, .type = POWER_SUPPLY_TYPE_MAINS,
.gpio = COLLIE_GPIO_AC_IN,
.supplied_to = collie_ac_supplied_to, .supplied_to = collie_ac_supplied_to,
.num_supplicants = ARRAY_SIZE(collie_ac_supplied_to), .num_supplicants = ARRAY_SIZE(collie_ac_supplied_to),
}; };
...@@ -386,6 +394,8 @@ static void __init collie_init(void) ...@@ -386,6 +394,8 @@ static void __init collie_init(void)
platform_scoop_config = &collie_pcmcia_config; platform_scoop_config = &collie_pcmcia_config;
gpiod_add_lookup_table(&collie_power_gpiod_table);
ret = platform_add_devices(devices, ARRAY_SIZE(devices)); ret = platform_add_devices(devices, ARRAY_SIZE(devices));
if (ret) { if (ret) {
printk(KERN_WARNING "collie: Unable to register LoCoMo device\n"); printk(KERN_WARNING "collie: Unable to register LoCoMo device\n");
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
*/ */
#include <linux/device.h> #include <linux/device.h>
#include <linux/gpio.h> /* For legacy platform data */
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/kernel.h> #include <linux/kernel.h>
...@@ -131,7 +130,6 @@ static int gpio_charger_probe(struct platform_device *pdev) ...@@ -131,7 +130,6 @@ static int gpio_charger_probe(struct platform_device *pdev)
struct power_supply_desc *charger_desc; struct power_supply_desc *charger_desc;
struct gpio_desc *charge_status; struct gpio_desc *charge_status;
int charge_status_irq; int charge_status_irq;
unsigned long flags;
int ret; int ret;
int num_props = 0; int num_props = 0;
...@@ -149,29 +147,7 @@ static int gpio_charger_probe(struct platform_device *pdev) ...@@ -149,29 +147,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
* boardfile descriptor tables. It's good to try this first. * boardfile descriptor tables. It's good to try this first.
*/ */
gpio_charger->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN); gpio_charger->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
if (IS_ERR(gpio_charger->gpiod)) {
/*
* Fallback to legacy platform data method, if no GPIO is specified
* using boardfile descriptor tables.
*/
if (!gpio_charger->gpiod && pdata) {
/* Non-DT: use legacy GPIO numbers */
if (!gpio_is_valid(pdata->gpio)) {
dev_err(dev, "Invalid gpio pin in pdata\n");
return -EINVAL;
}
flags = GPIOF_IN;
if (pdata->gpio_active_low)
flags |= GPIOF_ACTIVE_LOW;
ret = devm_gpio_request_one(dev, pdata->gpio, flags,
dev_name(dev));
if (ret) {
dev_err(dev, "Failed to request gpio pin: %d\n", ret);
return ret;
}
/* Then convert this to gpiod for now */
gpio_charger->gpiod = gpio_to_desc(pdata->gpio);
} else if (IS_ERR(gpio_charger->gpiod)) {
/* Just try again if this happens */ /* Just try again if this happens */
if (PTR_ERR(gpio_charger->gpiod) == -EPROBE_DEFER) if (PTR_ERR(gpio_charger->gpiod) == -EPROBE_DEFER)
return -EPROBE_DEFER; return -EPROBE_DEFER;
......
...@@ -13,18 +13,12 @@ ...@@ -13,18 +13,12 @@
* struct gpio_charger_platform_data - platform_data for gpio_charger devices * struct gpio_charger_platform_data - platform_data for gpio_charger devices
* @name: Name for the chargers power_supply device * @name: Name for the chargers power_supply device
* @type: Type of the charger * @type: Type of the charger
* @gpio: GPIO which is used to indicate the chargers status
* @gpio_active_low: Should be set to 1 if the GPIO is active low otherwise 0
* @supplied_to: Array of battery names to which this chargers supplies power * @supplied_to: Array of battery names to which this chargers supplies power
* @num_supplicants: Number of entries in the supplied_to array * @num_supplicants: Number of entries in the supplied_to array
*/ */
struct gpio_charger_platform_data { struct gpio_charger_platform_data {
const char *name; const char *name;
enum power_supply_type type; enum power_supply_type type;
int gpio;
int gpio_active_low;
char **supplied_to; char **supplied_to;
size_t num_supplicants; size_t num_supplicants;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment