From ded51819269a7089767b0d32c97b29b7b33325b1 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 29 Sep 2019 20:13:03 -0600 Subject: [PATCH] Organize into arch, board, and ec modules --- .../system76/galp3-c => arch/8051}/delay.c | 4 +- src/arch/8051/include/arch/delay.h | 6 + src/arch/8051/include/arch/reset.h | 6 + .../8051/include/arch}/timer.h | 6 +- .../system76/galp3-c => arch/8051}/reset.c | 2 +- .../system76/galp3-c => arch/8051}/timer.c | 2 +- .../include => arch/avr/include/arch}/uart.h | 9 +- .../arduino/mega2560 => arch/avr}/uart.c | 29 +++- .../arduino/mega2560/include/board/cpu.h | 6 + src/board/arduino/mega2560/include/cpu.h | 6 - src/board/arduino/mega2560/include/stdio.h | 7 - src/board/arduino/mega2560/main.c | 4 +- src/board/arduino/mega2560/stdio.c | 29 ---- src/board/system76/galp3-c/acpi.c | 2 +- src/board/system76/galp3-c/gctrl.c | 2 +- src/board/system76/galp3-c/gpio.c | 2 +- .../galp3-c/include/{ => board}/acpi.h | 6 +- .../system76/galp3-c/include/board/gctrl.h | 8 + .../system76/galp3-c/include/board/gpio.h | 9 + .../system76/galp3-c/include/board/kbc.h | 8 + .../system76/galp3-c/include/board/kbscan.h | 8 + .../system76/galp3-c/include/board/pmc.h | 8 + .../system76/galp3-c/include/board/ps2.h | 8 + src/board/system76/galp3-c/include/delay.h | 6 - src/board/system76/galp3-c/include/gctrl.h | 10 -- src/board/system76/galp3-c/include/gpio.h | 143 ---------------- src/board/system76/galp3-c/include/kbscan.h | 47 ----- src/board/system76/galp3-c/include/pin.h | 25 --- src/board/system76/galp3-c/include/ps2.h | 22 --- src/board/system76/galp3-c/include/reset.h | 6 - src/board/system76/galp3-c/kbc.c | 41 +---- src/board/system76/galp3-c/kbscan.c | 2 +- src/board/system76/galp3-c/main.c | 33 ++-- src/board/system76/galp3-c/pin.c | 17 -- src/board/system76/galp3-c/pmc.c | 80 +-------- src/board/system76/galp3-c/ps2.c | 2 +- src/board/system76/galp3-c/stdio.c | 4 +- src/ec/it8587e/gpio.c | 17 ++ src/ec/it8587e/include/ec/gctrl.h | 10 ++ src/ec/it8587e/include/ec/gpio.h | 160 ++++++++++++++++++ .../include => ec/it8587e/include/ec}/kbc.h | 6 +- src/ec/it8587e/include/ec/kbscan.h | 47 +++++ .../include => ec/it8587e/include/ec}/pmc.h | 8 +- src/ec/it8587e/include/ec/ps2.h | 22 +++ src/ec/it8587e/kbc.c | 40 +++++ src/ec/it8587e/pmc.c | 79 +++++++++ .../galp3-c => ec/it8587e}/signature.c | 0 47 files changed, 518 insertions(+), 486 deletions(-) rename src/{board/system76/galp3-c => arch/8051}/delay.c (88%) create mode 100644 src/arch/8051/include/arch/delay.h create mode 100644 src/arch/8051/include/arch/reset.h rename src/{board/system76/galp3-c/include => arch/8051/include/arch}/timer.h (53%) rename src/{board/system76/galp3-c => arch/8051}/reset.c (62%) rename src/{board/system76/galp3-c => arch/8051}/timer.c (91%) rename src/{board/arduino/mega2560/include => arch/avr/include/arch}/uart.h (80%) rename src/{board/arduino/mega2560 => arch/avr}/uart.c (71%) create mode 100644 src/board/arduino/mega2560/include/board/cpu.h delete mode 100644 src/board/arduino/mega2560/include/cpu.h delete mode 100644 src/board/arduino/mega2560/include/stdio.h delete mode 100644 src/board/arduino/mega2560/stdio.c rename src/board/system76/galp3-c/include/{ => board}/acpi.h (59%) create mode 100644 src/board/system76/galp3-c/include/board/gctrl.h create mode 100644 src/board/system76/galp3-c/include/board/gpio.h create mode 100644 src/board/system76/galp3-c/include/board/kbc.h create mode 100644 src/board/system76/galp3-c/include/board/kbscan.h create mode 100644 src/board/system76/galp3-c/include/board/pmc.h create mode 100644 src/board/system76/galp3-c/include/board/ps2.h delete mode 100644 src/board/system76/galp3-c/include/delay.h delete mode 100644 src/board/system76/galp3-c/include/gctrl.h delete mode 100644 src/board/system76/galp3-c/include/gpio.h delete mode 100644 src/board/system76/galp3-c/include/kbscan.h delete mode 100644 src/board/system76/galp3-c/include/pin.h delete mode 100644 src/board/system76/galp3-c/include/ps2.h delete mode 100644 src/board/system76/galp3-c/include/reset.h delete mode 100644 src/board/system76/galp3-c/pin.c create mode 100644 src/ec/it8587e/gpio.c create mode 100644 src/ec/it8587e/include/ec/gctrl.h create mode 100644 src/ec/it8587e/include/ec/gpio.h rename src/{board/system76/galp3-c/include => ec/it8587e/include/ec}/kbc.h (94%) create mode 100644 src/ec/it8587e/include/ec/kbscan.h rename src/{board/system76/galp3-c/include => ec/it8587e/include/ec}/pmc.h (92%) create mode 100644 src/ec/it8587e/include/ec/ps2.h create mode 100644 src/ec/it8587e/kbc.c create mode 100644 src/ec/it8587e/pmc.c rename src/{board/system76/galp3-c => ec/it8587e}/signature.c (100%) diff --git a/src/board/system76/galp3-c/delay.c b/src/arch/8051/delay.c similarity index 88% rename from src/board/system76/galp3-c/delay.c rename to src/arch/8051/delay.c index b32ec11..4f43021 100644 --- a/src/board/system76/galp3-c/delay.c +++ b/src/arch/8051/delay.c @@ -1,7 +1,7 @@ #include <8051.h> -#include "include/delay.h" -#include "include/timer.h" +#include +#include // One millisecond in ticks is determined as follows: // 9.2 MHz is the clock rate diff --git a/src/arch/8051/include/arch/delay.h b/src/arch/8051/include/arch/delay.h new file mode 100644 index 0000000..a99e44d --- /dev/null +++ b/src/arch/8051/include/arch/delay.h @@ -0,0 +1,6 @@ +#ifndef _ARCH_DELAY_H +#define _ARCH_DELAY_H + +void delay_ms(int ms); + +#endif // _ARCH_DELAY_H diff --git a/src/arch/8051/include/arch/reset.h b/src/arch/8051/include/arch/reset.h new file mode 100644 index 0000000..9c9e9a4 --- /dev/null +++ b/src/arch/8051/include/arch/reset.h @@ -0,0 +1,6 @@ +#ifndef _ARCH_RESET_H +#define _ARCH_RESET_H + +void reset(void); + +#endif // _ARCH_RESET_H diff --git a/src/board/system76/galp3-c/include/timer.h b/src/arch/8051/include/arch/timer.h similarity index 53% rename from src/board/system76/galp3-c/include/timer.h rename to src/arch/8051/include/arch/timer.h index 81d12ea..0845eff 100644 --- a/src/board/system76/galp3-c/include/timer.h +++ b/src/arch/8051/include/arch/timer.h @@ -1,8 +1,8 @@ -#ifndef _TIMER_H_ -#define _TIMER_H_ +#ifndef _ARCH_TIMER_H +#define _ARCH_TIMER_H void timer_mode_1(int value); void timer_wait(void); void timer_stop(void); -#endif // _TIMER_H_ +#endif // _ARCH_TIMER_H diff --git a/src/board/system76/galp3-c/reset.c b/src/arch/8051/reset.c similarity index 62% rename from src/board/system76/galp3-c/reset.c rename to src/arch/8051/reset.c index 3acf4ca..555e7f6 100644 --- a/src/board/system76/galp3-c/reset.c +++ b/src/arch/8051/reset.c @@ -1,4 +1,4 @@ -#include "include/reset.h" +#include void reset(void) { __asm__("ljmp 0"); diff --git a/src/board/system76/galp3-c/timer.c b/src/arch/8051/timer.c similarity index 91% rename from src/board/system76/galp3-c/timer.c rename to src/arch/8051/timer.c index 84e856e..54b0cda 100644 --- a/src/board/system76/galp3-c/timer.c +++ b/src/arch/8051/timer.c @@ -1,6 +1,6 @@ #include <8051.h> -#include "include/timer.h" +#include void timer_mode_1(int value) { timer_stop(); diff --git a/src/board/arduino/mega2560/include/uart.h b/src/arch/avr/include/arch/uart.h similarity index 80% rename from src/board/arduino/mega2560/include/uart.h rename to src/arch/avr/include/arch/uart.h index 1983531..588f295 100644 --- a/src/board/arduino/mega2560/include/uart.h +++ b/src/arch/avr/include/arch/uart.h @@ -1,5 +1,5 @@ -#ifndef UART_H -#define UART_H +#ifndef _ARCH_UART_H +#define _ARCH_UART_H #include @@ -28,4 +28,7 @@ unsigned char uart_can_write(struct Uart * uart); unsigned char uart_read(struct Uart * uart); void uart_write(struct Uart * uart, unsigned char data); -#endif // UART_H +extern struct Uart * uart_stdio; +void uart_stdio_init(int num, unsigned long baud); + +#endif // _ARCH_UART_H diff --git a/src/board/arduino/mega2560/uart.c b/src/arch/avr/uart.c similarity index 71% rename from src/board/arduino/mega2560/uart.c rename to src/arch/avr/uart.c index 8cb4edb..88cd7c0 100644 --- a/src/board/arduino/mega2560/uart.c +++ b/src/arch/avr/uart.c @@ -1,8 +1,8 @@ #include #include -#include "include/cpu.h" -#include "include/uart.h" +#include +#include #define UART(N) \ { \ @@ -72,3 +72,28 @@ void uart_write(struct Uart * uart, unsigned char data) { while (!uart_can_write(uart)) ; *(uart->data) = data; } + +struct Uart * uart_stdio = NULL; + +int uart_stdio_get(FILE * stream) { + return (int)uart_read(uart_stdio); +} + +int uart_stdio_put(char data, FILE * stream) { + if (data == '\n') { + uart_write(uart_stdio, '\r'); + } + uart_write(uart_stdio, (unsigned char)data); + return 0; +} + +FILE uart_stdio_file = FDEV_SETUP_STREAM(uart_stdio_put, uart_stdio_get, _FDEV_SETUP_RW); + +void uart_stdio_init(int num, unsigned long baud) { + struct Uart * uart = uart_new(num); + if(uart != NULL) { + uart_init(uart, baud); + uart_stdio = uart; + stdin = stdout = stderr = &uart_stdio_file; + } +} diff --git a/src/board/arduino/mega2560/include/board/cpu.h b/src/board/arduino/mega2560/include/board/cpu.h new file mode 100644 index 0000000..3d1fe04 --- /dev/null +++ b/src/board/arduino/mega2560/include/board/cpu.h @@ -0,0 +1,6 @@ +#ifndef _BOARD_CPU_H +#define _BOARD_CPU_H + +#define F_CPU 16000000ULL + +#endif // _BOARD_CPU_H diff --git a/src/board/arduino/mega2560/include/cpu.h b/src/board/arduino/mega2560/include/cpu.h deleted file mode 100644 index 9cca1db..0000000 --- a/src/board/arduino/mega2560/include/cpu.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef CPU_H -#define CPU_H - -#define F_CPU 16000000ULL - -#endif // CPU_H diff --git a/src/board/arduino/mega2560/include/stdio.h b/src/board/arduino/mega2560/include/stdio.h deleted file mode 100644 index 15a7669..0000000 --- a/src/board/arduino/mega2560/include/stdio.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -extern struct Uart * stdio_uart; -void stdio_init(int num, unsigned long baud); - -#endif // STDIO_H diff --git a/src/board/arduino/mega2560/main.c b/src/board/arduino/mega2560/main.c index efe1110..57b0942 100644 --- a/src/board/arduino/mega2560/main.c +++ b/src/board/arduino/mega2560/main.c @@ -1,9 +1,9 @@ #include -#include "include/stdio.h" +#include void init(void) { - stdio_init(0, 9600); + uart_stdio_init(0, 9600); } void main(void) { diff --git a/src/board/arduino/mega2560/stdio.c b/src/board/arduino/mega2560/stdio.c deleted file mode 100644 index 0a0cbf3..0000000 --- a/src/board/arduino/mega2560/stdio.c +++ /dev/null @@ -1,29 +0,0 @@ -#include - -#include "include/stdio.h" -#include "include/uart.h" - -struct Uart * stdio_uart = NULL; - -int stdio_get(FILE * stream) { - return (int)uart_read(stdio_uart); -} - -int stdio_put(char data, FILE * stream) { - if (data == '\n') { - uart_write(stdio_uart, '\r'); - } - uart_write(stdio_uart, (unsigned char)data); - return 0; -} - -FILE stdio_file = FDEV_SETUP_STREAM(stdio_put, stdio_get, _FDEV_SETUP_RW); - -void stdio_init(int num, unsigned long baud) { - struct Uart * uart = uart_new(num); - if(uart != NULL) { - uart_init(uart, baud); - stdio_uart = uart; - stdin = stdout = stderr = &stdio_file; - } -} diff --git a/src/board/system76/galp3-c/acpi.c b/src/board/system76/galp3-c/acpi.c index e8b3f3c..151489a 100644 --- a/src/board/system76/galp3-c/acpi.c +++ b/src/board/system76/galp3-c/acpi.c @@ -1,6 +1,6 @@ #include -#include "include/acpi.h" +#include uint8_t acpi_read(uint8_t addr) { uint8_t data = 0; diff --git a/src/board/system76/galp3-c/gctrl.c b/src/board/system76/galp3-c/gctrl.c index ad84aed..d66775f 100644 --- a/src/board/system76/galp3-c/gctrl.c +++ b/src/board/system76/galp3-c/gctrl.c @@ -1,4 +1,4 @@ -#include "include/gctrl.h" +#include void gctrl_init(void) { SPCTRL1 = 0x03; diff --git a/src/board/system76/galp3-c/gpio.c b/src/board/system76/galp3-c/gpio.c index dd7d223..8f7fc21 100644 --- a/src/board/system76/galp3-c/gpio.c +++ b/src/board/system76/galp3-c/gpio.c @@ -1,6 +1,6 @@ #include -#include "include/gpio.h" +#include void gpio_init() { // Enable LPC reset on GPD2 diff --git a/src/board/system76/galp3-c/include/acpi.h b/src/board/system76/galp3-c/include/board/acpi.h similarity index 59% rename from src/board/system76/galp3-c/include/acpi.h rename to src/board/system76/galp3-c/include/board/acpi.h index 2122af2..4a6df82 100644 --- a/src/board/system76/galp3-c/include/acpi.h +++ b/src/board/system76/galp3-c/include/board/acpi.h @@ -1,9 +1,9 @@ -#ifndef _ACPI_H_ -#define _ACPI_H_ +#ifndef _BOARD_ACPI_H +#define _BOARD_ACPI_H #include uint8_t acpi_read(uint8_t addr); void acpi_write(uint8_t addr, uint8_t data); -#endif // _ACPI_H_ +#endif // _BOARD_ACPI_H diff --git a/src/board/system76/galp3-c/include/board/gctrl.h b/src/board/system76/galp3-c/include/board/gctrl.h new file mode 100644 index 0000000..80eae12 --- /dev/null +++ b/src/board/system76/galp3-c/include/board/gctrl.h @@ -0,0 +1,8 @@ +#ifndef _BOARD_GCTRL_H +#define _BOARD_GCTRL_H + +#include + +void gctrl_init(void); + +#endif // _BOARD_GCTRL_H diff --git a/src/board/system76/galp3-c/include/board/gpio.h b/src/board/system76/galp3-c/include/board/gpio.h new file mode 100644 index 0000000..d3455e2 --- /dev/null +++ b/src/board/system76/galp3-c/include/board/gpio.h @@ -0,0 +1,9 @@ +#ifndef _BOARD_GPIO_H +#define _BOARD_GPIO_H + +#include + +void gpio_init(void); +void gpio_debug(void); + +#endif // _BOARD_GPIO_H diff --git a/src/board/system76/galp3-c/include/board/kbc.h b/src/board/system76/galp3-c/include/board/kbc.h new file mode 100644 index 0000000..0e6283a --- /dev/null +++ b/src/board/system76/galp3-c/include/board/kbc.h @@ -0,0 +1,8 @@ +#ifndef _BOARD_KBC_H +#define _BOARD_KBC_H + +#include + +void kbc_init(void); + +#endif // _BOARD_KBC_H diff --git a/src/board/system76/galp3-c/include/board/kbscan.h b/src/board/system76/galp3-c/include/board/kbscan.h new file mode 100644 index 0000000..8fa8cc6 --- /dev/null +++ b/src/board/system76/galp3-c/include/board/kbscan.h @@ -0,0 +1,8 @@ +#ifndef _BOARD_KBSCAN_H +#define _BOARD_KBSCAN_H + +#include + +void kbscan_init(void); + +#endif // _BOARD_KBSCAN_H diff --git a/src/board/system76/galp3-c/include/board/pmc.h b/src/board/system76/galp3-c/include/board/pmc.h new file mode 100644 index 0000000..8e49605 --- /dev/null +++ b/src/board/system76/galp3-c/include/board/pmc.h @@ -0,0 +1,8 @@ +#ifndef _BOARD_PMC_H +#define _BOARD_PMC_H + +#include + +void pmc_init(void); + +#endif // _BOARD_PMC_H diff --git a/src/board/system76/galp3-c/include/board/ps2.h b/src/board/system76/galp3-c/include/board/ps2.h new file mode 100644 index 0000000..34ad6ac --- /dev/null +++ b/src/board/system76/galp3-c/include/board/ps2.h @@ -0,0 +1,8 @@ +#ifndef _BOARD_PS2_H +#define _BOARD_PS2_H + +#include + +void ps2_init(void); + +#endif // _BOARD_PS2_H diff --git a/src/board/system76/galp3-c/include/delay.h b/src/board/system76/galp3-c/include/delay.h deleted file mode 100644 index cc9eef9..0000000 --- a/src/board/system76/galp3-c/include/delay.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _DELAY_H_ -#define _DELAY_H_ - -void delay_ms(int ms); - -#endif // _DELAY_H_ diff --git a/src/board/system76/galp3-c/include/gctrl.h b/src/board/system76/galp3-c/include/gctrl.h deleted file mode 100644 index b19086c..0000000 --- a/src/board/system76/galp3-c/include/gctrl.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _GCTRL_H_ -#define _GCTRL_H_ - -void gctrl_init(void); - -__xdata volatile unsigned char __at(0x2006) RSTS; -__xdata volatile unsigned char __at(0x200A) BADRSEL; -__xdata volatile unsigned char __at(0x200D) SPCTRL1; - -#endif // _GCTRL_H_ diff --git a/src/board/system76/galp3-c/include/gpio.h b/src/board/system76/galp3-c/include/gpio.h deleted file mode 100644 index 113c585..0000000 --- a/src/board/system76/galp3-c/include/gpio.h +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef _GPIO_H_ -#define _GPIO_H_ - -void gpio_init(void); -void gpio_debug(void); - -__xdata volatile unsigned char __at(0x1600) GCR; - -__xdata volatile unsigned char __at(0x1601) GPDRA; -__xdata volatile unsigned char __at(0x1602) GPDRB; -__xdata volatile unsigned char __at(0x1603) GPDRC; -__xdata volatile unsigned char __at(0x1604) GPDRD; -__xdata volatile unsigned char __at(0x1605) GPDRE; -__xdata volatile unsigned char __at(0x1606) GPDRF; -__xdata volatile unsigned char __at(0x1607) GPDRG; -__xdata volatile unsigned char __at(0x1608) GPDRH; -__xdata volatile unsigned char __at(0x1609) GPDRI; -__xdata volatile unsigned char __at(0x160A) GPDRJ; -__xdata volatile unsigned char __at(0x160D) GPDRM; - -__xdata volatile unsigned char __at(0x1661) GPDMRA; -__xdata volatile unsigned char __at(0x1662) GPDMRB; -__xdata volatile unsigned char __at(0x1663) GPDMRC; -__xdata volatile unsigned char __at(0x1664) GPDMRD; -__xdata volatile unsigned char __at(0x1665) GPDMRE; -__xdata volatile unsigned char __at(0x1666) GPDMRF; -__xdata volatile unsigned char __at(0x1667) GPDMRG; -__xdata volatile unsigned char __at(0x1668) GPDMRH; -__xdata volatile unsigned char __at(0x1669) GPDMRI; -__xdata volatile unsigned char __at(0x166A) GPDMRJ; -__xdata volatile unsigned char __at(0x166D) GPDMRM; - -__xdata volatile unsigned char __at(0x1671) GPOTA; -__xdata volatile unsigned char __at(0x1672) GPOTB; -__xdata volatile unsigned char __at(0x1673) GPOTC; -__xdata volatile unsigned char __at(0x1674) GPOTD; -__xdata volatile unsigned char __at(0x1675) GPOTE; -__xdata volatile unsigned char __at(0x1676) GPOTF; -__xdata volatile unsigned char __at(0x1677) GPOTG; -__xdata volatile unsigned char __at(0x1678) GPOTH; -__xdata volatile unsigned char __at(0x1679) GPOTI; -__xdata volatile unsigned char __at(0x167A) GPOTJ; -// GPOTM does not exist - -__xdata volatile unsigned char __at(0x1610) GPCRA0; -__xdata volatile unsigned char __at(0x1611) GPCRA1; -__xdata volatile unsigned char __at(0x1612) GPCRA2; -__xdata volatile unsigned char __at(0x1613) GPCRA3; -__xdata volatile unsigned char __at(0x1614) GPCRA4; -__xdata volatile unsigned char __at(0x1615) GPCRA5; -__xdata volatile unsigned char __at(0x1616) GPCRA6; -__xdata volatile unsigned char __at(0x1617) GPCRA7; - -__xdata volatile unsigned char __at(0x1618) GPCRB0; -__xdata volatile unsigned char __at(0x1619) GPCRB1; -__xdata volatile unsigned char __at(0x161A) GPCRB2; -__xdata volatile unsigned char __at(0x161B) GPCRB3; -__xdata volatile unsigned char __at(0x161C) GPCRB4; -__xdata volatile unsigned char __at(0x161D) GPCRB5; -__xdata volatile unsigned char __at(0x161E) GPCRB6; -__xdata volatile unsigned char __at(0x161F) GPCRB7; - -__xdata volatile unsigned char __at(0x1620) GPCRC0; -__xdata volatile unsigned char __at(0x1621) GPCRC1; -__xdata volatile unsigned char __at(0x1622) GPCRC2; -__xdata volatile unsigned char __at(0x1623) GPCRC3; -__xdata volatile unsigned char __at(0x1624) GPCRC4; -__xdata volatile unsigned char __at(0x1625) GPCRC5; -__xdata volatile unsigned char __at(0x1626) GPCRC6; -__xdata volatile unsigned char __at(0x1627) GPCRC7; - -__xdata volatile unsigned char __at(0x1628) GPCRD0; -__xdata volatile unsigned char __at(0x1629) GPCRD1; -__xdata volatile unsigned char __at(0x162A) GPCRD2; -__xdata volatile unsigned char __at(0x162B) GPCRD3; -__xdata volatile unsigned char __at(0x162C) GPCRD4; -__xdata volatile unsigned char __at(0x162D) GPCRD5; -__xdata volatile unsigned char __at(0x162E) GPCRD6; -__xdata volatile unsigned char __at(0x162F) GPCRD7; - -__xdata volatile unsigned char __at(0x1630) GPCRE0; -__xdata volatile unsigned char __at(0x1631) GPCRE1; -__xdata volatile unsigned char __at(0x1632) GPCRE2; -__xdata volatile unsigned char __at(0x1633) GPCRE3; -__xdata volatile unsigned char __at(0x1634) GPCRE4; -__xdata volatile unsigned char __at(0x1635) GPCRE5; -__xdata volatile unsigned char __at(0x1636) GPCRE6; -__xdata volatile unsigned char __at(0x1637) GPCRE7; - -__xdata volatile unsigned char __at(0x1638) GPCRF0; -__xdata volatile unsigned char __at(0x1639) GPCRF1; -__xdata volatile unsigned char __at(0x163A) GPCRF2; -__xdata volatile unsigned char __at(0x163B) GPCRF3; -__xdata volatile unsigned char __at(0x163C) GPCRF4; -__xdata volatile unsigned char __at(0x163D) GPCRF5; -__xdata volatile unsigned char __at(0x163E) GPCRF6; -__xdata volatile unsigned char __at(0x163F) GPCRF7; - -__xdata volatile unsigned char __at(0x1640) GPCRG0; -__xdata volatile unsigned char __at(0x1641) GPCRG1; -__xdata volatile unsigned char __at(0x1642) GPCRG2; -__xdata volatile unsigned char __at(0x1643) GPCRG3; -__xdata volatile unsigned char __at(0x1644) GPCRG4; -__xdata volatile unsigned char __at(0x1645) GPCRG5; -__xdata volatile unsigned char __at(0x1646) GPCRG6; -__xdata volatile unsigned char __at(0x1647) GPCRG7; - -__xdata volatile unsigned char __at(0x1648) GPCRH0; -__xdata volatile unsigned char __at(0x1649) GPCRH1; -__xdata volatile unsigned char __at(0x164A) GPCRH2; -__xdata volatile unsigned char __at(0x164B) GPCRH3; -__xdata volatile unsigned char __at(0x164C) GPCRH4; -__xdata volatile unsigned char __at(0x164D) GPCRH5; -__xdata volatile unsigned char __at(0x164E) GPCRH6; -__xdata volatile unsigned char __at(0x164F) GPCRH7; - -__xdata volatile unsigned char __at(0x1650) GPCRI0; -__xdata volatile unsigned char __at(0x1651) GPCRI1; -__xdata volatile unsigned char __at(0x1652) GPCRI2; -__xdata volatile unsigned char __at(0x1653) GPCRI3; -__xdata volatile unsigned char __at(0x1654) GPCRI4; -__xdata volatile unsigned char __at(0x1655) GPCRI5; -__xdata volatile unsigned char __at(0x1656) GPCRI6; -__xdata volatile unsigned char __at(0x1657) GPCRI7; - -__xdata volatile unsigned char __at(0x1658) GPCRJ0; -__xdata volatile unsigned char __at(0x1659) GPCRJ1; -__xdata volatile unsigned char __at(0x165A) GPCRJ2; -__xdata volatile unsigned char __at(0x165B) GPCRJ3; -__xdata volatile unsigned char __at(0x165C) GPCRJ4; -__xdata volatile unsigned char __at(0x165D) GPCRJ5; -__xdata volatile unsigned char __at(0x165E) GPCRJ6; -__xdata volatile unsigned char __at(0x165F) GPCRJ7; - -__xdata volatile unsigned char __at(0x16A0) GPCRM0; -__xdata volatile unsigned char __at(0x16A1) GPCRM1; -__xdata volatile unsigned char __at(0x16A2) GPCRM2; -__xdata volatile unsigned char __at(0x16A3) GPCRM3; -__xdata volatile unsigned char __at(0x16A4) GPCRM4; -__xdata volatile unsigned char __at(0x16A5) GPCRM5; -__xdata volatile unsigned char __at(0x16A6) GPCRM6; - -#endif // _GPIO_H_ diff --git a/src/board/system76/galp3-c/include/kbscan.h b/src/board/system76/galp3-c/include/kbscan.h deleted file mode 100644 index 82bdc24..0000000 --- a/src/board/system76/galp3-c/include/kbscan.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef _KBSCAN_H_ -#define _KBSCAN_H_ - -void kbscan_init(void); - -__xdata volatile unsigned char __at(0x1D00) KSOL; -__xdata volatile unsigned char __at(0x1D01) KSOH1; -__xdata volatile unsigned char __at(0x1D02) KSOCTRL; -__xdata volatile unsigned char __at(0x1D03) KSOH2; -__xdata volatile unsigned char __at(0x1D04) KSI; -__xdata volatile unsigned char __at(0x1D05) KSICTRLR; -__xdata volatile unsigned char __at(0x1D06) KSIGCTRL; -__xdata volatile unsigned char __at(0x1D07) KSIGOEN; -__xdata volatile unsigned char __at(0x1D08) KSIGDAT; -__xdata volatile unsigned char __at(0x1D09) KSIGDMRR; -__xdata volatile unsigned char __at(0x1D0A) KSOHGCTRL; -__xdata volatile unsigned char __at(0x1D0B) KSOHGOEN; -__xdata volatile unsigned char __at(0x1D0C) KSOHGDMRR; -__xdata volatile unsigned char __at(0x1D0D) KSOLGCTRL; -__xdata volatile unsigned char __at(0x1D0E) KSOLGOEN; -__xdata volatile unsigned char __at(0x1D0F) KSOLGDMRR; - -__xdata volatile unsigned char __at(0x1D10) KSO0LSDR; -__xdata volatile unsigned char __at(0x1D11) KSO1LSDR; -__xdata volatile unsigned char __at(0x1D12) KSO2LSDR; -__xdata volatile unsigned char __at(0x1D13) KSO3LSDR; -__xdata volatile unsigned char __at(0x1D14) KSO4LSDR; -__xdata volatile unsigned char __at(0x1D15) KSO5LSDR; -__xdata volatile unsigned char __at(0x1D16) KSO6LSDR; -__xdata volatile unsigned char __at(0x1D17) KSO7LSDR; -__xdata volatile unsigned char __at(0x1D18) KSO8LSDR; -__xdata volatile unsigned char __at(0x1D19) KSO9LSDR; -__xdata volatile unsigned char __at(0x1D1A) KSO10LSDR; -__xdata volatile unsigned char __at(0x1D1B) KSO11LSDR; -__xdata volatile unsigned char __at(0x1D1C) KSO12LSDR; -__xdata volatile unsigned char __at(0x1D1D) KSO13LSDR; -__xdata volatile unsigned char __at(0x1D1E) KSO14LSDR; -__xdata volatile unsigned char __at(0x1D1F) KSO15LSDR; -__xdata volatile unsigned char __at(0x1D20) KSO16LSDR; -__xdata volatile unsigned char __at(0x1D21) KSO17LSDR; - -__xdata volatile unsigned char __at(0x1D22) SDC1R; -__xdata volatile unsigned char __at(0x1D23) SDC2R; -__xdata volatile unsigned char __at(0x1D24) SDC3R; -__xdata volatile unsigned char __at(0x1D25) SDSR; - -#endif // _KBSCAN_H_ diff --git a/src/board/system76/galp3-c/include/pin.h b/src/board/system76/galp3-c/include/pin.h deleted file mode 100644 index 67e31df..0000000 --- a/src/board/system76/galp3-c/include/pin.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef _PIN_H_ -#define _PIN_H_ - -#include - -#include "gpio.h" - -struct Pin { - __xdata volatile unsigned char * data; - __xdata volatile unsigned char * mirror; - __xdata volatile unsigned char * control; - unsigned char value; -}; - -#define PIN(BLOCK, NUMBER) { \ - .data = &GPDR ## BLOCK, \ - .mirror = &GPDMR ## BLOCK, \ - .control = &GPCR ## BLOCK ## NUMBER, \ - .value = (1 << NUMBER), \ -} - -bool pin_get(struct Pin * pin); -void pin_set(struct Pin * pin, bool value); - -#endif // _PIN_H_ diff --git a/src/board/system76/galp3-c/include/ps2.h b/src/board/system76/galp3-c/include/ps2.h deleted file mode 100644 index 3975898..0000000 --- a/src/board/system76/galp3-c/include/ps2.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _PS2_H_ -#define _PS2_H_ - -void ps2_init(void); - -__xdata volatile unsigned char __at(0x1700) PSCTL1; -__xdata volatile unsigned char __at(0x1701) PSCTL2; -__xdata volatile unsigned char __at(0x1702) PSCTL3; - -__xdata volatile unsigned char __at(0x1704) PSINT1; -__xdata volatile unsigned char __at(0x1705) PSINT2; -__xdata volatile unsigned char __at(0x1706) PSINT3; - -__xdata volatile unsigned char __at(0x1708) PSSTS1; -__xdata volatile unsigned char __at(0x1709) PSSTS2; -__xdata volatile unsigned char __at(0x170A) PSSTS3; - -__xdata volatile unsigned char __at(0x170C) PSDAT1; -__xdata volatile unsigned char __at(0x170D) PSDAT2; -__xdata volatile unsigned char __at(0x170E) PSDAT3; - -#endif // _PS2_H_ diff --git a/src/board/system76/galp3-c/include/reset.h b/src/board/system76/galp3-c/include/reset.h deleted file mode 100644 index 0201dcc..0000000 --- a/src/board/system76/galp3-c/include/reset.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _RESET_H_ -#define _RESET_H_ - -void reset(void); - -#endif // _RESET_H_ diff --git a/src/board/system76/galp3-c/kbc.c b/src/board/system76/galp3-c/kbc.c index 20e1a49..d8a1609 100644 --- a/src/board/system76/galp3-c/kbc.c +++ b/src/board/system76/galp3-c/kbc.c @@ -1,45 +1,6 @@ -#include - -#include "include/kbc.h" - -__code struct Kbc KBC = { - .control = &KBHICR, - .irq = &KBIRQR, - .status = &KBHISR, - .keyboard_out = &KBHIKDOR, - .mouse_out = &KBHIMDOR, - .data_in = &KBHIDIR, -}; +#include void kbc_init(void) { *(KBC.irq) = 0; *(KBC.control) = 0x48; } - -uint8_t kbc_status(struct Kbc * kbc) { - return *(kbc->status); -} - -uint8_t kbc_read(struct Kbc * kbc) { - return *(kbc->data_in); -} - -void kbc_keyboard(struct Kbc * kbc, uint8_t data) { - *(kbc->keyboard_out) = data; -} - -void kbc_mouse(struct Kbc * kbc, uint8_t data) { - *(kbc->mouse_out) = data; -} - -void kbc_event(struct Kbc * kbc) { - uint8_t sts = kbc_status(kbc); - if (sts & KBC_STS_IBF) { - uint8_t data = kbc_read(kbc); - if (sts & KBC_STS_CMD) { - printf("kbc cmd: %02X\n", data); - } else { - printf("kbc data: %02X\n", data); - } - } -} diff --git a/src/board/system76/galp3-c/kbscan.c b/src/board/system76/galp3-c/kbscan.c index 7444211..2fbbeed 100644 --- a/src/board/system76/galp3-c/kbscan.c +++ b/src/board/system76/galp3-c/kbscan.c @@ -1,4 +1,4 @@ -#include "include/kbscan.h" +#include void kbscan_init(void) { KSOCTRL = 0x05; diff --git a/src/board/system76/galp3-c/main.c b/src/board/system76/galp3-c/main.c index 2ea3008..5250c12 100644 --- a/src/board/system76/galp3-c/main.c +++ b/src/board/system76/galp3-c/main.c @@ -2,14 +2,13 @@ #include #include -#include "include/delay.h" -#include "include/gpio.h" -#include "include/gctrl.h" -#include "include/kbc.h" -#include "include/pin.h" -#include "include/pmc.h" -#include "include/ps2.h" -#include "include/kbscan.h" +#include +#include +#include +#include +#include +#include +#include void external_0(void) __interrupt(0) { printf("external_0\n"); @@ -47,24 +46,24 @@ void init(void) { // PECI information can be found here: https://www.intel.com/content/dam/www/public/us/en/documents/design-guides/core-i7-lga-2011-guide.pdf } -void power_button(struct Pin * button) { +void power_button(struct Gpio * button) { static bool last = false; // Check if the power switch goes low - bool new = pin_get(button); + bool new = gpio_get(button); if (!new && last) { printf("Power Switch\n"); } last = new; } -struct Pin PWR_SW = PIN(D, 0); +struct Gpio PWR_SW = GPIO(D, 0); -struct Pin LED_BAT_CHG = PIN(A, 5); -struct Pin LED_BAT_FULL = PIN(A, 6); -struct Pin LED_PWR = PIN(A, 7); -struct Pin LED_ACIN = PIN(C, 7); -struct Pin LED_AIRPLANE_N = PIN(G, 6); +struct Gpio LED_BAT_CHG = GPIO(A, 5); +struct Gpio LED_BAT_FULL = GPIO(A, 6); +struct Gpio LED_PWR = GPIO(A, 7); +struct Gpio LED_ACIN = GPIO(C, 7); +struct Gpio LED_AIRPLANE_N = GPIO(G, 6); __code const char * MODEL = "galp3-c"; @@ -72,7 +71,7 @@ void main(void) { init(); // Set the battery full LED (to know our firmware is loaded) - pin_set(&LED_BAT_FULL, true); + gpio_set(&LED_BAT_FULL, true); printf("Hello from System76 EC for %s!\n", MODEL); gpio_debug(); diff --git a/src/board/system76/galp3-c/pin.c b/src/board/system76/galp3-c/pin.c deleted file mode 100644 index 47c0666..0000000 --- a/src/board/system76/galp3-c/pin.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "include/pin.h" - -bool pin_get(struct Pin * pin) { - if (*(pin->data) & pin->value) { - return true; - } else { - return false; - } -} - -void pin_set(struct Pin * pin, bool value) { - if (value) { - *(pin->data) |= pin->value; - } else { - *(pin->data) &= ~(pin->value); - } -} diff --git a/src/board/system76/galp3-c/pmc.c b/src/board/system76/galp3-c/pmc.c index b9ad3ee..e881695 100644 --- a/src/board/system76/galp3-c/pmc.c +++ b/src/board/system76/galp3-c/pmc.c @@ -1,84 +1,6 @@ -#include - -#include "include/acpi.h" -#include "include/pmc.h" - -#define PMC(NUM) { \ - .status = &PM ## NUM ## STS, \ - .data_out = &PM ## NUM ## DO, \ - .data_in = &PM ## NUM ## DI, \ - .control = &PM ## NUM ## CTL, \ -} - -__code struct Pmc PMC_1 = PMC(1); -__code struct Pmc PMC_2 = PMC(2); +#include void pmc_init(void) { *(PMC_1.control) = 0x41; *(PMC_2.control) = 0x41; } - -uint8_t pmc_status(struct Pmc * pmc) { - return *(pmc->status); -} - -uint8_t pmc_read(struct Pmc * pmc) { - return *(pmc->data_in); -} - -void pmc_write(struct Pmc * pmc, uint8_t data) { - *(pmc->data_out) = data; -} - -enum PmcState { - PMC_STATE_DEFAULT, - PMC_STATE_ACPI_READ, - PMC_STATE_ACPI_WRITE, - PMC_STATE_ACPI_WRITE_ADDR, -}; - -void pmc_event(struct Pmc * pmc) { - static enum PmcState state = PMC_STATE_DEFAULT; - static uint8_t state_data[2] = {0, 0}; - - uint8_t sts = pmc_status(pmc); - if (sts & PMC_STS_IBF) { - uint8_t data = pmc_read(pmc); - if (sts & PMC_STS_CMD) { - printf("pmc cmd: %02X\n", data); - - switch (data) { - case 0x80: - state = PMC_STATE_ACPI_READ; - break; - case 0x81: - state = PMC_STATE_ACPI_WRITE; - break; - default: - state = PMC_STATE_DEFAULT; - break; - } - } else { - printf("pmc data: %02X\n", data); - - switch (state) { - case PMC_STATE_ACPI_READ: - state = PMC_STATE_DEFAULT; - uint8_t value = acpi_read(data); - pmc_write(pmc, value); - break; - case PMC_STATE_ACPI_WRITE: - state = PMC_STATE_ACPI_WRITE_ADDR; - state_data[0] = data; - break; - case PMC_STATE_ACPI_WRITE_ADDR: - state = PMC_STATE_DEFAULT; - acpi_write(state_data[0], data); - break; - default: - state = PMC_STATE_DEFAULT; - break; - } - } - } -} diff --git a/src/board/system76/galp3-c/ps2.c b/src/board/system76/galp3-c/ps2.c index 24609ab..8fa34a9 100644 --- a/src/board/system76/galp3-c/ps2.c +++ b/src/board/system76/galp3-c/ps2.c @@ -1,4 +1,4 @@ -#include "include/ps2.h" +#include void ps2_init(void) { PSCTL1 = 0x11; diff --git a/src/board/system76/galp3-c/stdio.c b/src/board/system76/galp3-c/stdio.c index 3e356dd..3dbdeef 100644 --- a/src/board/system76/galp3-c/stdio.c +++ b/src/board/system76/galp3-c/stdio.c @@ -1,7 +1,7 @@ #include -#include "include/kbscan.h" -#include "include/timer.h" +#include +#include // Wait 25 us // 65536 - (25 / 1.304) = 65517 diff --git a/src/ec/it8587e/gpio.c b/src/ec/it8587e/gpio.c new file mode 100644 index 0000000..a0118f8 --- /dev/null +++ b/src/ec/it8587e/gpio.c @@ -0,0 +1,17 @@ +#include + +bool gpio_get(struct Gpio * gpio) { + if (*(gpio->data) & gpio->value) { + return true; + } else { + return false; + } +} + +void gpio_set(struct Gpio * gpio, bool value) { + if (value) { + *(gpio->data) |= gpio->value; + } else { + *(gpio->data) &= ~(gpio->value); + } +} diff --git a/src/ec/it8587e/include/ec/gctrl.h b/src/ec/it8587e/include/ec/gctrl.h new file mode 100644 index 0000000..a2a86bf --- /dev/null +++ b/src/ec/it8587e/include/ec/gctrl.h @@ -0,0 +1,10 @@ +#ifndef _EC_GCTRL_H +#define _EC_GCTRL_H + +#include + +__xdata volatile uint8_t __at(0x2006) RSTS; +__xdata volatile uint8_t __at(0x200A) BADRSEL; +__xdata volatile uint8_t __at(0x200D) SPCTRL1; + +#endif // _EC_GCTRL_H diff --git a/src/ec/it8587e/include/ec/gpio.h b/src/ec/it8587e/include/ec/gpio.h new file mode 100644 index 0000000..c1c2534 --- /dev/null +++ b/src/ec/it8587e/include/ec/gpio.h @@ -0,0 +1,160 @@ +#ifndef _EC_GPIO_H +#define _EC_GPIO_H + +#include +#include + +struct Gpio { + __xdata volatile uint8_t * data; + __xdata volatile uint8_t * mirror; + __xdata volatile uint8_t * control; + uint8_t value; +}; + +#define GPIO(BLOCK, NUMBER) { \ + .data = &GPDR ## BLOCK, \ + .mirror = &GPDMR ## BLOCK, \ + .control = &GPCR ## BLOCK ## NUMBER, \ + .value = (1 << NUMBER), \ +} + +bool gpio_get(struct Gpio * gpio); +void gpio_set(struct Gpio * gpio, bool value); + +__xdata volatile uint8_t __at(0x1600) GCR; + +__xdata volatile uint8_t __at(0x1601) GPDRA; +__xdata volatile uint8_t __at(0x1602) GPDRB; +__xdata volatile uint8_t __at(0x1603) GPDRC; +__xdata volatile uint8_t __at(0x1604) GPDRD; +__xdata volatile uint8_t __at(0x1605) GPDRE; +__xdata volatile uint8_t __at(0x1606) GPDRF; +__xdata volatile uint8_t __at(0x1607) GPDRG; +__xdata volatile uint8_t __at(0x1608) GPDRH; +__xdata volatile uint8_t __at(0x1609) GPDRI; +__xdata volatile uint8_t __at(0x160A) GPDRJ; +__xdata volatile uint8_t __at(0x160D) GPDRM; + +__xdata volatile uint8_t __at(0x1661) GPDMRA; +__xdata volatile uint8_t __at(0x1662) GPDMRB; +__xdata volatile uint8_t __at(0x1663) GPDMRC; +__xdata volatile uint8_t __at(0x1664) GPDMRD; +__xdata volatile uint8_t __at(0x1665) GPDMRE; +__xdata volatile uint8_t __at(0x1666) GPDMRF; +__xdata volatile uint8_t __at(0x1667) GPDMRG; +__xdata volatile uint8_t __at(0x1668) GPDMRH; +__xdata volatile uint8_t __at(0x1669) GPDMRI; +__xdata volatile uint8_t __at(0x166A) GPDMRJ; +__xdata volatile uint8_t __at(0x166D) GPDMRM; + +__xdata volatile uint8_t __at(0x1671) GPOTA; +__xdata volatile uint8_t __at(0x1672) GPOTB; +__xdata volatile uint8_t __at(0x1673) GPOTC; +__xdata volatile uint8_t __at(0x1674) GPOTD; +__xdata volatile uint8_t __at(0x1675) GPOTE; +__xdata volatile uint8_t __at(0x1676) GPOTF; +__xdata volatile uint8_t __at(0x1677) GPOTG; +__xdata volatile uint8_t __at(0x1678) GPOTH; +__xdata volatile uint8_t __at(0x1679) GPOTI; +__xdata volatile uint8_t __at(0x167A) GPOTJ; +// GPOTM does not exist + +__xdata volatile uint8_t __at(0x1610) GPCRA0; +__xdata volatile uint8_t __at(0x1611) GPCRA1; +__xdata volatile uint8_t __at(0x1612) GPCRA2; +__xdata volatile uint8_t __at(0x1613) GPCRA3; +__xdata volatile uint8_t __at(0x1614) GPCRA4; +__xdata volatile uint8_t __at(0x1615) GPCRA5; +__xdata volatile uint8_t __at(0x1616) GPCRA6; +__xdata volatile uint8_t __at(0x1617) GPCRA7; + +__xdata volatile uint8_t __at(0x1618) GPCRB0; +__xdata volatile uint8_t __at(0x1619) GPCRB1; +__xdata volatile uint8_t __at(0x161A) GPCRB2; +__xdata volatile uint8_t __at(0x161B) GPCRB3; +__xdata volatile uint8_t __at(0x161C) GPCRB4; +__xdata volatile uint8_t __at(0x161D) GPCRB5; +__xdata volatile uint8_t __at(0x161E) GPCRB6; +__xdata volatile uint8_t __at(0x161F) GPCRB7; + +__xdata volatile uint8_t __at(0x1620) GPCRC0; +__xdata volatile uint8_t __at(0x1621) GPCRC1; +__xdata volatile uint8_t __at(0x1622) GPCRC2; +__xdata volatile uint8_t __at(0x1623) GPCRC3; +__xdata volatile uint8_t __at(0x1624) GPCRC4; +__xdata volatile uint8_t __at(0x1625) GPCRC5; +__xdata volatile uint8_t __at(0x1626) GPCRC6; +__xdata volatile uint8_t __at(0x1627) GPCRC7; + +__xdata volatile uint8_t __at(0x1628) GPCRD0; +__xdata volatile uint8_t __at(0x1629) GPCRD1; +__xdata volatile uint8_t __at(0x162A) GPCRD2; +__xdata volatile uint8_t __at(0x162B) GPCRD3; +__xdata volatile uint8_t __at(0x162C) GPCRD4; +__xdata volatile uint8_t __at(0x162D) GPCRD5; +__xdata volatile uint8_t __at(0x162E) GPCRD6; +__xdata volatile uint8_t __at(0x162F) GPCRD7; + +__xdata volatile uint8_t __at(0x1630) GPCRE0; +__xdata volatile uint8_t __at(0x1631) GPCRE1; +__xdata volatile uint8_t __at(0x1632) GPCRE2; +__xdata volatile uint8_t __at(0x1633) GPCRE3; +__xdata volatile uint8_t __at(0x1634) GPCRE4; +__xdata volatile uint8_t __at(0x1635) GPCRE5; +__xdata volatile uint8_t __at(0x1636) GPCRE6; +__xdata volatile uint8_t __at(0x1637) GPCRE7; + +__xdata volatile uint8_t __at(0x1638) GPCRF0; +__xdata volatile uint8_t __at(0x1639) GPCRF1; +__xdata volatile uint8_t __at(0x163A) GPCRF2; +__xdata volatile uint8_t __at(0x163B) GPCRF3; +__xdata volatile uint8_t __at(0x163C) GPCRF4; +__xdata volatile uint8_t __at(0x163D) GPCRF5; +__xdata volatile uint8_t __at(0x163E) GPCRF6; +__xdata volatile uint8_t __at(0x163F) GPCRF7; + +__xdata volatile uint8_t __at(0x1640) GPCRG0; +__xdata volatile uint8_t __at(0x1641) GPCRG1; +__xdata volatile uint8_t __at(0x1642) GPCRG2; +__xdata volatile uint8_t __at(0x1643) GPCRG3; +__xdata volatile uint8_t __at(0x1644) GPCRG4; +__xdata volatile uint8_t __at(0x1645) GPCRG5; +__xdata volatile uint8_t __at(0x1646) GPCRG6; +__xdata volatile uint8_t __at(0x1647) GPCRG7; + +__xdata volatile uint8_t __at(0x1648) GPCRH0; +__xdata volatile uint8_t __at(0x1649) GPCRH1; +__xdata volatile uint8_t __at(0x164A) GPCRH2; +__xdata volatile uint8_t __at(0x164B) GPCRH3; +__xdata volatile uint8_t __at(0x164C) GPCRH4; +__xdata volatile uint8_t __at(0x164D) GPCRH5; +__xdata volatile uint8_t __at(0x164E) GPCRH6; +__xdata volatile uint8_t __at(0x164F) GPCRH7; + +__xdata volatile uint8_t __at(0x1650) GPCRI0; +__xdata volatile uint8_t __at(0x1651) GPCRI1; +__xdata volatile uint8_t __at(0x1652) GPCRI2; +__xdata volatile uint8_t __at(0x1653) GPCRI3; +__xdata volatile uint8_t __at(0x1654) GPCRI4; +__xdata volatile uint8_t __at(0x1655) GPCRI5; +__xdata volatile uint8_t __at(0x1656) GPCRI6; +__xdata volatile uint8_t __at(0x1657) GPCRI7; + +__xdata volatile uint8_t __at(0x1658) GPCRJ0; +__xdata volatile uint8_t __at(0x1659) GPCRJ1; +__xdata volatile uint8_t __at(0x165A) GPCRJ2; +__xdata volatile uint8_t __at(0x165B) GPCRJ3; +__xdata volatile uint8_t __at(0x165C) GPCRJ4; +__xdata volatile uint8_t __at(0x165D) GPCRJ5; +__xdata volatile uint8_t __at(0x165E) GPCRJ6; +__xdata volatile uint8_t __at(0x165F) GPCRJ7; + +__xdata volatile uint8_t __at(0x16A0) GPCRM0; +__xdata volatile uint8_t __at(0x16A1) GPCRM1; +__xdata volatile uint8_t __at(0x16A2) GPCRM2; +__xdata volatile uint8_t __at(0x16A3) GPCRM3; +__xdata volatile uint8_t __at(0x16A4) GPCRM4; +__xdata volatile uint8_t __at(0x16A5) GPCRM5; +__xdata volatile uint8_t __at(0x16A6) GPCRM6; + +#endif // _EC_GPIO_H diff --git a/src/board/system76/galp3-c/include/kbc.h b/src/ec/it8587e/include/ec/kbc.h similarity index 94% rename from src/board/system76/galp3-c/include/kbc.h rename to src/ec/it8587e/include/ec/kbc.h index 1a3b6d9..5db371d 100644 --- a/src/board/system76/galp3-c/include/kbc.h +++ b/src/ec/it8587e/include/ec/kbc.h @@ -1,5 +1,5 @@ -#ifndef _KBC_H_ -#define _KBC_H_ +#ifndef _EC_KBC_H +#define _EC_KBC_H #include @@ -40,4 +40,4 @@ __xdata volatile uint8_t __at(0x1306) KBHIKDOR; __xdata volatile uint8_t __at(0x1308) KBHIMDOR; __xdata volatile uint8_t __at(0x130A) KBHIDIR; -#endif // _KBC_H_ +#endif // _EC_KBC_H diff --git a/src/ec/it8587e/include/ec/kbscan.h b/src/ec/it8587e/include/ec/kbscan.h new file mode 100644 index 0000000..d821cb5 --- /dev/null +++ b/src/ec/it8587e/include/ec/kbscan.h @@ -0,0 +1,47 @@ +#ifndef _EC_KBSCAN_H +#define _EC_KBSCAN_H + +#include + +__xdata volatile uint8_t __at(0x1D00) KSOL; +__xdata volatile uint8_t __at(0x1D01) KSOH1; +__xdata volatile uint8_t __at(0x1D02) KSOCTRL; +__xdata volatile uint8_t __at(0x1D03) KSOH2; +__xdata volatile uint8_t __at(0x1D04) KSI; +__xdata volatile uint8_t __at(0x1D05) KSICTRLR; +__xdata volatile uint8_t __at(0x1D06) KSIGCTRL; +__xdata volatile uint8_t __at(0x1D07) KSIGOEN; +__xdata volatile uint8_t __at(0x1D08) KSIGDAT; +__xdata volatile uint8_t __at(0x1D09) KSIGDMRR; +__xdata volatile uint8_t __at(0x1D0A) KSOHGCTRL; +__xdata volatile uint8_t __at(0x1D0B) KSOHGOEN; +__xdata volatile uint8_t __at(0x1D0C) KSOHGDMRR; +__xdata volatile uint8_t __at(0x1D0D) KSOLGCTRL; +__xdata volatile uint8_t __at(0x1D0E) KSOLGOEN; +__xdata volatile uint8_t __at(0x1D0F) KSOLGDMRR; + +__xdata volatile uint8_t __at(0x1D10) KSO0LSDR; +__xdata volatile uint8_t __at(0x1D11) KSO1LSDR; +__xdata volatile uint8_t __at(0x1D12) KSO2LSDR; +__xdata volatile uint8_t __at(0x1D13) KSO3LSDR; +__xdata volatile uint8_t __at(0x1D14) KSO4LSDR; +__xdata volatile uint8_t __at(0x1D15) KSO5LSDR; +__xdata volatile uint8_t __at(0x1D16) KSO6LSDR; +__xdata volatile uint8_t __at(0x1D17) KSO7LSDR; +__xdata volatile uint8_t __at(0x1D18) KSO8LSDR; +__xdata volatile uint8_t __at(0x1D19) KSO9LSDR; +__xdata volatile uint8_t __at(0x1D1A) KSO10LSDR; +__xdata volatile uint8_t __at(0x1D1B) KSO11LSDR; +__xdata volatile uint8_t __at(0x1D1C) KSO12LSDR; +__xdata volatile uint8_t __at(0x1D1D) KSO13LSDR; +__xdata volatile uint8_t __at(0x1D1E) KSO14LSDR; +__xdata volatile uint8_t __at(0x1D1F) KSO15LSDR; +__xdata volatile uint8_t __at(0x1D20) KSO16LSDR; +__xdata volatile uint8_t __at(0x1D21) KSO17LSDR; + +__xdata volatile uint8_t __at(0x1D22) SDC1R; +__xdata volatile uint8_t __at(0x1D23) SDC2R; +__xdata volatile uint8_t __at(0x1D24) SDC3R; +__xdata volatile uint8_t __at(0x1D25) SDSR; + +#endif // _EC_KBSCAN_H diff --git a/src/board/system76/galp3-c/include/pmc.h b/src/ec/it8587e/include/ec/pmc.h similarity index 92% rename from src/board/system76/galp3-c/include/pmc.h rename to src/ec/it8587e/include/ec/pmc.h index 92eb120..13d1255 100644 --- a/src/board/system76/galp3-c/include/pmc.h +++ b/src/ec/it8587e/include/ec/pmc.h @@ -1,10 +1,8 @@ -#ifndef _PMC_H_ -#define _PMC_H_ +#ifndef _EC_PMC_H +#define _EC_PMC_H #include -void pmc_init(void); - struct Pmc { // Status register volatile uint8_t * status; @@ -39,4 +37,4 @@ __xdata volatile uint8_t __at(0x1511) PM2DO; __xdata volatile uint8_t __at(0x1514) PM2DI; __xdata volatile uint8_t __at(0x1516) PM2CTL; -#endif // _PMC_H_ +#endif // _EC_PMC_H diff --git a/src/ec/it8587e/include/ec/ps2.h b/src/ec/it8587e/include/ec/ps2.h new file mode 100644 index 0000000..73ee6a4 --- /dev/null +++ b/src/ec/it8587e/include/ec/ps2.h @@ -0,0 +1,22 @@ +#ifndef _EC_PS2_H +#define _EC_PS2_H + +#include + +__xdata volatile uint8_t __at(0x1700) PSCTL1; +__xdata volatile uint8_t __at(0x1701) PSCTL2; +__xdata volatile uint8_t __at(0x1702) PSCTL3; + +__xdata volatile uint8_t __at(0x1704) PSINT1; +__xdata volatile uint8_t __at(0x1705) PSINT2; +__xdata volatile uint8_t __at(0x1706) PSINT3; + +__xdata volatile uint8_t __at(0x1708) PSSTS1; +__xdata volatile uint8_t __at(0x1709) PSSTS2; +__xdata volatile uint8_t __at(0x170A) PSSTS3; + +__xdata volatile uint8_t __at(0x170C) PSDAT1; +__xdata volatile uint8_t __at(0x170D) PSDAT2; +__xdata volatile uint8_t __at(0x170E) PSDAT3; + +#endif // _EC_PS2_H diff --git a/src/ec/it8587e/kbc.c b/src/ec/it8587e/kbc.c new file mode 100644 index 0000000..2ea3aea --- /dev/null +++ b/src/ec/it8587e/kbc.c @@ -0,0 +1,40 @@ +#include + +#include + +__code struct Kbc KBC = { + .control = &KBHICR, + .irq = &KBIRQR, + .status = &KBHISR, + .keyboard_out = &KBHIKDOR, + .mouse_out = &KBHIMDOR, + .data_in = &KBHIDIR, +}; + +uint8_t kbc_status(struct Kbc * kbc) { + return *(kbc->status); +} + +uint8_t kbc_read(struct Kbc * kbc) { + return *(kbc->data_in); +} + +void kbc_keyboard(struct Kbc * kbc, uint8_t data) { + *(kbc->keyboard_out) = data; +} + +void kbc_mouse(struct Kbc * kbc, uint8_t data) { + *(kbc->mouse_out) = data; +} + +void kbc_event(struct Kbc * kbc) { + uint8_t sts = kbc_status(kbc); + if (sts & KBC_STS_IBF) { + uint8_t data = kbc_read(kbc); + if (sts & KBC_STS_CMD) { + printf("kbc cmd: %02X\n", data); + } else { + printf("kbc data: %02X\n", data); + } + } +} diff --git a/src/ec/it8587e/pmc.c b/src/ec/it8587e/pmc.c new file mode 100644 index 0000000..8e8e9e8 --- /dev/null +++ b/src/ec/it8587e/pmc.c @@ -0,0 +1,79 @@ +#include + +#include +#include + +#define PMC(NUM) { \ + .status = &PM ## NUM ## STS, \ + .data_out = &PM ## NUM ## DO, \ + .data_in = &PM ## NUM ## DI, \ + .control = &PM ## NUM ## CTL, \ +} + +__code struct Pmc PMC_1 = PMC(1); +__code struct Pmc PMC_2 = PMC(2); + +uint8_t pmc_status(struct Pmc * pmc) { + return *(pmc->status); +} + +uint8_t pmc_read(struct Pmc * pmc) { + return *(pmc->data_in); +} + +void pmc_write(struct Pmc * pmc, uint8_t data) { + *(pmc->data_out) = data; +} + +enum PmcState { + PMC_STATE_DEFAULT, + PMC_STATE_ACPI_READ, + PMC_STATE_ACPI_WRITE, + PMC_STATE_ACPI_WRITE_ADDR, +}; + +void pmc_event(struct Pmc * pmc) { + static enum PmcState state = PMC_STATE_DEFAULT; + static uint8_t state_data[2] = {0, 0}; + + uint8_t sts = pmc_status(pmc); + if (sts & PMC_STS_IBF) { + uint8_t data = pmc_read(pmc); + if (sts & PMC_STS_CMD) { + printf("pmc cmd: %02X\n", data); + + switch (data) { + case 0x80: + state = PMC_STATE_ACPI_READ; + break; + case 0x81: + state = PMC_STATE_ACPI_WRITE; + break; + default: + state = PMC_STATE_DEFAULT; + break; + } + } else { + printf("pmc data: %02X\n", data); + + switch (state) { + case PMC_STATE_ACPI_READ: + state = PMC_STATE_DEFAULT; + uint8_t value = acpi_read(data); + pmc_write(pmc, value); + break; + case PMC_STATE_ACPI_WRITE: + state = PMC_STATE_ACPI_WRITE_ADDR; + state_data[0] = data; + break; + case PMC_STATE_ACPI_WRITE_ADDR: + state = PMC_STATE_DEFAULT; + acpi_write(state_data[0], data); + break; + default: + state = PMC_STATE_DEFAULT; + break; + } + } + } +} diff --git a/src/board/system76/galp3-c/signature.c b/src/ec/it8587e/signature.c similarity index 100% rename from src/board/system76/galp3-c/signature.c rename to src/ec/it8587e/signature.c