coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ec.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <arch/io.h>
4 #include <console/console.h>
5 #include <delay.h>
6 #include <device/device.h>
7 #include <device/pnp.h>
8 #include <pc80/keyboard.h>
9 
10 #include "ec.h"
11 #include "chip.h"
12 
13 /* helper functions from drivers/pc80/keyboard.c */
14 static int input_buffer_empty(u16 status_reg)
15 {
16  u32 timeout;
17  for (timeout = KBC_TIMEOUT_IN_MS; timeout && (inb(status_reg) & KBD_IBF);
18  timeout--) {
19  udelay(1000);
20  }
21 
22  if (!timeout) {
23  printk(BIOS_WARNING, "EC-IT8518 Unexpected input buffer full\n");
24  printk(BIOS_WARNING, " Status (0x%x): 0x%x\n", status_reg, inb(status_reg));
25  }
26  return !!timeout;
27 }
28 
29 static int output_buffer_full(u16 status_reg)
30 {
31  u32 timeout;
32  for (timeout = KBC_TIMEOUT_IN_MS; timeout && ((inb(status_reg)
33  & KBD_OBF) == 0); timeout--) {
34  udelay(1000);
35  }
36 
37  if (!timeout) {
38  printk(BIOS_INFO, "EC-IT8518 output buffer result timeout\n");
39  printk(BIOS_INFO, " Status (0x%x): 0x%x\n", status_reg, inb(status_reg));
40  }
41  return !!timeout;
42 }
43 
44 /* The IT8518 60/64 EC registers are the same command/status IB/OB KBC pair.
45  * Check status from 64 port before each command.
46  *
47  * Ex. Get panel ID command C43/D77
48  * Check IBF empty. Then Write 0x43(CMD) to 0x64 Port
49  * Check IBF empty. Then Write 0x77(DATA) to 0x60 Port
50  * Check OBF set. Then Get Data(0x03:panel ID) from 0x60
51  * Different commands return may or may not respond and may have multiple
52  * bytes. Keep it simple for nor
53  */
54 
56 {
57  if (!output_buffer_full(KBD_STATUS)) return 0;
58  return inb(KBD_DATA);
59 }
60 
62 {
63  if (!input_buffer_empty(KBD_STATUS)) return;
64  outb(cmd, KBD_COMMAND);
65 }
66 
67 void ec_kbc_write_ib(u8 data)
68 {
69  if (!input_buffer_empty(KBD_STATUS)) return;
70  outb(data, KBD_DATA);
71 }
72 
73 /*
74  * These functions are for accessing the IT8518 device RAM space via 0x66/0x68
75  */
76 
78 {
79  if (!output_buffer_full(EC_SC)) return 0;
80  return inb(EC_DATA);
81 }
82 
83 void ec_write_cmd(u8 cmd)
84 {
85  if (!input_buffer_empty(EC_SC)) return;
86  outb(cmd, EC_SC);
87 }
88 
89 void ec_write_ib(u8 data)
90 {
91  if (!input_buffer_empty(EC_SC)) return;
92  outb(data, EC_DATA);
93 }
94 
96 {
99  return ec_read_ob();
100 }
101 
102 void ec_write(u16 addr, u8 data)
103 {
105  ec_write_ib(addr);
106  ec_write_ib(data);
107 }
108 
110 {
111  u8 cmd = 0;
112  u8 status = inb(EC_SC);
113  if (status & SCI_EVT) {
115  cmd = ec_read_ob();
116  } else if (status & SMI_EVT) {
118  cmd = ec_kbc_read_ob();
119  }
120  return cmd;
121 }
122 
124 {
125  /*
126  * Set the bit in ECRAM that will enable the Lid switch as a wake source
127  */
128  u8 reg8 = ec_read(EC_WAKE_SRC_ENABLE);
130 }
131 
132 static void it8518_init(struct device *dev)
133 {
134  if (!dev->enabled)
135  return;
136 
137  printk(BIOS_DEBUG, "Quanta IT8518: Initializing keyboard.\n");
139 }
140 
141 static struct device_operations ops = {
142  .init = it8518_init,
143  .read_resources = noop_read_resources,
144  .set_resources = noop_set_resources,
145 };
146 
147 static struct pnp_info pnp_dev_info[] = {
148  { NULL, 0, 0, 0, }
149 };
150 
151 static void enable_dev(struct device *dev)
152 {
154 }
155 
157  CHIP_NAME("QUANTA IT8518 EC")
158  .enable_dev = enable_dev
159 };
#define ARRAY_SIZE(a)
Definition: helpers.h:12
static u32 addr
Definition: cirrus.c:14
#define printk(level,...)
Definition: stdlib.h:16
u8 inb(u16 port)
void outb(u8 val, u16 port)
u8 ec_read(u8 addr)
Definition: ec.c:107
int ec_write(u8 addr, u8 data)
Definition: ec.c:115
#define RD_EC
Definition: ec.h:20
#define EC_DATA
Definition: ec.h:8
#define EC_SC
Definition: ec.h:9
#define WR_EC
Definition: ec.h:21
#define QR_EC
Definition: ec.h:24
u8 ec_kbc_read_ob(void)
Definition: ec.c:71
void ec_kbc_write_ib(u8 data)
Definition: ec.c:83
void ec_kbc_write_cmd(u8 cmd)
Definition: ec.c:77
#define KBD_IBF
Definition: ec.c:14
#define KBD_OBF
Definition: ec.c:15
void ec_write_ib(u8 data)
Definition: ec.c:85
void ec_write_cmd(u8 cmd)
Definition: ec.c:79
u8 ec_read_ob(void)
Definition: ec.c:73
static void it8518_init(struct device *dev)
Definition: ec.c:132
u8 ec_it8518_get_event(void)
Definition: ec.c:109
static int output_buffer_full(u16 status_reg)
Definition: ec.c:29
static int input_buffer_empty(u16 status_reg)
Definition: ec.c:14
static void enable_dev(struct device *dev)
Definition: ec.c:151
static struct device_operations ops
Definition: ec.c:141
static struct pnp_info pnp_dev_info[]
Definition: ec.c:147
void ec_it8518_enable_wake_events(void)
Definition: ec.c:123
struct chip_operations ec_quanta_it8518_ops
Definition: ec.c:156
#define SMI_EVT
Definition: ec.h:36
#define EC_LID_WAKE_ENABLE
Definition: ec.h:68
#define EC_KBD_SMI_EVENT
Definition: ec.h:25
#define SCI_EVT
Definition: ec.h:37
#define EC_WAKE_SRC_ENABLE
Definition: ec.h:54
#define CHIP_NAME(X)
Definition: device.h:32
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
#define KBC_TIMEOUT_IN_MS
Definition: keyboard.c:49
#define KBD_DATA
Definition: keyboard.c:11
#define KBD_STATUS
Definition: keyboard.c:13
#define KBD_COMMAND
Definition: keyboard.c:12
uint8_t pc_keyboard_init(uint8_t probe_aux)
Definition: keyboard.c:229
#define NO_AUX_DEVICE
Definition: keyboard.h:6
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
void pnp_enable_devices(struct device *base_dev, struct device_operations *ops, unsigned int functions, struct pnp_info *info)
Definition: pnp_device.c:371
#define NULL
Definition: stddef.h:19
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
void(* init)(struct device *dev)
Definition: device.h:42
Definition: device.h:107
unsigned int enabled
Definition: device.h:122
Definition: pnp.h:37
void udelay(uint32_t us)
Definition: udelay.c:15