diff options
author | Chris Lapa <chris@lapa.com.au> | 2016-06-23 22:26:12 -0400 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2016-06-28 14:16:26 -0400 |
commit | c5ed3307940bc4584ce99236f033d60435d83036 (patch) | |
tree | 3f4831cb1984fe5041ed344adaf1de560848546f /drivers/power | |
parent | 4aff217e77a88f6d8c21156e02dfcd32e65171a3 (diff) |
max8903: adds support for initiation via device tree
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>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/max8903_charger.c | 78 |
1 files changed, 72 insertions, 6 deletions
diff --git a/drivers/power/max8903_charger.c b/drivers/power/max8903_charger.c index 9453bbff6075..fdc73d686153 100644 --- a/drivers/power/max8903_charger.c +++ b/drivers/power/max8903_charger.c | |||
@@ -23,6 +23,9 @@ | |||
23 | #include <linux/gpio.h> | 23 | #include <linux/gpio.h> |
24 | #include <linux/interrupt.h> | 24 | #include <linux/interrupt.h> |
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/of.h> | ||
27 | #include <linux/of_device.h> | ||
28 | #include <linux/of_gpio.h> | ||
26 | #include <linux/slab.h> | 29 | #include <linux/slab.h> |
27 | #include <linux/power_supply.h> | 30 | #include <linux/power_supply.h> |
28 | #include <linux/platform_device.h> | 31 | #include <linux/platform_device.h> |
@@ -75,6 +78,7 @@ static int max8903_get_property(struct power_supply *psy, | |||
75 | default: | 78 | default: |
76 | return -EINVAL; | 79 | return -EINVAL; |
77 | } | 80 | } |
81 | |||
78 | return 0; | 82 | return 0; |
79 | } | 83 | } |
80 | 84 | ||
@@ -179,6 +183,56 @@ static irqreturn_t max8903_fault(int irq, void *_data) | |||
179 | return IRQ_HANDLED; | 183 | return IRQ_HANDLED; |
180 | } | 184 | } |
181 | 185 | ||
186 | static struct max8903_pdata *max8903_parse_dt_data(struct device *dev) | ||
187 | { | ||
188 | struct device_node *np = dev->of_node; | ||
189 | struct max8903_pdata *pdata = NULL; | ||
190 | |||
191 | if (!np) | ||
192 | return NULL; | ||
193 | |||
194 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); | ||
195 | if (!pdata) | ||
196 | return NULL; | ||
197 | |||
198 | pdata->dc_valid = false; | ||
199 | pdata->usb_valid = false; | ||
200 | |||
201 | pdata->cen = of_get_named_gpio(np, "cen-gpios", 0); | ||
202 | if (!gpio_is_valid(pdata->cen)) | ||
203 | pdata->cen = -EINVAL; | ||
204 | |||
205 | pdata->chg = of_get_named_gpio(np, "chg-gpios", 0); | ||
206 | if (!gpio_is_valid(pdata->chg)) | ||
207 | pdata->chg = -EINVAL; | ||
208 | |||
209 | pdata->flt = of_get_named_gpio(np, "flt-gpios", 0); | ||
210 | if (!gpio_is_valid(pdata->flt)) | ||
211 | pdata->flt = -EINVAL; | ||
212 | |||
213 | pdata->usus = of_get_named_gpio(np, "usus-gpios", 0); | ||
214 | if (!gpio_is_valid(pdata->usus)) | ||
215 | pdata->usus = -EINVAL; | ||
216 | |||
217 | pdata->dcm = of_get_named_gpio(np, "dcm-gpios", 0); | ||
218 | if (!gpio_is_valid(pdata->dcm)) | ||
219 | pdata->dcm = -EINVAL; | ||
220 | |||
221 | pdata->dok = of_get_named_gpio(np, "dok-gpios", 0); | ||
222 | if (!gpio_is_valid(pdata->dok)) | ||
223 | pdata->dok = -EINVAL; | ||
224 | else | ||
225 | pdata->dc_valid = true; | ||
226 | |||
227 | pdata->uok = of_get_named_gpio(np, "uok-gpios", 0); | ||
228 | if (!gpio_is_valid(pdata->uok)) | ||
229 | pdata->uok = -EINVAL; | ||
230 | else | ||
231 | pdata->usb_valid = true; | ||
232 | |||
233 | return pdata; | ||
234 | } | ||
235 | |||
182 | static int max8903_setup_gpios(struct platform_device *pdev) | 236 | static int max8903_setup_gpios(struct platform_device *pdev) |
183 | { | 237 | { |
184 | struct max8903_data *data = platform_get_drvdata(pdev); | 238 | struct max8903_data *data = platform_get_drvdata(pdev); |
@@ -298,16 +352,20 @@ static int max8903_probe(struct platform_device *pdev) | |||
298 | struct power_supply_config psy_cfg = {}; | 352 | struct power_supply_config psy_cfg = {}; |
299 | int ret = 0; | 353 | int ret = 0; |
300 | 354 | ||
301 | if (pdata == NULL) { | ||
302 | dev_err(dev, "No platform data.\n"); | ||
303 | return -EINVAL; | ||
304 | } | ||
305 | |||
306 | data = devm_kzalloc(dev, sizeof(struct max8903_data), GFP_KERNEL); | 355 | data = devm_kzalloc(dev, sizeof(struct max8903_data), GFP_KERNEL); |
307 | if (!data) | 356 | if (!data) |
308 | return -ENOMEM; | 357 | return -ENOMEM; |
309 | 358 | ||
310 | data->pdata = pdev->dev.platform_data; | 359 | if (IS_ENABLED(CONFIG_OF) && !pdata && dev->of_node) |
360 | pdata = max8903_parse_dt_data(dev); | ||
361 | |||
362 | if (!pdata) { | ||
363 | dev_err(dev, "No platform data.\n"); | ||
364 | return -EINVAL; | ||
365 | } | ||
366 | |||
367 | pdev->dev.platform_data = pdata; | ||
368 | data->pdata = pdata; | ||
311 | data->dev = dev; | 369 | data->dev = dev; |
312 | platform_set_drvdata(pdev, data); | 370 | platform_set_drvdata(pdev, data); |
313 | 371 | ||
@@ -328,6 +386,7 @@ static int max8903_probe(struct platform_device *pdev) | |||
328 | data->psy_desc.properties = max8903_charger_props; | 386 | data->psy_desc.properties = max8903_charger_props; |
329 | data->psy_desc.num_properties = ARRAY_SIZE(max8903_charger_props); | 387 | data->psy_desc.num_properties = ARRAY_SIZE(max8903_charger_props); |
330 | 388 | ||
389 | psy_cfg.of_node = dev->of_node; | ||
331 | psy_cfg.drv_data = data; | 390 | psy_cfg.drv_data = data; |
332 | 391 | ||
333 | data->psy = devm_power_supply_register(dev, &data->psy_desc, &psy_cfg); | 392 | data->psy = devm_power_supply_register(dev, &data->psy_desc, &psy_cfg); |
@@ -378,10 +437,17 @@ static int max8903_probe(struct platform_device *pdev) | |||
378 | return 0; | 437 | return 0; |
379 | } | 438 | } |
380 | 439 | ||
440 | static const struct of_device_id max8903_match_ids[] = { | ||
441 | { .compatible = "maxim,max8903", }, | ||
442 | { /* sentinel */ } | ||
443 | }; | ||
444 | MODULE_DEVICE_TABLE(of, max8903_match_ids); | ||
445 | |||
381 | static struct platform_driver max8903_driver = { | 446 | static struct platform_driver max8903_driver = { |
382 | .probe = max8903_probe, | 447 | .probe = max8903_probe, |
383 | .driver = { | 448 | .driver = { |
384 | .name = "max8903-charger", | 449 | .name = "max8903-charger", |
450 | .of_match_table = max8903_match_ids | ||
385 | }, | 451 | }, |
386 | }; | 452 | }; |
387 | 453 | ||