Debian Codegraph @

src/superio/nuvoton/nct6687d/nct6687d_ec.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <arch/io.h>
4
5 #include "nct6687d_ec.h"
6
7 void nct6687d_ec_write_page(uint16_t iobase, uint8_t page, uint8_t index, uint8_t value)
8 {
9 /* Need to write 0xff first to set the page */
10 outb(0xff, iobase + EC_PORT0_PAGE);
11 outb(page, iobase + EC_PORT0_PAGE);
12 outb(index, iobase + EC_PORT0_INDEX);
13 outb(value, iobase + EC_PORT0_DATA);
14 /* Need to write 0xff at the end of transaction */
15 outb(0xff, iobase + EC_PORT0_PAGE);
16 }
17
18 void nct6687d_ec_write_page_ff(uint16_t iobase, uint8_t page, uint8_t index, uint8_t value)
19 {
20 /* Need to write 0xff first to set the page */
21 outb(0xff, iobase + EC_PORT0_PAGE);
22 outb(page, iobase + EC_PORT0_PAGE);
23 /* Extra 0xff to the index register */
24 outb(0xff, iobase + EC_PORT0_INDEX);
25 outb(index, iobase + EC_PORT0_INDEX);
26 outb(value, iobase + EC_PORT0_DATA);
27 /* Need to write 0xff at the end of transaction */
28 outb(0xff, iobase + EC_PORT0_PAGE);
29 }
30
31 void nct6687d_ec_and_or_page(uint16_t iobase, uint8_t page, uint8_t index,
32 uint8_t and_mask, uint8_t or_mask)
33 {
34 uint8_t val;
35 /* Need to write 0xff first to set the page */
36 outb(0xff, iobase + EC_PORT0_PAGE);
37 outb(page, iobase + EC_PORT0_PAGE);
38 outb(index, iobase + EC_PORT0_INDEX);
39 val = inb(iobase + EC_PORT0_DATA);
40 val &= and_mask;
41 val |= or_mask;
42 outb(val, iobase + EC_PORT0_DATA);
43 /* Need to write 0xff at the end of transaction */
44 outb(0xff, iobase + EC_PORT0_PAGE);
45 }
46
47 void nct6687d_ec_and_or_page_ff(uint16_t iobase, uint8_t page, uint8_t index,
48 uint8_t and_mask, uint8_t or_mask)
49 {
50 uint8_t val;
51 /* Need to write 0xff first to set the page */
52 outb(0xff, iobase + EC_PORT0_PAGE);
53 outb(page, iobase + EC_PORT0_PAGE);
54 /* Extra 0xff to the index register */
55 outb(0xff, iobase + EC_PORT0_INDEX);
56 outb(index, iobase + EC_PORT0_INDEX);
57 val = inb(iobase + EC_PORT0_DATA);
58 val &= and_mask;
59 val |= or_mask;
60 outb(val, iobase + EC_PORT0_DATA);
61 /* Need to write 0xff at the end of transaction */
62 outb(0xff, iobase + EC_PORT0_PAGE);
63 }
64
65 uint8_t nct6687d_ec_read_page(uint16_t iobase, uint8_t page, uint8_t index)
66 {
67 uint8_t value;
68 /* Need to write 0xff first to set the page */
69 outb(0xff, iobase + EC_PORT0_PAGE);
70 outb(page, iobase + EC_PORT0_PAGE);
71 outb(index, iobase + EC_PORT0_INDEX);
72 value = inb(iobase + EC_PORT0_DATA);
73 /* Need to write 0xff at the end of transaction */
74 outb(0xff, iobase + EC_PORT0_PAGE);
75
76 return value;
77 }