platform/x86: bitland-mifs-wmi: platform profiles cannot be changed on USB-C-only RedmiBook Pro 15 (TM2017)
Subsystems (2)
Same model line, different board and CPU vendor: I see this on a RedmiBook Pro 15 2023, board TM2209, AMD Ryzen 7 7840HS. Adding it as a second affected machine plus a few observations that may be relevant to the quirks table.
XIAOMI Redmi Book Pro 15 2023, TM2209
BIOS RMAPH5B0P0909, EC 1.9, USB-C charging only, 100 W PD adapter Fedora 45, kernel 7.2.15; identical on 7.1.8, 7.1.13, 7.2.7
Same symptoms as reported: performance and balanced-performance return -EOPNOTSUPP while charging, low-power is accepted but reads back as balanced, and --block-driver=platform_profile restores working profiles via amd_pstate EPP.
Three things I have not seen mentioned:
1. On this board the platform profile does not track the effective EC power mode. The budget is set by the Fn+K OEM hotkey, which cycles three EC steps. Measured at the package: ~15 W, ~35 W (the state after every boot), and a top step that bursts to ~65 W and settles at ~54 W / 4.4 GHz all-core.
While the top step is active, laptop_profile_get() still returns balanced. So relaxing the AC-type check alone would not give userspace control of the power budget here.
2. Ownership of the event GUID 46C93E13-EE9B-4262-8488-563BCA757FEF flips between boots on the same kernel: some boots redmi-wmi (input "Redmibook WMI keys"), others bitland-mifs-wmi (input "Bitland MIFS WMI hotkeys").
3. Writing 'balanced' to platform_profile while an Fn+K step is active is accepted and wedges the EC: package power drops to ~9 W, all-core to 1.0-1.1 GHz, Fn+K stops switching modes, and scaling_max_freq stays unchanged so the cap is firmware-side. Only a reboot recovers it.
I can test a TM2209 quirk or any patch on request.
Due to a language barrier, this text was prepared with Claude.
Quoted 36 lines · Олег Рыбалов
Same model line, different board and CPU vendor: I see this on a RedmiBook Pro 15 2023, board TM2209, AMD Ryzen 7 7840HS. Adding it as a second affected machine plus a few observations that may be relevant to the quirks table.
XIAOMI Redmi Book Pro 15 2023, TM2209 BIOS RMAPH5B0P0909, EC 1.9, USB-C charging only, 100 W PD adapter Fedora 45, kernel 7.2.15; identical on 7.1.8, 7.1.13, 7.2.7Same symptoms as reported: performance and balanced-performance return
-EOPNOTSUPPwhile charging, low-power is accepted but reads back as balanced, and --block-driver=platform_profile restores working profiles viaamd_pstateEPP.Three things I have not seen mentioned:
1. On this board the platform profile does not track the effective EC power mode. The budget is set by the Fn+K OEM hotkey, which cycles three EC steps. Measured at the package: ~15 W, ~35 W (the state after every boot), and a top step that bursts to ~65 W and settles at ~54 W / 4.4 GHz all-core.
While the top step is active,laptop_profile_get()still returns balanced. So relaxing the AC-type check alone would not give userspace control of the power budget here.2. Ownership of the event GUID 46C93E13-EE9B-4262-8488-563BCA757FEF flips between boots on the same kernel: some boots redmi-wmi (input "Redmibook WMI keys"), others bitland-mifs-wmi (input "Bitland MIFS WMI hotkeys").
3. Writing 'balanced' to
platform_profilewhile an Fn+K step is active is accepted and wedges the EC: package power drops to ~9 W, all-core to 1.0-1.1 GHz, Fn+K stops switching modes, andscaling_max_freqstays unchanged so the cap is firmware-side. Only a reboot recovers it.
Quoted 3 lines
I can test a TM2209 quirk or any patch on request.
Due to a language barrier, this text was prepared with Claude.
Hi,
A short tip at first, please use the reply all feature in your email client instead manual insert "Re:" in the email title, so we can keep the thread tracked.
Could you send the acpidump (from the acpica package) output? Then we can draft a quirk entry from this.
Quoted 9 lines · Mingyou Chen
Hi,
A short tip at first, please use the reply all feature in your email client instead manual insert "Re:" in the email title,
so we can keep the thread tracked.Could you send the acpidump (from the acpica package) output? Then we can draft a quirk entry from this.
Hi,
Attached is the compressed acpidump output from the TM2209 board. The MSDM table is stripped since it carries the Windows activation key; everything else is untouched.
Thanks for the reply-all tip, using reply-all now.
Quoted 7 lines · Олег Рыбалов
Hi,
Attached is the compressed acpidump output from the TM2209 board. The MSDM table is stripped since it carries the Windows activation key; everything else is untouched.
Thanks for the reply-all tip, using reply-all now.
Hi,
Here's your quirk (inside the email attachments).
Please apply it on top of my patch series in this email: https://lore.kernel.org/r/[email protected]
drivers/platform/x86/bitland-mifs-wmi.c +18 -0
@@ -113,7 +113,25 @@ static const struct bitland_mifs_quirks default_quirks = { .num_profile_entries = ARRAY_SIZE(default_profile_entries), }; +static const struct bitland_profile_entry tm2209_profile_entries[] = { + {PLATFORM_PROFILE_LOW_POWER ,2 }, + {PLATFORM_PROFILE_BALANCED ,1 }, + {PLATFORM_PROFILE_PERFORMANCE ,3 }, +}; + +static const struct bitland_mifs_quirks tm2209_quirks = { + .profile_entries = tm2209_profile_entries, + .num_profile_entries =ARRAY_SIZE (tm2209_profile_entries), +}; +static const struct dmi_system_id bitland_mifs_dmi_table[] = { + { + .matches = { +DMI_EXACT_MATCH (DMI_SYS_VENDOR ,"TIMI" ), +DMI_EXACT_MATCH (DMI_PRODUCT_NAME ,"TM2209" ), + }, + .driver_data = (void *)&tm2209_quirks, + }, {} };
Quoted 6 lines · Mingyou Chen
Hi,
Here's your quirk (inside the email attachments).
Please apply it on top of my patch series in this email:
https://lore.kernel.org/r/[email protected]
Tested your quirk on top of v15, built out-of-tree against 7.2.15.
Three problems:
1. The DMI entry does not match here:DMI_SYS_VENDOR = "XIAOMI"DMI_BOARD_NAME = "TM2209"DMI_PRODUCT_NAME = "Redmi Book Pro 15 2023"
TM2209 is the board name, not the product name. As sent, the driver falls back to default_quirks - four entries in platform_profile_choices instead of three.
2. .return_code_at_end = true is needed. A WMI_FN_SYSTEM_PER_MODE call returns:
00000000: 00 08 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00000010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80
function echo 0x0800 at offset 0, mode value at offset 2, 0x8000 at offsets 30..31. Head-first parsing reads the function echo as the return code, so every call ends in -EIO and profile_get always fails.
3. .skip_ac_type_check = true is needed; USB-C only board, AC type is never CIRCULARHOLE.
Your profile values are correct - Fn+K emits hotkey events whose value_low cycles 1 -> 3 -> 2.
Corrected quirk attached. With it, from a clean boot all three profiles set and stay set through power-profiles-daemon, no reverts and no -EOPNOTSUPP.
Two further observations.
Fn+K emits WMI_EVENT_PERFORMANCE_PLAN_ALT (22), not WMI_EVENT_PERFORMANCE_PLAN (15); only the latter is handled, so platform_profile_notify() is never called here. value_low carries the resulting mode. Possibly relevant to the question in your v15 cover letter.
The platform profile does not affect the power budget. Writes are accepted and read back, but package power does not change. stress -c 16 at both ends of the Fn+K range:
Fn+K high low-power 4391 balanced 4348 performance 4217 MHz Fn+K low low-power 1726 balanced 1825 performance 1953 MHz
Varying the order of the profiles gave no consistent effect. The same sweep with --block-driver=platform_profile, amd_pstate only, gives 1464 / 3550 / 3519, so the drop under power-saver comes from amd_pstate.
Correction to my first mail: ~35 W is not one of the three Fn+K steps, it is the EC power-on state. The steps are 15 W, 54-60 W and 54-65 W; the first Fn+K press leaves the power-on state and it does not return until the next boot.
drivers/platform/x86/bitland-mifs-wmi.c +20 -0
@@ -113,7 +113,27 @@ static const struct bitland_mifs_quirks default_quirks = { .num_profile_entries = ARRAY_SIZE(default_profile_entries), }; +static const struct bitland_profile_entry tm2209_profile_entries[] = { + {PLATFORM_PROFILE_LOW_POWER ,2 }, + {PLATFORM_PROFILE_BALANCED ,1 }, + {PLATFORM_PROFILE_PERFORMANCE ,3 }, +}; + +static const struct bitland_mifs_quirks tm2209_quirks = { + .profile_entries = tm2209_profile_entries, + .num_profile_entries =ARRAY_SIZE (tm2209_profile_entries), + .return_code_at_end = true, + .skip_ac_type_check = true, +}; +static const struct dmi_system_id bitland_mifs_dmi_table[] = { + { + .matches = { +DMI_EXACT_MATCH (DMI_SYS_VENDOR ,"XIAOMI" ), +DMI_EXACT_MATCH (DMI_BOARD_NAME ,"TM2209" ), + }, + .driver_data = (void *)&tm2209_quirks, + }, {} };
Follow-up with what I found while testing, and a correction.
Correction: v15 does handle WMI_EVENT_PERFORMANCE_PLAN_ALT, so platform_profile_notify() is called on Fn+K. I misread that earlier. The profile did not change in my tests because profile_get read SystemPerMode, which Fn+K does not seem to touch.
From the decompiled tables, as far as I can tell, the mode on this board is a byte in EC RAM, STNM (\_SB.PCI0.LPC0.EC0, SystemMemory 0xFE0B0300 + 0x7E). Fn+K raises EC0._Q24, which notifies WMID, sleeps 500 ms and calls HPTC (STNM). STNM itself is rotated by EV20 case 0x16, which runs only when the event is read through _WED, so without a driver reading the event Fn+K does not change the mode. HPTC appears to program the SoC limits from STNM.
What I observed: with your quirk loaded, writes to platform_profile returned 0, but STNM did not change.
Attached is a patch (written with an AI assistant, feel free to reuse or rewrite) on top of v15 that works on my machine. It replaces my previous one. It may well not be the right way to do it in the driver, I'm sharing it in case it helps:
- profile_get reads STNM with acpi_evaluate_integer()
- profile_set writes STNM via ioremap under the ACPI global lock (the field is declared with Lock) and evaluates EC0.HPTC
- AE_AML_BUFFER_LIMIT from HPTC is treated as success: SVRP sets the size field to 0x12 for three 5-byte entries (0x11 bytes), so A032 starts a fourth entry and reads past the end of the buffer, after the limits have already been sent. The ACPI error is still printed to dmesg on every profile change
- The capability check still applies, and on this board it gets in the
way: on battery, setting performance fails with EOPNOTSUPP and power-profiles-daemon rolls the profile back, while Fn+K selects the top step without problems. The firmware already bounds the limits by AC state and battery level (HDC1..3), so the check looks unnecessary here
With it, on AC, through power-profiles-daemon: profiles set and stay set, Fn+K changes the reported profile, and package power looks consistent with the firmware tables.
Not covered: the address comes from BIOS RMAPH5B0P0909 only; profile_get returns an error if STNM is outside 1..3.
Cc'ing Musaev Ibragim, who tested the Redmibook side of this series on the same board and BIOS in July.
drivers/platform/x86/bitland-mifs-wmi.c +81 -2
@@ -18,6 +18,7 @@#include <linux/err.h> #include <linux/hwmon.h> #include <linux/init.h> +#include <linux/io.h> #include <linux/input-event-codes.h> #include <linux/input.h> #include <linux/input/sparse-keymap.h>
@@ -99,6 +100,10 @@ struct bitland_mifs_quirks {bool return_code_at_end;bool skip_ac_type_check; + +const char *ec_mode_field; +const char *ec_mode_apply; +phys_addr_t ec_mode_addr; };static const struct bitland_profile_entry default_profile_entries[] = {
@@ -113,7 +118,30 @@ static const struct bitland_mifs_quirks default_quirks = { .num_profile_entries = ARRAY_SIZE(default_profile_entries), }; +static const struct bitland_profile_entry tm2209_profile_entries[] = { + {PLATFORM_PROFILE_LOW_POWER ,2 }, + {PLATFORM_PROFILE_BALANCED ,1 }, + {PLATFORM_PROFILE_PERFORMANCE ,3 }, +}; + +static const struct bitland_mifs_quirks tm2209_quirks = { + .profile_entries = tm2209_profile_entries, + .num_profile_entries =ARRAY_SIZE (tm2209_profile_entries), + .return_code_at_end = true, + .skip_ac_type_check = true, + .ec_mode_field ="\\_SB.PCI0.LPC0.EC0.STNM" , + .ec_mode_apply ="\\_SB.PCI0.LPC0.EC0.HPTC" , + .ec_mode_addr =0xFE0B0300 +0x7E , +}; +static const struct dmi_system_id bitland_mifs_dmi_table[] = { + { + .matches = { +DMI_EXACT_MATCH (DMI_SYS_VENDOR ,"XIAOMI" ), +DMI_EXACT_MATCH (DMI_BOARD_NAME ,"TM2209" ), + }, + .driver_data = (void *)&tm2209_quirks, + }, {} };
@@ -271,6 +299,48 @@ static int bitland_mifs_wmi_call(struct bitland_mifs_wmi_data *data,return 0 ; } +static int bitland_ec_mode_get (const struct bitland_mifs_quirks *quirks,u8 *val) +{ +unsigned long long v; +acpi_status status; + + status =acpi_evaluate_integer (NULL , (acpi_string )quirks->ec_mode_field, +NULL , &v); +if (ACPI_FAILURE (status)) +return -EIO ; + + *val = v; +return 0 ; +} + +static int bitland_ec_mode_set (const struct bitland_mifs_quirks *quirks,u8 val) +{ +void __iomem *addr; +acpi_status status; +u32 glk; + + addr =ioremap (quirks->ec_mode_addr,1 ); +if (!addr) +return -ENOMEM ; + + status =acpi_acquire_global_lock (1000 , &glk); +if (ACPI_FAILURE (status)) { +iounmap (addr); +return -EBUSY ; + } +writeb (val, addr); +acpi_release_global_lock (glk); +iounmap (addr); + + status =acpi_execute_simple_method (NULL , (char *)quirks->ec_mode_apply, val); +if (status ==AE_AML_BUFFER_LIMIT ) +return 0 ; +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} +static int laptop_profile_get (struct device *dev,enum platform_profile_option *profile) {
@@ -282,14 +352,20 @@ static int laptop_profile_get(struct device *dev, };struct bitland_mifs_output_head_rc result;size_t i; +u8 val;int ret; - ret =bitland_mifs_wmi_call (data, &input, &result); +if (quirks->ec_mode_field) { + ret =bitland_ec_mode_get (quirks, &val); + }else { + ret =bitland_mifs_wmi_call (data, &input, &result); + val = result.data[0 ]; + }if (ret)return ret;for (i =0 ; i < quirks->num_profile_entries; i++) { -if (quirks->profile_entries[i].wmi_val == result.data[0 ]) { +if (quirks->profile_entries[i].wmi_val == val) { *profile = quirks->profile_entries[i].profile;return 0 ; }
@@ -350,6 +426,9 @@ static int laptop_profile_set(struct device *dev,for (i =0 ; i < quirks->num_profile_entries; i++) {if (quirks->profile_entries[i].profile == profile && !quirks->profile_entries[i].no_set) { +if (quirks->ec_mode_addr) +return bitland_ec_mode_set (quirks, + quirks->profile_entries[i].wmi_val); input.payload[0 ] = quirks->profile_entries[i].wmi_val;return bitland_mifs_wmi_call (data, &input,NULL ); }
Quoted 9 lines · Oleg Rybalov
Follow-up with what I found while testing, and a correction.
[...]
Not covered: the address comes from BIOS RMAPH5B0P0909 only;
profile_getreturns an error if STNM is outside 1..3.Cc'ing Musaev Ibragim, who tested the Redmibook side of this series on the same board and BIOS in July.
Please send your patch with git send-email.
RFC PATCH 1/1 platform/x86: bitland-mifs-wmi: Add Redmi Book Pro 15 2023 (TM2209) quirk
On TM2209 the power mode is the STNM byte in EC RAM. Fn+K rotates it in EV20 and the EC0._Q24 handler then applies the matching SoC limits with HPTC. SystemPerMode does not affect STNM, so changing the platform profile had no effect on power.
Read the mode from STNM and, on set, write STNM and evaluate EC0.HPTC as the Fn+K handler does. HPTC returns AE_AML_BUFFER_LIMIT because SVRP declares its ALIB buffer one byte longer than its data; the limits are already sent at that point, so treat it as success.
The board reports DMI_SYS_VENDOR "XIAOMI" with TM2209 in DMI_BOARD_NAME, returns the WMI return code at the end of the buffer and charges over USB-C only.
---
Based on v15 of "Merge redmi-wmi into bitland-mifs-wmi":
https://lore.kernel.org/r/[email protected]
Tested on BIOS RMAPH5B0P0909 only.
drivers/platform/x86/bitland-mifs-wmi.c | 83 ++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-)
drivers/platform/x86/bitland-mifs-wmi.c +81 -2
@@ -21,6 +21,7 @@#include <linux/input-event-codes.h> #include <linux/input.h> #include <linux/input/sparse-keymap.h> +#include <linux/io.h> #include <linux/kernel.h> #include <linux/leds.h> #include <linux/module.h>
@@ -99,6 +100,10 @@ struct bitland_mifs_quirks {bool return_code_at_end;bool skip_ac_type_check; + +const char *ec_mode_field; +const char *ec_mode_apply; +phys_addr_t ec_mode_addr; };static const struct bitland_profile_entry default_profile_entries[] = {
@@ -113,7 +118,30 @@ static const struct bitland_mifs_quirks default_quirks = { .num_profile_entries = ARRAY_SIZE(default_profile_entries), }; +static const struct bitland_profile_entry tm2209_profile_entries[] = { + {PLATFORM_PROFILE_LOW_POWER ,2 }, + {PLATFORM_PROFILE_BALANCED ,1 }, + {PLATFORM_PROFILE_PERFORMANCE ,3 }, +}; + +static const struct bitland_mifs_quirks tm2209_quirks = { + .profile_entries = tm2209_profile_entries, + .num_profile_entries =ARRAY_SIZE (tm2209_profile_entries), + .return_code_at_end = true, + .skip_ac_type_check = true, + .ec_mode_field ="\\_SB.PCI0.LPC0.EC0.STNM" , + .ec_mode_apply ="\\_SB.PCI0.LPC0.EC0.HPTC" , + .ec_mode_addr =0xFE0B0300 +0x7E , +}; +static const struct dmi_system_id bitland_mifs_dmi_table[] = { + { + .matches = { +DMI_EXACT_MATCH (DMI_SYS_VENDOR ,"XIAOMI" ), +DMI_EXACT_MATCH (DMI_BOARD_NAME ,"TM2209" ), + }, + .driver_data = (void *)&tm2209_quirks, + }, {} };
@@ -271,6 +299,48 @@ static int bitland_mifs_wmi_call(struct bitland_mifs_wmi_data *data,return 0 ; } +static int bitland_ec_mode_get (const struct bitland_mifs_quirks *quirks,u8 *val) +{ +unsigned long long v; +acpi_status status; + + status =acpi_evaluate_integer (NULL , (acpi_string )quirks->ec_mode_field, +NULL , &v); +if (ACPI_FAILURE (status)) +return -EIO ; + + *val = v; +return 0 ; +} + +static int bitland_ec_mode_set (const struct bitland_mifs_quirks *quirks,u8 val) +{ +void __iomem *addr; +acpi_status status; +u32 glk; + + addr =ioremap (quirks->ec_mode_addr,1 ); +if (!addr) +return -ENOMEM ; + + status =acpi_acquire_global_lock (1000 , &glk); +if (ACPI_FAILURE (status)) { +iounmap (addr); +return -EBUSY ; + } +writeb (val, addr); +acpi_release_global_lock (glk); +iounmap (addr); + + status =acpi_execute_simple_method (NULL , (char *)quirks->ec_mode_apply, val); +if (status ==AE_AML_BUFFER_LIMIT ) +return 0 ; +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} +static int laptop_profile_get (struct device *dev,enum platform_profile_option *profile) {
@@ -282,14 +352,20 @@ static int laptop_profile_get(struct device *dev, };struct bitland_mifs_output_head_rc result;size_t i; +u8 val;int ret; - ret =bitland_mifs_wmi_call (data, &input, &result); +if (quirks->ec_mode_field) { + ret =bitland_ec_mode_get (quirks, &val); + }else { + ret =bitland_mifs_wmi_call (data, &input, &result); + val = result.data[0 ]; + }if (ret)return ret;for (i =0 ; i < quirks->num_profile_entries; i++) { -if (quirks->profile_entries[i].wmi_val == result.data[0 ]) { +if (quirks->profile_entries[i].wmi_val == val) { *profile = quirks->profile_entries[i].profile;return 0 ; }
@@ -350,6 +426,9 @@ static int laptop_profile_set(struct device *dev,for (i =0 ; i < quirks->num_profile_entries; i++) {if (quirks->profile_entries[i].profile == profile && !quirks->profile_entries[i].no_set) { +if (quirks->ec_mode_addr) +return bitland_ec_mode_set (quirks, + quirks->profile_entries[i].wmi_val); input.payload[0 ] = quirks->profile_entries[i].wmi_val;return bitland_mifs_wmi_call (data, &input,NULL ); }
Signature · 1 line
2.56.0
Re: [RFC PATCH] platform/x86: bitland-mifs-wmi: Add Redmi Book Pro 15 2023 (TM2209) quirk
Quoted 56 lines · Oleg Rybalov
On TM2209 the power mode is the STNM byte in EC RAM. Fn+K rotates it in EV20 and the EC0._Q24 handler then applies the matching SoC limits with HPTC. SystemPerMode does not affect STNM, so changing the platform profile had no effect on power.
Read the mode from STNM and, on set, write STNM and evaluate EC0.HPTC as the Fn+K handler does. HPTC returns
AE_AML_BUFFER_LIMITbecause SVRP declares its ALIB buffer one byte longer than its data; the limits are already sent at that point, so treat it as success.The board reports
DMI_SYS_VENDOR"XIAOMI" with TM2209 inDMI_BOARD_NAME, returns the WMI return code at the end of the buffer and charges over USB-C only.Signed-off-by Oleg Rybalov <[email protected]>---
Based on v15 of "Merge redmi-wmi into bitland-mifs-wmi":
https://lore.kernel.org/r/[email protected]Tested on BIOS RMAPH5B0P0909 only.
drivers/platform/x86/bitland-mifs-wmi.c | 83 ++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-)drivers/platform/x86/bitland-mifs-wmi.c +10
-0@@ -21,6 +21,7 @@#include <linux/input-event-codes.h> #include <linux/input.h> #include <linux/input/sparse-keymap.h> +#include <linux/io.h> #include <linux/kernel.h> #include <linux/leds.h> #include <linux/module.h> @@ -99,6 +100,10 @@ struct bitland_mifs_quirks {bool return_code_at_end;bool skip_ac_type_check; + +const char *ec_mode_field; +const char *ec_mode_apply; +phys_addr_t ec_mode_addr; };static const struct bitland_profile_entry default_profile_entries[] = {@@ -113,7 +118,30 @@ static const struct bitland_mifs_quirks default_quirks = { .num_profile_entries = ARRAY_SIZE(default_profile_entries), }; +static const struct bitland_profile_entry tm2209_profile_entries[] = { + {PLATFORM_PROFILE_LOW_POWER ,2 }, + {PLATFORM_PROFILE_BALANCED ,1 }, + {PLATFORM_PROFILE_PERFORMANCE ,3 }, +};
drivers/platform/x86/bitland-mifs-wmi.c static const struct bitland_mifs_quirks default_quirks = { · line 135
Quoted 10 lines
drivers/platform/x86/bitland-mifs-wmi.c +10
-0+ +static const struct bitland_mifs_quirks tm2209_quirks = { + .profile_entries = tm2209_profile_entries, + .num_profile_entries =ARRAY_SIZE (tm2209_profile_entries), + .return_code_at_end = true, + .skip_ac_type_check = true, + .ec_mode_field ="\\_SB.PCI0.LPC0.EC0.STNM" , + .ec_mode_apply ="\\_SB.PCI0.LPC0.EC0.HPTC" , + .ec_mode_addr =0xFE0B0300 +0x7E , +};
I think this is an anti-pattern.
Do we get a WMI method for this?
Quoted 94 lines
drivers/platform/x86/bitland-mifs-wmi.c +61
-2+static const struct dmi_system_id bitland_mifs_dmi_table[] = { + { + .matches = { +DMI_EXACT_MATCH (DMI_SYS_VENDOR ,"XIAOMI" ), +DMI_EXACT_MATCH (DMI_BOARD_NAME ,"TM2209" ), + }, + .driver_data = (void *)&tm2209_quirks, + }, {} };@@ -271,6 +299,48 @@ static int bitland_mifs_wmi_call(struct bitland_mifs_wmi_data *data,return 0 ; } +static int bitland_ec_mode_get (const struct bitland_mifs_quirks *quirks,u8 *val) +{ +unsigned long long v; +acpi_status status; + + status =acpi_evaluate_integer (NULL , (acpi_string )quirks->ec_mode_field, +NULL , &v); +if (ACPI_FAILURE (status)) +return -EIO ; + + *val = v; +return 0 ; +} + +static int bitland_ec_mode_set (const struct bitland_mifs_quirks *quirks,u8 val) +{ +void __iomem *addr; +acpi_status status; +u32 glk; + + addr =ioremap (quirks->ec_mode_addr,1 ); +if (!addr) +return -ENOMEM ; + + status =acpi_acquire_global_lock (1000 , &glk); +if (ACPI_FAILURE (status)) { +iounmap (addr); +return -EBUSY ; + } +writeb (val, addr); +acpi_release_global_lock (glk); +iounmap (addr); + + status =acpi_execute_simple_method (NULL , (char *)quirks->ec_mode_apply, val); +if (status ==AE_AML_BUFFER_LIMIT ) +return 0 ; +if (ACPI_FAILURE (status)) +return -EIO ; + +return 0 ; +} +static int laptop_profile_get (struct device *dev,enum platform_profile_option *profile) {@@ -282,14 +352,20 @@ static int laptop_profile_get(struct device *dev, };struct bitland_mifs_output_head_rc result;size_t i; +u8 val;int ret; - ret =bitland_mifs_wmi_call (data, &input, &result); +if (quirks->ec_mode_field) { + ret =bitland_ec_mode_get (quirks, &val); + }else { + ret =bitland_mifs_wmi_call (data, &input, &result); + val = result.data[0 ]; + }if (ret)return ret;for (i =0 ; i < quirks->num_profile_entries; i++) { -if (quirks->profile_entries[i].wmi_val == result.data[0 ]) { +if (quirks->profile_entries[i].wmi_val == val) { *profile = quirks->profile_entries[i].profile;return 0 ; }@@ -350,6 +426,9 @@ static int laptop_profile_set(struct device *dev,for (i =0 ; i < quirks->num_profile_entries; i++) {if (quirks->profile_entries[i].profile == profile && !quirks->profile_entries[i].no_set) { +if (quirks->ec_mode_addr) +return bitland_ec_mode_set (quirks, + quirks->profile_entries[i].wmi_val); input.payload[0 ] = quirks->profile_entries[i].wmi_val;return bitland_mifs_wmi_call (data, &input,NULL ); }