1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pnp.h>
8 #include <pc80/keyboard.h>
12 /* kbc helper functions from drivers/pc80/keyboard.c. TODO: share functions. */
13 static int kbc_input_buffer_empty(void)
16 for (timeout
= KBC_TIMEOUT_IN_MS
; timeout
&& (inb(KBD_STATUS
) & KBD_IBF
);
23 "Unexpected Keyboard controller input buffer full\n");
28 static int kbc_output_buffer_full(void)
31 for (timeout
= KBC_TIMEOUT_IN_MS
; timeout
&& ((inb(KBD_STATUS
)
32 & KBD_OBF
) == 0); timeout
--) {
37 printk(BIOS_INFO
, "Keyboard controller output buffer result timeout\n");
42 int kbc_cleanup_buffers(void)
45 for (timeout
= KBC_TIMEOUT_IN_MS
; timeout
&& (inb(KBD_STATUS
)
46 & (KBD_OBF
| KBD_IBF
)); 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
));
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;
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;
90 * These functions are for accessing the ENE932 device space, but are not
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
)
114 printk(BIOS_DEBUG
, "Compal ENE932: Initializing keyboard.\n");
115 pc_keyboard_init(NO_AUX_DEVICE
);
118 static struct device_operations ops
= {
120 .read_resources
= noop_read_resources
,
121 .set_resources
= noop_set_resources
,
124 static struct pnp_info pnp_dev_info
[] = {
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