Skip to content

Commit a3a8799

Browse files
jwrdegoedesre
authored andcommitted
platform/x86: dell-laptop: Use power_supply_charge_types_show/_parse() helpers
Make battery_modes a map between tokens and enum power_supply_charge_type values instead of between tokens and strings and use the new power_supply_charge_types_show/_parse() helpers for show()/store() to ensure that things are handled in the same way as in other drivers. This also changes battery_supported_modes to be a bitmap of charge-types (enum power_supply_charge_type values) rather then a bitmap of indices into battery_modes[]. Reviewed-by: Thomas Weißschuh <[email protected]> Signed-off-by: Hans de Goede <[email protected]> Acked-by: Ilpo Järvinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent f6945d5 commit a3a8799

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

drivers/platform/x86/dell/dell-laptop.c

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ static bool mute_led_registered;
103103

104104
struct battery_mode_info {
105105
int token;
106-
const char *label;
106+
enum power_supply_charge_type charge_type;
107107
};
108108

109109
static const struct battery_mode_info battery_modes[] = {
110-
{ BAT_PRI_AC_MODE_TOKEN, "Trickle" },
111-
{ BAT_EXPRESS_MODE_TOKEN, "Fast" },
112-
{ BAT_STANDARD_MODE_TOKEN, "Standard" },
113-
{ BAT_ADAPTIVE_MODE_TOKEN, "Adaptive" },
114-
{ BAT_CUSTOM_MODE_TOKEN, "Custom" },
110+
{ BAT_PRI_AC_MODE_TOKEN, POWER_SUPPLY_CHARGE_TYPE_TRICKLE },
111+
{ BAT_EXPRESS_MODE_TOKEN, POWER_SUPPLY_CHARGE_TYPE_FAST },
112+
{ BAT_STANDARD_MODE_TOKEN, POWER_SUPPLY_CHARGE_TYPE_STANDARD },
113+
{ BAT_ADAPTIVE_MODE_TOKEN, POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE },
114+
{ BAT_CUSTOM_MODE_TOKEN, POWER_SUPPLY_CHARGE_TYPE_CUSTOM },
115115
};
116116
static u32 battery_supported_modes;
117117

@@ -2261,46 +2261,42 @@ static ssize_t charge_types_show(struct device *dev,
22612261
struct device_attribute *attr,
22622262
char *buf)
22632263
{
2264-
ssize_t count = 0;
2264+
enum power_supply_charge_type charge_type;
22652265
int i;
22662266

22672267
for (i = 0; i < ARRAY_SIZE(battery_modes); i++) {
2268-
bool active;
2268+
charge_type = battery_modes[i].charge_type;
22692269

2270-
if (!(battery_supported_modes & BIT(i)))
2270+
if (!(battery_supported_modes & BIT(charge_type)))
22712271
continue;
22722272

2273-
active = dell_battery_mode_is_active(battery_modes[i].token);
2274-
count += sysfs_emit_at(buf, count, active ? "[%s] " : "%s ",
2275-
battery_modes[i].label);
2276-
}
2273+
if (!dell_battery_mode_is_active(battery_modes[i].token))
2274+
continue;
22772275

2278-
/* convert the last space to a newline */
2279-
if (count > 0)
2280-
count--;
2281-
count += sysfs_emit_at(buf, count, "\n");
2276+
return power_supply_charge_types_show(dev, battery_supported_modes,
2277+
charge_type, buf);
2278+
}
22822279

2283-
return count;
2280+
/* No active mode found */
2281+
return -EIO;
22842282
}
22852283

22862284
static ssize_t charge_types_store(struct device *dev,
22872285
struct device_attribute *attr,
22882286
const char *buf, size_t size)
22892287
{
2290-
bool matched = false;
2291-
int err, i;
2288+
int charge_type, err, i;
22922289

2293-
for (i = 0; i < ARRAY_SIZE(battery_modes); i++) {
2294-
if (!(battery_supported_modes & BIT(i)))
2295-
continue;
2290+
charge_type = power_supply_charge_types_parse(battery_supported_modes, buf);
2291+
if (charge_type < 0)
2292+
return charge_type;
22962293

2297-
if (sysfs_streq(battery_modes[i].label, buf)) {
2298-
matched = true;
2294+
for (i = 0; i < ARRAY_SIZE(battery_modes); i++) {
2295+
if (battery_modes[i].charge_type == charge_type)
22992296
break;
2300-
}
23012297
}
2302-
if (!matched)
2303-
return -EINVAL;
2298+
if (i == ARRAY_SIZE(battery_modes))
2299+
return -ENOENT;
23042300

23052301
err = dell_battery_set_mode(battery_modes[i].token);
23062302
if (err)
@@ -2430,7 +2426,7 @@ static u32 __init battery_get_supported_modes(void)
24302426

24312427
for (i = 0; i < ARRAY_SIZE(battery_modes); i++) {
24322428
if (dell_smbios_find_token(battery_modes[i].token))
2433-
modes |= BIT(i);
2429+
modes |= BIT(battery_modes[i].charge_type);
24342430
}
24352431

24362432
return modes;

0 commit comments

Comments
 (0)