summaryrefslogtreecommitdiff
path: root/drivers/power/supply/charger-manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/supply/charger-manager.c')
-rw-r--r--drivers/power/supply/charger-manager.c89
1 files changed, 36 insertions, 53 deletions
diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
index faa1a67cf3d2..38be91f21cc4 100644
--- a/drivers/power/supply/charger-manager.c
+++ b/drivers/power/supply/charger-manager.c
@@ -363,7 +363,7 @@ static int try_charger_enable(struct charger_manager *cm, bool enable)
int err = 0, i;
struct charger_desc *desc = cm->desc;
- /* Ignore if it's redundent command */
+ /* Ignore if it's redundant command */
if (enable == cm->charger_enabled)
return 0;
@@ -1212,7 +1212,6 @@ static int charger_extcon_init(struct charger_manager *cm,
if (ret < 0) {
pr_info("Cannot register extcon_dev for %s(cable: %s)\n",
cable->extcon_name, cable->name);
- ret = -EINVAL;
}
return ret;
@@ -1352,7 +1351,7 @@ static ssize_t charger_externally_control_store(struct device *dev,
}
/**
- * charger_manager_register_sysfs - Register sysfs entry for each charger
+ * charger_manager_prepare_sysfs - Prepare sysfs entry for each charger
* @cm: the Charger Manager representing the battery.
*
* This function add sysfs entry for charger(regulator) to control charger from
@@ -1364,34 +1363,30 @@ static ssize_t charger_externally_control_store(struct device *dev,
* externally_control, this charger isn't controlled from charger-manager and
* always stay off state of regulator.
*/
-static int charger_manager_register_sysfs(struct charger_manager *cm)
+static int charger_manager_prepare_sysfs(struct charger_manager *cm)
{
struct charger_desc *desc = cm->desc;
struct charger_regulator *charger;
int chargers_externally_control = 1;
- char buf[11];
- char *str;
- int ret;
+ char *name;
int i;
/* Create sysfs entry to control charger(regulator) */
for (i = 0; i < desc->num_charger_regulators; i++) {
charger = &desc->charger_regulators[i];
- snprintf(buf, 10, "charger.%d", i);
- str = devm_kzalloc(cm->dev,
- strlen(buf) + 1, GFP_KERNEL);
- if (!str)
+ name = devm_kasprintf(cm->dev, GFP_KERNEL, "charger.%d", i);
+ if (!name)
return -ENOMEM;
- strcpy(str, buf);
-
charger->attrs[0] = &charger->attr_name.attr;
charger->attrs[1] = &charger->attr_state.attr;
charger->attrs[2] = &charger->attr_externally_control.attr;
charger->attrs[3] = NULL;
- charger->attr_g.name = str;
- charger->attr_g.attrs = charger->attrs;
+
+ charger->attr_grp.name = name;
+ charger->attr_grp.attrs = charger->attrs;
+ desc->sysfs_groups[i] = &charger->attr_grp;
sysfs_attr_init(&charger->attr_name.attr);
charger->attr_name.attr.name = "name";
@@ -1418,14 +1413,6 @@ static int charger_manager_register_sysfs(struct charger_manager *cm)
dev_info(cm->dev, "'%s' regulator's externally_control is %d\n",
charger->regulator_name, charger->externally_control);
-
- ret = sysfs_create_group(&cm->charger_psy->dev.kobj,
- &charger->attr_g);
- if (ret < 0) {
- dev_err(cm->dev, "Cannot create sysfs entry of %s regulator\n",
- charger->regulator_name);
- return ret;
- }
}
if (chargers_externally_control) {
@@ -1521,19 +1508,19 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev)
/* chargers */
of_property_read_u32(np, "cm-num-chargers", &num_chgs);
if (num_chgs) {
+ int i;
+
/* Allocate empty bin at the tail of array */
desc->psy_charger_stat = devm_kcalloc(dev,
num_chgs + 1,
sizeof(char *),
GFP_KERNEL);
- if (desc->psy_charger_stat) {
- int i;
- for (i = 0; i < num_chgs; i++)
- of_property_read_string_index(np, "cm-chargers",
- i, &desc->psy_charger_stat[i]);
- } else {
+ if (!desc->psy_charger_stat)
return ERR_PTR(-ENOMEM);
- }
+
+ for (i = 0; i < num_chgs; i++)
+ of_property_read_string_index(np, "cm-chargers",
+ i, &desc->psy_charger_stat[i]);
}
of_property_read_string(np, "cm-fuel-gauge", &desc->psy_fuel_gauge);
@@ -1566,6 +1553,13 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev)
desc->charger_regulators = chg_regs;
+ desc->sysfs_groups = devm_kcalloc(dev,
+ desc->num_charger_regulators + 1,
+ sizeof(*desc->sysfs_groups),
+ GFP_KERNEL);
+ if (!desc->sysfs_groups)
+ return ERR_PTR(-ENOMEM);
+
for_each_child_of_node(np, child) {
struct charger_cable *cables;
struct device_node *_child;
@@ -1633,7 +1627,7 @@ static int charger_manager_probe(struct platform_device *pdev)
if (IS_ERR(desc)) {
dev_err(&pdev->dev, "No platform data (desc) found\n");
- return -ENODEV;
+ return PTR_ERR(desc);
}
cm = devm_kzalloc(&pdev->dev, sizeof(*cm), GFP_KERNEL);
@@ -1687,10 +1681,6 @@ static int charger_manager_probe(struct platform_device *pdev)
return -EINVAL;
}
- /* Counting index only */
- while (desc->psy_charger_stat[i])
- i++;
-
/* Check if charger's supplies are present at probe */
for (i = 0; desc->psy_charger_stat[i]; i++) {
struct power_supply *psy;
@@ -1772,6 +1762,15 @@ static int charger_manager_probe(struct platform_device *pdev)
INIT_DELAYED_WORK(&cm->fullbatt_vchk_work, fullbatt_vchk);
+ /* Register sysfs entry for charger(regulator) */
+ ret = charger_manager_prepare_sysfs(cm);
+ if (ret < 0) {
+ dev_err(&pdev->dev,
+ "Cannot prepare sysfs entry of regulators\n");
+ return ret;
+ }
+ psy_cfg.attr_grp = desc->sysfs_groups;
+
cm->charger_psy = power_supply_register(&pdev->dev,
&cm->charger_psy_desc,
&psy_cfg);
@@ -1788,14 +1787,6 @@ static int charger_manager_probe(struct platform_device *pdev)
goto err_reg_extcon;
}
- /* Register sysfs entry for charger(regulator) */
- ret = charger_manager_register_sysfs(cm);
- if (ret < 0) {
- dev_err(&pdev->dev,
- "Cannot initialize sysfs entry of regulator\n");
- goto err_reg_sysfs;
- }
-
/* Add to the list */
mutex_lock(&cm_list_mtx);
list_add(&cm->entry, &cm_list);
@@ -1803,7 +1794,7 @@ static int charger_manager_probe(struct platform_device *pdev)
/*
* Charger-manager is capable of waking up the systme from sleep
- * when event is happend through cm_notify_event()
+ * when event is happened through cm_notify_event()
*/
device_init_wakeup(&pdev->dev, true);
device_set_wakeup_capable(&pdev->dev, false);
@@ -1819,14 +1810,6 @@ static int charger_manager_probe(struct platform_device *pdev)
return 0;
-err_reg_sysfs:
- for (i = 0; i < desc->num_charger_regulators; i++) {
- struct charger_regulator *charger;
-
- charger = &desc->charger_regulators[i];
- sysfs_remove_group(&cm->charger_psy->dev.kobj,
- &charger->attr_g);
- }
err_reg_extcon:
for (i = 0; i < desc->num_charger_regulators; i++) {
struct charger_regulator *charger;
@@ -2023,7 +2006,7 @@ module_exit(charger_manager_cleanup);
* cm_notify_event - charger driver notify Charger Manager of charger event
* @psy: pointer to instance of charger's power_supply
* @type: type of charger event
- * @msg: optional message passed to uevent_notify fuction
+ * @msg: optional message passed to uevent_notify function
*/
void cm_notify_event(struct power_supply *psy, enum cm_event_types type,
char *msg)