diff options
author | Jonghwa Lee <jonghwa3.lee@samsung.com> | 2013-12-18 01:42:35 -0500 |
---|---|---|
committer | Anton Vorontsov <anton@enomsg.org> | 2013-12-23 20:10:07 -0500 |
commit | 856ee6115e2de98cb83389ce18116e6d5b90e817 (patch) | |
tree | 2af5c8a176f41b26940f87c9416b9ece79363a6d /drivers/power | |
parent | 5c49a6256bed52f639ed70d252b1c91d1ab899d6 (diff) |
charger-manager: Support deivce tree in charger manager driver
Charger-manager can parse charger_desc data from devicetree which is used
to register charger manager.
Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
Signed-off-by: Myungjoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Anton Vorontsov <anton@enomsg.org>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/charger-manager.c | 138 |
1 files changed, 135 insertions, 3 deletions
diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c index 6b68d158e3c1..ec5c140a52b8 100644 --- a/drivers/power/charger-manager.c +++ b/drivers/power/charger-manager.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/power/charger-manager.h> | 25 | #include <linux/power/charger-manager.h> |
26 | #include <linux/regulator/consumer.h> | 26 | #include <linux/regulator/consumer.h> |
27 | #include <linux/sysfs.h> | 27 | #include <linux/sysfs.h> |
28 | #include <linux/of.h> | ||
28 | #include <linux/thermal.h> | 29 | #include <linux/thermal.h> |
29 | 30 | ||
30 | /* | 31 | /* |
@@ -528,7 +529,7 @@ static int check_charging_duration(struct charger_manager *cm) | |||
528 | duration = curr - cm->charging_start_time; | 529 | duration = curr - cm->charging_start_time; |
529 | 530 | ||
530 | if (duration > desc->charging_max_duration_ms) { | 531 | if (duration > desc->charging_max_duration_ms) { |
531 | dev_info(cm->dev, "Charging duration exceed %lldms\n", | 532 | dev_info(cm->dev, "Charging duration exceed %ums\n", |
532 | desc->charging_max_duration_ms); | 533 | desc->charging_max_duration_ms); |
533 | uevent_notify(cm, "Discharging"); | 534 | uevent_notify(cm, "Discharging"); |
534 | try_charger_enable(cm, false); | 535 | try_charger_enable(cm, false); |
@@ -539,7 +540,7 @@ static int check_charging_duration(struct charger_manager *cm) | |||
539 | 540 | ||
540 | if (duration > desc->charging_max_duration_ms && | 541 | if (duration > desc->charging_max_duration_ms && |
541 | is_ext_pwr_online(cm)) { | 542 | is_ext_pwr_online(cm)) { |
542 | dev_info(cm->dev, "Discharging duration exceed %lldms\n", | 543 | dev_info(cm->dev, "Discharging duration exceed %ums\n", |
543 | desc->discharging_max_duration_ms); | 544 | desc->discharging_max_duration_ms); |
544 | uevent_notify(cm, "Recharging"); | 545 | uevent_notify(cm, "Recharging"); |
545 | try_charger_enable(cm, true); | 546 | try_charger_enable(cm, true); |
@@ -1528,9 +1529,139 @@ static int cm_init_thermal_data(struct charger_manager *cm) | |||
1528 | return ret; | 1529 | return ret; |
1529 | } | 1530 | } |
1530 | 1531 | ||
1532 | static struct of_device_id charger_manager_match[] = { | ||
1533 | { | ||
1534 | .compatible = "charger-manager", | ||
1535 | }, | ||
1536 | {}, | ||
1537 | }; | ||
1538 | |||
1539 | struct charger_desc *of_cm_parse_desc(struct device *dev) | ||
1540 | { | ||
1541 | struct charger_desc *desc; | ||
1542 | struct device_node *np = dev->of_node; | ||
1543 | u32 poll_mode = CM_POLL_DISABLE; | ||
1544 | u32 battery_stat = CM_NO_BATTERY; | ||
1545 | int num_chgs = 0; | ||
1546 | |||
1547 | desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL); | ||
1548 | if (!desc) | ||
1549 | return ERR_PTR(-ENOMEM); | ||
1550 | |||
1551 | of_property_read_string(np, "cm-name", &desc->psy_name); | ||
1552 | |||
1553 | of_property_read_u32(np, "cm-poll-mode", &poll_mode); | ||
1554 | desc->polling_mode = poll_mode; | ||
1555 | |||
1556 | of_property_read_u32(np, "cm-poll-interval", | ||
1557 | &desc->polling_interval_ms); | ||
1558 | |||
1559 | of_property_read_u32(np, "cm-fullbatt-vchkdrop-ms", | ||
1560 | &desc->fullbatt_vchkdrop_ms); | ||
1561 | of_property_read_u32(np, "cm-fullbatt-vchkdrop-volt", | ||
1562 | &desc->fullbatt_vchkdrop_uV); | ||
1563 | of_property_read_u32(np, "cm-fullbatt-voltage", &desc->fullbatt_uV); | ||
1564 | of_property_read_u32(np, "cm-fullbatt-soc", &desc->fullbatt_soc); | ||
1565 | of_property_read_u32(np, "cm-fullbatt-capacity", | ||
1566 | &desc->fullbatt_full_capacity); | ||
1567 | |||
1568 | of_property_read_u32(np, "cm-battery-stat", &battery_stat); | ||
1569 | desc->battery_present = battery_stat; | ||
1570 | |||
1571 | /* chargers */ | ||
1572 | of_property_read_u32(np, "cm-num-chargers", &num_chgs); | ||
1573 | if (num_chgs) { | ||
1574 | /* Allocate empty bin at the tail of array */ | ||
1575 | desc->psy_charger_stat = devm_kzalloc(dev, sizeof(char *) | ||
1576 | * (num_chgs + 1), GFP_KERNEL); | ||
1577 | if (desc->psy_charger_stat) { | ||
1578 | int i; | ||
1579 | for (i = 0; i < num_chgs; i++) | ||
1580 | of_property_read_string_index(np, "cm-chargers", | ||
1581 | i, &desc->psy_charger_stat[i]); | ||
1582 | } else { | ||
1583 | return ERR_PTR(-ENOMEM); | ||
1584 | } | ||
1585 | } | ||
1586 | |||
1587 | of_property_read_string(np, "cm-fuel-gauge", &desc->psy_fuel_gauge); | ||
1588 | |||
1589 | of_property_read_string(np, "cm-thermal-zone", &desc->thermal_zone); | ||
1590 | |||
1591 | of_property_read_u32(np, "cm-battery-cold", &desc->temp_min); | ||
1592 | if (of_get_property(np, "cm-battery-cold-in-minus", NULL)) | ||
1593 | desc->temp_min *= -1; | ||
1594 | of_property_read_u32(np, "cm-battery-hot", &desc->temp_max); | ||
1595 | of_property_read_u32(np, "cm-battery-temp-diff", &desc->temp_diff); | ||
1596 | |||
1597 | of_property_read_u32(np, "cm-charging-max", | ||
1598 | &desc->charging_max_duration_ms); | ||
1599 | of_property_read_u32(np, "cm-discharging-max", | ||
1600 | &desc->discharging_max_duration_ms); | ||
1601 | |||
1602 | /* battery charger regualtors */ | ||
1603 | desc->num_charger_regulators = of_get_child_count(np); | ||
1604 | if (desc->num_charger_regulators) { | ||
1605 | struct charger_regulator *chg_regs; | ||
1606 | struct device_node *child; | ||
1607 | |||
1608 | chg_regs = devm_kzalloc(dev, sizeof(*chg_regs) | ||
1609 | * desc->num_charger_regulators, | ||
1610 | GFP_KERNEL); | ||
1611 | if (!chg_regs) | ||
1612 | return ERR_PTR(-ENOMEM); | ||
1613 | |||
1614 | desc->charger_regulators = chg_regs; | ||
1615 | |||
1616 | for_each_child_of_node(np, child) { | ||
1617 | struct charger_cable *cables; | ||
1618 | struct device_node *_child; | ||
1619 | |||
1620 | of_property_read_string(child, "cm-regulator-name", | ||
1621 | &chg_regs->regulator_name); | ||
1622 | |||
1623 | /* charger cables */ | ||
1624 | chg_regs->num_cables = of_get_child_count(child); | ||
1625 | if (chg_regs->num_cables) { | ||
1626 | cables = devm_kzalloc(dev, sizeof(*cables) | ||
1627 | * chg_regs->num_cables, | ||
1628 | GFP_KERNEL); | ||
1629 | if (!cables) | ||
1630 | return ERR_PTR(-ENOMEM); | ||
1631 | |||
1632 | chg_regs->cables = cables; | ||
1633 | |||
1634 | for_each_child_of_node(child, _child) { | ||
1635 | of_property_read_string(_child, | ||
1636 | "cm-cable-name", &cables->name); | ||
1637 | of_property_read_string(_child, | ||
1638 | "cm-cable-extcon", | ||
1639 | &cables->extcon_name); | ||
1640 | of_property_read_u32(_child, | ||
1641 | "cm-cable-min", | ||
1642 | &cables->min_uA); | ||
1643 | of_property_read_u32(_child, | ||
1644 | "cm-cable-max", | ||
1645 | &cables->max_uA); | ||
1646 | cables++; | ||
1647 | } | ||
1648 | } | ||
1649 | chg_regs++; | ||
1650 | } | ||
1651 | } | ||
1652 | return desc; | ||
1653 | } | ||
1654 | |||
1655 | static inline struct charger_desc *cm_get_drv_data(struct platform_device *pdev) | ||
1656 | { | ||
1657 | if (pdev->dev.of_node) | ||
1658 | return of_cm_parse_desc(&pdev->dev); | ||
1659 | return (struct charger_desc *)dev_get_platdata(&pdev->dev); | ||
1660 | } | ||
1661 | |||
1531 | static int charger_manager_probe(struct platform_device *pdev) | 1662 | static int charger_manager_probe(struct platform_device *pdev) |
1532 | { | 1663 | { |
1533 | struct charger_desc *desc = dev_get_platdata(&pdev->dev); | 1664 | struct charger_desc *desc = cm_get_drv_data(pdev); |
1534 | struct charger_manager *cm; | 1665 | struct charger_manager *cm; |
1535 | int ret = 0, i = 0; | 1666 | int ret = 0, i = 0; |
1536 | int j = 0; | 1667 | int j = 0; |
@@ -1887,6 +2018,7 @@ static struct platform_driver charger_manager_driver = { | |||
1887 | .name = "charger-manager", | 2018 | .name = "charger-manager", |
1888 | .owner = THIS_MODULE, | 2019 | .owner = THIS_MODULE, |
1889 | .pm = &charger_manager_pm, | 2020 | .pm = &charger_manager_pm, |
2021 | .of_match_table = charger_manager_match, | ||
1890 | }, | 2022 | }, |
1891 | .probe = charger_manager_probe, | 2023 | .probe = charger_manager_probe, |
1892 | .remove = charger_manager_remove, | 2024 | .remove = charger_manager_remove, |