| 1 |
|
| 2 |
|
| 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" |
| 11 |
|
| 12 |
|
| 13 |
static int kbc_input_buffer_empty(void) |
| 14 |
{ |
| 15 |
u32 timeout; |
| 16 |
for (timeout = KBC_TIMEOUT_IN_MS; timeout && (inb(KBD_STATUS) & KBD_IBF); |
| 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 |
|
| 28 |
static int kbc_output_buffer_full(void) |
| 29 |
{ |
| 30 |
u32 timeout; |
| 31 |
for (timeout = KBC_TIMEOUT_IN_MS; timeout && ((inb(KBD_STATUS) |
| 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; |
| 45 |
for (timeout = KBC_TIMEOUT_IN_MS; timeout && (inb(KBD_STATUS) |
| 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 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 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 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
static void ene932_init(struct device *dev) |
| 110 |
{ |
| 111 |
if (!dev->enabled) |
| 112 |
return; |
| 113 |
|
| 114 |
printk(BIOS_DEBUG, "Compal ENE932: Initializing keyboard.\n"); |
| 115 |
pc_keyboard_init(NO_AUX_DEVICE); |
| 116 |
} |
| 117 |
|
| 118 |
static struct device_operations ops = { |
| 119 |
.init = ene932_init, |
| 120 |
.read_resources = noop_read_resources, |
| 121 |
.set_resources = noop_set_resources, |
| 122 |
}; |
| 123 |
|
| 124 |
static struct pnp_info pnp_dev_info[] = { |
| 125 |
{ NULL, 0, 0, 0, } |
| 126 |
}; |
| 127 |
|
| 128 |
static void enable_dev(struct device *dev) |
| 129 |
{ |
| 130 |
pnp_enable_devices(dev, &ops, ARRAY_SIZE(pnp_dev_info), pnp_dev_info); |
| 131 |
} |
| 132 |
|
| 133 |
struct chip_operations ec_compal_ene932_ops = { |
| 134 |
.name = "COMPAL ENE932 EC", |
| 135 |
.enable_dev = enable_dev |
| 136 |
}; |