Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Rajanikanth H.V and committed by
Anton Vorontsov
a12810ab 4aef72db

+64 -22
+16
Documentation/devicetree/bindings/power_supply/ab8500/chargalg.txt
··· 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
+5
arch/arm/boot/dts/dbx5x0.dtsi
··· 373 373 vddadc-supply = <&ab8500_ldo_tvout_reg>; 374 374 }; 375 375 376 + ab8500_chargalg { 377 + compatible = "stericsson,ab8500-chargalg"; 378 + battery = <&ab8500_battery>; 379 + }; 380 + 376 381 ab8500_usb { 377 382 compatible = "stericsson,ab8500-usb"; 378 383 interrupts = < 90 0x4
+5
drivers/mfd/ab8500-core.c
··· 1071 1071 }, 1072 1072 { 1073 1073 .name = "ab8500-chargalg", 1074 + .of_compatible = "stericsson,ab8500-chargalg", 1074 1075 .num_resources = ARRAY_SIZE(ab8500_chargalg_resources), 1075 1076 .resources = ab8500_chargalg_resources, 1077 + #ifndef CONFIG_OF 1078 + .platform_data = &ab8500_bm_data, 1079 + .pdata_size = sizeof(ab8500_bm_data), 1080 + #endif 1076 1081 }, 1077 1082 }; 1078 1083
+38 -16
drivers/power/abx500_chargalg.c
··· 21 21 #include <linux/completion.h> 22 22 #include <linux/workqueue.h> 23 23 #include <linux/kobject.h> 24 + #include <linux/of.h> 25 + #include <linux/mfd/core.h> 24 26 #include <linux/mfd/abx500.h> 25 27 #include <linux/mfd/abx500/ux500_chargalg.h> 26 28 #include <linux/mfd/abx500/ab8500-bm.h> ··· 207 205 * @chg_info: information about connected charger types 208 206 * @batt_data: data of the battery 209 207 * @susp_status: current charger suspension status 210 - * @pdata: pointer to the abx500_chargalg platform data 211 208 * @bat: pointer to the abx500_bm platform data 212 209 * @chargalg_psy: structure that holds the battery properties exposed by 213 210 * the charging algorithm ··· 232 231 struct abx500_chargalg_charger_info chg_info; 233 232 struct abx500_chargalg_battery_data batt_data; 234 233 struct abx500_chargalg_suspension_status susp_status; 235 - struct abx500_bmdevs_plat_data *pdata; 236 234 struct abx500_bm_data *bat; 237 235 struct power_supply chargalg_psy; 238 236 struct ux500_charger *ac_chg; ··· 1795 1795 flush_scheduled_work(); 1796 1796 power_supply_unregister(&di->chargalg_psy); 1797 1797 platform_set_drvdata(pdev, NULL); 1798 - kfree(di); 1799 1798 1800 1799 return 0; 1801 1800 } 1802 1801 1802 + static char *supply_interface[] = { 1803 + "ab8500_fg", 1804 + }; 1805 + 1803 1806 static int __devinit abx500_chargalg_probe(struct platform_device *pdev) 1804 1807 { 1805 - struct abx500_bmdevs_plat_data *plat_data; 1808 + struct device_node *np = pdev->dev.of_node; 1809 + struct abx500_chargalg *di; 1806 1810 int ret = 0; 1807 1811 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__); 1811 1815 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 + } 1812 1833 1813 1834 /* get device struct */ 1814 1835 di->dev = &pdev->dev; 1815 - plat_data = pdev->dev.platform_data; 1816 - di->pdata = plat_data; 1817 1836 1818 1837 /* chargalg supply */ 1819 1838 di->chargalg_psy.name = "abx500_chargalg"; ··· 1840 1821 di->chargalg_psy.properties = abx500_chargalg_props; 1841 1822 di->chargalg_psy.num_properties = ARRAY_SIZE(abx500_chargalg_props); 1842 1823 di->chargalg_psy.get_property = abx500_chargalg_get_property; 1843 - di->chargalg_psy.supplied_to = di->pdata->supplied_to; 1844 - di->chargalg_psy.num_supplicants = di->pdata->num_supplicants; 1824 + di->chargalg_psy.supplied_to = supply_interface; 1825 + di->chargalg_psy.num_supplicants = ARRAY_SIZE(supply_interface), 1845 1826 di->chargalg_psy.external_power_changed = 1846 1827 abx500_chargalg_external_power_changed; 1847 1828 ··· 1861 1842 create_singlethread_workqueue("abx500_chargalg_wq"); 1862 1843 if (di->chargalg_wq == NULL) { 1863 1844 dev_err(di->dev, "failed to create work queue\n"); 1864 - goto free_device_info; 1845 + return -ENOMEM; 1865 1846 } 1866 1847 1867 1848 /* Init work for chargalg */ ··· 1902 1883 power_supply_unregister(&di->chargalg_psy); 1903 1884 free_chargalg_wq: 1904 1885 destroy_workqueue(di->chargalg_wq); 1905 - free_device_info: 1906 - kfree(di); 1907 - 1908 1886 return ret; 1909 1887 } 1888 + 1889 + static const struct of_device_id ab8500_chargalg_match[] = { 1890 + { .compatible = "stericsson,ab8500-chargalg", }, 1891 + { }, 1892 + }; 1910 1893 1911 1894 static struct platform_driver abx500_chargalg_driver = { 1912 1895 .probe = abx500_chargalg_probe, ··· 1916 1895 .suspend = abx500_chargalg_suspend, 1917 1896 .resume = abx500_chargalg_resume, 1918 1897 .driver = { 1919 - .name = "abx500-chargalg", 1898 + .name = "ab8500-chargalg", 1920 1899 .owner = THIS_MODULE, 1900 + .of_match_table = ab8500_chargalg_match, 1921 1901 }, 1922 1902 }; 1923 1903
-6
include/linux/mfd/abx500.h
··· 274 274 275 275 extern struct abx500_bm_data ab8500_bm_data; 276 276 277 - struct abx500_bmdevs_plat_data { 278 - char **supplied_to; 279 - size_t num_supplicants; 280 - bool autopower_cfg; 281 - }; 282 - 283 277 enum { 284 278 NTC_EXTERNAL = 0, 285 279 NTC_INTERNAL,