Commit 4cb38258 authored by Sebastian Reichel's avatar Sebastian Reichel Committed by Sebastian Reichel

power: supply: charger-manager: Prepare for const properties

This prepares the driver to work with the properties entry
in power_supply_desc marked as const.
Reviewed-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent de46e028
...@@ -1422,7 +1422,9 @@ static int charger_manager_prepare_sysfs(struct charger_manager *cm) ...@@ -1422,7 +1422,9 @@ static int charger_manager_prepare_sysfs(struct charger_manager *cm)
} }
static int cm_init_thermal_data(struct charger_manager *cm, static int cm_init_thermal_data(struct charger_manager *cm,
struct power_supply *fuel_gauge) struct power_supply *fuel_gauge,
enum power_supply_property *properties,
size_t *num_properties)
{ {
struct charger_desc *desc = cm->desc; struct charger_desc *desc = cm->desc;
union power_supply_propval val; union power_supply_propval val;
...@@ -1433,9 +1435,8 @@ static int cm_init_thermal_data(struct charger_manager *cm, ...@@ -1433,9 +1435,8 @@ static int cm_init_thermal_data(struct charger_manager *cm,
POWER_SUPPLY_PROP_TEMP, &val); POWER_SUPPLY_PROP_TEMP, &val);
if (!ret) { if (!ret) {
cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = properties[*num_properties] = POWER_SUPPLY_PROP_TEMP;
POWER_SUPPLY_PROP_TEMP; (*num_properties)++;
cm->charger_psy_desc.num_properties++;
cm->desc->measure_battery_temp = true; cm->desc->measure_battery_temp = true;
} }
#ifdef CONFIG_THERMAL #ifdef CONFIG_THERMAL
...@@ -1446,9 +1447,8 @@ static int cm_init_thermal_data(struct charger_manager *cm, ...@@ -1446,9 +1447,8 @@ static int cm_init_thermal_data(struct charger_manager *cm,
return PTR_ERR(cm->tzd_batt); return PTR_ERR(cm->tzd_batt);
/* Use external thermometer */ /* Use external thermometer */
cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = properties[*num_properties] = POWER_SUPPLY_PROP_TEMP_AMBIENT;
POWER_SUPPLY_PROP_TEMP_AMBIENT; (*num_properties)++;
cm->charger_psy_desc.num_properties++;
cm->desc->measure_battery_temp = true; cm->desc->measure_battery_temp = true;
ret = 0; ret = 0;
} }
...@@ -1621,6 +1621,8 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1621,6 +1621,8 @@ static int charger_manager_probe(struct platform_device *pdev)
int j = 0; int j = 0;
union power_supply_propval val; union power_supply_propval val;
struct power_supply *fuel_gauge; struct power_supply *fuel_gauge;
enum power_supply_property *properties;
size_t num_properties;
struct power_supply_config psy_cfg = {}; struct power_supply_config psy_cfg = {};
if (IS_ERR(desc)) { if (IS_ERR(desc)) {
...@@ -1717,18 +1719,17 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1717,18 +1719,17 @@ static int charger_manager_probe(struct platform_device *pdev)
cm->charger_psy_desc.name = cm->psy_name_buf; cm->charger_psy_desc.name = cm->psy_name_buf;
/* Allocate for psy properties because they may vary */ /* Allocate for psy properties because they may vary */
cm->charger_psy_desc.properties = properties = devm_kcalloc(&pdev->dev,
devm_kcalloc(&pdev->dev,
ARRAY_SIZE(default_charger_props) + ARRAY_SIZE(default_charger_props) +
NUM_CHARGER_PSY_OPTIONAL, NUM_CHARGER_PSY_OPTIONAL,
sizeof(enum power_supply_property), GFP_KERNEL); sizeof(*properties), GFP_KERNEL);
if (!cm->charger_psy_desc.properties) if (!properties)
return -ENOMEM; return -ENOMEM;
memcpy(cm->charger_psy_desc.properties, default_charger_props, memcpy(properties, default_charger_props,
sizeof(enum power_supply_property) * sizeof(enum power_supply_property) *
ARRAY_SIZE(default_charger_props)); ARRAY_SIZE(default_charger_props));
cm->charger_psy_desc.num_properties = psy_default.num_properties; num_properties = psy_default.num_properties;
/* Find which optional psy-properties are available */ /* Find which optional psy-properties are available */
fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge); fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge);
...@@ -1739,25 +1740,28 @@ static int charger_manager_probe(struct platform_device *pdev) ...@@ -1739,25 +1740,28 @@ static int charger_manager_probe(struct platform_device *pdev)
} }
if (!power_supply_get_property(fuel_gauge, if (!power_supply_get_property(fuel_gauge,
POWER_SUPPLY_PROP_CHARGE_NOW, &val)) { POWER_SUPPLY_PROP_CHARGE_NOW, &val)) {
cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = properties[num_properties] =
POWER_SUPPLY_PROP_CHARGE_NOW; POWER_SUPPLY_PROP_CHARGE_NOW;
cm->charger_psy_desc.num_properties++; num_properties++;
} }
if (!power_supply_get_property(fuel_gauge, if (!power_supply_get_property(fuel_gauge,
POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_CURRENT_NOW,
&val)) { &val)) {
cm->charger_psy_desc.properties[cm->charger_psy_desc.num_properties] = properties[num_properties] =
POWER_SUPPLY_PROP_CURRENT_NOW; POWER_SUPPLY_PROP_CURRENT_NOW;
cm->charger_psy_desc.num_properties++; num_properties++;
} }
ret = cm_init_thermal_data(cm, fuel_gauge); ret = cm_init_thermal_data(cm, fuel_gauge, properties, &num_properties);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to initialize thermal data\n"); dev_err(&pdev->dev, "Failed to initialize thermal data\n");
cm->desc->measure_battery_temp = false; cm->desc->measure_battery_temp = false;
} }
power_supply_put(fuel_gauge); power_supply_put(fuel_gauge);
cm->charger_psy_desc.properties = properties;
cm->charger_psy_desc.num_properties = num_properties;
INIT_DELAYED_WORK(&cm->fullbatt_vchk_work, fullbatt_vchk); INIT_DELAYED_WORK(&cm->fullbatt_vchk_work, fullbatt_vchk);
/* Register sysfs entry for charger(regulator) */ /* Register sysfs entry for charger(regulator) */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment