Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5409cbd authored by Joe Perches's avatar Joe Perches Committed by Anton Vorontsov
Browse files

charger-manager: Add missing newlines, fix a couple of typos, add pr_fmt



Make sure that dev_<level> calls are newline terminated.
Add #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt to prefix
all pr_<level> calls with "charger-manager: "

Fix a couple of typos.
Fix formats with terminating n that should be \n.
Coalesce formats for easier grep.
Align arguments to open parenthesis for these dev_<level> calls.
Add missing spaces after coalescing multiple string segments.

Signed-off-by: default avatarJoe Perches <joe@perches.com>
Acked-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarAnton Vorontsov <anton@enomsg.org>
parent e2414217
Loading
Loading
Loading
Loading
+57 −80
Original line number Original line Diff line number Diff line
@@ -12,6 +12,8 @@
 * published by the Free Software Foundation.
 * published by the Free Software Foundation.
**/
**/


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/io.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/module.h>
#include <linux/irq.h>
#include <linux/irq.h>
@@ -195,7 +197,7 @@ static bool is_charging(struct charger_manager *cm)
				cm->charger_stat[i],
				cm->charger_stat[i],
				POWER_SUPPLY_PROP_ONLINE, &val);
				POWER_SUPPLY_PROP_ONLINE, &val);
		if (ret) {
		if (ret) {
			dev_warn(cm->dev, "Cannot read ONLINE value from %s.\n",
			dev_warn(cm->dev, "Cannot read ONLINE value from %s\n",
				 cm->desc->psy_charger_stat[i]);
				 cm->desc->psy_charger_stat[i]);
			continue;
			continue;
		}
		}
@@ -210,7 +212,7 @@ static bool is_charging(struct charger_manager *cm)
				cm->charger_stat[i],
				cm->charger_stat[i],
				POWER_SUPPLY_PROP_STATUS, &val);
				POWER_SUPPLY_PROP_STATUS, &val);
		if (ret) {
		if (ret) {
			dev_warn(cm->dev, "Cannot read STATUS value from %s.\n",
			dev_warn(cm->dev, "Cannot read STATUS value from %s\n",
				 cm->desc->psy_charger_stat[i]);
				 cm->desc->psy_charger_stat[i]);
			continue;
			continue;
		}
		}
@@ -331,8 +333,7 @@ static int try_charger_enable(struct charger_manager *cm, bool enable)


			err = regulator_enable(desc->charger_regulators[i].consumer);
			err = regulator_enable(desc->charger_regulators[i].consumer);
			if (err < 0) {
			if (err < 0) {
				dev_warn(cm->dev,
				dev_warn(cm->dev, "Cannot enable %s regulator\n",
					"Cannot enable %s regulator\n",
					 desc->charger_regulators[i].regulator_name);
					 desc->charger_regulators[i].regulator_name);
			}
			}
		}
		}
@@ -350,8 +351,7 @@ static int try_charger_enable(struct charger_manager *cm, bool enable)


			err = regulator_disable(desc->charger_regulators[i].consumer);
			err = regulator_disable(desc->charger_regulators[i].consumer);
			if (err < 0) {
			if (err < 0) {
				dev_warn(cm->dev,
				dev_warn(cm->dev, "Cannot disable %s regulator\n",
					"Cannot disable %s regulator\n",
					 desc->charger_regulators[i].regulator_name);
					 desc->charger_regulators[i].regulator_name);
			}
			}
		}
		}
@@ -365,8 +365,7 @@ static int try_charger_enable(struct charger_manager *cm, bool enable)
				    desc->charger_regulators[i].consumer)) {
				    desc->charger_regulators[i].consumer)) {
				regulator_force_disable(
				regulator_force_disable(
					desc->charger_regulators[i].consumer);
					desc->charger_regulators[i].consumer);
				dev_warn(cm->dev,
				dev_warn(cm->dev, "Disable regulator(%s) forcibly\n",
					"Disable regulator(%s) forcibly.\n",
					 desc->charger_regulators[i].regulator_name);
					 desc->charger_regulators[i].regulator_name);
			}
			}
		}
		}
@@ -450,7 +449,7 @@ static void uevent_notify(struct charger_manager *cm, const char *event)
	strncpy(env_str, event, UEVENT_BUF_SIZE);
	strncpy(env_str, event, UEVENT_BUF_SIZE);
	kobject_uevent(&cm->dev->kobj, KOBJ_CHANGE);
	kobject_uevent(&cm->dev->kobj, KOBJ_CHANGE);


	dev_info(cm->dev, "%s", event);
	dev_info(cm->dev, "%s\n", event);
}
}


/**
/**
@@ -478,7 +477,7 @@ static void fullbatt_vchk(struct work_struct *work)


	err = get_batt_uV(cm, &batt_uV);
	err = get_batt_uV(cm, &batt_uV);
	if (err) {
	if (err) {
		dev_err(cm->dev, "%s: get_batt_uV error(%d).\n", __func__, err);
		dev_err(cm->dev, "%s: get_batt_uV error(%d)\n", __func__, err);
		return;
		return;
	}
	}


@@ -486,7 +485,7 @@ static void fullbatt_vchk(struct work_struct *work)
	if (diff < 0)
	if (diff < 0)
		return;
		return;


	dev_info(cm->dev, "VBATT dropped %duV after full-batt.\n", diff);
	dev_info(cm->dev, "VBATT dropped %duV after full-batt\n", diff);


	if (diff > desc->fullbatt_vchkdrop_uV) {
	if (diff > desc->fullbatt_vchkdrop_uV) {
		try_charger_restart(cm);
		try_charger_restart(cm);
@@ -519,7 +518,7 @@ static int check_charging_duration(struct charger_manager *cm)
		duration = curr - cm->charging_start_time;
		duration = curr - cm->charging_start_time;


		if (duration > desc->charging_max_duration_ms) {
		if (duration > desc->charging_max_duration_ms) {
			dev_info(cm->dev, "Charging duration exceed %lldms",
			dev_info(cm->dev, "Charging duration exceed %lldms\n",
				 desc->charging_max_duration_ms);
				 desc->charging_max_duration_ms);
			uevent_notify(cm, "Discharging");
			uevent_notify(cm, "Discharging");
			try_charger_enable(cm, false);
			try_charger_enable(cm, false);
@@ -530,9 +529,9 @@ static int check_charging_duration(struct charger_manager *cm)


		if (duration > desc->charging_max_duration_ms &&
		if (duration > desc->charging_max_duration_ms &&
				is_ext_pwr_online(cm)) {
				is_ext_pwr_online(cm)) {
			dev_info(cm->dev, "DisCharging duration exceed %lldms",
			dev_info(cm->dev, "Discharging duration exceed %lldms\n",
				 desc->discharging_max_duration_ms);
				 desc->discharging_max_duration_ms);
			uevent_notify(cm, "Recharing");
			uevent_notify(cm, "Recharging");
			try_charger_enable(cm, true);
			try_charger_enable(cm, true);
			ret = true;
			ret = true;
		}
		}
@@ -579,7 +578,7 @@ static bool _cm_monitor(struct charger_manager *cm)
	 */
	 */
	} else if (!cm->emergency_stop && check_charging_duration(cm)) {
	} else if (!cm->emergency_stop && check_charging_duration(cm)) {
		dev_dbg(cm->dev,
		dev_dbg(cm->dev,
			"Charging/Discharging duration is out of range");
			"Charging/Discharging duration is out of range\n");
	/*
	/*
	 * Check dropped voltage of battery. If battery voltage is more
	 * Check dropped voltage of battery. If battery voltage is more
	 * dropped than fullbatt_vchkdrop_uV after fully charged state,
	 * dropped than fullbatt_vchkdrop_uV after fully charged state,
@@ -595,7 +594,7 @@ static bool _cm_monitor(struct charger_manager *cm)
	 */
	 */
	} else if (!cm->emergency_stop && is_full_charged(cm) &&
	} else if (!cm->emergency_stop && is_full_charged(cm) &&
			cm->charger_enabled) {
			cm->charger_enabled) {
		dev_info(cm->dev, "EVENT_HANDLE: Battery Fully Charged.\n");
		dev_info(cm->dev, "EVENT_HANDLE: Battery Fully Charged\n");
		uevent_notify(cm, default_event_names[CM_EVENT_BATT_FULL]);
		uevent_notify(cm, default_event_names[CM_EVENT_BATT_FULL]);


		try_charger_enable(cm, false);
		try_charger_enable(cm, false);
@@ -725,7 +724,7 @@ static void fullbatt_handler(struct charger_manager *cm)
		cm->fullbatt_vchk_jiffies_at = 1;
		cm->fullbatt_vchk_jiffies_at = 1;


out:
out:
	dev_info(cm->dev, "EVENT_HANDLE: Battery Fully Charged.\n");
	dev_info(cm->dev, "EVENT_HANDLE: Battery Fully Charged\n");
	uevent_notify(cm, default_event_names[CM_EVENT_BATT_FULL]);
	uevent_notify(cm, default_event_names[CM_EVENT_BATT_FULL]);
}
}


@@ -972,7 +971,7 @@ static bool cm_setup_timer(void)
	mutex_unlock(&cm_list_mtx);
	mutex_unlock(&cm_list_mtx);


	if (wakeup_ms < UINT_MAX && wakeup_ms > 0) {
	if (wakeup_ms < UINT_MAX && wakeup_ms > 0) {
		pr_info("Charger Manager wakeup timer: %u ms.\n", wakeup_ms);
		pr_info("Charger Manager wakeup timer: %u ms\n", wakeup_ms);
		if (rtc_dev) {
		if (rtc_dev) {
			struct rtc_wkalrm tmp;
			struct rtc_wkalrm tmp;
			unsigned long time, now;
			unsigned long time, now;
@@ -1005,8 +1004,7 @@ static bool cm_setup_timer(void)
				ret = false;
				ret = false;
			}
			}


			pr_info("Waking up after %lu secs.\n",
			pr_info("Waking up after %lu secs\n", time - now);
					time - now);


			rtc_time_to_tm(time, &tmp.time);
			rtc_time_to_tm(time, &tmp.time);
			rtc_set_alarm(rtc_dev, &tmp);
			rtc_set_alarm(rtc_dev, &tmp);
@@ -1101,7 +1099,7 @@ int setup_charger_manager(struct charger_global_desc *gd)
	g_desc = NULL;
	g_desc = NULL;


	if (!gd->rtc_only_wakeup) {
	if (!gd->rtc_only_wakeup) {
		pr_err("The callback rtc_only_wakeup is not given.\n");
		pr_err("The callback rtc_only_wakeup is not given\n");
		return -EINVAL;
		return -EINVAL;
	}
	}


@@ -1210,9 +1208,8 @@ static int charger_extcon_init(struct charger_manager *cm,
	ret = extcon_register_interest(&cable->extcon_dev,
	ret = extcon_register_interest(&cable->extcon_dev,
			cable->extcon_name, cable->name, &cable->nb);
			cable->extcon_name, cable->name, &cable->nb);
	if (ret < 0) {
	if (ret < 0) {
		pr_info("Cannot register extcon_dev for %s(cable: %s).\n",
		pr_info("Cannot register extcon_dev for %s(cable: %s)\n",
				cable->extcon_name,
			cable->extcon_name, cable->name);
				cable->name);
		ret = -EINVAL;
		ret = -EINVAL;
	}
	}


@@ -1243,7 +1240,7 @@ static int charger_manager_register_extcon(struct charger_manager *cm)
		charger->consumer = regulator_get(cm->dev,
		charger->consumer = regulator_get(cm->dev,
					charger->regulator_name);
					charger->regulator_name);
		if (charger->consumer == NULL) {
		if (charger->consumer == NULL) {
			dev_err(cm->dev, "Cannot find charger(%s)n",
			dev_err(cm->dev, "Cannot find charger(%s)\n",
				charger->regulator_name);
				charger->regulator_name);
			ret = -EINVAL;
			ret = -EINVAL;
			goto err;
			goto err;
@@ -1255,7 +1252,7 @@ static int charger_manager_register_extcon(struct charger_manager *cm)


			ret = charger_extcon_init(cm, cable);
			ret = charger_extcon_init(cm, cable);
			if (ret < 0) {
			if (ret < 0) {
				dev_err(cm->dev, "Cannot initialize charger(%s)n",
				dev_err(cm->dev, "Cannot initialize charger(%s)\n",
					charger->regulator_name);
					charger->regulator_name);
				goto err;
				goto err;
			}
			}
@@ -1347,9 +1344,7 @@ static ssize_t charger_externally_control_store(struct device *dev,
		}
		}
	} else {
	} else {
		dev_warn(cm->dev,
		dev_warn(cm->dev,
			"'%s' regulator should be controlled "
			 "'%s' regulator should be controlled in charger-manager because charger-manager must need at least one charger for charging\n",
			"in charger-manager because charger-manager "
			"must need at least one charger for charging\n",
			 charger->regulator_name);
			 charger->regulator_name);
	}
	}


@@ -1386,8 +1381,6 @@ static int charger_manager_register_sysfs(struct charger_manager *cm)
		snprintf(buf, 10, "charger.%d", i);
		snprintf(buf, 10, "charger.%d", i);
		str = kzalloc(sizeof(char) * (strlen(buf) + 1), GFP_KERNEL);
		str = kzalloc(sizeof(char) * (strlen(buf) + 1), GFP_KERNEL);
		if (!str) {
		if (!str) {
			dev_err(cm->dev, "Cannot allocate memory: %s\n",
					charger->regulator_name);
			ret = -ENOMEM;
			ret = -ENOMEM;
			goto err;
			goto err;
		}
		}
@@ -1423,15 +1416,13 @@ static int charger_manager_register_sysfs(struct charger_manager *cm)
				!chargers_externally_control)
				!chargers_externally_control)
			chargers_externally_control = 0;
			chargers_externally_control = 0;


		dev_info(cm->dev, "'%s' regulator's externally_control"
		dev_info(cm->dev, "'%s' regulator's externally_control is %d\n",
				"is %d\n", charger->regulator_name,
			 charger->regulator_name, charger->externally_control);
				charger->externally_control);


		ret = sysfs_create_group(&cm->charger_psy.dev->kobj,
		ret = sysfs_create_group(&cm->charger_psy.dev->kobj,
					&charger->attr_g);
					&charger->attr_g);
		if (ret < 0) {
		if (ret < 0) {
			dev_err(cm->dev, "Cannot create sysfs entry"
			dev_err(cm->dev, "Cannot create sysfs entry of %s regulator\n",
					"of %s regulator\n",
				charger->regulator_name);
				charger->regulator_name);
			ret = -EINVAL;
			ret = -EINVAL;
			goto err;
			goto err;
@@ -1439,10 +1430,7 @@ static int charger_manager_register_sysfs(struct charger_manager *cm)
	}
	}


	if (chargers_externally_control) {
	if (chargers_externally_control) {
		dev_err(cm->dev, "Cannot register regulator because "
		dev_err(cm->dev, "Cannot register regulator because charger-manager must need at least one charger for charging battery\n");
				"charger-manager must need at least "
				"one charger for charging battery\n");

		ret = -EINVAL;
		ret = -EINVAL;
		goto err;
		goto err;
	}
	}
@@ -1463,7 +1451,7 @@ static int charger_manager_probe(struct platform_device *pdev)
		rtc_dev = rtc_class_open(g_desc->rtc_name);
		rtc_dev = rtc_class_open(g_desc->rtc_name);
		if (IS_ERR_OR_NULL(rtc_dev)) {
		if (IS_ERR_OR_NULL(rtc_dev)) {
			rtc_dev = NULL;
			rtc_dev = NULL;
			dev_err(&pdev->dev, "Cannot get RTC %s.\n",
			dev_err(&pdev->dev, "Cannot get RTC %s\n",
				g_desc->rtc_name);
				g_desc->rtc_name);
			ret = -ENODEV;
			ret = -ENODEV;
			goto err_alloc;
			goto err_alloc;
@@ -1471,14 +1459,13 @@ static int charger_manager_probe(struct platform_device *pdev)
	}
	}


	if (!desc) {
	if (!desc) {
		dev_err(&pdev->dev, "No platform data (desc) found.\n");
		dev_err(&pdev->dev, "No platform data (desc) found\n");
		ret = -ENODEV;
		ret = -ENODEV;
		goto err_alloc;
		goto err_alloc;
	}
	}


	cm = kzalloc(sizeof(struct charger_manager), GFP_KERNEL);
	cm = kzalloc(sizeof(struct charger_manager), GFP_KERNEL);
	if (!cm) {
	if (!cm) {
		dev_err(&pdev->dev, "Cannot allocate memory.\n");
		ret = -ENOMEM;
		ret = -ENOMEM;
		goto err_alloc;
		goto err_alloc;
	}
	}
@@ -1487,7 +1474,6 @@ static int charger_manager_probe(struct platform_device *pdev)
	cm->dev = &pdev->dev;
	cm->dev = &pdev->dev;
	cm->desc = kmemdup(desc, sizeof(struct charger_desc), GFP_KERNEL);
	cm->desc = kmemdup(desc, sizeof(struct charger_desc), GFP_KERNEL);
	if (!cm->desc) {
	if (!cm->desc) {
		dev_err(&pdev->dev, "Cannot allocate memory.\n");
		ret = -ENOMEM;
		ret = -ENOMEM;
		goto err_alloc_desc;
		goto err_alloc_desc;
	}
	}
@@ -1498,33 +1484,28 @@ static int charger_manager_probe(struct platform_device *pdev)
	 * Users may intentionally ignore those two features.
	 * Users may intentionally ignore those two features.
	 */
	 */
	if (desc->fullbatt_uV == 0) {
	if (desc->fullbatt_uV == 0) {
		dev_info(&pdev->dev, "Ignoring full-battery voltage threshold"
		dev_info(&pdev->dev, "Ignoring full-battery voltage threshold as it is not supplied\n");
					" as it is not supplied.");
	}
	}
	if (!desc->fullbatt_vchkdrop_ms || !desc->fullbatt_vchkdrop_uV) {
	if (!desc->fullbatt_vchkdrop_ms || !desc->fullbatt_vchkdrop_uV) {
		dev_info(&pdev->dev, "Disabling full-battery voltage drop "
		dev_info(&pdev->dev, "Disabling full-battery voltage drop checking mechanism as it is not supplied\n");
				"checking mechanism as it is not supplied.");
		desc->fullbatt_vchkdrop_ms = 0;
		desc->fullbatt_vchkdrop_ms = 0;
		desc->fullbatt_vchkdrop_uV = 0;
		desc->fullbatt_vchkdrop_uV = 0;
	}
	}
	if (desc->fullbatt_soc == 0) {
	if (desc->fullbatt_soc == 0) {
		dev_info(&pdev->dev, "Ignoring full-battery soc(state of"
		dev_info(&pdev->dev, "Ignoring full-battery soc(state of charge) threshold as it is not supplied\n");
					" charge) threshold as it is not"
					" supplied.");
	}
	}
	if (desc->fullbatt_full_capacity == 0) {
	if (desc->fullbatt_full_capacity == 0) {
		dev_info(&pdev->dev, "Ignoring full-battery full capacity"
		dev_info(&pdev->dev, "Ignoring full-battery full capacity threshold as it is not supplied\n");
					" threshold as it is not supplied.");
	}
	}


	if (!desc->charger_regulators || desc->num_charger_regulators < 1) {
	if (!desc->charger_regulators || desc->num_charger_regulators < 1) {
		ret = -EINVAL;
		ret = -EINVAL;
		dev_err(&pdev->dev, "charger_regulators undefined.\n");
		dev_err(&pdev->dev, "charger_regulators undefined\n");
		goto err_no_charger;
		goto err_no_charger;
	}
	}


	if (!desc->psy_charger_stat || !desc->psy_charger_stat[0]) {
	if (!desc->psy_charger_stat || !desc->psy_charger_stat[0]) {
		dev_err(&pdev->dev, "No power supply defined.\n");
		dev_err(&pdev->dev, "No power supply defined\n");
		ret = -EINVAL;
		ret = -EINVAL;
		goto err_no_charger_stat;
		goto err_no_charger_stat;
	}
	}
@@ -1544,8 +1525,7 @@ static int charger_manager_probe(struct platform_device *pdev)
		cm->charger_stat[i] = power_supply_get_by_name(
		cm->charger_stat[i] = power_supply_get_by_name(
					desc->psy_charger_stat[i]);
					desc->psy_charger_stat[i]);
		if (!cm->charger_stat[i]) {
		if (!cm->charger_stat[i]) {
			dev_err(&pdev->dev, "Cannot find power supply "
			dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
					"\"%s\"\n",
				desc->psy_charger_stat[i]);
				desc->psy_charger_stat[i]);
			ret = -ENODEV;
			ret = -ENODEV;
			goto err_chg_stat;
			goto err_chg_stat;
@@ -1575,9 +1555,7 @@ static int charger_manager_probe(struct platform_device *pdev)


	if (!desc->charging_max_duration_ms ||
	if (!desc->charging_max_duration_ms ||
			!desc->discharging_max_duration_ms) {
			!desc->discharging_max_duration_ms) {
		dev_info(&pdev->dev, "Cannot limit charging duration "
		dev_info(&pdev->dev, "Cannot limit charging duration checking mechanism to prevent overcharge/overheat and control discharging duration\n");
			 "checking mechanism to prevent overcharge/overheat "
			 "and control discharging duration");
		desc->charging_max_duration_ms = 0;
		desc->charging_max_duration_ms = 0;
		desc->discharging_max_duration_ms = 0;
		desc->discharging_max_duration_ms = 0;
	}
	}
@@ -1598,7 +1576,6 @@ static int charger_manager_probe(struct platform_device *pdev)
				NUM_CHARGER_PSY_OPTIONAL),
				NUM_CHARGER_PSY_OPTIONAL),
				GFP_KERNEL);
				GFP_KERNEL);
	if (!cm->charger_psy.properties) {
	if (!cm->charger_psy.properties) {
		dev_err(&pdev->dev, "Cannot allocate for psy properties.\n");
		ret = -ENOMEM;
		ret = -ENOMEM;
		goto err_chg_stat;
		goto err_chg_stat;
	}
	}
@@ -1636,8 +1613,8 @@ static int charger_manager_probe(struct platform_device *pdev)


	ret = power_supply_register(NULL, &cm->charger_psy);
	ret = power_supply_register(NULL, &cm->charger_psy);
	if (ret) {
	if (ret) {
		dev_err(&pdev->dev, "Cannot register charger-manager with"
		dev_err(&pdev->dev, "Cannot register charger-manager with name \"%s\"\n",
				" name \"%s\".\n", cm->charger_psy.name);
			cm->charger_psy.name);
		goto err_register;
		goto err_register;
	}
	}


@@ -1948,7 +1925,7 @@ void cm_notify_event(struct power_supply *psy, enum cm_event_types type,
		uevent_notify(cm, msg ? msg : default_event_names[type]);
		uevent_notify(cm, msg ? msg : default_event_names[type]);
		break;
		break;
	default:
	default:
		dev_err(cm->dev, "%s type not specified.\n", __func__);
		dev_err(cm->dev, "%s: type not specified\n", __func__);
		break;
		break;
	}
	}
}
}