Makefile.inc: Remove workaround ACPI warnings
[coreboot.git] / src / ec / compal / ene932 / ec.c
blob6389383b21db293621c67639b1b2dd8f1a2fcff9
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 <arch/io.h>
7 #include <delay.h>
8 #include <pc80/keyboard.h>
9 #include "ec.h"
10 #include "chip.h"
12 /* kbc helper functions from drivers/pc80/keyboard.c. TODO: share functions. */
13 static int kbc_input_buffer_empty(void)
15 u32 timeout;
16 for (timeout = KBC_TIMEOUT_IN_MS; timeout && (inb(KBD_STATUS) & KBD_IBF);
17 timeout--) {
18 mdelay(1);
21 if (!timeout) {
22 printk(BIOS_WARNING,
23 "Unexpected Keyboard controller input buffer full\n");
25 return !!timeout;
28 static int kbc_output_buffer_full(void)
30 u32 timeout;
31 for (timeout = KBC_TIMEOUT_IN_MS; timeout && ((inb(KBD_STATUS)
32 & KBD_OBF) == 0); timeout--) {
33 mdelay(1);
36 if (!timeout) {
37 printk(BIOS_INFO, "Keyboard controller output buffer result timeout\n");
39 return !!timeout;
42 int kbc_cleanup_buffers(void)
44 u32 timeout;
45 for (timeout = KBC_TIMEOUT_IN_MS; timeout && (inb(KBD_STATUS)
46 & (KBD_OBF | KBD_IBF)); timeout--) {
47 mdelay(1);
48 inb(KBD_DATA);
51 if (!timeout) {
52 printk(BIOS_ERR, "Couldn't cleanup the keyboard controller buffers\n");
53 printk(BIOS_ERR, "Status (0x%x): 0x%x, Buffer (0x%x): 0x%x\n",
54 KBD_STATUS, inb(KBD_STATUS), KBD_DATA, inb(KBD_DATA));
57 return !!timeout;
60 /* The ENE 60/64 EC registers are the same command/status IB/OB KBC pair.
61 * Check status from 64 port before each command.
63 * Ex. Get panel ID command C43/D77
64 * Check IBF empty. Then Write 0x43(CMD) to 0x64 Port
65 * Check IBF empty. Then Write 0x77(DATA) to 0x60 Port
66 * Check OBF set. Then Get Data(0x03:panel ID) from 0x60
67 * Different commands return may or may not respond and may have multiple
68 * bytes. Keep it simple for nor
71 u8 ec_kbc_read_ob(void)
73 if (!kbc_output_buffer_full()) return 0;
74 return inb(KBD_DATA);
77 void ec_kbc_write_cmd(u8 cmd)
79 if (!kbc_input_buffer_empty()) return;
80 outb(cmd, KBD_COMMAND);
83 void ec_kbc_write_ib(u8 data)
85 if (!kbc_input_buffer_empty()) return;
86 outb(data, KBD_DATA);
90 * These functions are for accessing the ENE932 device space, but are not
91 * currently used.
94 static u8 ec_io_read(u16 addr)
96 outb(addr >> 8, EC_IO_HIGH);
97 outb(addr & 0xff, EC_IO_LOW);
98 return inb(EC_IO_DATA);
101 /*static void ec_write(u16 addr, u8 data)
103 outb(addr >> 8, EC_IO_HIGH);
104 outb(addr & 0xff, EC_IO_LOW;
105 outb(data, EC_IO_DATA);
109 static void ene932_init(struct device *dev)
111 if (!dev->enabled)
112 return;
114 printk(BIOS_DEBUG, "Compal ENE932: Initializing keyboard.\n");
115 pc_keyboard_init(NO_AUX_DEVICE);
118 static struct device_operations ops = {
119 .init = ene932_init,
120 .read_resources = noop_read_resources,
121 .set_resources = noop_set_resources,
124 static struct pnp_info pnp_dev_info[] = {
125 { NULL, 0, 0, 0, }
128 static void enable_dev(struct device *dev)
130 pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info);
133 struct chip_operations ec_compal_ene932_ops = {
134 CHIP_NAME("COMPAL ENE932 EC")
135 .enable_dev = enable_dev