Angel Pons | 210a008 | 2020-04-02 23:48:24 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 2 | |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
| 5 | #include <device/pnp.h> |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 6 | #include <arch/io.h> |
| 7 | #include <delay.h> |
Edward O'Callaghan | e1fe688 | 2014-04-30 20:41:41 +1000 | [diff] [blame] | 8 | #include <pc80/keyboard.h> |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 9 | #include "ec.h" |
| 10 | #include "chip.h" |
| 11 | |
| 12 | /* kbc helper functions from drivers/pc80/keyboard.c. TODO: share functions. */ |
| 13 | static int kbc_input_buffer_empty(void) |
| 14 | { |
| 15 | u32 timeout; |
Elyes HAOUAS | 2b010b8 | 2016-08-25 20:57:08 +0200 | [diff] [blame] | 16 | for (timeout = KBC_TIMEOUT_IN_MS; timeout && (inb(KBD_STATUS) & KBD_IBF); |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 17 | timeout--) { |
| 18 | mdelay(1); |
| 19 | } |
| 20 | |
| 21 | if (!timeout) { |
| 22 | printk(BIOS_WARNING, |
| 23 | "Unexpected Keyboard controller input buffer full\n"); |
| 24 | } |
| 25 | return !!timeout; |
| 26 | } |
| 27 | |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 28 | static int kbc_output_buffer_full(void) |
| 29 | { |
| 30 | u32 timeout; |
Elyes HAOUAS | 2b010b8 | 2016-08-25 20:57:08 +0200 | [diff] [blame] | 31 | for (timeout = KBC_TIMEOUT_IN_MS; timeout && ((inb(KBD_STATUS) |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 32 | & KBD_OBF) == 0); timeout--) { |
| 33 | mdelay(1); |
| 34 | } |
| 35 | |
| 36 | if (!timeout) { |
| 37 | printk(BIOS_INFO, "Keyboard controller output buffer result timeout\n"); |
| 38 | } |
| 39 | return !!timeout; |
| 40 | } |
| 41 | |
| 42 | int kbc_cleanup_buffers(void) |
| 43 | { |
| 44 | u32 timeout; |
Elyes HAOUAS | 2b010b8 | 2016-08-25 20:57:08 +0200 | [diff] [blame] | 45 | for (timeout = KBC_TIMEOUT_IN_MS; timeout && (inb(KBD_STATUS) |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 46 | & (KBD_OBF | KBD_IBF)); timeout--) { |
| 47 | mdelay(1); |
| 48 | inb(KBD_DATA); |
| 49 | } |
| 50 | |
| 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)); |
| 55 | } |
| 56 | |
| 57 | return !!timeout; |
| 58 | } |
| 59 | |
Martin Roth | 8940d3e | 2013-07-09 21:52:41 -0600 | [diff] [blame] | 60 | /* The ENE 60/64 EC registers are the same command/status IB/OB KBC pair. |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 61 | * Check status from 64 port before each command. |
| 62 | * |
| 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 |
Martin Roth | 8940d3e | 2013-07-09 21:52:41 -0600 | [diff] [blame] | 67 | * Different commands return may or may not respond and may have multiple |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 68 | * bytes. Keep it simple for nor |
| 69 | */ |
| 70 | |
| 71 | u8 ec_kbc_read_ob(void) |
| 72 | { |
| 73 | if (!kbc_output_buffer_full()) return 0; |
| 74 | return inb(KBD_DATA); |
| 75 | } |
| 76 | |
| 77 | void ec_kbc_write_cmd(u8 cmd) |
| 78 | { |
| 79 | if (!kbc_input_buffer_empty()) return; |
| 80 | outb(cmd, KBD_COMMAND); |
| 81 | } |
| 82 | |
| 83 | void ec_kbc_write_ib(u8 data) |
| 84 | { |
| 85 | if (!kbc_input_buffer_empty()) return; |
| 86 | outb(data, KBD_DATA); |
| 87 | } |
| 88 | |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 89 | /* |
| 90 | * These functions are for accessing the ENE932 device space, but are not |
| 91 | * currently used. |
| 92 | */ |
| 93 | /* |
| 94 | static u8 ec_io_read(u16 addr) |
| 95 | { |
| 96 | outb(addr >> 8, EC_IO_HIGH); |
| 97 | outb(addr & 0xff, EC_IO_LOW); |
| 98 | return inb(EC_IO_DATA); |
| 99 | } |
| 100 | */ |
| 101 | /*static void ec_write(u16 addr, u8 data) |
| 102 | { |
| 103 | outb(addr >> 8, EC_IO_HIGH); |
| 104 | outb(addr & 0xff, EC_IO_LOW; |
| 105 | outb(data, EC_IO_DATA); |
| 106 | } |
| 107 | */ |
| 108 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 109 | static void ene932_init(struct device *dev) |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 110 | { |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 111 | if (!dev->enabled) |
| 112 | return; |
| 113 | |
| 114 | printk(BIOS_DEBUG, "Compal ENE932: Initializing keyboard.\n"); |
Timothy Pearson | 448e386 | 2015-11-24 14:12:01 -0600 | [diff] [blame] | 115 | pc_keyboard_init(NO_AUX_DEVICE); |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 116 | } |
| 117 | |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 118 | static struct device_operations ops = { |
| 119 | .init = ene932_init, |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 120 | .read_resources = noop_read_resources, |
Elyes HAOUAS | 4d319c3 | 2020-04-07 13:51:13 +0200 | [diff] [blame] | 121 | .set_resources = noop_set_resources, |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | static struct pnp_info pnp_dev_info[] = { |
Felix Held | dd770a8 | 2018-07-07 00:03:47 +0200 | [diff] [blame] | 125 | { NULL, 0, 0, 0, } |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 126 | }; |
| 127 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 128 | static void enable_dev(struct device *dev) |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 129 | { |
Felix Held | dd770a8 | 2018-07-07 00:03:47 +0200 | [diff] [blame] | 130 | pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
Stefan Reinauer | d8a5fd2 | 2012-12-11 15:51:47 -0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | struct chip_operations ec_compal_ene932_ops = { |
| 134 | CHIP_NAME("COMPAL ENE932 EC") |
| 135 | .enable_dev = enable_dev |
| 136 | }; |