coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ec_oem.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <arch/io.h>
5 #include <delay.h>
6 #include <ec/acpi/ec.h>
7 #include "ec_oem.h"
8 
9 int send_ec_oem_command(u8 command)
10 {
11  int timeout;
12 
13  timeout = 0x7ff;
14  while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) {
15  udelay(10);
16  if ((timeout & 0xff) == 0)
17  printk(BIOS_SPEW, ".");
18  }
19  if (!timeout) {
20  printk(BIOS_DEBUG, "Timeout while sending OEM command 0x%02x to EC!\n",
21  command);
22  // return -1;
23  }
24 
25  outb(command, EC_OEM_SC);
26  return 0;
27 }
28 
30 {
31  int timeout;
32 
33  timeout = 0x7ff;
34  while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) { // wait for IBF = 0
35  udelay(10);
36  if ((timeout & 0xff) == 0)
37  printk(BIOS_SPEW, ".");
38  }
39  if (!timeout) {
40  printk(BIOS_DEBUG, "Timeout while sending OEM data 0x%02x to EC!\n",
41  data);
42  // return -1;
43  }
44 
45  outb(data, EC_OEM_DATA);
46 
47  return 0;
48 }
49 
51 {
52  outb(data, EC_OEM_DATA);
53 
54  return 0;
55 }
56 
58 {
59  int timeout;
60  u8 data;
61 
62  timeout = 0x7fff;
63  while (--timeout) { // Wait for OBF = 1
64  if (inb(EC_OEM_SC) & EC_OBF) {
65  break;
66  }
67  udelay(10);
68  if ((timeout & 0xff) == 0)
69  printk(BIOS_SPEW, ".");
70  }
71  if (!timeout) {
72  printk(BIOS_DEBUG, "\nTimeout while receiving OEM data from EC!\n");
73  // return -1;
74  }
75 
76  data = inb(EC_OEM_DATA);
77  // printk(BIOS_SPEW, "recv_ec_oem_data: 0x%02x\n", data);
78 
79  return data;
80 }
81 
83 {
84  send_ec_oem_command(0x80);
86 
87  return recv_ec_oem_data();
88 }
89 
90 int ec_oem_write(u8 addr, u8 data)
91 {
92  send_ec_oem_command(0x81);
94  return send_ec_oem_data(data);
95 }
96 
98 {
99  u8 ec_sc = inb(EC_OEM_SC);
100  printk(BIOS_DEBUG, "Embedded Controller Status: ");
101  if (ec_sc & (1 << 6)) printk(BIOS_DEBUG, "SMI_EVT ");
102  if (ec_sc & (1 << 5)) printk(BIOS_DEBUG, "SCI_EVT ");
103  if (ec_sc & (1 << 4)) printk(BIOS_DEBUG, "BURST ");
104  if (ec_sc & (1 << 3)) printk(BIOS_DEBUG, "CMD ");
105  if (ec_sc & (1 << 1)) printk(BIOS_DEBUG, "IBF ");
106  if (ec_sc & (1 << 0)) printk(BIOS_DEBUG, "OBF ");
107  printk(BIOS_DEBUG, "\n");
108 
109  return ec_sc;
110 }
static u32 addr
Definition: cirrus.c:14
#define printk(level,...)
Definition: stdlib.h:16
u8 inb(u16 port)
void outb(u8 val, u16 port)
#define EC_OBF
Definition: ec.h:18
#define EC_IBF
Definition: ec.h:17
int send_ec_oem_command(u8 command)
Definition: ec_oem.c:9
u8 ec_oem_read(u8 addr)
Definition: ec_oem.c:82
int ec_oem_write(u8 addr, u8 data)
Definition: ec_oem.c:90
int send_ec_oem_data_nowait(u8 data)
Definition: ec_oem.c:50
int ec_oem_dump_status(void)
Definition: ec_oem.c:97
int send_ec_oem_data(u8 data)
Definition: ec_oem.c:29
u8 recv_ec_oem_data(void)
Definition: ec_oem.c:57
#define EC_OEM_DATA
Definition: ec_oem.h:6
#define EC_OEM_SC
Definition: ec_oem.h:7
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_SPEW
BIOS_SPEW - Excessively verbose output.
Definition: loglevel.h:142
uint8_t u8
Definition: stdint.h:45
void udelay(uint32_t us)
Definition: udelay.c:15