Michael Niewöhner | e1e65cb | 2021-12-01 19:09:13 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <cpu/x86/msr.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/mmio.h> |
| 7 | #include <device/pnp.h> |
| 8 | #include <ec/acpi/ec.h> |
| 9 | #include <option.h> |
| 10 | #include <pc80/keyboard.h> |
| 11 | #include <soc/msr.h> |
| 12 | #include <superio/conf_mode.h> |
| 13 | |
| 14 | #include "chip.h" |
| 15 | #include "commands.h" |
| 16 | #include "ec.h" |
| 17 | |
| 18 | static void pnp_configure_smfi(void) |
| 19 | { |
| 20 | if (!CONFIG_EC_CLEVO_IT5570E_MEM_BASE) { |
| 21 | printk(BIOS_ERR, "EC: no LGMR base address configured. Check your config!\n"); |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | /* Check for valid address (0xfeXXX000/0xffXXX000) */ |
| 26 | if ((CONFIG_EC_CLEVO_IT5570E_MEM_BASE & 0xfe000fff) != 0xfe000000) { |
| 27 | printk(BIOS_ERR, "EC: LGMR base address 0x%08x invalid. Check your config!\n", |
| 28 | CONFIG_EC_CLEVO_IT5570E_MEM_BASE); |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | struct device dev = { |
| 33 | .path.type = DEVICE_PATH_PNP, |
| 34 | .path.pnp.port = 0x2e, |
| 35 | .path.pnp.device = IT5570E_SMFI, |
| 36 | }; |
| 37 | dev.ops->ops_pnp_mode = &pnp_conf_mode_870155_aa; |
| 38 | |
| 39 | /* Configure SMFI for LGMR */ |
| 40 | pnp_enter_conf_mode(&dev); |
| 41 | pnp_set_logical_device(&dev); |
| 42 | pnp_set_enable(&dev, 1); |
| 43 | pnp_write_config(&dev, HLPCRAMBA_24, CONFIG_EC_CLEVO_IT5570E_MEM_BASE >> 24 & 0x01); |
| 44 | pnp_write_config(&dev, HLPCRAMBA_23_16, CONFIG_EC_CLEVO_IT5570E_MEM_BASE >> 16 & 0xff); |
| 45 | pnp_write_config(&dev, HLPCRAMBA_15_12, CONFIG_EC_CLEVO_IT5570E_MEM_BASE >> 8 & 0xf0); |
| 46 | pnp_exit_conf_mode(&dev); |
| 47 | } |
| 48 | |
| 49 | static void ec_init(struct device *dev) |
| 50 | { |
| 51 | if (!dev->enabled) |
| 52 | return; |
| 53 | |
| 54 | const ec_config_t *config = config_of(dev); |
| 55 | printk(BIOS_DEBUG, "%s init.\n", dev->chip_ops->name); |
| 56 | |
| 57 | const char *const model = ec_read_model(); |
| 58 | const char *const version = ec_read_fw_version(); |
| 59 | printk(BIOS_DEBUG, "EC FW: model %s, version %s\n", model, version); |
| 60 | |
| 61 | pnp_configure_smfi(); |
| 62 | |
| 63 | ec_set_ac_fan_always_on( |
| 64 | get_uint_option("ac_fan_always_on", CONFIG(EC_CLEVO_IT5570E_AC_FAN_ALWAYS_ON))); |
| 65 | |
| 66 | ec_set_kbled_timeout( |
| 67 | get_uint_option("kbled_timeout", CONFIG_EC_CLEVO_IT5570E_KBLED_TIMEOUT)); |
| 68 | |
| 69 | ec_set_fn_win_swap( |
| 70 | get_uint_option("fn_win_swap", CONFIG(EC_CLEVO_IT5570E_FN_WIN_SWAP))); |
| 71 | |
| 72 | ec_set_flexicharger( |
| 73 | get_uint_option("flexicharger", CONFIG(EC_CLEVO_IT5570E_FLEXICHARGER)), |
| 74 | get_uint_option("flexicharger_start", CONFIG_EC_CLEVO_IT5570E_FLEXICHG_START), |
| 75 | get_uint_option("flexicharger_stop", CONFIG_EC_CLEVO_IT5570E_FLEXICHG_STOP)); |
| 76 | |
| 77 | ec_set_camera_boot_state( |
| 78 | get_uint_option("camera_boot_state", CONFIG_EC_CLEVO_IT5570E_CAM_BOOT_STATE)); |
| 79 | |
| 80 | ec_set_tp_toggle_mode( |
| 81 | get_uint_option("tp_toggle_mode", CONFIG_EC_CLEVO_IT5570E_TP_TOGGLE_MODE)); |
| 82 | |
| 83 | /* |
| 84 | * The vendor abuses the field PL2B (originally named PL1T) to set PL2 via PECI on |
| 85 | * battery-only. With AC attached, PL2B (PL1T) gets set as PL1 and PL2T as PL2, but |
| 86 | * both are never enabled (bit 15). Since PL1 is never enabled, Tau isn't either. |
| 87 | * Thus, set PL2T, TAUT to zero, so the EC doesn't write these non-effective values. |
| 88 | */ |
| 89 | const uint16_t power_unit = 1 << (msr_read(MSR_PKG_POWER_SKU_UNIT) & 0xf); |
| 90 | write16p(ECRAM + PL2B, config->pl2_on_battery * power_unit); |
| 91 | write16p(ECRAM + PL2T, 0); |
| 92 | write16p(ECRAM + TAUT, 0); |
| 93 | |
| 94 | ec_set_aprd(); |
| 95 | |
| 96 | pc_keyboard_init(NO_AUX_DEVICE); |
| 97 | } |
| 98 | |
| 99 | static const char *ec_acpi_name(const struct device *dev) |
| 100 | { |
| 101 | return "EC0"; |
| 102 | } |
| 103 | |
| 104 | static void ec_fill_ssdt_generator(const struct device *dev) |
| 105 | { |
| 106 | ec_fan_curve_fill_ssdt(dev); |
| 107 | } |
| 108 | |
| 109 | static struct device_operations ec_ops = { |
| 110 | .init = ec_init, |
| 111 | .read_resources = noop_read_resources, |
| 112 | .set_resources = noop_set_resources, |
| 113 | .acpi_fill_ssdt = ec_fill_ssdt_generator, |
| 114 | .acpi_name = ec_acpi_name, |
| 115 | }; |
| 116 | |
| 117 | static void enable_dev(struct device *dev) |
| 118 | { |
| 119 | if (dev->path.type == DEVICE_PATH_GENERIC && dev->path.generic.id == 0) |
| 120 | dev->ops = &ec_ops; |
| 121 | else |
| 122 | printk(BIOS_ERR, "EC: Unknown device. Check your devicetree!\n"); |
| 123 | } |
| 124 | |
| 125 | struct chip_operations ec_clevo_it5570e_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 126 | .name = "Clevo IT5570E EC", |
Michael Niewöhner | e1e65cb | 2021-12-01 19:09:13 +0100 | [diff] [blame] | 127 | .enable_dev = enable_dev, |
| 128 | }; |