Skip to content

Commit a12810a

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

5 files changed

Lines changed: 64 additions & 22 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== AB8500 Charging Algorithm Driver ===
2+
3+
The properties below describes the node for chargalg driver.
4+
5+
Required Properties:
6+
- compatible = Shall be: "stericsson,ab8500-chargalg"
7+
- battery = Shall be battery specific information
8+
9+
Example:
10+
ab8500_chargalg {
11+
compatible = "stericsson,ab8500-chargalg";
12+
battery = <&ab8500_battery>;
13+
};
14+
15+
For information on battery specific node, Ref:
16+
Documentation/devicetree/bindings/power_supply/ab8500/fg.txt

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@
373373
vddadc-supply = <&ab8500_ldo_tvout_reg>;
374374
};
375375

376+
ab8500_chargalg {
377+
compatible = "stericsson,ab8500-chargalg";
378+
battery = <&ab8500_battery>;
379+
};
380+
376381
ab8500_usb {
377382
compatible = "stericsson,ab8500-usb";
378383
interrupts = < 90 0x4

‎drivers/mfd/ab8500-core.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,8 +1071,13 @@ static struct mfd_cell __devinitdata ab8500_bm_devs[] = {
10711071
},
10721072
{
10731073
.name = "ab8500-chargalg",
1074+
.of_compatible = "stericsson,ab8500-chargalg",
10741075
.num_resources = ARRAY_SIZE(ab8500_chargalg_resources),
10751076
.resources = ab8500_chargalg_resources,
1077+
#ifndef CONFIG_OF
1078+
.platform_data = &ab8500_bm_data,
1079+
.pdata_size = sizeof(ab8500_bm_data),
1080+
#endif
10761081
},
10771082
};
10781083

‎drivers/power/abx500_chargalg.c‎

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <linux/completion.h>
2222
#include <linux/workqueue.h>
2323
#include <linux/kobject.h>
24+
#include <linux/of.h>
25+
#include <linux/mfd/core.h>
2426
#include <linux/mfd/abx500.h>
2527
#include <linux/mfd/abx500/ux500_chargalg.h>
2628
#include <linux/mfd/abx500/ab8500-bm.h>
@@ -205,7 +207,6 @@ enum maxim_ret {
205207
* @chg_info: information about connected charger types
206208
* @batt_data: data of the battery
207209
* @susp_status: current charger suspension status
208-
* @pdata: pointer to the abx500_chargalg platform data
209210
* @bat: pointer to the abx500_bm platform data
210211
* @chargalg_psy: structure that holds the battery properties exposed by
211212
* the charging algorithm
@@ -231,7 +232,6 @@ struct abx500_chargalg {
231232
struct abx500_chargalg_charger_info chg_info;
232233
struct abx500_chargalg_battery_data batt_data;
233234
struct abx500_chargalg_suspension_status susp_status;
234-
struct abx500_bmdevs_plat_data *pdata;
235235
struct abx500_bm_data *bat;
236236
struct power_supply chargalg_psy;
237237
struct ux500_charger *ac_chg;
@@ -1795,34 +1795,53 @@ static int __devexit abx500_chargalg_remove(struct platform_device *pdev)
17951795
flush_scheduled_work();
17961796
power_supply_unregister(&di->chargalg_psy);
17971797
platform_set_drvdata(pdev, NULL);
1798-
kfree(di);
17991798

18001799
return 0;
18011800
}
18021801

1802+
static char *supply_interface[] = {
1803+
"ab8500_fg",
1804+
};
1805+
18031806
static int __devinit abx500_chargalg_probe(struct platform_device *pdev)
18041807
{
1805-
struct abx500_bmdevs_plat_data *plat_data;
1808+
struct device_node *np = pdev->dev.of_node;
1809+
struct abx500_chargalg *di;
18061810
int ret = 0;
18071811

1808-
struct abx500_chargalg *di =
1809-
kzalloc(sizeof(struct abx500_chargalg), GFP_KERNEL);
1810-
if (!di)
1812+
di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL);
1813+
if (!di) {
1814+
dev_err(&pdev->dev, "%s no mem for ab8500_chargalg\n", __func__);
18111815
return -ENOMEM;
1816+
}
1817+
di->bat = pdev->mfd_cell->platform_data;
1818+
if (!di->bat) {
1819+
if (np) {
1820+
ret = bmdevs_of_probe(&pdev->dev, np, &di->bat);
1821+
if (ret) {
1822+
dev_err(&pdev->dev,
1823+
"failed to get battery information\n");
1824+
return ret;
1825+
}
1826+
} else {
1827+
dev_err(&pdev->dev, "missing dt node for ab8500_chargalg\n");
1828+
return -EINVAL;
1829+
}
1830+
} else {
1831+
dev_info(&pdev->dev, "falling back to legacy platform data\n");
1832+
}
18121833

18131834
/* get device struct */
18141835
di->dev = &pdev->dev;
1815-
plat_data = pdev->dev.platform_data;
1816-
di->pdata = plat_data;
18171836

18181837
/* chargalg supply */
18191838
di->chargalg_psy.name = "abx500_chargalg";
18201839
di->chargalg_psy.type = POWER_SUPPLY_TYPE_BATTERY;
18211840
di->chargalg_psy.properties = abx500_chargalg_props;
18221841
di->chargalg_psy.num_properties = ARRAY_SIZE(abx500_chargalg_props);
18231842
di->chargalg_psy.get_property = abx500_chargalg_get_property;
1824-
di->chargalg_psy.supplied_to = di->pdata->supplied_to;
1825-
di->chargalg_psy.num_supplicants = di->pdata->num_supplicants;
1843+
di->chargalg_psy.supplied_to = supply_interface;
1844+
di->chargalg_psy.num_supplicants = ARRAY_SIZE(supply_interface),
18261845
di->chargalg_psy.external_power_changed =
18271846
abx500_chargalg_external_power_changed;
18281847

@@ -1842,7 +1861,7 @@ static int __devinit abx500_chargalg_probe(struct platform_device *pdev)
18421861
create_singlethread_workqueue("abx500_chargalg_wq");
18431862
if (di->chargalg_wq == NULL) {
18441863
dev_err(di->dev, "failed to create work queue\n");
1845-
goto free_device_info;
1864+
return -ENOMEM;
18461865
}
18471866

18481867
/* Init work for chargalg */
@@ -1883,20 +1902,23 @@ static int __devinit abx500_chargalg_probe(struct platform_device *pdev)
18831902
power_supply_unregister(&di->chargalg_psy);
18841903
free_chargalg_wq:
18851904
destroy_workqueue(di->chargalg_wq);
1886-
free_device_info:
1887-
kfree(di);
1888-
18891905
return ret;
18901906
}
18911907

1908+
static const struct of_device_id ab8500_chargalg_match[] = {
1909+
{ .compatible = "stericsson,ab8500-chargalg", },
1910+
{ },
1911+
};
1912+
18921913
static struct platform_driver abx500_chargalg_driver = {
18931914
.probe = abx500_chargalg_probe,
18941915
.remove = __devexit_p(abx500_chargalg_remove),
18951916
.suspend = abx500_chargalg_suspend,
18961917
.resume = abx500_chargalg_resume,
18971918
.driver = {
1898-
.name = "abx500-chargalg",
1919+
.name = "ab8500-chargalg",
18991920
.owner = THIS_MODULE,
1921+
.of_match_table = ab8500_chargalg_match,
19001922
},
19011923
};
19021924

‎include/linux/mfd/abx500.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,6 @@ struct abx500_bm_data {
274274

275275
extern struct abx500_bm_data ab8500_bm_data;
276276

277-
struct abx500_bmdevs_plat_data {
278-
char **supplied_to;
279-
size_t num_supplicants;
280-
bool autopower_cfg;
281-
};
282-
283277
enum {
284278
NTC_EXTERNAL = 0,
285279
NTC_INTERNAL,

0 commit comments

Comments
 (0)