Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1426278
| From | Chris Lapa <chris@lapa.com.au> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v4 7/7] max8903: adds support for initiation via device tree |
| Date | 2016-06-20 09:30 +0200 |
| Message-ID | <rM1OF-5eM-17@gated-at.bofh.it> (permalink) |
| References | <rFuC5-2sz-13@gated-at.bofh.it> <rM1OF-5eM-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Chris Lapa <chris@lapa.com.au>
Adds support for device tree to setup a max8903 battery charger. DC and USB
validity are determined by looking the presence of the dok and uok gpios.
Signed-off-by: Chris Lapa <chris@lapa.com.au>
---
drivers/power/max8903_charger.c | 78 +++++++++++++++++++++++++++++++++++++----
1 file changed, 72 insertions(+), 6 deletions(-)
diff --git a/drivers/power/max8903_charger.c b/drivers/power/max8903_charger.c
index 9453bbf..47e3929 100644
--- a/drivers/power/max8903_charger.c
+++ b/drivers/power/max8903_charger.c
@@ -23,6 +23,9 @@
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_gpio.h>
#include <linux/slab.h>
#include <linux/power_supply.h>
#include <linux/platform_device.h>
@@ -75,6 +78,7 @@ static int max8903_get_property(struct power_supply *psy,
default:
return -EINVAL;
}
+
return 0;
}
@@ -179,6 +183,56 @@ static irqreturn_t max8903_fault(int irq, void *_data)
return IRQ_HANDLED;
}
+static struct max8903_pdata *max8903_parse_dt_data(struct device *dev)
+{
+ struct device_node *np = dev->of_node;
+ struct max8903_pdata *pdata = NULL;
+
+ if (!np)
+ return NULL;
+
+ pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
+ return NULL;
+
+ pdata->dc_valid = false;
+ pdata->usb_valid = false;
+
+ pdata->cen = of_get_named_gpio(np, "cen-gpios", 0);
+ if (!gpio_is_valid(pdata->cen))
+ pdata->cen = -EINVAL;
+
+ pdata->chg = of_get_named_gpio(np, "chg-gpios", 0);
+ if (!gpio_is_valid(pdata->chg))
+ pdata->chg = -EINVAL;
+
+ pdata->flt = of_get_named_gpio(np, "flt-gpios", 0);
+ if (!gpio_is_valid(pdata->flt))
+ pdata->flt = -EINVAL;
+
+ pdata->usus = of_get_named_gpio(np, "usus-gpios", 0);
+ if (!gpio_is_valid(pdata->usus))
+ pdata->usus = -EINVAL;
+
+ pdata->dcm = of_get_named_gpio(np, "dcm-gpios", 0);
+ if (!gpio_is_valid(pdata->dcm))
+ pdata->dcm = -EINVAL;
+
+ pdata->dok = of_get_named_gpio(np, "dok-gpios", 0);
+ if (!gpio_is_valid(pdata->dok))
+ pdata->dok = -EINVAL;
+ else
+ pdata->dc_valid = true;
+
+ pdata->uok = of_get_named_gpio(np, "uok-gpios", 0);
+ if (!gpio_is_valid(pdata->uok))
+ pdata->uok = -EINVAL;
+ else
+ pdata->usb_valid = true;
+
+ return pdata;
+}
+
static int max8903_setup_gpios(struct platform_device *pdev)
{
struct max8903_data *data = platform_get_drvdata(pdev);
@@ -298,16 +352,20 @@ static int max8903_probe(struct platform_device *pdev)
struct power_supply_config psy_cfg = {};
int ret = 0;
- if (pdata == NULL) {
- dev_err(dev, "No platform data.\n");
- return -EINVAL;
- }
-
data = devm_kzalloc(dev, sizeof(struct max8903_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
- data->pdata = pdev->dev.platform_data;
+ if (IS_ENABLED(CONFIG_OF) && !pdata && dev->of_node)
+ pdata = max8903_parse_dt_data(dev);
+
+ if (!pdata) {
+ dev_err(dev, "No platform data.\n");
+ return -EINVAL;
+ }
+
+ pdev->dev.platform_data = pdata;
+ data->pdata = pdata;
data->dev = dev;
platform_set_drvdata(pdev, data);
@@ -328,6 +386,7 @@ static int max8903_probe(struct platform_device *pdev)
data->psy_desc.properties = max8903_charger_props;
data->psy_desc.num_properties = ARRAY_SIZE(max8903_charger_props);
+ psy_cfg.of_node = dev->of_node;
psy_cfg.drv_data = data;
data->psy = devm_power_supply_register(dev, &data->psy_desc, &psy_cfg);
@@ -378,10 +437,17 @@ static int max8903_probe(struct platform_device *pdev)
return 0;
}
+static const struct of_device_id max8903_match_ids[] = {
+ { .compatible = "maxim,max8903-charger", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, max8903_match_ids);
+
static struct platform_driver max8903_driver = {
.probe = max8903_probe,
.driver = {
.name = "max8903-charger",
+ .of_match_table = max8903_match_ids
},
};
--
1.9.1
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v4 0/7] max8903: Add device tree support and misc fixes Chris Lapa <chris@lapa.com.au> - 2016-06-20 09:30 +0200
[PATCH v4 6/7] max8903: remove unnecessary 'out of memory' error message. Chris Lapa <chris@lapa.com.au> - 2016-06-20 09:30 +0200
Re: [PATCH v4 6/7] max8903: remove unnecessary 'out of memory' error message. Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2016-06-20 14:30 +0200
[PATCH v4 4/7] max8903: adds requesting of gpios. Chris Lapa <chris@lapa.com.au> - 2016-06-20 09:30 +0200
Re: [PATCH v4 4/7] max8903: adds requesting of gpios. Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2016-06-20 14:30 +0200
[PATCH v4 7/7] max8903: adds support for initiation via device tree Chris Lapa <chris@lapa.com.au> - 2016-06-20 09:30 +0200
Re: [PATCH v4 7/7] max8903: adds support for initiation via device tree Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2016-06-20 14:30 +0200
[PATCH v4 2/7] max8903: store pointer to pdata instead of copying it. Chris Lapa <chris@lapa.com.au> - 2016-06-20 09:30 +0200
Re: [PATCH v4 2/7] max8903: store pointer to pdata instead of copying it. Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2016-06-20 14:30 +0200
[PATCH v4 3/7] max8903: cleans up confusing relationship between dc_valid, dok and dcm. Chris Lapa <chris@lapa.com.au> - 2016-06-20 10:10 +0200
Re: [PATCH v4 3/7] max8903: cleans up confusing relationship between dc_valid, dok and dcm. Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2016-06-20 14:30 +0200
[PATCH v4 5/7] max8903: removes non zero validity checks on gpios. Chris Lapa <chris@lapa.com.au> - 2016-06-20 10:10 +0200
Re: [PATCH v4 5/7] max8903: removes non zero validity checks on gpios. Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2016-06-20 14:30 +0200
csiph-web