Skip to content

Commit 4aef72d

Browse files
Rajanikanth H.VAnton Vorontsov
authored andcommitted
ab8500: Add devicetree support for charger
This patch adds device tree support for ab8500-charger driver Signed-off-by: Rajanikanth H.V <rajanikanth.hv@stericsson.com> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
1 parent bd9e8ab commit 4aef72d

5 files changed

Lines changed: 95 additions & 29 deletions

File tree

‎Documentation/devicetree/bindings/mfd/ab8500.txt‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ ab8500-btemp : : vtvout : Battery Temperature
3636
: BTEMP_LOW_MEDIUM : : BtempLow < Btemp < BtempMedium,if battery temperature is between -10 and 0°C
3737
: BTEMP_MEDIUM_HIGH : : BtempMedium < Btemp < BtempHigh,if battery temperature is between 0°C and“MaxTemp
3838
: BTEMP_HIGH : : Btemp > BtempHigh, if battery temperature is higher than “MaxTemp
39+
ab8500-charger : : vddadc : Charger interface
40+
: MAIN_CH_UNPLUG_DET : : main charger unplug detection management (not in 8505)
41+
: MAIN_CHARGE_PLUG_DET : : main charger plug detection management (not in 8505)
42+
: MAIN_EXT_CH_NOT_OK : : main charger not OK
43+
: MAIN_CH_TH_PROT_R : : Die temp is above main charger
44+
: MAIN_CH_TH_PROT_F : : Die temp is below main charger
45+
: VBUS_DET_F : : VBUS falling detected
46+
: VBUS_DET_R : : VBUS rising detected
47+
: USB_LINK_STATUS : : USB link status has changed
48+
: USB_CH_TH_PROT_R : : Die temp is above usb charger
49+
: USB_CH_TH_PROT_F : : Die temp is below usb charger
50+
: USB_CHARGER_NOT_OKR : : allowed USB charger not ok detection
51+
: VBUS_OVV : : Overvoltage on Vbus ball detected (USB charge is stopped)
52+
: CH_WD_EXP : : Charger watchdog detected
3953
ab8500-gpadc : HW_CONV_END : vddadc : Analogue to Digital Converter
4054
SW_CONV_END : :
4155
ab8500-gpio : : : GPIO Controller
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== AB8500 Charger Driver ===
2+
3+
Required Properties:
4+
- compatible = Shall be "stericsson,ab8500-charger"
5+
- battery = Shall be battery specific information
6+
Example:
7+
ab8500_charger {
8+
compatible = "stericsson,ab8500-charger";
9+
battery = <&ab8500_battery>;
10+
};
11+
12+
- vddadc-supply: Supply for USB and Main charger
13+
Example:
14+
ab8500-charger {
15+
vddadc-supply = <&ab8500_ldo_tvout_reg>;
16+
}
17+
- autopower_cfg:
18+
Boolean value depicting the presence of 'automatic poweron after powerloss'
19+
Example:
20+
ab8500-charger {
21+
autopower_cfg;
22+
};
23+
24+
For information on battery specific node, Ref:
25+
Documentation/devicetree/bindings/power_supply/ab8500/fg.txt

‎arch/arm/boot/dts/dbx5x0.dtsi‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,12 @@
367367
battery = <&ab8500_battery>;
368368
};
369369

370+
ab8500_charger {
371+
compatible = "stericsson,ab8500-charger";
372+
battery = <&ab8500_battery>;
373+
vddadc-supply = <&ab8500_ldo_tvout_reg>;
374+
};
375+
370376
ab8500_usb {
371377
compatible = "stericsson,ab8500-usb";
372378
interrupts = < 90 0x4

‎drivers/mfd/ab8500-core.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,8 +1041,13 @@ static struct mfd_cell __devinitdata abx500_common_devs[] = {
10411041
static struct mfd_cell __devinitdata ab8500_bm_devs[] = {
10421042
{
10431043
.name = "ab8500-charger",
1044+
.of_compatible = "stericsson,ab8500-charger",
10441045
.num_resources = ARRAY_SIZE(ab8500_charger_resources),
10451046
.resources = ab8500_charger_resources,
1047+
#ifndef CONFIG_OF
1048+
.platform_data = &ab8500_bm_data,
1049+
.pdata_size = sizeof(ab8500_bm_data),
1050+
#endif
10461051
},
10471052
{
10481053
.name = "ab8500-btemp",

‎drivers/power/ab8500_charger.c‎

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <linux/err.h>
2424
#include <linux/workqueue.h>
2525
#include <linux/kobject.h>
26+
#include <linux/of.h>
27+
#include <linux/mfd/core.h>
2628
#include <linux/mfd/abx500/ab8500.h>
2729
#include <linux/mfd/abx500.h>
2830
#include <linux/mfd/abx500/ab8500-bm.h>
@@ -181,9 +183,9 @@ struct ab8500_charger_usb_state {
181183
* @vbat Battery voltage
182184
* @old_vbat Previously measured battery voltage
183185
* @autopower Indicate if we should have automatic pwron after pwrloss
186+
* @autopower_cfg platform specific power config support for "pwron after pwrloss"
184187
* @parent: Pointer to the struct ab8500
185188
* @gpadc: Pointer to the struct gpadc
186-
* @pdata: Pointer to the abx500_charger platform data
187189
* @bat: Pointer to the abx500_bm platform data
188190
* @flags: Structure for information about events triggered
189191
* @usb_state: Structure for usb stack information
@@ -218,9 +220,9 @@ struct ab8500_charger {
218220
int vbat;
219221
int old_vbat;
220222
bool autopower;
223+
bool autopower_cfg;
221224
struct ab8500 *parent;
222225
struct ab8500_gpadc *gpadc;
223-
struct abx500_bmdevs_plat_data *pdata;
224226
struct abx500_bm_data *bat;
225227
struct ab8500_charger_event_flags flags;
226228
struct ab8500_charger_usb_state usb_state;
@@ -322,7 +324,7 @@ static void ab8500_power_loss_handling(struct ab8500_charger *di)
322324
static void ab8500_power_supply_changed(struct ab8500_charger *di,
323325
struct power_supply *psy)
324326
{
325-
if (di->pdata->autopower_cfg) {
327+
if (di->autopower_cfg) {
326328
if (!di->usb.charger_connected &&
327329
!di->ac.charger_connected &&
328330
di->autopower) {
@@ -2526,25 +2528,45 @@ static int __devexit ab8500_charger_remove(struct platform_device *pdev)
25262528
power_supply_unregister(&di->usb_chg.psy);
25272529
power_supply_unregister(&di->ac_chg.psy);
25282530
platform_set_drvdata(pdev, NULL);
2529-
kfree(di);
25302531

25312532
return 0;
25322533
}
25332534

2535+
static char *supply_interface[] = {
2536+
"ab8500_chargalg",
2537+
"ab8500_fg",
2538+
"ab8500_btemp",
2539+
};
2540+
25342541
static int __devinit ab8500_charger_probe(struct platform_device *pdev)
25352542
{
2536-
struct abx500_bmdevs_plat_data *plat_data = pdev->dev.platform_data;
2543+
struct device_node *np = pdev->dev.of_node;
25372544
struct ab8500_charger *di;
25382545
int irq, i, charger_status, ret = 0;
25392546

2540-
if (!plat_data) {
2541-
dev_err(&pdev->dev, "No platform data\n");
2542-
return -EINVAL;
2543-
}
2544-
2545-
di = kzalloc(sizeof(*di), GFP_KERNEL);
2546-
if (!di)
2547+
di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
2548+
if (!di) {
2549+
dev_err(&pdev->dev, "%s no mem for ab8500_charger\n", __func__);
25472550
return -ENOMEM;
2551+
}
2552+
di->bat = pdev->mfd_cell->platform_data;
2553+
if (!di->bat) {
2554+
if (np) {
2555+
ret = bmdevs_of_probe(&pdev->dev, np, &di->bat);
2556+
if (ret) {
2557+
dev_err(&pdev->dev,
2558+
"failed to get battery information\n");
2559+
return ret;
2560+
}
2561+
di->autopower_cfg = of_property_read_bool(np, "autopower_cfg");
2562+
} else {
2563+
dev_err(&pdev->dev, "missing dt node for ab8500_charger\n");
2564+
return -EINVAL;
2565+
}
2566+
} else {
2567+
dev_info(&pdev->dev, "falling back to legacy platform data\n");
2568+
di->autopower_cfg = false;
2569+
}
25482570

25492571
/* get parent data */
25502572
di->dev = &pdev->dev;
@@ -2554,14 +2576,6 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)
25542576
/* initialize lock */
25552577
spin_lock_init(&di->usb_state.usb_lock);
25562578

2557-
/* get charger specific platform data */
2558-
di->pdata = plat_data;
2559-
if (!di->pdata) {
2560-
dev_err(di->dev, "no charger platform data supplied\n");
2561-
ret = -EINVAL;
2562-
goto free_device_info;
2563-
}
2564-
25652579
di->autopower = false;
25662580

25672581
/* AC supply */
@@ -2571,8 +2585,8 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)
25712585
di->ac_chg.psy.properties = ab8500_charger_ac_props;
25722586
di->ac_chg.psy.num_properties = ARRAY_SIZE(ab8500_charger_ac_props);
25732587
di->ac_chg.psy.get_property = ab8500_charger_ac_get_property;
2574-
di->ac_chg.psy.supplied_to = di->pdata->supplied_to;
2575-
di->ac_chg.psy.num_supplicants = di->pdata->num_supplicants;
2588+
di->ac_chg.psy.supplied_to = supply_interface;
2589+
di->ac_chg.psy.num_supplicants = ARRAY_SIZE(supply_interface),
25762590
/* ux500_charger sub-class */
25772591
di->ac_chg.ops.enable = &ab8500_charger_ac_en;
25782592
di->ac_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
@@ -2589,8 +2603,8 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)
25892603
di->usb_chg.psy.properties = ab8500_charger_usb_props;
25902604
di->usb_chg.psy.num_properties = ARRAY_SIZE(ab8500_charger_usb_props);
25912605
di->usb_chg.psy.get_property = ab8500_charger_usb_get_property;
2592-
di->usb_chg.psy.supplied_to = di->pdata->supplied_to;
2593-
di->usb_chg.psy.num_supplicants = di->pdata->num_supplicants;
2606+
di->usb_chg.psy.supplied_to = supply_interface;
2607+
di->usb_chg.psy.num_supplicants = ARRAY_SIZE(supply_interface),
25942608
/* ux500_charger sub-class */
25952609
di->usb_chg.ops.enable = &ab8500_charger_usb_en;
25962610
di->usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
@@ -2606,8 +2620,7 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)
26062620
create_singlethread_workqueue("ab8500_charger_wq");
26072621
if (di->charger_wq == NULL) {
26082622
dev_err(di->dev, "failed to create work queue\n");
2609-
ret = -ENOMEM;
2610-
goto free_device_info;
2623+
return -ENOMEM;
26112624
}
26122625

26132626
/* Init work for HW failure check */
@@ -2749,12 +2762,14 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)
27492762
regulator_put(di->regu);
27502763
free_charger_wq:
27512764
destroy_workqueue(di->charger_wq);
2752-
free_device_info:
2753-
kfree(di);
2754-
27552765
return ret;
27562766
}
27572767

2768+
static const struct of_device_id ab8500_charger_match[] = {
2769+
{ .compatible = "stericsson,ab8500-charger", },
2770+
{ },
2771+
};
2772+
27582773
static struct platform_driver ab8500_charger_driver = {
27592774
.probe = ab8500_charger_probe,
27602775
.remove = __devexit_p(ab8500_charger_remove),
@@ -2763,6 +2778,7 @@ static struct platform_driver ab8500_charger_driver = {
27632778
.driver = {
27642779
.name = "ab8500-charger",
27652780
.owner = THIS_MODULE,
2781+
.of_match_table = ab8500_charger_match,
27662782
},
27672783
};
27682784

0 commit comments

Comments
 (0)