power: pm8921-charger: implement thermal mitigation

Implement thermal mitigation in the charger driver. The userspace
daemon can get the battery temperature from
/sys/class/power_supply/battery/temp

and set the mitigation levels on
/sys/module/pm8921_charger/parameters/thermal_mitigation

The battery driver supports 4 levels [0 through 3]. O being normal
and 3 being extreme thermal mitigation.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
This commit is contained in:
Abhijeet Dharmapurikar
2011-08-29 19:50:02 -07:00
committed by Bryan Huntsman
parent bc1f0e4bff
commit ad74236b90
3 changed files with 61 additions and 1 deletions

View File

@@ -3339,6 +3339,13 @@ static struct pm8xxx_keypad_platform_data keypad_data_sim = {
.keymap_data = &keymap_data_sim,
};
static int pm8921_therm_mitigation[] = {
1100,
700,
600,
325,
};
static struct pm8921_charger_platform_data pm8921_chg_pdata __devinitdata = {
.safety_time = 180,
.update_time = 1,
@@ -3349,11 +3356,13 @@ static struct pm8921_charger_platform_data pm8921_chg_pdata __devinitdata = {
.cool_temp = 10,
.warm_temp = 40,
.temp_check_period = 1,
.max_bat_chg_current = 400,
.max_bat_chg_current = 1100,
.cool_bat_chg_current = 350,
.warm_bat_chg_current = 350,
.cool_bat_voltage = 4100,
.warm_bat_voltage = 4100,
.thermal_mitigation = pm8921_therm_mitigation,
.thermal_levels = ARRAY_SIZE(pm8921_therm_mitigation),
};
static struct pm8xxx_misc_platform_data pm8xxx_misc_pdata = {

View File

@@ -198,9 +198,12 @@ struct pm8921_chg_chip {
int trkl_current;
int weak_current;
int vin_min;
int *thermal_mitigation;
int thermal_levels;
};
static int charging_disabled;
static int thermal_mitigation;
static struct pm8921_chg_chip *the_chip;
@@ -1490,6 +1493,47 @@ static int set_disable_status_param(const char *val, struct kernel_param *kp)
module_param_call(disabled, set_disable_status_param, param_get_uint,
&charging_disabled, 0644);
/**
* set_thermal_mitigation_level -
*
* Internal function to control battery charging current to reduce
* temperature
*/
static int set_therm_mitigation_level(const char *val, struct kernel_param *kp)
{
int ret;
struct pm8921_chg_chip *chip = the_chip;
ret = param_set_int(val, kp);
if (ret) {
pr_err("error setting value %d\n", ret);
return ret;
}
if (!chip) {
pr_err("called before init\n");
return -EINVAL;
}
if (!chip->thermal_mitigation) {
pr_err("no thermal mitigation\n");
return -EINVAL;
}
if (thermal_mitigation < 0
|| thermal_mitigation >= chip->thermal_levels) {
pr_err("out of bound level selected\n");
return -EINVAL;
}
ret = pm_chg_ibatmax_set(chip,
chip->thermal_mitigation[thermal_mitigation]);
return ret;
}
module_param_call(thermal_mitigation, set_therm_mitigation_level,
param_get_uint,
&thermal_mitigation, 0644);
static void free_irqs(struct pm8921_chg_chip *chip)
{
int i;
@@ -1995,6 +2039,8 @@ static int __devinit pm8921_charger_probe(struct platform_device *pdev)
chip->trkl_current = pdata->trkl_current;
chip->weak_current = pdata->weak_current;
chip->vin_min = pdata->vin_min;
chip->thermal_mitigation = pdata->thermal_mitigation;
chip->thermal_levels = pdata->thermal_levels;
rc = pm8921_chg_hw_init(chip);
if (rc) {

View File

@@ -60,6 +60,9 @@ struct pm8xxx_charger_core_data {
* @vin_min: the input voltage regulation point (mV) - if the
* voltage falls below this, the charger reduces charge
* current or stop charging temporarily
* @thermal_mitigation: the array of charge currents to use as temperature
* increases
* @thermal_levels: the number of thermal mitigation levels supported
*
*/
struct pm8921_charger_platform_data {
@@ -87,6 +90,8 @@ struct pm8921_charger_platform_data {
int trkl_current;
int weak_current;
int vin_min;
int *thermal_mitigation;
int thermal_levels;
};
enum pm8921_charger_source {