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>
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
,
25 unsigned int index
= get_uint_option(name
, fallback
);
26 if (index
>= lut_size
)
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
)
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");
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
);
62 * Restore settings from CMOS into EC RAM:
75 * Keyboard Backlight Timeout
77 * Setting: kbl_timeout
79 * Values: 30 Seconds, 1 Minute, 3 Minutes, 5 Minutes, Never
83 const uint8_t kbl_timeout
[] = {
91 ec_write(ECRAM_KBL_TIMEOUT
,
92 get_ec_value_from_option("kbl_timeout",
95 ARRAY_SIZE(kbl_timeout
)));
100 * Setting: fn_ctrl_swap
102 * Values: Enabled, Disabled
106 const uint8_t fn_ctrl_swap
[] = {
111 ec_write(ECRAM_FN_CTRL_REVERSE
,
112 get_ec_value_from_option("fn_ctrl_swap",
115 ARRAY_SIZE(fn_ctrl_swap
)));
118 * Maximum Charge Level
120 * Setting: max_charge
122 * Values: 60%, 80%, 100%
126 const uint8_t max_charge
[] = {
132 if (CONFIG(EC_STARLABS_MAX_CHARGE
))
133 ec_write(ECRAM_MAX_CHARGE
,
134 get_ec_value_from_option("max_charge",
137 ARRAY_SIZE(max_charge
)));
144 * Values: Quiet, Normal, Aggressive
148 const uint8_t fan_mode
[] = {
154 if (CONFIG(EC_STARLABS_FAN
))
155 ec_write(ECRAM_FAN_MODE
,
156 get_ec_value_from_option("fan_mode",
159 ARRAY_SIZE(fan_mode
)));
164 * Setting: fn_lock_state
166 * Values: Locked, Unlocked
170 const uint8_t fn_lock_state
[] = {
175 ec_write(ECRAM_FN_LOCK_STATE
,
176 get_ec_value_from_option("fn_lock_state",
179 ARRAY_SIZE(fn_lock_state
)));
184 * Setting: trackpad_state
186 * Values: Enabled, Disabled
190 const uint8_t trackpad_state
[] = {
195 ec_write(ECRAM_TRACKPAD_STATE
,
196 get_ec_value_from_option("trackpad_state",
199 ARRAY_SIZE(trackpad_state
)));
202 * Keyboard Backlight Brightness
204 * Setting: kbl_brightness
206 * Values: Off, Low, High / Off, On
210 const uint8_t kbl_brightness
[] = {
217 if (CONFIG(EC_STARLABS_KBL_LEVELS
))
218 ec_write(ECRAM_KBL_BRIGHTNESS
,
219 get_ec_value_from_option("kbl_brightness",
222 ARRAY_SIZE(kbl_brightness
)));
224 ec_write(ECRAM_KBL_BRIGHTNESS
,
225 get_ec_value_from_option("kbl_brightness",
228 ARRAY_SIZE(kbl_brightness
)));
231 * Keyboard Backlight State
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
= {
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,
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
= {
293 .enable_dev
= enable_dev