soc/intel/ptl: Update ME specification version to 21
[coreboot.git] / src / ec / starlabs / merlin / ite.c
blob2f8bced3241ac26ac2fa011c3787d3ed2b044d9c
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pnp.h>
6 #include <ec/acpi/ec.h>
7 #include <option.h>
9 #include "ec.h"
10 #include "ecdefs.h"
12 #define ITE_IT5570 0x5570
13 #define ITE_IT8987 0x8987
15 uint16_t ec_get_version(void)
17 return (ec_read(ECRAM_MAJOR_VERSION) << 8) | ec_read(ECRAM_MINOR_VERSION);
20 static uint8_t get_ec_value_from_option(const char *name,
21 unsigned int fallback,
22 const uint8_t *lut,
23 size_t lut_size)
25 unsigned int index = get_uint_option(name, fallback);
26 if (index >= lut_size)
27 index = fallback;
28 return lut[index];
31 static uint16_t ec_get_chip_id(unsigned int port)
33 return (pnp_read_index(port, ITE_CHIPID1) << 8) |
34 pnp_read_index(port, ITE_CHIPID2);
37 static void merlin_init(struct device *dev)
39 if (!dev->enabled)
40 return;
43 * The address/data IO port pair for the ite EC are configurable
44 * through the EC domain and are fixed by the EC's firmware blob. If
45 * the value(s) passed through the "dev" structure don't match the
46 * expected values then output severe warnings.
48 if (dev->path.pnp.port != ITE_FIXED_ADDR) {
49 printk(BIOS_ERR, "ITE: Incorrect ports defined in devicetree.cb.\n");
50 printk(BIOS_ERR, "ITE: Serious operational issues will arise.\n");
51 return;
54 const uint16_t chip_id = ec_get_chip_id(dev->path.pnp.port);
56 if (chip_id != ITE_IT5570 && chip_id != ITE_IT8987) {
57 printk(BIOS_ERR, "ITE: Unsupported chip ID 0x%04x.\n", chip_id);
58 return;
62 * Restore settings from CMOS into EC RAM:
64 * kbl_timeout
65 * fn_ctrl_swap
66 * max_charge
67 * fan_mode
68 * fn_lock_state
69 * trackpad_state
70 * kbl_brightness
71 * kbl_state
75 * Keyboard Backlight Timeout
77 * Setting: kbl_timeout
79 * Values: 30 Seconds, 1 Minute, 3 Minutes, 5 Minutes, Never
80 * Default: 30 Seconds
83 const uint8_t kbl_timeout[] = {
84 SEC_30,
85 MIN_1,
86 MIN_3,
87 MIN_5,
88 NEVER
91 ec_write(ECRAM_KBL_TIMEOUT,
92 get_ec_value_from_option("kbl_timeout",
94 kbl_timeout,
95 ARRAY_SIZE(kbl_timeout)));
98 * Fn Ctrl Reverse
100 * Setting: fn_ctrl_swap
102 * Values: Enabled, Disabled
103 * Default: Disabled
106 const uint8_t fn_ctrl_swap[] = {
107 FN_CTRL,
108 CTRL_FN
111 ec_write(ECRAM_FN_CTRL_REVERSE,
112 get_ec_value_from_option("fn_ctrl_swap",
114 fn_ctrl_swap,
115 ARRAY_SIZE(fn_ctrl_swap)));
118 * Maximum Charge Level
120 * Setting: max_charge
122 * Values: 60%, 80%, 100%
123 * Default: 100%
126 const uint8_t max_charge[] = {
127 CHARGE_100,
128 CHARGE_80,
129 CHARGE_60
132 if (CONFIG(EC_STARLABS_MAX_CHARGE))
133 ec_write(ECRAM_MAX_CHARGE,
134 get_ec_value_from_option("max_charge",
136 max_charge,
137 ARRAY_SIZE(max_charge)));
140 * Fan Mode
142 * Setting: fan_mode
144 * Values: Quiet, Normal, Aggressive
145 * Default: Normal
148 const uint8_t fan_mode[] = {
149 FAN_NORMAL,
150 FAN_AGGRESSIVE,
151 FAN_QUIET
154 if (CONFIG(EC_STARLABS_FAN))
155 ec_write(ECRAM_FAN_MODE,
156 get_ec_value_from_option("fan_mode",
158 fan_mode,
159 ARRAY_SIZE(fan_mode)));
162 * Function Lock
164 * Setting: fn_lock_state
166 * Values: Locked, Unlocked
167 * Default: Locked
170 const uint8_t fn_lock_state[] = {
171 UNLOCKED,
172 LOCKED
175 ec_write(ECRAM_FN_LOCK_STATE,
176 get_ec_value_from_option("fn_lock_state",
178 fn_lock_state,
179 ARRAY_SIZE(fn_lock_state)));
182 * Trackpad State
184 * Setting: trackpad_state
186 * Values: Enabled, Disabled
187 * Default: Enabled
190 const uint8_t trackpad_state[] = {
191 TRACKPAD_ENABLED,
192 TRACKPAD_DISABLED
195 ec_write(ECRAM_TRACKPAD_STATE,
196 get_ec_value_from_option("trackpad_state",
198 trackpad_state,
199 ARRAY_SIZE(trackpad_state)));
202 * Keyboard Backlight Brightness
204 * Setting: kbl_brightness
206 * Values: Off, Low, High / Off, On
207 * Default: Low
210 const uint8_t kbl_brightness[] = {
211 KBL_ON,
212 KBL_OFF,
213 KBL_LOW,
214 KBL_HIGH
217 if (CONFIG(EC_STARLABS_KBL_LEVELS))
218 ec_write(ECRAM_KBL_BRIGHTNESS,
219 get_ec_value_from_option("kbl_brightness",
221 kbl_brightness,
222 ARRAY_SIZE(kbl_brightness)));
223 else
224 ec_write(ECRAM_KBL_BRIGHTNESS,
225 get_ec_value_from_option("kbl_brightness",
227 kbl_brightness,
228 ARRAY_SIZE(kbl_brightness)));
231 * Keyboard Backlight State
233 * Setting: kbl_state
235 * Values: Off, On
236 * Default: On
238 * Note: Always enable, as the brightness level of `off` disables it.
242 ec_write(ECRAM_KBL_STATE, KBL_ENABLED);
245 static struct device_operations ops = {
246 .init = merlin_init,
247 .read_resources = noop_read_resources,
248 .set_resources = noop_set_resources,
251 static struct pnp_info pnp_dev_info[] = {
252 /* Serial Port 1 (UART1) */
253 { NULL, ITE_SP1, PNP_IO0 | PNP_IRQ0, 0x0ff8, },
254 /* Serial Port 2 (UART2) */
255 { NULL, ITE_SP2, PNP_IO0 | PNP_IRQ0, 0x0ff8, },
256 /* System Wake-Up Control (SWUC) */
257 { NULL, ITE_SWUC, PNP_IO0 | PNP_IRQ0, 0xfff0, },
258 /* KBC / Mouse Interface */
259 { NULL, ITE_SWUC, PNP_IRQ0, },
260 /* KBC / Keyboard Interface */
261 { NULL, ITE_KBCK, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
262 /* Consumer IR (CIR) */
263 { NULL, ITE_IR, PNP_IO0 | PNP_IRQ0, 0xfff8, },
264 /* Shared Memory / Flash Interface (SMFI) */
265 { NULL, ITE_SMFI, PNP_IO0 | PNP_IRQ0, 0xfff0, },
266 /* RTC-like Timer (RCTC) */
267 { NULL, ITE_RTCT, PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_IO3 | PNP_IRQ0,
268 0xfffe, 0xfffe, 0xfffe, 0xfffe, },
269 /* Power Management I/F Channel 1 (PMC1) */
270 { NULL, ITE_PMC1, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
271 /* Power Management I/F Channel 2 (PMC2) */
272 { NULL, ITE_PMC2, PNP_IO0 | PNP_IO1 | PNP_IO2 | PNP_IRQ0, 0x07fc,
273 0x07fc, 0xfff0, },
274 /* Serial Peripheral Interface (SSPI) */
275 { NULL, ITE_SSPI, PNP_IO0 | PNP_IRQ0, 0xfff8, },
276 /* Platform Environment Control Interface (PECI) */
277 { NULL, ITE_PECI, PNP_IRQ0, 0xfff8, },
278 /* Power Management I/F Channel 3 (PMC3) */
279 { NULL, ITE_PMC3, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
280 /* Power Management I/F Channel 4 (PMC4) */
281 { NULL, ITE_PMC4, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
282 /* Power Management I/F Channel 5 (PMC5) */
283 { NULL, ITE_PMC5, PNP_IO0 | PNP_IO1 | PNP_IRQ0, 0x07ff, 0x07ff, },
286 static void enable_dev(struct device *dev)
288 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
291 struct chip_operations ec_starlabs_merlin_ops = {
292 .name = "ITE EC",
293 .enable_dev = enable_dev