platform/x86: bitland-mifs-wmi: Support WUJIE15 PRO HPT
v4 cover platform/x86: bitland-mifs-wmi: Support WUJIE15 PRO HPT
Hi Ilpo,
Thanks for the review. I've split out the preparatory changes as you suggested. HPT support is now in the last patch. The final driver code is unchanged from v3.
I build-tested each patch with W=1.
Bozhen Peng (4):
platform/x86: bitland-mifs-wmi: Allow per-model hwmon configuration platform/x86: bitland-mifs-wmi: Allow quirks to override the power
check
platform/x86: bitland-mifs-wmi: Add a quirk to hide extra controls platform/x86: bitland-mifs-wmi: Support WUJIE15 PRO HPT
drivers/platform/x86/bitland-mifs-wmi.c | 134 ++++++++++++++++++++++-- 1 file changed, 124 insertions(+), 10 deletions(-)
base-commit: 9c82959c37bf69c2ace8a0f975cf2129ec1fd982
PATCH v4 1/4 platform/x86: bitland-mifs-wmi: Allow per-model hwmon configuration
The WUJIE15 PRO HPT has two fans and no CPU temperature reading. Move the hwmon chip info and fan labels into a per-model configuration so its sensor layout can be added separately. Keep the current layout as the default.
No functional change intended.
--- drivers/platform/x86/bitland-mifs-wmi.c | 43 +++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-)
drivers/platform/x86/bitland-mifs-wmi.c +34 -9
@@ -94,9 +94,18 @@ struct bitland_profile_entry {bool battery;/* Set in place of the AC entry while on battery */ }; +struct bitland_hwmon_config { +const struct hwmon_chip_info *chip_info; +const char *const *fan_labels; +size_t num_fans; +}; + +static const struct bitland_hwmon_config default_hwmon_config; +struct bitland_mifs_quirks {const struct bitland_profile_entry *profile_entries;size_t num_profile_entries; +const struct bitland_hwmon_config *hwmon;bool return_code_at_end;bool skip_ac_type_check;
@@ -552,12 +561,18 @@ static const struct platform_profile_ops laptop_profile_ops = { .profile_set = laptop_profile_set, }; -static const char *const fan_labels[] = { +static const char *const default_fan_labels[] = {"CPU" ,/* 0 */ "GPU" ,/* 1 */ "SYS" ,/* 2 */ }; +static const struct bitland_hwmon_config * +bitland_hwmon_config (const struct bitland_mifs_wmi_data *data) +{ +return data->quirks->hwmon ?: &default_hwmon_config; +} +static int laptop_hwmon_read (struct device *dev,enum hwmon_sensor_types type,u32 attr,int channel,long *val) {
@@ -603,13 +618,15 @@ static int laptop_hwmon_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, const char **str) { - if (type == hwmon_fan && attr == hwmon_fan_label) { - if (channel >= 0 && channel < ARRAY_SIZE(fan_labels)) { - *str = fan_labels[channel]; -return 0 ; - } - } -return -EINVAL ; + struct bitland_mifs_wmi_data *data = dev_get_drvdata(dev); +const struct bitland_hwmon_config *config =bitland_hwmon_config (data); + +if (type != hwmon_fan || attr != hwmon_fan_label || + channel <0 || channel >= config->num_fans) +return -EINVAL ; + + *str = config->fan_labels[channel]; +return 0 ; } static const struct hwmon_channel_info *laptop_hwmon_info[] = {
@@ -631,6 +648,12 @@ static const struct hwmon_chip_info laptop_chip_info = { .info = laptop_hwmon_info, }; +static const struct bitland_hwmon_config default_hwmon_config = { + .chip_info = &laptop_chip_info, + .fan_labels = default_fan_labels, + .num_fans =ARRAY_SIZE (default_fan_labels), +}; +static int laptop_kbd_led_set (struct led_classdev *led_cdev,enum led_brightness value) {
@@ -900,6 +923,7 @@ static int bitland_notifier_callback(struct notifier_block *nb,static int bitland_mifs_wmi_probe (struct wmi_device *wdev,const void *context) { +const struct bitland_hwmon_config *hwmon;struct bitland_mifs_wmi_data *drv_data;enum bitland_wmi_device_type dev_type = (enum bitland_wmi_device_type )(unsigned long )context;
@@ -971,10 +995,11 @@ static int bitland_mifs_wmi_probe(struct wmi_device *wdev, const void *context) }/* Register hwmon */ + hwmon =bitland_hwmon_config (drv_data); drv_data->hwmon_dev =devm_hwmon_device_register_with_info (&wdev->dev,"bitland_mifs" , drv_data, - &laptop_chip_info, + hwmon->chip_info,NULL );if (IS_ERR (drv_data->hwmon_dev))return PTR_ERR (drv_data->hwmon_dev);
PATCH v4 2/4 platform/x86: bitland-mifs-wmi: Allow quirks to override the power check
In reply to Bozhen PengThe WUJIE15 PRO HPT needs a different power check before allowing the performance profile. Add an optional callback to the quirks and keep the existing check when no callback is provided.
No functional change intended.
--- drivers/platform/x86/bitland-mifs-wmi.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/platform/x86/bitland-mifs-wmi.c +4 -0
@@ -105,6 +105,7 @@ static const struct bitland_hwmon_config default_hwmon_config;struct bitland_mifs_quirks {const struct bitland_profile_entry *profile_entries;size_t num_profile_entries; +int (*check_performance_capability)(void );const struct bitland_hwmon_config *hwmon;bool return_code_at_end;
@@ -362,6 +363,9 @@ static int bitland_pp_check_capability(struct bitland_mifs_wmi_data *data)struct bitland_mifs_output_head_rc output;int ret; +if (data->quirks->check_performance_capability) +return data->quirks->check_performance_capability (); +if (data->quirks->skip_ac_type_check)return power_supply_is_system_supplied () >0 ?0 : -EOPNOTSUPP ;
PATCH v4 3/4 platform/x86: bitland-mifs-wmi: Add a quirk to hide extra controls
In reply to Bozhen PengThe WUJIE15 PRO HPT does not support the GPU mode, keyboard RGB mode or fan-boost controls. Add a quirk to hide their sysfs attributes. Existing models keep the same attributes and permissions.
No functional change intended.
--- drivers/platform/x86/bitland-mifs-wmi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
drivers/platform/x86/bitland-mifs-wmi.c +22 -1
@@ -108,6 +108,7 @@ struct bitland_mifs_quirks {int (*check_performance_capability)(void );const struct bitland_hwmon_config *hwmon; +bool disable_extra_controls;bool return_code_at_end;bool skip_ac_type_check; };
@@ -836,7 +837,27 @@ static const struct attribute *const laptop_attrs[] = { &dev_attr_fan_boost.attr, NULL, }; -ATTRIBUTE_GROUPS (laptop); + +static umode_t laptop_attr_is_visible (struct kobject *kobj, +const struct attribute *attr,int n) +{ +struct bitland_mifs_wmi_data *data =dev_get_drvdata (kobj_to_dev (kobj)); + +if (data->quirks->disable_extra_controls) +return 0 ; + +return attr->mode; +} + +static const struct attribute_group laptop_group = { + .attrs_const = laptop_attrs, + .is_visible_const = laptop_attr_is_visible, +}; + +static const struct attribute_group *laptop_groups[] = { + &laptop_group, +NULL +};static const struct key_entry bitland_mifs_wmi_keymap[] = { { KE_KEY, BI_HOTKEY_CODE(WMI_EVENT_OPEN_APP, 1, 0), { KEY_PROG1 } },
PATCH v4 4/4 platform/x86: bitland-mifs-wmi: Support WUJIE15 PRO HPT
In reply to Bozhen PengMy WUJIE15 PRO HPT uses performance (0), balanced (1) and low-power (2), which differ from the default mapping.
USB-C is its only external power input. I use the ACPI adapter's _PSR to check power because the USB-C supply's cached ONLINE value can be stale after unplugging during suspend. Failed or invalid queries return an error.
HPT reports two fans, in Fan 2/Fan 1 order, and no CPU temperature. I hide the unsupported GPU mode, keyboard RGB mode and fan-boost controls, while keeping keyboard backlight brightness available.
--- drivers/platform/x86/bitland-mifs-wmi.c | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
drivers/platform/x86/bitland-mifs-wmi.c +64 -0
@@ -101,6 +101,9 @@ struct bitland_hwmon_config { };static const struct bitland_hwmon_config default_hwmon_config; +static const struct bitland_hwmon_config hpt_hwmon_config; + +static int bitland_hpt_check_performance_capability (void );struct bitland_mifs_quirks {const struct bitland_profile_entry *profile_entries;
@@ -151,6 +154,20 @@ static const struct bitland_mifs_quirks tm2424_quirks = { .skip_ac_type_check = true, }; +static const struct bitland_profile_entry hpt_profile_entries[] = { + {PLATFORM_PROFILE_LOW_POWER ,0x02 }, + {PLATFORM_PROFILE_BALANCED ,0x01 }, + {PLATFORM_PROFILE_PERFORMANCE ,0x00 }, +}; + +static const struct bitland_mifs_quirks hpt_quirks = { + .profile_entries = hpt_profile_entries, + .num_profile_entries =ARRAY_SIZE (hpt_profile_entries), + .check_performance_capability = bitland_hpt_check_performance_capability, + .hwmon = &hpt_hwmon_config, + .disable_extra_controls = true, +}; +static const struct dmi_system_id bitland_mifs_dmi_table[] = { { .matches = {
@@ -166,6 +183,14 @@ static const struct dmi_system_id bitland_mifs_dmi_table[] = { }, .driver_data = (void *)&tm2424_quirks, }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MECHREVO"), + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "WUJIE15 PRO"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "WUJIE15 Series-HPT"), + }, + .driver_data = (void *)&hpt_quirks, + }, {} };
@@ -355,6 +380,25 @@ static int laptop_profile_get(struct device *dev,return -EINVAL ; } +static int bitland_hpt_check_performance_capability (void ) +{ +struct acpi_device *adapter; +unsigned long long online; +acpi_status status; + + adapter =acpi_dev_get_first_match_dev ("ACPI0003" ,NULL ,-1 ); +if (!adapter) +return -ENODEV ; + +/* USB-C ONLINE may be stale on resume; _PSR reads current EC state. */ + status =acpi_evaluate_integer (adapter->handle,"_PSR" ,NULL , &online); +acpi_dev_put (adapter); +if (ACPI_FAILURE (status) || online >1 ) +return -EIO ; + +return online ?0 : -EOPNOTSUPP ; +} +static int bitland_pp_check_capability (struct bitland_mifs_wmi_data *data) {struct bitland_mifs_input input = {
@@ -572,6 +616,9 @@ static const char * const default_fan_labels[] = { "SYS", /* 2 */ }; +/* The HPT firmware returns Fan 2 before Fan 1. */ +static const char *const hpt_fan_labels[] = {"Fan 2" ,"Fan 1" }; +static const struct bitland_hwmon_config *bitland_hwmon_config (const struct bitland_mifs_wmi_data *data) {
@@ -642,6 +689,12 @@ static const struct hwmon_channel_info *laptop_hwmon_info[] = {NULL }; +static const struct hwmon_channel_info *hpt_hwmon_info[] = { +HWMON_CHANNEL_INFO (fan,HWMON_F_INPUT |HWMON_F_LABEL , +HWMON_F_INPUT |HWMON_F_LABEL ), +NULL +}; +static const struct hwmon_ops laptop_hwmon_ops = { .visible =0444 , .read = laptop_hwmon_read,
@@ -653,12 +706,23 @@ static const struct hwmon_chip_info laptop_chip_info = { .info = laptop_hwmon_info, }; +static const struct hwmon_chip_info hpt_chip_info = { + .ops = &laptop_hwmon_ops, + .info = hpt_hwmon_info, +}; +static const struct bitland_hwmon_config default_hwmon_config = { .chip_info = &laptop_chip_info, .fan_labels = default_fan_labels, .num_fans =ARRAY_SIZE (default_fan_labels), }; +static const struct bitland_hwmon_config hpt_hwmon_config = { + .chip_info = &hpt_chip_info, + .fan_labels = hpt_fan_labels, + .num_fans =ARRAY_SIZE (hpt_fan_labels), +}; +static int laptop_kbd_led_set (struct led_classdev *led_cdev,enum led_brightness value) {
Quoted 6 lines · Bozhen Peng
My WUJIE15 PRO HPT uses performance (0), balanced (1) and low-power (2), which differ from the default mapping.
USB-C is its only external power input. I use the ACPI adapter's
_PSRto check power because the USB-C supply's cached ONLINE value can be stale after unplugging during suspend. Failed or invalid queries return an error.
I don't agree with this method, here's why:
I think this is just a temporary workaround, it doesn't solve the actual stale state problem in the power_supply subsystem.
Is there a reason this can't be fixed in the underlying USB-C driver's resume path instead (likely under drivers/usb/typec/ucsi/)?
Quoted 133 lines
HPT reports two fans, in Fan 2/Fan 1 order, and no CPU temperature. I hide the unsupported GPU mode, keyboard RGB mode and fan-boost controls, while keeping keyboard backlight brightness available.
Signed-off-by Bozhen Peng <[email protected]>--- drivers/platform/x86/bitland-mifs-wmi.c | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+)drivers/platform/x86/bitland-mifs-wmi.c +64
-0@@ -101,6 +101,9 @@ struct bitland_hwmon_config { };static const struct bitland_hwmon_config default_hwmon_config; +static const struct bitland_hwmon_config hpt_hwmon_config; + +static int bitland_hpt_check_performance_capability (void );struct bitland_mifs_quirks {const struct bitland_profile_entry *profile_entries;@@ -151,6 +154,20 @@ static const struct bitland_mifs_quirks tm2424_quirks = { .skip_ac_type_check = true, }; +static const struct bitland_profile_entry hpt_profile_entries[] = { + {PLATFORM_PROFILE_LOW_POWER ,0x02 }, + {PLATFORM_PROFILE_BALANCED ,0x01 }, + {PLATFORM_PROFILE_PERFORMANCE ,0x00 }, +}; + +static const struct bitland_mifs_quirks hpt_quirks = { + .profile_entries = hpt_profile_entries, + .num_profile_entries =ARRAY_SIZE (hpt_profile_entries), + .check_performance_capability = bitland_hpt_check_performance_capability, + .hwmon = &hpt_hwmon_config, + .disable_extra_controls = true, +}; +static const struct dmi_system_id bitland_mifs_dmi_table[] = { { .matches = {@@ -166,6 +183,14 @@ static const struct dmi_system_id bitland_mifs_dmi_table[] = { }, .driver_data = (void *)&tm2424_quirks, }, + { + .matches = { + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MECHREVO"), + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "WUJIE15 PRO"), + DMI_EXACT_MATCH(DMI_BOARD_NAME, "WUJIE15 Series-HPT"), + }, + .driver_data = (void *)&hpt_quirks, + }, {} };@@ -355,6 +380,25 @@ static int laptop_profile_get(struct device *dev,return -EINVAL ; } +static int bitland_hpt_check_performance_capability (void ) +{ +struct acpi_device *adapter; +unsigned long long online; +acpi_status status; + + adapter =acpi_dev_get_first_match_dev ("ACPI0003" ,NULL ,-1 ); +if (!adapter) +return -ENODEV ; + +/* USB-C ONLINE may be stale on resume; _PSR reads current EC state. */ + status =acpi_evaluate_integer (adapter->handle,"_PSR" ,NULL , &online); +acpi_dev_put (adapter); +if (ACPI_FAILURE (status) || online >1 ) +return -EIO ; + +return online ?0 : -EOPNOTSUPP ; +} +static int bitland_pp_check_capability (struct bitland_mifs_wmi_data *data) {struct bitland_mifs_input input = {@@ -572,6 +616,9 @@ static const char * const default_fan_labels[] = { "SYS", /* 2 */ }; +/* The HPT firmware returns Fan 2 before Fan 1. */ +static const char *const hpt_fan_labels[] = {"Fan 2" ,"Fan 1" }; +static const struct bitland_hwmon_config *bitland_hwmon_config (const struct bitland_mifs_wmi_data *data) {@@ -642,6 +689,12 @@ static const struct hwmon_channel_info *laptop_hwmon_info[] = {NULL }; +static const struct hwmon_channel_info *hpt_hwmon_info[] = { +HWMON_CHANNEL_INFO (fan,HWMON_F_INPUT |HWMON_F_LABEL , +HWMON_F_INPUT |HWMON_F_LABEL ), +NULL +}; +static const struct hwmon_ops laptop_hwmon_ops = { .visible =0444 , .read = laptop_hwmon_read,@@ -653,12 +706,23 @@ static const struct hwmon_chip_info laptop_chip_info = { .info = laptop_hwmon_info, }; +static const struct hwmon_chip_info hpt_chip_info = { + .ops = &laptop_hwmon_ops, + .info = hpt_hwmon_info, +}; +static const struct bitland_hwmon_config default_hwmon_config = { .chip_info = &laptop_chip_info, .fan_labels = default_fan_labels, .num_fans =ARRAY_SIZE (default_fan_labels), }; +static const struct bitland_hwmon_config hpt_hwmon_config = { + .chip_info = &hpt_chip_info, + .fan_labels = hpt_fan_labels, + .num_fans =ARRAY_SIZE (hpt_fan_labels), +}; +static int laptop_kbd_led_set (struct led_classdev *led_cdev,enum led_brightness value) {
Re: [PATCH v4 3/4] platform/x86: bitland-mifs-wmi: Add a quirk to hide extra controls
In reply to Bozhen PengQuoted 16 lines · Bozhen Peng
The WUJIE15 PRO HPT does not support the GPU mode, keyboard RGB mode or fan-boost controls. Add a quirk to hide their sysfs attributes. Existing models keep the same attributes and permissions.
No functional change intended.
Signed-off-by Bozhen Peng <[email protected]>--- drivers/platform/x86/bitland-mifs-wmi.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)drivers/platform/x86/bitland-mifs-wmi.c +0
-0
drivers/platform/x86/bitland-mifs-wmi.c struct bitland_mifs_quirks { · line 111
Quoted 4 lines
drivers/platform/x86/bitland-mifs-wmi.c +1
-0@@ -108,6 +108,7 @@ struct bitland_mifs_quirks {int (*check_performance_capability)(void );const struct bitland_hwmon_config *hwmon; +bool disable_extra_controls;
I'd suggest adding bitflags like the uniwill driver. Then we can control what sysfs attrs to enable with the bitflag.
Quoted 3 lines
drivers/platform/x86/bitland-mifs-wmi.c +0
-0bool return_code_at_end;bool skip_ac_type_check; };