1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/pnp.h>
7 #include <pc80/keyboard.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)
30 outb(0, MAILBOX_INDEX
);
31 busy
= inb(MAILBOX_DATA
);
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__
);
44 *data
= __get_mailbox_register(start
);
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__
);
60 __set_mailbox_register(start
, *data
);
68 static void ec_command(u8 cmd
)
70 outb(0, MAILBOX_INDEX
);
71 outb(cmd
, MAILBOX_DATA
);
75 u8
mec5035_mouse_touchpad(u8 setting
)
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);
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
[] = {
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
,