Commit 1d85f6d1 authored by Sebastian Reichel's avatar Sebastian Reichel Committed by Sebastian Reichel

power: supply: gpio-charger: Make gpios optional

While strongly recommended, not all devices have a gpio to
detect if the charger is connected. This moves the 'gpios'
from required to optional section.

This also modifies error handling for the GPIO a bit: We
no longer fallback to pdata, if a GPIO is specified using
GPIO descriptor tables. This is a bit cleaner and does
not have any real impact: There are only two mainline pdata
users (arm/mach-sa1100/collie.c, arm/mach-pxa/tosa.c) and
none of them specify the GPIO via gpiod descriptor tables.
Once both have been converted the driver's support for
specifying GPIOs numbers in pdata will be dropped.
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Acked-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent dad980f1
...@@ -41,7 +41,12 @@ properties: ...@@ -41,7 +41,12 @@ properties:
required: required:
- compatible - compatible
- gpios
anyOf:
- required:
- gpios
- required:
- charge-status-gpios
additionalProperties: false additionalProperties: false
......
...@@ -112,9 +112,14 @@ static int gpio_charger_get_irq(struct device *dev, void *dev_id, ...@@ -112,9 +112,14 @@ static int gpio_charger_get_irq(struct device *dev, void *dev_id,
return irq; return irq;
} }
/*
* The entries will be overwritten by driver's probe routine depending
* on the available features. This list ensures, that the array is big
* enough for all optional features.
*/
static enum power_supply_property gpio_charger_properties[] = { static enum power_supply_property gpio_charger_properties[] = {
POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_STATUS /* Must always be last in the array. */ POWER_SUPPLY_PROP_STATUS,
}; };
static int gpio_charger_probe(struct platform_device *pdev) static int gpio_charger_probe(struct platform_device *pdev)
...@@ -128,6 +133,7 @@ static int gpio_charger_probe(struct platform_device *pdev) ...@@ -128,6 +133,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
int charge_status_irq; int charge_status_irq;
unsigned long flags; unsigned long flags;
int ret; int ret;
int num_props = 0;
if (!pdata && !dev->of_node) { if (!pdata && !dev->of_node) {
dev_err(dev, "No platform data\n"); dev_err(dev, "No platform data\n");
...@@ -142,13 +148,13 @@ static int gpio_charger_probe(struct platform_device *pdev) ...@@ -142,13 +148,13 @@ static int gpio_charger_probe(struct platform_device *pdev)
* This will fetch a GPIO descriptor from device tree, ACPI or * This will fetch a GPIO descriptor from device tree, ACPI or
* 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(dev, NULL, GPIOD_IN); gpio_charger->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
/* /*
* If this fails and we're not using device tree, try the * Fallback to legacy platform data method, if no GPIO is specified
* legacy platform data method. * using boardfile descriptor tables.
*/ */
if (IS_ERR(gpio_charger->gpiod) && !dev->of_node) { if (!gpio_charger->gpiod && pdata) {
/* Non-DT: use legacy GPIO numbers */ /* Non-DT: use legacy GPIO numbers */
if (!gpio_is_valid(pdata->gpio)) { if (!gpio_is_valid(pdata->gpio)) {
dev_err(dev, "Invalid gpio pin in pdata\n"); dev_err(dev, "Invalid gpio pin in pdata\n");
...@@ -173,17 +179,23 @@ static int gpio_charger_probe(struct platform_device *pdev) ...@@ -173,17 +179,23 @@ static int gpio_charger_probe(struct platform_device *pdev)
return PTR_ERR(gpio_charger->gpiod); return PTR_ERR(gpio_charger->gpiod);
} }
if (gpio_charger->gpiod) {
gpio_charger_properties[num_props] = POWER_SUPPLY_PROP_ONLINE;
num_props++;
}
charge_status = devm_gpiod_get_optional(dev, "charge-status", GPIOD_IN); charge_status = devm_gpiod_get_optional(dev, "charge-status", GPIOD_IN);
gpio_charger->charge_status = charge_status; if (IS_ERR(charge_status))
if (IS_ERR(gpio_charger->charge_status)) return PTR_ERR(charge_status);
return PTR_ERR(gpio_charger->charge_status); if (charge_status) {
gpio_charger->charge_status = charge_status;
gpio_charger_properties[num_props] = POWER_SUPPLY_PROP_STATUS;
num_props++;
}
charger_desc = &gpio_charger->charger_desc; charger_desc = &gpio_charger->charger_desc;
charger_desc->properties = gpio_charger_properties; charger_desc->properties = gpio_charger_properties;
charger_desc->num_properties = ARRAY_SIZE(gpio_charger_properties); charger_desc->num_properties = num_props;
/* Remove POWER_SUPPLY_PROP_STATUS from the supported properties. */
if (!gpio_charger->charge_status)
charger_desc->num_properties -= 1;
charger_desc->get_property = gpio_charger_get_property; charger_desc->get_property = gpio_charger_get_property;
psy_cfg.of_node = dev->of_node; psy_cfg.of_node = dev->of_node;
...@@ -269,6 +281,6 @@ static struct platform_driver gpio_charger_driver = { ...@@ -269,6 +281,6 @@ static struct platform_driver gpio_charger_driver = {
module_platform_driver(gpio_charger_driver); module_platform_driver(gpio_charger_driver);
MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
MODULE_DESCRIPTION("Driver for chargers which report their online status through a GPIO"); MODULE_DESCRIPTION("Driver for chargers only communicating via GPIO(s)");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:gpio-charger"); MODULE_ALIAS("platform:gpio-charger");
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