1 // SPDX-License-Identifier: GPL-2.0
3 * Inspur WMI Platform Profile
5 * Copyright (C) 2018 Ai Chao <aichao@kylinos.cn>
8 #include <linux/acpi.h>
9 #include <linux/device.h>
10 #include <linux/module.h>
11 #include <linux/platform_profile.h>
12 #include <linux/wmi.h>
14 #define WMI_INSPUR_POWERMODE_BIOS_GUID "596C31E3-332D-43C9-AEE9-585493284F5D"
16 enum inspur_wmi_method_ids
{
17 INSPUR_WMI_GET_POWERMODE
= 0x02,
18 INSPUR_WMI_SET_POWERMODE
= 0x03,
24 * 0x1: Performance Mode
25 * 0x2: Power Saver Mode
27 enum inspur_tmp_profile
{
28 INSPUR_TMP_PROFILE_BALANCE
= 0,
29 INSPUR_TMP_PROFILE_PERFORMANCE
= 1,
30 INSPUR_TMP_PROFILE_POWERSAVE
= 2,
33 struct inspur_wmi_priv
{
34 struct wmi_device
*wdev
;
35 struct platform_profile_handler handler
;
38 static int inspur_wmi_perform_query(struct wmi_device
*wdev
,
39 enum inspur_wmi_method_ids query_id
,
40 void *buffer
, size_t insize
,
43 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
44 struct acpi_buffer input
= { insize
, buffer
};
45 union acpi_object
*obj
;
49 status
= wmidev_evaluate_method(wdev
, 0, query_id
, &input
, &output
);
50 if (ACPI_FAILURE(status
)) {
51 dev_err(&wdev
->dev
, "EC Powermode control failed: %s\n",
52 acpi_format_exception(status
));
60 if (obj
->type
!= ACPI_TYPE_BUFFER
||
61 obj
->buffer
.length
!= outsize
) {
66 memcpy(buffer
, obj
->buffer
.pointer
, obj
->buffer
.length
);
74 * Set Power Mode to EC RAM. If Power Mode value greater than 0x3,
78 * Byte [0]: Power Mode:
80 * 0x1: Performance Mode
81 * 0x2: Power Saver Mode
82 * Return Value: 4 Bytes
83 * Byte [0]: Return Code
87 static int inspur_platform_profile_set(struct platform_profile_handler
*pprof
,
88 enum platform_profile_option profile
)
90 struct inspur_wmi_priv
*priv
= container_of(pprof
, struct inspur_wmi_priv
,
92 u8 ret_code
[4] = {0, 0, 0, 0};
96 case PLATFORM_PROFILE_BALANCED
:
97 ret_code
[0] = INSPUR_TMP_PROFILE_BALANCE
;
99 case PLATFORM_PROFILE_PERFORMANCE
:
100 ret_code
[0] = INSPUR_TMP_PROFILE_PERFORMANCE
;
102 case PLATFORM_PROFILE_LOW_POWER
:
103 ret_code
[0] = INSPUR_TMP_PROFILE_POWERSAVE
;
109 ret
= inspur_wmi_perform_query(priv
->wdev
, INSPUR_WMI_SET_POWERMODE
,
110 ret_code
, sizeof(ret_code
),
123 * Get Power Mode from EC RAM, If Power Mode value greater than 0x3,
126 * Return Value: 4 Bytes
127 * Byte [0]: Return Code
130 * Byte [1]: Power Mode
132 * 0x1: Performance Mode
133 * 0x2: Power Saver Mode
135 static int inspur_platform_profile_get(struct platform_profile_handler
*pprof
,
136 enum platform_profile_option
*profile
)
138 struct inspur_wmi_priv
*priv
= container_of(pprof
, struct inspur_wmi_priv
,
140 u8 ret_code
[4] = {0, 0, 0, 0};
143 ret
= inspur_wmi_perform_query(priv
->wdev
, INSPUR_WMI_GET_POWERMODE
,
144 &ret_code
, sizeof(ret_code
),
152 switch (ret_code
[1]) {
153 case INSPUR_TMP_PROFILE_BALANCE
:
154 *profile
= PLATFORM_PROFILE_BALANCED
;
156 case INSPUR_TMP_PROFILE_PERFORMANCE
:
157 *profile
= PLATFORM_PROFILE_PERFORMANCE
;
159 case INSPUR_TMP_PROFILE_POWERSAVE
:
160 *profile
= PLATFORM_PROFILE_LOW_POWER
;
169 static int inspur_wmi_probe(struct wmi_device
*wdev
, const void *context
)
171 struct inspur_wmi_priv
*priv
;
173 priv
= devm_kzalloc(&wdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
178 dev_set_drvdata(&wdev
->dev
, priv
);
180 priv
->handler
.profile_get
= inspur_platform_profile_get
;
181 priv
->handler
.profile_set
= inspur_platform_profile_set
;
183 set_bit(PLATFORM_PROFILE_LOW_POWER
, priv
->handler
.choices
);
184 set_bit(PLATFORM_PROFILE_BALANCED
, priv
->handler
.choices
);
185 set_bit(PLATFORM_PROFILE_PERFORMANCE
, priv
->handler
.choices
);
187 return platform_profile_register(&priv
->handler
);
190 static void inspur_wmi_remove(struct wmi_device
*wdev
)
192 platform_profile_remove();
195 static const struct wmi_device_id inspur_wmi_id_table
[] = {
196 { .guid_string
= WMI_INSPUR_POWERMODE_BIOS_GUID
},
200 MODULE_DEVICE_TABLE(wmi
, inspur_wmi_id_table
);
202 static struct wmi_driver inspur_wmi_driver
= {
204 .name
= "inspur-wmi-platform-profile",
205 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
207 .id_table
= inspur_wmi_id_table
,
208 .probe
= inspur_wmi_probe
,
209 .remove
= inspur_wmi_remove
,
210 .no_singleton
= true,
213 module_wmi_driver(inspur_wmi_driver
);
215 MODULE_AUTHOR("Ai Chao <aichao@kylinos.cn>");
216 MODULE_DESCRIPTION("Platform Profile Support for Inspur");
217 MODULE_LICENSE("GPL");