soc/intel/alderlake: Add ADL-P 4+4 with 28W TDP
[coreboot.git] / src / ec / dell / mec5035 / mec5035.c
blob8da11e5b1cc3d4c5a2a964627d257fbf19458e73
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <arch/io.h>
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/pnp.h>
7 #include <pc80/keyboard.h>
8 #include <stdint.h>
9 #include "mec5035.h"
11 static const u16 MAILBOX_INDEX = 0x910;
12 static const u16 MAILBOX_DATA = MAILBOX_INDEX + 1;
14 static inline u8 __get_mailbox_register(u8 index)
16 outb(index + 0x10, MAILBOX_INDEX);
17 return inb(MAILBOX_DATA);
20 static inline void __set_mailbox_register(u8 index, u8 data)
22 outb(index + 0x10, MAILBOX_INDEX);
23 outb(data, MAILBOX_DATA);
26 static void wait_ec(void)
28 u8 busy;
29 do {
30 outb(0, MAILBOX_INDEX);
31 busy = inb(MAILBOX_DATA);
32 } while (busy);
36 static enum cb_err read_mailbox_regs(u8 *data, u8 start, u8 count)
38 if (start + count >= NUM_REGISTERS) {
39 printk(BIOS_ERR, "%s: Invalid start or count argument.\n", __func__);
40 return CB_ERR_ARG;
43 while (count--) {
44 *data = __get_mailbox_register(start);
45 data++;
46 start++;
49 return CB_SUCCESS;
52 static enum cb_err write_mailbox_regs(const u8 *data, u8 start, u8 count)
54 if (start + count >= NUM_REGISTERS) {
55 printk(BIOS_ERR, "%s: Invalid start or count argument.\n", __func__);
56 return CB_ERR_ARG;
59 while (count--) {
60 __set_mailbox_register(start, *data);
61 data++;
62 start++;
65 return CB_SUCCESS;
68 static void ec_command(u8 cmd)
70 outb(0, MAILBOX_INDEX);
71 outb(cmd, MAILBOX_DATA);
72 wait_ec();
75 u8 mec5035_mouse_touchpad(u8 setting)
77 u8 buf[15] = {0};
78 write_mailbox_regs(&setting, 2, 1);
79 ec_command(CMD_MOUSE_TP);
80 /* The vendor firmware reads 15 bytes starting at index 1, presumably
81 to get some sort of return code. Though I don't know for sure if
82 this is the case. Assume the first byte is the return code. */
83 read_mailbox_regs(buf, 1, 15);
84 return buf[0];
87 void mec5035_early_init(void)
89 /* If this isn't sent the EC shuts down the system after about 15
90 seconds, flashing a pattern on the keyboard LEDs corresponding
91 to "processor failure" according to Dell service manuals. */
92 ec_command(CMD_CPU_OK);
95 static void mec5035_init(struct device *dev)
97 /* Unconditionally use this argument for now as this setting
98 is probably the most sensible default out of the 3 choices. */
99 mec5035_mouse_touchpad(TP_PS2_MOUSE);
101 pc_keyboard_init(NO_AUX_DEVICE);
104 static struct device_operations ops = {
105 .init = mec5035_init,
106 .read_resources = noop_read_resources,
107 .set_resources = noop_set_resources
110 static struct pnp_info pnp_dev_info[] = {
111 { NULL, 0, 0, 0, }
114 static void mec5035_enable(struct device *dev)
116 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
119 struct chip_operations ec_dell_mec5035_ops = {
120 CHIP_NAME("MEC5035 EC")
121 .enable_dev = mec5035_enable,