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/ec.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/ec.c')
-rw-r--r-- | src/ec/clevo/it5570e/ec.c | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/ec/clevo/it5570e/ec.c b/src/ec/clevo/it5570e/ec.c new file mode 100644 index 0000000000..4f10750b51 --- /dev/null +++ b/src/ec/clevo/it5570e/ec.c @@ -0,0 +1,128 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <console/console.h> +#include <cpu/x86/msr.h> +#include <device/device.h> +#include <device/mmio.h> +#include <device/pnp.h> +#include <ec/acpi/ec.h> +#include <option.h> +#include <pc80/keyboard.h> +#include <soc/msr.h> +#include <superio/conf_mode.h> + +#include "chip.h" +#include "commands.h" +#include "ec.h" + +static void pnp_configure_smfi(void) +{ + if (!CONFIG_EC_CLEVO_IT5570E_MEM_BASE) { + printk(BIOS_ERR, "EC: no LGMR base address configured. Check your config!\n"); + return; + } + + /* Check for valid address (0xfeXXX000/0xffXXX000) */ + if ((CONFIG_EC_CLEVO_IT5570E_MEM_BASE & 0xfe000fff) != 0xfe000000) { + printk(BIOS_ERR, "EC: LGMR base address 0x%08x invalid. Check your config!\n", + CONFIG_EC_CLEVO_IT5570E_MEM_BASE); + return; + } + + struct device dev = { + .path.type = DEVICE_PATH_PNP, + .path.pnp.port = 0x2e, + .path.pnp.device = IT5570E_SMFI, + }; + dev.ops->ops_pnp_mode = &pnp_conf_mode_870155_aa; + + /* Configure SMFI for LGMR */ + pnp_enter_conf_mode(&dev); + pnp_set_logical_device(&dev); + pnp_set_enable(&dev, 1); + pnp_write_config(&dev, HLPCRAMBA_24, CONFIG_EC_CLEVO_IT5570E_MEM_BASE >> 24 & 0x01); + pnp_write_config(&dev, HLPCRAMBA_23_16, CONFIG_EC_CLEVO_IT5570E_MEM_BASE >> 16 & 0xff); + pnp_write_config(&dev, HLPCRAMBA_15_12, CONFIG_EC_CLEVO_IT5570E_MEM_BASE >> 8 & 0xf0); + pnp_exit_conf_mode(&dev); +} + +static void ec_init(struct device *dev) +{ + if (!dev->enabled) + return; + + const ec_config_t *config = config_of(dev); + printk(BIOS_DEBUG, "%s init.\n", dev->chip_ops->name); + + const char *const model = ec_read_model(); + const char *const version = ec_read_fw_version(); + printk(BIOS_DEBUG, "EC FW: model %s, version %s\n", model, version); + + pnp_configure_smfi(); + + ec_set_ac_fan_always_on( + get_uint_option("ac_fan_always_on", CONFIG(EC_CLEVO_IT5570E_AC_FAN_ALWAYS_ON))); + + ec_set_kbled_timeout( + get_uint_option("kbled_timeout", CONFIG_EC_CLEVO_IT5570E_KBLED_TIMEOUT)); + + ec_set_fn_win_swap( + get_uint_option("fn_win_swap", CONFIG(EC_CLEVO_IT5570E_FN_WIN_SWAP))); + + ec_set_flexicharger( + get_uint_option("flexicharger", CONFIG(EC_CLEVO_IT5570E_FLEXICHARGER)), + get_uint_option("flexicharger_start", CONFIG_EC_CLEVO_IT5570E_FLEXICHG_START), + get_uint_option("flexicharger_stop", CONFIG_EC_CLEVO_IT5570E_FLEXICHG_STOP)); + + ec_set_camera_boot_state( + get_uint_option("camera_boot_state", CONFIG_EC_CLEVO_IT5570E_CAM_BOOT_STATE)); + + ec_set_tp_toggle_mode( + get_uint_option("tp_toggle_mode", CONFIG_EC_CLEVO_IT5570E_TP_TOGGLE_MODE)); + + /* + * The vendor abuses the field PL2B (originally named PL1T) to set PL2 via PECI on + * battery-only. With AC attached, PL2B (PL1T) gets set as PL1 and PL2T as PL2, but + * both are never enabled (bit 15). Since PL1 is never enabled, Tau isn't either. + * Thus, set PL2T, TAUT to zero, so the EC doesn't write these non-effective values. + */ + const uint16_t power_unit = 1 << (msr_read(MSR_PKG_POWER_SKU_UNIT) & 0xf); + write16p(ECRAM + PL2B, config->pl2_on_battery * power_unit); + write16p(ECRAM + PL2T, 0); + write16p(ECRAM + TAUT, 0); + + ec_set_aprd(); + + pc_keyboard_init(NO_AUX_DEVICE); +} + +static const char *ec_acpi_name(const struct device *dev) +{ + return "EC0"; +} + +static void ec_fill_ssdt_generator(const struct device *dev) +{ + ec_fan_curve_fill_ssdt(dev); +} + +static struct device_operations ec_ops = { + .init = ec_init, + .read_resources = noop_read_resources, + .set_resources = noop_set_resources, + .acpi_fill_ssdt = ec_fill_ssdt_generator, + .acpi_name = ec_acpi_name, +}; + +static void enable_dev(struct device *dev) +{ + if (dev->path.type == DEVICE_PATH_GENERIC && dev->path.generic.id == 0) + dev->ops = &ec_ops; + else + printk(BIOS_ERR, "EC: Unknown device. Check your devicetree!\n"); +} + +struct chip_operations ec_clevo_it5570e_ops = { + CHIP_NAME("Clevo IT5570E EC") + .enable_dev = enable_dev, +}; |