From e1e65cb0f1cad6117d48503f2f78d115caecc55b Mon Sep 17 00:00:00 2001 From: Michael Niewöhner Date: Wed, 1 Dec 2021 19:09:13 +0100 Subject: ec/clevo/it5570e: add driver for EC used on various Clevo laptops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ć Co-authored-by: Michał Żygowski Co-authored-by: Michael Niewöhner Signed-off-by: Michał Kopeć Signed-off-by: Michał Żygowski Signed-off-by: Michael Niewöhner Reviewed-on: https://review.coreboot.org/c/coreboot/+/68791 Tested-by: build bot (Jenkins) Reviewed-by: Angel Pons --- src/ec/clevo/it5570e/i2ec.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/ec/clevo/it5570e/i2ec.c (limited to 'src/ec/clevo/it5570e/i2ec.c') diff --git a/src/ec/clevo/it5570e/i2ec.c b/src/ec/clevo/it5570e/i2ec.c new file mode 100644 index 0000000000..2d7dd6c37c --- /dev/null +++ b/src/ec/clevo/it5570e/i2ec.c @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include + +#include "i2ec.h" + +#define SIO_DEV PNP_DEV(0x2e, 0) + +/* SIO depth 2 index/data pair */ +#define D2ADR 0x2e +#define D2DAT 0x2f + +/* SIO depth 2 address space */ +#define I2EC_ADDR_L 0x10 +#define I2EC_ADDR_H 0x11 +#define I2EC_DATA 0x12 + +/* + * Read/write SIO "depth 2" registers + */ + +static uint8_t sio_d2_read(uint8_t addr) +{ + pnp_write_config(SIO_DEV, D2ADR, addr); + return pnp_read_config(SIO_DEV, D2DAT); +} + +static void sio_d2_write(uint8_t addr, uint8_t val) +{ + pnp_write_config(SIO_DEV, D2ADR, addr); + pnp_write_config(SIO_DEV, D2DAT, val); +} + +/* + * Read/write I2EC registers through SIO "depth 2" address space + */ + +uint8_t ec_d2i2ec_read(uint16_t addr) +{ + sio_d2_write(I2EC_ADDR_H, addr >> 8 & 0xff); + sio_d2_write(I2EC_ADDR_L, addr & 0xff); + return sio_d2_read(I2EC_DATA); +} + +void ec_d2i2ec_write(uint16_t addr, uint8_t val) +{ + sio_d2_write(I2EC_ADDR_H, addr >> 8 & 0xff); + sio_d2_write(I2EC_ADDR_L, addr & 0xff); + sio_d2_write(I2EC_DATA, val); +} -- cgit v1.2.3