* [PATCH 2/5] power_supply: max14577: Don't store charging and battery states for later
2015-02-24 9:54 [PATCH 1/5] power_supply: max77693: Properly handle error conditions Krzysztof Kozlowski
@ 2015-02-24 9:54 ` Krzysztof Kozlowski
2015-02-24 9:54 ` [PATCH 3/5] power_supply: max14577: Properly handle error conditions Krzysztof Kozlowski
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2015-02-24 9:54 UTC (permalink / raw)
To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
linux-pm, linux-kernel
Cc: Krzysztof Kozlowski
Remove caching of charging and battery states in driver's state
container because the cached value was not used later.
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
drivers/power/max14577_charger.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c
index ef4103ee6021..c72238aa011b 100644
--- a/drivers/power/max14577_charger.c
+++ b/drivers/power/max14577_charger.c
@@ -26,9 +26,6 @@ struct max14577_charger {
struct max14577 *max14577;
struct power_supply charger;
- unsigned int charging_state;
- unsigned int battery_state;
-
struct max14577_charger_platform_data *pdata;
};
@@ -89,7 +86,6 @@ static int max14577_get_charger_state(struct max14577_charger *chg)
}
state_set:
- chg->charging_state = state;
return state;
}
@@ -167,7 +163,6 @@ static int max14577_get_battery_health(struct max14577_charger *chg)
}
state_set:
- chg->battery_state = state;
return state;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/5] power_supply: max14577: Properly handle error conditions
2015-02-24 9:54 [PATCH 1/5] power_supply: max77693: Properly handle error conditions Krzysztof Kozlowski
2015-02-24 9:54 ` [PATCH 2/5] power_supply: max14577: Don't store charging and battery states for later Krzysztof Kozlowski
@ 2015-02-24 9:54 ` Krzysztof Kozlowski
2015-02-24 9:54 ` [PATCH 4/5] power_supply: max17040: Use system efficient workqueues Krzysztof Kozlowski
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2015-02-24 9:54 UTC (permalink / raw)
To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
linux-pm, linux-kernel
Cc: Krzysztof Kozlowski
Re-work and fix handling of errors when retrieving power supply
properties:
1. Return errno values directly from get_property() instead of
storing 'unknown' as intval for given property.
2. Handle regmap_read() errors and return errno code. Previously the
regmap_read() return code was ignored so an uninitialized value from
the stack could be used for calculating the property.
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
drivers/power/max14577_charger.c | 109 ++++++++++++++++++++++++++-------------
1 file changed, 73 insertions(+), 36 deletions(-)
diff --git a/drivers/power/max14577_charger.c b/drivers/power/max14577_charger.c
index c72238aa011b..4736dc478578 100644
--- a/drivers/power/max14577_charger.c
+++ b/drivers/power/max14577_charger.c
@@ -54,10 +54,10 @@ static enum max14577_muic_charger_type maxim_get_charger_type(
}
}
-static int max14577_get_charger_state(struct max14577_charger *chg)
+static int max14577_get_charger_state(struct max14577_charger *chg, int *val)
{
struct regmap *rmap = chg->max14577->regmap;
- int state = POWER_SUPPLY_STATUS_DISCHARGING;
+ int ret;
u8 reg_data;
/*
@@ -71,22 +71,32 @@ static int max14577_get_charger_state(struct max14577_charger *chg)
* - handle properly dead-battery charging (respect timer)
* - handle timers (fast-charge and prequal) /MBCCHGERR/
*/
- max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, ®_data);
- if ((reg_data & CHGCTRL2_MBCHOSTEN_MASK) == 0)
- goto state_set;
+ ret = max14577_read_reg(rmap, MAX14577_CHG_REG_CHG_CTRL2, ®_data);
+ if (ret < 0)
+ goto out;
+
+ if ((reg_data & CHGCTRL2_MBCHOSTEN_MASK) == 0) {
+ *val = POWER_SUPPLY_STATUS_DISCHARGING;
+ goto out;
+ }
+
+ ret = max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
+ if (ret < 0)
+ goto out;
- max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
if (reg_data & STATUS3_CGMBC_MASK) {
/* Charger or USB-cable is connected */
if (reg_data & STATUS3_EOC_MASK)
- state = POWER_SUPPLY_STATUS_FULL;
+ *val = POWER_SUPPLY_STATUS_FULL;
else
- state = POWER_SUPPLY_STATUS_CHARGING;
- goto state_set;
+ *val = POWER_SUPPLY_STATUS_CHARGING;
+ goto out;
}
-state_set:
- return state;
+ *val = POWER_SUPPLY_STATUS_DISCHARGING;
+
+out:
+ return ret;
}
/*
@@ -94,8 +104,10 @@ state_set:
* - POWER_SUPPLY_CHARGE_TYPE_NONE
* - POWER_SUPPLY_CHARGE_TYPE_FAST
*/
-static int max14577_get_charge_type(struct max14577_charger *chg)
+static int max14577_get_charge_type(struct max14577_charger *chg, int *val)
{
+ int ret, charging;
+
/*
* TODO: CHARGE_TYPE_TRICKLE (VCHGR_RC or EOC)?
* As spec says:
@@ -104,18 +116,29 @@ static int max14577_get_charge_type(struct max14577_charger *chg)
* top-off timer starts. The device continues to trickle
* charge the battery until the top-off timer runs out."
*/
- if (max14577_get_charger_state(chg) == POWER_SUPPLY_STATUS_CHARGING)
- return POWER_SUPPLY_CHARGE_TYPE_FAST;
- return POWER_SUPPLY_CHARGE_TYPE_NONE;
+ ret = max14577_get_charger_state(chg, &charging);
+ if (ret < 0)
+ return ret;
+
+ if (charging == POWER_SUPPLY_STATUS_CHARGING)
+ *val = POWER_SUPPLY_CHARGE_TYPE_FAST;
+ else
+ *val = POWER_SUPPLY_CHARGE_TYPE_NONE;
+
+ return 0;
}
-static int max14577_get_online(struct max14577_charger *chg)
+static int max14577_get_online(struct max14577_charger *chg, int *val)
{
struct regmap *rmap = chg->max14577->regmap;
u8 reg_data;
+ int ret;
enum max14577_muic_charger_type chg_type;
- max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data);
+ ret = max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data);
+ if (ret < 0)
+ return ret;
+
reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT);
chg_type = maxim_get_charger_type(chg->max14577->dev_type, reg_data);
switch (chg_type) {
@@ -125,14 +148,17 @@ static int max14577_get_online(struct max14577_charger *chg)
case MAX14577_CHARGER_TYPE_SPECIAL_1A:
case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
case MAX77836_CHARGER_TYPE_SPECIAL_BIAS:
- return 1;
+ *val = 1;
+ break;
case MAX14577_CHARGER_TYPE_NONE:
case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
case MAX14577_CHARGER_TYPE_RESERVED:
case MAX77836_CHARGER_TYPE_RESERVED:
default:
- return 0;
+ *val = 0;
}
+
+ return 0;
}
/*
@@ -141,29 +167,38 @@ static int max14577_get_online(struct max14577_charger *chg)
* - POWER_SUPPLY_HEALTH_OVERVOLTAGE
* - POWER_SUPPLY_HEALTH_GOOD
*/
-static int max14577_get_battery_health(struct max14577_charger *chg)
+static int max14577_get_battery_health(struct max14577_charger *chg, int *val)
{
struct regmap *rmap = chg->max14577->regmap;
- int state = POWER_SUPPLY_HEALTH_GOOD;
+ int ret;
u8 reg_data;
enum max14577_muic_charger_type chg_type;
- max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data);
+ ret = max14577_read_reg(rmap, MAX14577_MUIC_REG_STATUS2, ®_data);
+ if (ret < 0)
+ goto out;
+
reg_data = ((reg_data & STATUS2_CHGTYP_MASK) >> STATUS2_CHGTYP_SHIFT);
chg_type = maxim_get_charger_type(chg->max14577->dev_type, reg_data);
if (chg_type == MAX14577_CHARGER_TYPE_DEAD_BATTERY) {
- state = POWER_SUPPLY_HEALTH_DEAD;
- goto state_set;
+ *val = POWER_SUPPLY_HEALTH_DEAD;
+ goto out;
}
- max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
+ ret = max14577_read_reg(rmap, MAX14577_CHG_REG_STATUS3, ®_data);
+ if (ret < 0)
+ goto out;
+
if (reg_data & STATUS3_OVP_MASK) {
- state = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
- goto state_set;
+ *val = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
+ goto out;
}
-state_set:
- return state;
+ /* Not dead, not overvoltage */
+ *val = POWER_SUPPLY_HEALTH_GOOD;
+
+out:
+ return ret;
}
/*
@@ -171,9 +206,11 @@ state_set:
* The max14577 chip doesn't report any status of battery presence.
* Lets assume that it will always be used with some battery.
*/
-static int max14577_get_present(struct max14577_charger *chg)
+static int max14577_get_present(struct max14577_charger *chg, int *val)
{
- return 1;
+ *val = 1;
+
+ return 0;
}
static int max14577_set_fast_charge_timer(struct max14577_charger *chg,
@@ -391,19 +428,19 @@ static int max14577_charger_get_property(struct power_supply *psy,
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
- val->intval = max14577_get_charger_state(chg);
+ ret = max14577_get_charger_state(chg, &val->intval);
break;
case POWER_SUPPLY_PROP_CHARGE_TYPE:
- val->intval = max14577_get_charge_type(chg);
+ ret = max14577_get_charge_type(chg, &val->intval);
break;
case POWER_SUPPLY_PROP_HEALTH:
- val->intval = max14577_get_battery_health(chg);
+ ret = max14577_get_battery_health(chg, &val->intval);
break;
case POWER_SUPPLY_PROP_PRESENT:
- val->intval = max14577_get_present(chg);
+ ret = max14577_get_present(chg, &val->intval);
break;
case POWER_SUPPLY_PROP_ONLINE:
- val->intval = max14577_get_online(chg);
+ ret = max14577_get_online(chg, &val->intval);
break;
case POWER_SUPPLY_PROP_MODEL_NAME:
BUILD_BUG_ON(ARRAY_SIZE(model_names) != MAXIM_DEVICE_TYPE_NUM);
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 4/5] power_supply: max17040: Use system efficient workqueues
2015-02-24 9:54 [PATCH 1/5] power_supply: max77693: Properly handle error conditions Krzysztof Kozlowski
2015-02-24 9:54 ` [PATCH 2/5] power_supply: max14577: Don't store charging and battery states for later Krzysztof Kozlowski
2015-02-24 9:54 ` [PATCH 3/5] power_supply: max14577: Properly handle error conditions Krzysztof Kozlowski
@ 2015-02-24 9:54 ` Krzysztof Kozlowski
2015-02-24 9:54 ` [PATCH 5/5] power_supply: max17042: Use regmap_update_bits instead read and write Krzysztof Kozlowski
2015-02-25 20:46 ` [PATCH 1/5] power_supply: max77693: Properly handle error conditions Sebastian Reichel
4 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2015-02-24 9:54 UTC (permalink / raw)
To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
linux-pm, linux-kernel
Cc: Krzysztof Kozlowski
The scheduled work in max17040_battery driver reads device parameters
and stores them in memory. Any CPU could do that so use system efficient
workqueues to limit unnecessary CPU wake ups.
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
drivers/power/max17040_battery.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/power/max17040_battery.c b/drivers/power/max17040_battery.c
index 14d44706327b..63ff3f705154 100644
--- a/drivers/power/max17040_battery.c
+++ b/drivers/power/max17040_battery.c
@@ -188,7 +188,8 @@ static void max17040_work(struct work_struct *work)
max17040_get_online(chip->client);
max17040_get_status(chip->client);
- schedule_delayed_work(&chip->work, MAX17040_DELAY);
+ queue_delayed_work(system_power_efficient_wq, &chip->work,
+ MAX17040_DELAY);
}
static enum power_supply_property max17040_battery_props[] = {
@@ -233,7 +234,8 @@ static int max17040_probe(struct i2c_client *client,
max17040_get_version(client);
INIT_DEFERRABLE_WORK(&chip->work, max17040_work);
- schedule_delayed_work(&chip->work, MAX17040_DELAY);
+ queue_delayed_work(system_power_efficient_wq, &chip->work,
+ MAX17040_DELAY);
return 0;
}
@@ -263,7 +265,8 @@ static int max17040_resume(struct device *dev)
struct i2c_client *client = to_i2c_client(dev);
struct max17040_chip *chip = i2c_get_clientdata(client);
- schedule_delayed_work(&chip->work, MAX17040_DELAY);
+ queue_delayed_work(system_power_efficient_wq, &chip->work,
+ MAX17040_DELAY);
return 0;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 5/5] power_supply: max17042: Use regmap_update_bits instead read and write
2015-02-24 9:54 [PATCH 1/5] power_supply: max77693: Properly handle error conditions Krzysztof Kozlowski
` (2 preceding siblings ...)
2015-02-24 9:54 ` [PATCH 4/5] power_supply: max17040: Use system efficient workqueues Krzysztof Kozlowski
@ 2015-02-24 9:54 ` Krzysztof Kozlowski
2015-02-25 20:46 ` [PATCH 1/5] power_supply: max77693: Properly handle error conditions Sebastian Reichel
4 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2015-02-24 9:54 UTC (permalink / raw)
To: Sebastian Reichel, Dmitry Eremin-Solenikov, David Woodhouse,
linux-pm, linux-kernel
Cc: Krzysztof Kozlowski
Consolidate regmap_read() and regmap_write() into one
regmap_update_bits() call. This is more readable and safer because
regmap's mutex will prevent any concurrent access to modified registers
(the concurrent access could happen through max17042_init_chip() in
scheduled work).
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
---
drivers/power/max17042_battery.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index 1da6c5fbdff5..830435adfb64 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -529,7 +529,6 @@ static int max17042_init_chip(struct max17042_chip *chip)
{
struct regmap *map = chip->regmap;
int ret;
- int val;
max17042_override_por_values(chip);
/* After Power up, the MAX17042 requires 500mS in order
@@ -572,8 +571,7 @@ static int max17042_init_chip(struct max17042_chip *chip)
max17042_load_new_capacity_params(chip);
/* Init complete, Clear the POR bit */
- regmap_read(map, MAX17042_STATUS, &val);
- regmap_write(map, MAX17042_STATUS, val & (~STATUS_POR_BIT));
+ regmap_update_bits(map, MAX17042_STATUS, STATUS_POR_BIT, 0x0);
return 0;
}
@@ -745,9 +743,9 @@ static int max17042_probe(struct i2c_client *client,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
chip->battery.name, chip);
if (!ret) {
- regmap_read(chip->regmap, MAX17042_CONFIG, &val);
- val |= CONFIG_ALRT_BIT_ENBL;
- regmap_write(chip->regmap, MAX17042_CONFIG, val);
+ regmap_update_bits(chip->regmap, MAX17042_CONFIG,
+ CONFIG_ALRT_BIT_ENBL,
+ CONFIG_ALRT_BIT_ENBL);
max17042_set_soc_threshold(chip, 1);
} else {
client->irq = 0;
--
1.9.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 1/5] power_supply: max77693: Properly handle error conditions
2015-02-24 9:54 [PATCH 1/5] power_supply: max77693: Properly handle error conditions Krzysztof Kozlowski
` (3 preceding siblings ...)
2015-02-24 9:54 ` [PATCH 5/5] power_supply: max17042: Use regmap_update_bits instead read and write Krzysztof Kozlowski
@ 2015-02-25 20:46 ` Sebastian Reichel
4 siblings, 0 replies; 6+ messages in thread
From: Sebastian Reichel @ 2015-02-25 20:46 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Dmitry Eremin-Solenikov, David Woodhouse, linux-pm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 617 bytes --]
Hi,
On Tue, Feb 24, 2015 at 10:54:43AM +0100, Krzysztof Kozlowski wrote:
> Re-work and fix handling of errors when retrieving power supply
> properties:
>
> 1. Return errno values directly from get_property() instead of storing
> 'unknown' as intval for given property.
>
> 2. Handle regmap_read() errors when getting 'online' and 'present'
> proprties and return errno code. Previously the regmap_read() return
> code was ignored so an uninitialized value from the stack could be
> used for calculating the property.
Thanks, whole patchset pulled into battery-2.6.git.
-- Sebastian
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread