Skip to content

Commit 027b93c

Browse files
committed
acpi_asus_wmi(4): Handle TUF-specific hotkeys internally
- Cycle TUF laptop RGB mode on AURA key press - Switch TUF 'Throttle Thermal Policy' with 'Fan' key Sponsored by: Future Crew LLC MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D48985
1 parent d5bf6a7 commit 027b93c

File tree

1 file changed

+54
-8
lines changed

1 file changed

+54
-8
lines changed

sys/dev/acpi_support/acpi_asus_wmi.c

+54-8
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ ACPI_MODULE_NAME("ASUS-WMI")
9999
#define ASUS_WMI_DEVID_CARDREADER 0x00080013
100100
#define ASUS_WMI_DEVID_TOUCHPAD 0x00100011
101101
#define ASUS_WMI_DEVID_TOUCHPAD_LED 0x00100012
102+
#define ASUS_WMI_DEVID_TUF_RGB_MODE 0x00100056
102103
#define ASUS_WMI_DEVID_THERMAL_CTRL 0x00110011
103104
#define ASUS_WMI_DEVID_FAN_CTRL 0x00110012
104105
#define ASUS_WMI_DEVID_PROCESSOR_STATE 0x00120012
106+
#define ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY 0x00120075
105107

106108
/* DSTS masks */
107109
#define ASUS_WMI_DSTS_STATUS_BIT 0x00000001
@@ -129,6 +131,8 @@ struct acpi_asus_wmi_softc {
129131
bool event_queue;
130132
struct cdev *kbd_bkl;
131133
uint32_t kbd_bkl_level;
134+
uint32_t tuf_rgb_mode;
135+
uint32_t ttp_mode;
132136
#ifdef EVDEV_SUPPORT
133137
struct evdev_dev *evdev;
134138
#endif
@@ -272,6 +276,12 @@ static struct {
272276
.dev_id = ASUS_WMI_DEVID_PROCESSOR_STATE,
273277
.flag_rdonly = 1
274278
},
279+
{
280+
.name = "throttle_thermal_policy",
281+
.dev_id = ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
282+
.description = "Throttle Thermal Policy "
283+
"(0 - default, 1 - overboost, 2 - silent)",
284+
},
275285
{ NULL, 0, NULL, 0 }
276286
};
277287

@@ -365,7 +375,7 @@ static int acpi_asus_wmi_sysctl_set(struct acpi_asus_wmi_softc *sc, int dev_id,
365375
int arg, int oldarg);
366376
static int acpi_asus_wmi_sysctl_get(struct acpi_asus_wmi_softc *sc, int dev_id);
367377
static int acpi_asus_wmi_evaluate_method(device_t wmi_dev, int method,
368-
UINT32 arg0, UINT32 arg1, UINT32 *retval);
378+
UINT32 arg0, UINT32 arg1, UINT32 arg2, UINT32 *retval);
369379
static int acpi_wpi_asus_get_devstate(struct acpi_asus_wmi_softc *sc,
370380
UINT32 dev_id, UINT32 *retval);
371381
static int acpi_wpi_asus_set_devstate(struct acpi_asus_wmi_softc *sc,
@@ -528,14 +538,14 @@ acpi_asus_wmi_attach(device_t dev)
528538

529539
/* Initialize. */
530540
if (!acpi_asus_wmi_evaluate_method(sc->wmi_dev,
531-
ASUS_WMI_METHODID_INIT, 0, 0, &val) && bootverbose)
541+
ASUS_WMI_METHODID_INIT, 0, 0, 0, &val) && bootverbose)
532542
device_printf(dev, "Initialization: %#x\n", val);
533543
if (!acpi_asus_wmi_evaluate_method(sc->wmi_dev,
534-
ASUS_WMI_METHODID_SPEC, 0, 0x9, &val) && bootverbose)
544+
ASUS_WMI_METHODID_SPEC, 0, 0x9, 0, &val) && bootverbose)
535545
device_printf(dev, "WMI BIOS version: %d.%d\n",
536546
val >> 16, val & 0xFF);
537547
if (!acpi_asus_wmi_evaluate_method(sc->wmi_dev,
538-
ASUS_WMI_METHODID_SFUN, 0, 0, &val) && bootverbose)
548+
ASUS_WMI_METHODID_SFUN, 0, 0, 0, &val) && bootverbose)
539549
device_printf(dev, "SFUN value: %#x\n", val);
540550

541551
ACPI_SERIAL_BEGIN(asus_wmi);
@@ -720,6 +730,13 @@ acpi_asus_wmi_sysctl_get(struct acpi_asus_wmi_softc *sc, int dev_id)
720730
ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
721731
ACPI_SERIAL_ASSERT(asus_wmi);
722732

733+
switch(dev_id) {
734+
case ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY:
735+
return (sc->ttp_mode);
736+
default:
737+
break;
738+
}
739+
723740
acpi_wpi_asus_get_devstate(sc, dev_id, &val);
724741

725742
switch(dev_id) {
@@ -758,6 +775,10 @@ acpi_asus_wmi_sysctl_set(struct acpi_asus_wmi_softc *sc, int dev_id, int arg, in
758775
if (arg != 0)
759776
arg |= 0x80;
760777
break;
778+
case ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY:
779+
arg = min(0x2, arg);
780+
sc->ttp_mode = arg;
781+
break;
761782
}
762783

763784
acpi_wpi_asus_set_devstate(sc, dev_id, arg, NULL);
@@ -848,6 +869,31 @@ acpi_asus_wmi_handle_event(struct acpi_asus_wmi_softc *sc, int code)
848869
acpi_wpi_asus_set_devstate(sc,
849870
ASUS_WMI_DEVID_TOUCHPAD, val, NULL);
850871
}
872+
/* Throttle thermal policy control. */
873+
if (code == 0xae) {
874+
sc->ttp_mode++;
875+
if (sc->ttp_mode > 2)
876+
sc->ttp_mode = 0;
877+
acpi_wpi_asus_set_devstate(sc,
878+
ASUS_WMI_DEVID_THROTTLE_THERMAL_POLICY,
879+
sc->ttp_mode, NULL);
880+
}
881+
/* TUF laptop RGB mode control. */
882+
if (code == 0xb3) {
883+
const uint32_t cmd = 0xb4; /* Save to BIOS */
884+
const uint32_t r = 0xff, g = 0xff, b = 0xff;
885+
const uint32_t speed = 0xeb; /* Medium */
886+
if (sc->tuf_rgb_mode < 2)
887+
sc->tuf_rgb_mode++;
888+
else if (sc->tuf_rgb_mode == 2)
889+
sc->tuf_rgb_mode = 10;
890+
else sc->tuf_rgb_mode = 0;
891+
acpi_asus_wmi_evaluate_method(sc->wmi_dev,
892+
ASUS_WMI_METHODID_DEVS,
893+
ASUS_WMI_DEVID_TUF_RGB_MODE,
894+
cmd | (sc->tuf_rgb_mode << 8) | (r << 16) | (g << 24),
895+
b | (speed << 8), NULL);
896+
}
851897
}
852898
}
853899

@@ -882,9 +928,9 @@ acpi_asus_wmi_notify(ACPI_HANDLE h, UINT32 notify, void *context)
882928

883929
static int
884930
acpi_asus_wmi_evaluate_method(device_t wmi_dev, int method,
885-
UINT32 arg0, UINT32 arg1, UINT32 *retval)
931+
UINT32 arg0, UINT32 arg1, UINT32 arg2, UINT32 *retval)
886932
{
887-
UINT32 params[2] = { arg0, arg1 };
933+
UINT32 params[3] = { arg0, arg1, arg2 };
888934
UINT32 result;
889935
ACPI_OBJECT *obj;
890936
ACPI_BUFFER in = { sizeof(params), &params };
@@ -912,7 +958,7 @@ acpi_wpi_asus_get_devstate(struct acpi_asus_wmi_softc *sc,
912958
{
913959

914960
return (acpi_asus_wmi_evaluate_method(sc->wmi_dev,
915-
sc->dsts_id, dev_id, 0, retval));
961+
sc->dsts_id, dev_id, 0, 0, retval));
916962
}
917963

918964
static int
@@ -921,7 +967,7 @@ acpi_wpi_asus_set_devstate(struct acpi_asus_wmi_softc *sc,
921967
{
922968

923969
return (acpi_asus_wmi_evaluate_method(sc->wmi_dev,
924-
ASUS_WMI_METHODID_DEVS, dev_id, ctrl_param, retval));
970+
ASUS_WMI_METHODID_DEVS, dev_id, ctrl_param, 0, retval));
925971
}
926972

927973
static int

0 commit comments

Comments
 (0)