mb/ocp/tiogapass: Fix GPIOs
[coreboot2.git] / src / mainboard / dell / optiplex_9020 / sch5555_ec.c
blob1df5026531c6b70b0db9c1909d5f599c16c07a00
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <arch/io.h>
4 #include <device/pnp_ops.h>
5 #include <superio/smsc/sch555x/sch555x.h>
6 #include "sch5555_ec.h"
8 uint8_t sch5555_mbox_read(uint8_t addr1, uint16_t addr2)
10 // clear ec-to-host mailbox
11 uint8_t tmp = inb(SCH555x_EMI_IOBASE + 1);
12 outb(tmp, SCH555x_EMI_IOBASE + 1);
14 // send address
15 outw(0 | 0x8001, SCH555x_EMI_IOBASE + 2);
16 outw((addr1 * 2) | 0x100, SCH555x_EMI_IOBASE + 4);
18 outw(4 | 0x8002, SCH555x_EMI_IOBASE + 2);
19 outl(addr2 << 16, SCH555x_EMI_IOBASE + 4);
21 // send message to ec
22 outb(1, SCH555x_EMI_IOBASE);
24 // wait for ack
25 for (size_t retry = 0; retry < 0xfff; ++retry)
26 if (inb(SCH555x_EMI_IOBASE + 1) & 1)
27 break;
29 // read result
30 outw(4 | 0x8000, SCH555x_EMI_IOBASE + 2);
31 return inb(SCH555x_EMI_IOBASE + 4);
34 void sch5555_mbox_write(uint8_t addr1, uint16_t addr2, uint8_t val)
36 // clear ec-to-host mailbox
37 uint8_t tmp = inb(SCH555x_EMI_IOBASE + 1);
38 outb(tmp, SCH555x_EMI_IOBASE + 1);
40 // send address and value
41 outw(0 | 0x8001, SCH555x_EMI_IOBASE + 2);
42 outw((addr1 * 2) | 0x101, SCH555x_EMI_IOBASE + 4);
44 outw(4 | 0x8002, SCH555x_EMI_IOBASE + 2);
45 outl(val | (addr2 << 16), SCH555x_EMI_IOBASE + 4);
47 // send message to ec
48 outb(1, SCH555x_EMI_IOBASE);
50 // wait for ack
51 for (size_t retry = 0; retry < 0xfff; ++retry)
52 if (inb(SCH555x_EMI_IOBASE + 1) & 1)
53 break;