This series adds devicetree support to the gpio-charger and fixes a small
issue with the return value of gpio_get_value.
changes since v1:
- adapt binding example to show how the charger fits into the
power-supplies structure
Heiko Stuebner (3):
dt-bindings: document gpio-charger bindings
power: gpio-charger: add device tree support
power: gpio-charger: do not use gpio value directly
.../bindings/power_supply/gpio-charger.txt | 27 +++++++++
drivers/power/gpio-charger.c | 68 ++++++++++++++++++++--
2 files changed, 91 insertions(+), 4 deletions(-)
create mode 100644 Documentation/devicetree/bindings/power_supply/gpio-charger.txt
--
1.9.0
From: Heiko Stuebner <redacted>
Some gpio implementations return interesting values for gpio_get_value when
the value is not 0 - as seen on a imx6sl board. Therefore do not use the
value returned from gpio_get_value directly but simply check for 0 or not 0.
Signed-off-by: Heiko Stuebner <redacted>
---
drivers/power/gpio-charger.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
It would be nice to check the gpio for errors here, including handling
the possibility of EPROBE_DEFER.
quoted hunk
+ pdata->gpio_active_low = flags & OF_GPIO_ACTIVE_LOW;++ pdata->type = POWER_SUPPLY_TYPE_UNKNOWN;+ ret = of_property_read_string(np, "charger-type", &chargetype);+ if (ret >= 0) {+ if (!strncmp("unknown", chargetype, 7))+ pdata->type = POWER_SUPPLY_TYPE_UNKNOWN;+ else if (!strncmp("battery", chargetype, 7))+ pdata->type = POWER_SUPPLY_TYPE_BATTERY;+ else if (!strncmp("ups", chargetype, 3))+ pdata->type = POWER_SUPPLY_TYPE_UPS;+ else if (!strncmp("mains", chargetype, 5))+ pdata->type = POWER_SUPPLY_TYPE_MAINS;+ else if (!strncmp("usb-sdp", chargetype, 7))+ pdata->type = POWER_SUPPLY_TYPE_USB;+ else if (!strncmp("usb-dcp", chargetype, 7))+ pdata->type = POWER_SUPPLY_TYPE_USB_DCP;+ else if (!strncmp("usb-cdp", chargetype, 7))+ pdata->type = POWER_SUPPLY_TYPE_USB_CDP;+ else if (!strncmp("usb-aca", chargetype, 7))+ pdata->type = POWER_SUPPLY_TYPE_USB_ACA;+ else+ dev_warn(dev, "unknown charger type %s\n", chargetype);+ }++ return pdata;+}+ static int gpio_charger_probe(struct platform_device *pdev) {- const struct gpio_charger_platform_data *pdata = pdev->dev.platform_data;+ struct gpio_charger_platform_data *pdata = pdev->dev.platform_data;
Do you really need to remove const? If I remember correctly the const
here is not saying that the variable "pdata" won't change but that the
data pointed to by pdata won't change. I think that's still the case
(from the perspective of this function).
quoted hunk
struct gpio_charger *gpio_charger; struct power_supply *charger; int ret; int irq; if (!pdata) {- dev_err(&pdev->dev, "No platform data\n");- return -EINVAL;+ pdata = gpio_charger_parse_dt(&pdev->dev);+ if (IS_ERR(pdata)) {+ dev_err(&pdev->dev, "No platform data\n");+ return -EINVAL;
Probably should pass back the error code since it might be
EPROBE_DEFER. ...and <sigh> I guess you need the special case of
"don't print if it's EPROBE_DEFER". I almost wish we had a helper
function for that. ;)
Given that you don't have any #ifdefs with "CONFIG_OF", I think
gpio_charger_match will always exist. It seems like you should remove
the of_match_ptr or add some #ifdefs. I can't quite keep up with what
the currently suggested best practice is here, though.
-Doug
From: Doug Anderson <dianders@chromium.org> Date: 2014-09-22 16:50:58
Heiko,
On Sun, Sep 21, 2014 at 1:05 PM, Heiko Stuebner [off-list ref] wrote:
quoted hunk
From: Heiko Stuebner <redacted>
Some gpio implementations return interesting values for gpio_get_value when
the value is not 0 - as seen on a imx6sl board. Therefore do not use the
value returned from gpio_get_value directly but simply check for 0 or not 0.
Signed-off-by: Heiko Stuebner <redacted>
---
drivers/power/gpio-charger.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -57,7 +57,7 @@ static int gpio_charger_get_property(struct power_supply *psy,switch(psp){casePOWER_SUPPLY_PROP_ONLINE:-val->intval=gpio_get_value_cansleep(pdata->gpio);+val->intval=gpio_get_value_cansleep(pdata->gpio)?1:0;
There is a common practice about using "!!" for this. AKA:
"val->intval = !!gpio_get_value_cansleep(pdata->gpio);".
val->intval ^= pdata->gpio_active_low;
It seems like while you're at it you could also fix
"pdata->gpio_active_low" to have the "!!", just to be safe.
...if you don't fix this, perhaps you should fix your last patch to
add a "!!", like:
pdata->gpio_active_low = !!(flags & OF_GPIO_ACTIVE_LOW);
...technically OF_GPIO_ACTIVE_LOW is 0x1 so it's not a bug, but...
Given that you don't have any #ifdefs with "CONFIG_OF", I think
gpio_charger_match will always exist. It seems like you should remove
the of_match_ptr or add some #ifdefs. I can't quite keep up with what
the currently suggested best practice is here, though.
I've kept the of_match_ptr in v3. The dt parsing functions (of_read_foo,...)
define stubs for the !CONFIG_OF case which we use here in this case and
of_match_ptr is also defined differently for both OF and !OF, so it feels like
it should be there ;-)
Heiko
Given that you don't have any #ifdefs with "CONFIG_OF", I think
gpio_charger_match will always exist. It seems like you should remove
the of_match_ptr or add some #ifdefs. I can't quite keep up with what
the currently suggested best practice is here, though.
I've kept the of_match_ptr in v3. The dt parsing functions (of_read_foo,...)
define stubs for the !CONFIG_OF case which we use here in this case and
of_match_ptr is also defined differently for both OF and !OF, so it feels like
it should be there ;-)
...I was thinking you'd get a compile-time warning about
gpio_charger_match not being used. ...but I can't seem to trigger it
with my compiler settings. In any case, I'm fairly certain that in
the !CONFIG_OF case (plus non-module case) that "gpio_charger_match"
will be defined but not used in your code.
I was under the impression that of_match_ptr was defined differently
for OF and !OF so that you could use it in the case where the
structure itself (gpio_charger_match) had #ifdefs around it...
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html