Skip to content

Commit 66cb96a

Browse files
dilingerjwrdegoede
authored andcommitted
platform/x86:dell-laptop: remove duplicate code w/ battery function
The dell battery patch added dell_send_request_for_tokenid() and dell_set_std_token_value(), which encapsulates a very common pattern when SMBIOS queries are addressed to token->location. This calls them in various places outside of the dell laptop code, allowing us to delete a bunch of code. Also some very minor cleanups: - mark the kbd init functions as __init - don't read buffer.output unless dell_send_request() was successful. - actually return errors from micmute_led_set/mute_led_set instead of always returning 0. Only minor behavior changes; the delayed read of buffer.output and actually returning errors for the brightness_set_blocking hooks. Signed-off-by: Andres Salomon <dilinger@queued.net> Reviewed-by: Pali Rohár <pali@kernel.org> Link: https://lore.kernel.org/r/20240820033335.4f68b162@5400 Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent ab58016 commit 66cb96a

1 file changed

Lines changed: 27 additions & 82 deletions

File tree

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

Lines changed: 27 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -937,43 +937,24 @@ static void dell_cleanup_rfkill(void)
937937
static int dell_send_intensity(struct backlight_device *bd)
938938
{
939939
struct calling_interface_buffer buffer;
940-
struct calling_interface_token *token;
941-
int ret;
942-
943-
token = dell_smbios_find_token(BRIGHTNESS_TOKEN);
944-
if (!token)
945-
return -ENODEV;
946-
947-
dell_fill_request(&buffer,
948-
token->location, bd->props.brightness, 0, 0);
949-
if (power_supply_is_system_supplied() > 0)
950-
ret = dell_send_request(&buffer,
951-
CLASS_TOKEN_WRITE, SELECT_TOKEN_AC);
952-
else
953-
ret = dell_send_request(&buffer,
954-
CLASS_TOKEN_WRITE, SELECT_TOKEN_BAT);
940+
u16 select;
955941

956-
return ret;
942+
select = power_supply_is_system_supplied() > 0 ?
943+
SELECT_TOKEN_AC : SELECT_TOKEN_BAT;
944+
return dell_send_request_for_tokenid(&buffer, CLASS_TOKEN_WRITE,
945+
select, BRIGHTNESS_TOKEN, bd->props.brightness);
957946
}
958947

959948
static int dell_get_intensity(struct backlight_device *bd)
960949
{
961950
struct calling_interface_buffer buffer;
962-
struct calling_interface_token *token;
963951
int ret;
952+
u16 select;
964953

965-
token = dell_smbios_find_token(BRIGHTNESS_TOKEN);
966-
if (!token)
967-
return -ENODEV;
968-
969-
dell_fill_request(&buffer, token->location, 0, 0, 0);
970-
if (power_supply_is_system_supplied() > 0)
971-
ret = dell_send_request(&buffer,
972-
CLASS_TOKEN_READ, SELECT_TOKEN_AC);
973-
else
974-
ret = dell_send_request(&buffer,
975-
CLASS_TOKEN_READ, SELECT_TOKEN_BAT);
976-
954+
select = power_supply_is_system_supplied() > 0 ?
955+
SELECT_TOKEN_AC : SELECT_TOKEN_BAT;
956+
ret = dell_send_request_for_tokenid(&buffer, CLASS_TOKEN_READ,
957+
select, BRIGHTNESS_TOKEN, 0);
977958
if (ret == 0)
978959
ret = buffer.output[1];
979960

@@ -1397,20 +1378,11 @@ static int kbd_set_state_safe(struct kbd_state *state, struct kbd_state *old)
13971378
static int kbd_set_token_bit(u8 bit)
13981379
{
13991380
struct calling_interface_buffer buffer;
1400-
struct calling_interface_token *token;
1401-
int ret;
14021381

14031382
if (bit >= ARRAY_SIZE(kbd_tokens))
14041383
return -EINVAL;
14051384

1406-
token = dell_smbios_find_token(kbd_tokens[bit]);
1407-
if (!token)
1408-
return -EINVAL;
1409-
1410-
dell_fill_request(&buffer, token->location, token->value, 0, 0);
1411-
ret = dell_send_request(&buffer, CLASS_TOKEN_WRITE, SELECT_TOKEN_STD);
1412-
1413-
return ret;
1385+
return dell_set_std_token_value(&buffer, kbd_tokens[bit], USE_TVAL);
14141386
}
14151387

14161388
static int kbd_get_token_bit(u8 bit)
@@ -1429,11 +1401,10 @@ static int kbd_get_token_bit(u8 bit)
14291401

14301402
dell_fill_request(&buffer, token->location, 0, 0, 0);
14311403
ret = dell_send_request(&buffer, CLASS_TOKEN_READ, SELECT_TOKEN_STD);
1432-
val = buffer.output[1];
1433-
14341404
if (ret)
14351405
return ret;
14361406

1407+
val = buffer.output[1];
14371408
return (val == token->value);
14381409
}
14391410

@@ -1539,7 +1510,7 @@ static inline int kbd_init_info(void)
15391510

15401511
}
15411512

1542-
static inline void kbd_init_tokens(void)
1513+
static inline void __init kbd_init_tokens(void)
15431514
{
15441515
int i;
15451516

@@ -1548,7 +1519,7 @@ static inline void kbd_init_tokens(void)
15481519
kbd_token_bits |= BIT(i);
15491520
}
15501521

1551-
static void kbd_init(void)
1522+
static void __init kbd_init(void)
15521523
{
15531524
int ret;
15541525

@@ -2173,21 +2144,11 @@ static int micmute_led_set(struct led_classdev *led_cdev,
21732144
enum led_brightness brightness)
21742145
{
21752146
struct calling_interface_buffer buffer;
2176-
struct calling_interface_token *token;
2177-
int state = brightness != LED_OFF;
2178-
2179-
if (state == 0)
2180-
token = dell_smbios_find_token(GLOBAL_MIC_MUTE_DISABLE);
2181-
else
2182-
token = dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE);
2183-
2184-
if (!token)
2185-
return -ENODEV;
2147+
u32 tokenid;
21862148

2187-
dell_fill_request(&buffer, token->location, token->value, 0, 0);
2188-
dell_send_request(&buffer, CLASS_TOKEN_WRITE, SELECT_TOKEN_STD);
2189-
2190-
return 0;
2149+
tokenid = brightness == LED_OFF ?
2150+
GLOBAL_MIC_MUTE_DISABLE : GLOBAL_MIC_MUTE_ENABLE;
2151+
return dell_set_std_token_value(&buffer, tokenid, USE_TVAL);
21912152
}
21922153

21932154
static struct led_classdev micmute_led_cdev = {
@@ -2201,21 +2162,11 @@ static int mute_led_set(struct led_classdev *led_cdev,
22012162
enum led_brightness brightness)
22022163
{
22032164
struct calling_interface_buffer buffer;
2204-
struct calling_interface_token *token;
2205-
int state = brightness != LED_OFF;
2206-
2207-
if (state == 0)
2208-
token = dell_smbios_find_token(GLOBAL_MUTE_DISABLE);
2209-
else
2210-
token = dell_smbios_find_token(GLOBAL_MUTE_ENABLE);
2165+
u32 tokenid;
22112166

2212-
if (!token)
2213-
return -ENODEV;
2214-
2215-
dell_fill_request(&buffer, token->location, token->value, 0, 0);
2216-
dell_send_request(&buffer, CLASS_TOKEN_WRITE, SELECT_TOKEN_STD);
2217-
2218-
return 0;
2167+
tokenid = brightness == LED_OFF ?
2168+
GLOBAL_MUTE_DISABLE : GLOBAL_MUTE_ENABLE;
2169+
return dell_set_std_token_value(&buffer, tokenid, USE_TVAL);
22192170
}
22202171

22212172
static struct led_classdev mute_led_cdev = {
@@ -2492,7 +2443,7 @@ static void dell_battery_exit(void)
24922443

24932444
static int __init dell_init(void)
24942445
{
2495-
struct calling_interface_token *token;
2446+
struct calling_interface_buffer buffer;
24962447
int max_intensity = 0;
24972448
int ret;
24982449

@@ -2554,16 +2505,10 @@ static int __init dell_init(void)
25542505
if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
25552506
return 0;
25562507

2557-
token = dell_smbios_find_token(BRIGHTNESS_TOKEN);
2558-
if (token) {
2559-
struct calling_interface_buffer buffer;
2560-
2561-
dell_fill_request(&buffer, token->location, 0, 0, 0);
2562-
ret = dell_send_request(&buffer,
2563-
CLASS_TOKEN_READ, SELECT_TOKEN_AC);
2564-
if (ret == 0)
2565-
max_intensity = buffer.output[3];
2566-
}
2508+
ret = dell_send_request_for_tokenid(&buffer, CLASS_TOKEN_READ,
2509+
SELECT_TOKEN_AC, BRIGHTNESS_TOKEN, 0);
2510+
if (ret == 0)
2511+
max_intensity = buffer.output[3];
25672512

25682513
if (max_intensity) {
25692514
struct backlight_properties props;

0 commit comments

Comments
 (0)