diff options
author | Michael Niewöhner <foss@mniewoehner.de> | 2021-12-01 19:09:13 +0100 |
---|---|---|
committer | Michael Niewöhner <foss@mniewoehner.de> | 2022-11-11 22:42:46 +0000 |
commit | e1e65cb0f1cad6117d48503f2f78d115caecc55b (patch) | |
tree | b6d42b3968fd2e6d57062031a48ac65123bb03ca /src/ec/clevo/it5570e/ssdt.c | |
parent | 064c6ced40a0acd7c4127414ee04c90b3a458751 (diff) |
ec/clevo/it5570e: add driver for EC used on various Clevo laptops
This adds a driver for the ITE IT5570E EC in combination with Clevo
vendor EC firmware. The interface is mostly identical on various laptop
models. Thus, we have implemented one common driver to support them all.
The following features were implemented:
- Basics like battery, ac, etc.
- Suspend/hibernate support: S0ix, S3*, S4/S5
- Save/restore of keyboard backlight level during S0ix without the need
for Clevo vendor software (ControlCenter)
- Flexicharger
- Fn keys (backlight, volume, airplane etc.)
- Various configuration options via Kconfig / CMOS options
* Note: S3 support works at least on L140CU (Cometlake), but it's not
enabled for this board because S0ix is used.
Not implemented, yet:
- Type-C UCSI: the EC firmware seems to be buggy (with vendor fw, too)
- dGPU support is WIP
An example of how this driver can be hooked up by a board can be seen in
in change CB:59850, where support for the L140MU is added.
Known issues:
- Touchpad toggle:
The touchpad toggle (Fn-F1) has two modes, Ctrl-Alt-F9 mode and
keycodes 0xf7/0xf8 mode. Ctrl-Alt-F9 is the native touchpad toggle
shortcut on Windows. On Linux this would switch to virtual console 9,
if enabled. Thus, one should use the keycodes mode and add udev
rules as specified in [1]. If VT9 is disabled, Ctrl-Alt-F9 mode could
be used to set up a keyboard shortcut command toggling the touchpad.
- Multi-fan systems
The Clevo NV41MZ (w/o dGPU) has two fans that should be in-sync.
However, the second fan does not spin. This needs further
investigation.
[1] https://docs.dasharo.com/variants/clevo_nv41/post_install/
Testing the various functionalities of this EC driver was done in the
changes hooking up this driver for the boards.
Change-Id: Ic8c0bee9002ad9edcd10c83b775fc723744caaa0
Co-authored-by: Michał Kopeć <michal.kopec@3mdeb.com>
Co-authored-by: Michał Żygowski <michal.zygowski@3mdeb.com>
Co-authored-by: Michael Niewöhner <foss@mniewoehner.de>
Signed-off-by: Michał Kopeć <michal.kopec@3mdeb.com>
Signed-off-by: Michał Żygowski <michal.zygowski@3mdeb.com>
Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/68791
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Diffstat (limited to 'src/ec/clevo/it5570e/ssdt.c')
-rw-r--r-- | src/ec/clevo/it5570e/ssdt.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/src/ec/clevo/it5570e/ssdt.c b/src/ec/clevo/it5570e/ssdt.c new file mode 100644 index 0000000000..a0d746ac00 --- /dev/null +++ b/src/ec/clevo/it5570e/ssdt.c @@ -0,0 +1,152 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <acpi/acpigen.h> +#include <console/console.h> +#include <device/device.h> +#include <device/mmio.h> + +#include "chip.h" +#include "ec.h" +#include "commands.h" + +static bool is_curve_valid(struct ec_clevo_it5570e_fan_curve curve) +{ + /* + * Fan curve speeds have to be non-decreasing. + * Fan curve temperatures have to be increasing (to avoid division by 0). + * This also covers the case when the curve is all zeroes (i.e. not configured). + */ + + for (int i = 1; i < IT5570E_FAN_CURVE_LEN; i++) { + if (curve.speed[i] < curve.speed[i - 1] || + curve.temperature[i] <= curve.temperature[i - 1]) + return false; + } + + return true; +} + +static void write_fan_curve(struct ec_clevo_it5570e_fan_curve curve, int fan) +{ + uint16_t ramp; + char fieldname[5]; + + /* Curve points */ + for (int i = 0; i < IT5570E_FAN_CURVE_LEN; i++) { + snprintf(fieldname, 5, "F%dT%d", fan + 1, i + 1); + acpigen_write_store_int_to_namestr(curve.temperature[i], fieldname); + snprintf(fieldname, 5, "F%dD%d", fan + 1, i + 1); + acpigen_write_store_int_to_namestr(curve.speed[i] * 255 / 100, fieldname); + } + + /* Ramps */ + for (int i = 0; i < (IT5570E_FAN_CURVE_LEN - 1); i++) { + ramp = 255 * 16 * + (curve.speed[i + 1] - curve.speed[i]) / + (curve.temperature[i + 1] - curve.temperature[i]) / + 100; + + snprintf(fieldname, 5, "F%dR%d", fan + 1, i + 1); + acpigen_write_store_int_to_namestr(ramp, fieldname); + } +} + +static void write_fan_opregion(int fan_cnt) +{ + char fieldname[5]; + uint8_t flags = FIELD_ANYACC | FIELD_LOCK | FIELD_PRESERVE; + struct opregion opreg = { + .name = "FNCV", + .regionspace = SYSTEMMEMORY, + .regionoffset = CONFIG_EC_CLEVO_IT5570E_MEM_BASE + 0x38c, + .regionlen = fan_cnt * 14, + }; + + acpigen_write_opregion(&opreg); + acpigen_emit_ext_op(FIELD_OP); + acpigen_write_len_f(); + acpigen_emit_namestring(opreg.name); + acpigen_emit_byte(flags); + + for (int fan = 1; fan <= fan_cnt; fan++) { + /* temps */ + for (int i = 1; i <= IT5570E_FAN_CURVE_LEN; i++) { + snprintf(fieldname, 5, "F%dT%d", fan, i); + acpigen_write_field_name(fieldname, 8); + } + + /* duties */ + for (int i = 1; i <= IT5570E_FAN_CURVE_LEN; i++) { + snprintf(fieldname, 5, "F%dD%d", fan, i); + acpigen_write_field_name(fieldname, 8); + } + + /* ramps */ + for (int i = 1; i < IT5570E_FAN_CURVE_LEN; i++) { + snprintf(fieldname, 5, "F%dR%d", fan, i); + acpigen_write_field_name(fieldname, 16); + } + } + + acpigen_pop_len(); /* Field */ +} + +/* + * Set Fan curve + * The function must exist even if the fan curve isn't enabled in devicetree. + */ +void ec_fan_curve_fill_ssdt(const struct device *dev) +{ + const ec_config_t *config = config_of(dev); + const int fan_cnt = read8p(ECRAM + FANC); + + acpigen_write_scope(acpi_device_path(dev)); + write_fan_opregion(fan_cnt); + acpigen_write_method("SFCV", 0); + + if (config->fan_mode == FAN_MODE_CUSTOM) { + int curve_cnt = 0; + + /* Check curve count against fan count from EC */ + for (int i = 0; i < IT5570E_MAX_FAN_CNT; i++) + if (*config->fan_curves[i].speed && *config->fan_curves[i].temperature) + curve_cnt++; + + if (curve_cnt != fan_cnt) { + printk(BIOS_WARNING, + "EC: Fan curve count (%d) does not match fan count (%d). " + "Check your devicetree!\n", curve_cnt, fan_cnt); + goto pop; + } + + /* + * Check all curves. + * Custom mode can only be enabled for all fans or none. Thus, all + * custom curves must be valid before custom mode can be enabled. + */ + bool error = false; + for (int i = 0; i < fan_cnt; i++) { + if (!is_curve_valid(config->fan_curves[i])) { + printk(BIOS_ERR, + "EC: Fan %d curve invalid. Check your devicetree!\n", i); + error = true; + } + } + if (error) + goto pop; + + acpigen_write_debug_string("EC: Apply custom fan curve"); + + for (int i = 0; i < fan_cnt; i++) + write_fan_curve(config->fan_curves[i], i); + + /* Enable custom fan mode */ + acpigen_write_store_int_to_namestr(0x04, "FDAT"); + acpigen_emit_namestring("SFCC"); + acpigen_write_integer(0xd7); + } + +pop: + acpigen_pop_len(); /* Method */ + acpigen_pop_len(); /* Scope */ +} |