coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
sch5545_ec_early.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <arch/io.h>
6 
7 #include <baseboard/sch5545_ec.h>
8 
10 
11 static const struct ec_val_reg ec_gpio_init_table[] = {
12  /*
13  * Probably some early GPIO initialization, setting GPIO functions.
14  * The LSBs in third column match the GPIO config registers offsets for
15  * non-default GPIOs.
16  */
17  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x08cc }, /* GP063 (def) / KBDRST# */
18  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x08d0 }, /* GP064 (def) / A20M */
19  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x089c }, /* GP047 / TXD1 (def) */
20  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x0878 }, /* GP036 (def) / SMBCLK1 */
21  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x0880 }, /* GP040 (def) / SMBDAT1 */
22  { EC_GPIO_OD | EC_GPIO_FUNC1, 0x0884 }, /* GP041 (def) / IO_PME# */
23  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x08e4 }, /* GP071 (def) / IO_SMI# */
24  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x08e0 }, /* GP070 (def) / SPEAKER */
25  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x0848 }, /* GP022 (def) / PWM1 */
26  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x084c }, /* GP023 (def) / PWM2 */
27  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x0850 }, /* GP024 (def) / PWM3 */
28  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x083c }, /* GP017 / TACH1 (def) */
29  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x0840 }, /* GP020 / TACH2 (def) */
30  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x0844 }, /* GP021 / TACH3 (def) */
31  { EC_GPIO_PP | EC_GPIO_FUNC1, 0x0814 }, /* GP005 (def) / PECI_REQ# */
32 };
33 
34 static const struct ec_val_reg ec_hwm_early_init_table[] = {
35  /* Probably some early hardware monitor initialization */
36  { 0xff, 0x0005 },
37  { 0x30, 0x00f0 },
38  { 0x10, 0x00f8 },
39  { 0x00, 0x00f9 },
40  { 0x00, 0x00fa },
41  { 0x00, 0x00fb },
42  { 0x00, 0x00ea },
43  { 0x00, 0x00eb },
44  { 0x7c, 0x00ef },
45  { 0x03, 0x006e },
46  { 0x51, 0x02d0 },
47  { 0x01, 0x02d2 },
48  { 0x12, 0x059a },
49  { 0x11, 0x059e },
50  { 0x14, 0x05a2 },
51  { 0x55, 0x05a3 },
52  { 0x01, 0x02db },
53  { 0x01, 0x0040 },
54 };
55 
57  uint8_t rw_bit)
58 {
59  uint16_t timeout = 0;
60  rw_bit &= 1;
62  sch5545_emi_ec_write16(0x8000, (ldn << 1) | 0x100 | rw_bit);
63 
65 
66  if (rw_bit)
68 
69  outb(reg & 0xff, emi_bar + SCH5545_EMI_EC_DATA + 2);
70  outb((reg >> 8) & 0xff, emi_bar + SCH5545_EMI_EC_DATA + 3);
72 
73  do {
74  timeout++;
75  if ((sch5545_emi_ec2h_mbox_read() & 1) != 0)
76  break;
77  } while (timeout < 0xfff);
78 
81 
82  if (!rw_bit)
84 }
85 
86 static void ec_init_gpios(void)
87 {
88  unsigned int i;
89  uint8_t val;
90 
91  for (i = 0; i < ARRAY_SIZE(ec_gpio_init_table); i++) {
94  WRITE_OP);
95  }
96 }
97 
98 static void ec_early_hwm_init(void)
99 {
100  unsigned int i;
101  uint8_t val;
102 
103  for (i = 0; i < ARRAY_SIZE(ec_hwm_early_init_table); i++) {
106  WRITE_OP);
107  }
108 }
109 
111 {
113 
114  ec_init_gpios();
116 }
#define ARRAY_SIZE(a)
Definition: helpers.h:12
u8 inb(u16 port)
void outb(u8 val, u16 port)
#define EC_GPIO_OD
Definition: sch5545_ec.h:16
#define EC_HWM_LDN
Definition: sch5545_ec.h:11
#define WRITE_OP
Definition: sch5545_ec.h:9
#define EC_GPIO_LDN
Definition: sch5545_ec.h:12
#define EC_GPIO_PP
Definition: sch5545_ec.h:15
#define EC_GPIO_FUNC1
Definition: sch5545_ec.h:18
void sch5545_ec_early_init(void)
static void ec_read_write_reg_timeout(uint16_t ldn, uint8_t *val, uint16_t reg, uint8_t rw_bit)
static const struct ec_val_reg ec_gpio_init_table[]
static uint16_t emi_bar
static void ec_early_hwm_init(void)
static const struct ec_val_reg ec_hwm_early_init_table[]
static void ec_init_gpios(void)
void sch5545_emi_set_int_src(uint16_t int_src)
Writes int_src bits to clear the desired interrupt source bits.
Definition: sch5545_emi.c:145
void sch5545_emi_h2ec_mbox_write(uint8_t mbox_message)
Writes the Host to EC mailbox 8bit register with mbox_message.
Definition: sch5545_emi.c:71
void sch5545_emi_ec2h_mailbox_clear(void)
Reads the EC to Host mailbox register and then writes the same content to clear it.
Definition: sch5545_emi.c:61
void sch5545_emi_ec_write16(uint16_t addr, uint16_t data)
Writes any word of 2 words from the 32bit dword indicated by addr.
Definition: sch5545_emi.c:166
uint16_t sch5545_read_emi_bar(uint8_t sio_port)
Reads and returns the base address of EMI from the SuperIO.
Definition: sch5545_emi.c:29
uint8_t sch5545_emi_ec2h_mbox_read(void)
Reads and returns the EC to Host mailbox 8bit register.
Definition: sch5545_emi.c:86
void sch5545_emi_set_ec_addr(uint16_t addr)
Sets the EC address registers with given addr for indirect access to Embedded Memory.
Definition: sch5545_emi.c:150
#define SCH5545_EMI_EC_DATA
Definition: sch5545_emi.h:13
unsigned short uint16_t
Definition: stdint.h:11
unsigned char uint8_t
Definition: stdint.h:8
uint8_t val
Definition: sch5545_ec.h:23
uint16_t reg
Definition: sch5545_ec.h:24
u8 val
Definition: sys.c:300