diff --git a/src/board/system76/addw2/board.mk b/src/board/system76/addw2/board.mk index 4911364..ee7c660 100644 --- a/src/board/system76/addw2/board.mk +++ b/src/board/system76/addw2/board.mk @@ -4,18 +4,6 @@ EC=it5570e KEYMAP?=default SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c -# Set log level -# 0 - NONE -# 1 - ERROR -# 2 - WARN -# 3 - INFO -# 4 - DEBUG -# 5 - TRACE -CFLAGS+=-DLEVEL=4 - -# Enable I2C debug on 0x76 -#CFLAGS+=-DI2C_DEBUGGER=0x76 - # Set discrete GPU I2C bus CFLAGS+=-DI2C_DGPU=I2C_1 @@ -25,6 +13,17 @@ CFLAGS+=-DI2C_SMBUS=I2C_4 # Set touchpad PS2 bus CFLAGS+=-DPS2_TOUCHPAD=PS2_3 +# Set smart charger parameters +CFLAGS+=\ + -DCHARGER_CHARGE_CURRENT=1536 \ + -DCHARGER_CHARGE_VOLTAGE=12600 \ + -DCHARGER_INPUT_CURRENT=11800 + +# Set CPU power limits in watts +CFLAGS+=\ + -DPOWER_LIMIT_AC=180 \ + -DPOWER_LIMIT_DC=28 + # Custom fan curve CLFAGS+=-DBOARD_HEATUP=5 CFLAGS+=-DBOARD_COOLDOWN=20 @@ -36,12 +35,6 @@ CFLAGS+=-DBOARD_FAN_POINTS="\ FAN_POINT(80, 100) \ " -# Set smart charger parameters -CFLAGS+=\ - -DCHARGER_CHARGE_CURRENT=1536 \ - -DCHARGER_CHARGE_VOLTAGE=12600 \ - -DCHARGER_INPUT_CURRENT=11800 - # Enable DGPU support CFLAGS+=-DHAVE_DGPU=1 CLFAGS+=-DBOARD_DGPU_HEATUP=5 @@ -54,13 +47,5 @@ CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\ FAN_POINT(80, 100) \ " -# Set CPU power limits in watts -CFLAGS+=\ - -DPOWER_LIMIT_AC=180 \ - -DPOWER_LIMIT_DC=28 - -# Enable debug logging over keyboard parallel port -#CFLAGS+=-DPARPORT_DEBUG - # Add system76 common code include src/board/system76/common/common.mk diff --git a/src/board/system76/common/common.mk b/src/board/system76/common/common.mk index 9183d8c..30c9bff 100644 --- a/src/board/system76/common/common.mk +++ b/src/board/system76/common/common.mk @@ -1,11 +1,27 @@ +# Set log level +# 0 - NONE +# 1 - ERROR +# 2 - WARN +# 3 - INFO +# 4 - DEBUG +# 5 - TRACE +CFLAGS+=-DLEVEL=4 + +# Uncomment to enable debug logging over keyboard parallel port +#CFLAGS+=-DPARALLEL_DEBUG + +# Uncomment to enable I2C debug on 0x76 +#CFLAGS+=-DI2C_DEBUGGER=0x76 + +# Set external programmer +PROGRAMMER=$(wildcard /dev/serial/by-id/usb-Arduino*) + # Include system76 common source SYSTEM76_COMMON_DIR=src/board/system76/common SRC+=$(wildcard $(SYSTEM76_COMMON_DIR)/*.c) INCLUDE+=$(wildcard $(SYSTEM76_COMMON_DIR)/include/common/*.h) $(SYSTEM76_COMMON_DIR)/common.mk CFLAGS+=-I$(SYSTEM76_COMMON_DIR)/include -PROGRAMMER=$(wildcard /dev/serial/by-id/usb-Arduino*) - # Add scratch ROM include $(SYSTEM76_COMMON_DIR)/scratch/scratch.mk diff --git a/src/board/system76/common/include/board/parallel.h b/src/board/system76/common/include/board/parallel.h new file mode 100644 index 0000000..9eb78dc --- /dev/null +++ b/src/board/system76/common/include/board/parallel.h @@ -0,0 +1,11 @@ +#ifndef _BOARD_PARALLEL_H +#define _BOARD_PARALLEL_H + +#include +#include + +extern bool parallel_debug; +bool parallel_init(void); +int parallel_write(uint8_t * data, int length); + +#endif // _BOARD_PARALLEL_H diff --git a/src/board/system76/common/kbscan.c b/src/board/system76/common/kbscan.c index 90c77c2..ed94ec3 100644 --- a/src/board/system76/common/kbscan.c +++ b/src/board/system76/common/kbscan.c @@ -27,6 +27,11 @@ void kbscan_init(void) { KSOHGCTRL = 0xFF; KSOHGOEN = 0; KSOH2 = 0; + + // Set all inputs to KBS mode, low, and inputs + KSIGCTRL = 0; + KSIGOEN = 0; + KSIGDAT = 0; } // Debounce time in milliseconds diff --git a/src/board/system76/common/main.c b/src/board/system76/common/main.c index 4b62578..bf52f9c 100644 --- a/src/board/system76/common/main.c +++ b/src/board/system76/common/main.c @@ -27,9 +27,9 @@ #include #include -#ifdef PARPORT_DEBUG - #include -#endif +#ifdef PARALLEL_DEBUG + #include +#endif // PARALLEL_DEBUG void external_0(void) __interrupt(0) {} // timer_0 is in time.c @@ -55,11 +55,15 @@ void init(void) { ecpm_init(); kbc_init(); kbled_init(); -#ifdef PARPORT_DEBUG - parport_init(); -#else - kbscan_init(); -#endif +#ifdef PARALLEL_DEBUG + parallel_debug = false; + if (parallel_init()) { + parallel_debug = true; + } else +#endif // PARALLEL_DEBUG + { + kbscan_init(); + } peci_init(); pmc_init(); pwm_init(); @@ -91,10 +95,13 @@ void main(void) { power_event(); break; case 1: -#ifndef PARPORT_DEBUG - // Scans keyboard and sends keyboard packets - kbscan_event(); -#endif +#if PARALLEL_DEBUG + if (!parallel_debug) +#endif // PARALLEL_DEBUG + { + // Scans keyboard and sends keyboard packets + kbscan_event(); + } break; case 2: // Passes through touchpad packets diff --git a/src/ec/it5570e/parallel.c b/src/board/system76/common/parallel.c similarity index 79% rename from src/ec/it5570e/parallel.c rename to src/board/system76/common/parallel.c index 0094653..c8f2346 100644 --- a/src/ec/it5570e/parallel.c +++ b/src/board/system76/common/parallel.c @@ -1,7 +1,7 @@ #include #include +#include #include -#include #include @@ -24,9 +24,23 @@ #define STS_WAIT (1 << 1) // Maximum peripheral response time in ms -#define PARPORT_TIMEOUT 35 +#define PARALLEL_TIMEOUT 10 -void parport_init(void) { +bool parallel_debug = false; + +static bool parallel_wait_peripheral(uint8_t mask, uint8_t value) { + uint32_t start = time_get(); + + while (time_get() < start + PARALLEL_TIMEOUT) { + if ((KSOHGDMRR & mask) == value) { + return true; + } + } + + return false; +} + +bool parallel_init(void) { // XXX: Needed? Pull-ups, open-drain are always disabled in GPIO mode KSOCTRL = 0; // XXX: Needed? OVRPPK is for KBS mode, pull-ups are always disabled in GPIO mode @@ -52,7 +66,7 @@ void parport_init(void) { // Deassert nWRITE, nDATASTB, nADDRSTB KSIGDAT |= CTL_WRITE | CTL_DATA | CTL_ADDR; - // Set nWAIT high + // PUll up nWAIT KSOH1 |= STS_WAIT; // Pull up data lines @@ -60,21 +74,12 @@ void parport_init(void) { // Deassert nRESET KSIGDAT |= CTL_RESET; + + // Check if there is a peripheral waiting + return parallel_wait_peripheral(STS_WAIT, 0); } -bool parport_wait_peripheral(uint8_t mask, uint8_t value) { - uint32_t start = time_get(); - - while (time_get() < start + PARPORT_TIMEOUT) { - if ((KSOHGDMRR & mask) == value) { - return true; - } - } - - return false; -} - -int parport_write(uint8_t * data, int length) { +int parallel_write(uint8_t * data, int length) { // Assert nWRITE KSIGDAT &= ~CTL_WRITE; @@ -84,7 +89,7 @@ int parport_write(uint8_t * data, int length) { int i; for (i = 0; i < length; i++) { // Wait for peripheral to indicate it's ready for next cycle - if (!parport_wait_peripheral(STS_WAIT, 0)) { + if (!parallel_wait_peripheral(STS_WAIT, 0)) { break; } @@ -95,7 +100,7 @@ int parport_write(uint8_t * data, int length) { KSIGDAT &= ~CTL_DATA; // Wait for peripheral to indicate it's processing - if (!parport_wait_peripheral(STS_WAIT, STS_WAIT)) { + if (!parallel_wait_peripheral(STS_WAIT, STS_WAIT)) { KSIGDAT |= CTL_DATA; break; } @@ -104,7 +109,7 @@ int parport_write(uint8_t * data, int length) { KSIGDAT |= CTL_DATA; // Wait for peripheral to indicate it's ready for next cycle - if (!parport_wait_peripheral(STS_WAIT, 0)) { + if (!parallel_wait_peripheral(STS_WAIT, 0)) { break; } diff --git a/src/board/system76/common/stdio.c b/src/board/system76/common/stdio.c index 97faa0f..f44fe2f 100644 --- a/src/board/system76/common/stdio.c +++ b/src/board/system76/common/stdio.c @@ -10,21 +10,28 @@ #include #endif -#ifdef PARPORT_DEBUG - #include -#endif +#ifdef PARALLEL_DEBUG + #include +#endif // PARALLEL_DEBUG int putchar(int c) { unsigned char byte = (unsigned char)c; + smfi_debug(byte); + #ifdef SERIAL_DEBUGGER SBUF = byte; #endif + #ifdef I2C_DEBUGGER i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1); #endif -#ifdef PARPORT_DEBUG - parport_write(&byte, 1); -#endif + +#ifdef PARALLEL_DEBUG + if (parallel_debug) { + parallel_write(&byte, 1); + } +#endif // PARALLEL_DEBUG + return (int)byte; } diff --git a/src/board/system76/darp5/board.mk b/src/board/system76/darp5/board.mk index c9ab1dc..d2058e1 100644 --- a/src/board/system76/darp5/board.mk +++ b/src/board/system76/darp5/board.mk @@ -4,21 +4,12 @@ EC=it8587e KEYMAP?=default SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c -# Set log level -# 0 - NONE -# 1 - ERROR -# 2 - WARN -# 3 - INFO -# 4 - DEBUG -# 5 - TRACE -CFLAGS+=-DLEVEL=4 - -# Enable I2C debug on 0x76 -#CFLAGS+=-DI2C_DEBUGGER=0x76 - # Set battery I2C bus CFLAGS+=-DI2C_SMBUS=I2C_0 +# Set keyboard LED I2C bus +CFLAGS+=-DI2C_KBLED=I2C_1 + # Set touchpad PS2 bus CFLAGS+=-DPS2_TOUCHPAD=PS2_3 @@ -28,11 +19,5 @@ CFLAGS+=\ -DCHARGER_CHARGE_VOLTAGE=17600 \ -DCHARGER_INPUT_CURRENT=3200 -# Set keyboard LED I2C bus -CFLAGS+=-DI2C_KBLED=I2C_1 - -# Enable debug logging over keyboard parallel port -#CFLAGS+=-DPARPORT_DEBUG - # Add system76 common code include src/board/system76/common/common.mk diff --git a/src/board/system76/galp3-c/board.mk b/src/board/system76/galp3-c/board.mk index c56e6b9..a0c042c 100644 --- a/src/board/system76/galp3-c/board.mk +++ b/src/board/system76/galp3-c/board.mk @@ -4,18 +4,6 @@ EC=it8587e KEYMAP?=default SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c -# Set log level -# 0 - NONE -# 1 - ERROR -# 2 - WARN -# 3 - INFO -# 4 - DEBUG -# 5 - TRACE -CFLAGS+=-DLEVEL=4 - -# Enable I2C debug on 0x76 -#CFLAGS+=-DI2C_DEBUGGER=0x76 - # Set battery I2C bus CFLAGS+=-DI2C_SMBUS=I2C_0 @@ -28,8 +16,5 @@ CFLAGS+=\ -DCHARGER_CHARGE_VOLTAGE=13056 \ -DCHARGER_INPUT_CURRENT=1920 -# Enable debug logging over keyboard parallel port -#CFLAGS+=-DPARPORT_DEBUG - # Add system76 common code include src/board/system76/common/common.mk diff --git a/src/board/system76/gaze15/board.mk b/src/board/system76/gaze15/board.mk index 3f90c90..0b52039 100644 --- a/src/board/system76/gaze15/board.mk +++ b/src/board/system76/gaze15/board.mk @@ -4,18 +4,6 @@ EC=it5570e KEYMAP?=default SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c -# Set log level -# 0 - NONE -# 1 - ERROR -# 2 - WARN -# 3 - INFO -# 4 - DEBUG -# 5 - TRACE -CFLAGS+=-DLEVEL=4 - -# Enable I2C debug on 0x76 -#CFLAGS+=-DI2C_DEBUGGER=0x76 - # Set discrete GPU I2C bus CFLAGS+=-DI2C_DGPU=I2C_1 @@ -25,6 +13,17 @@ CFLAGS+=-DI2C_SMBUS=I2C_4 # Set touchpad PS2 bus CFLAGS+=-DPS2_TOUCHPAD=PS2_3 +# Set smart charger parameters +CFLAGS+=\ + -DCHARGER_CHARGE_CURRENT=1536 \ + -DCHARGER_CHARGE_VOLTAGE=16800 \ + -DCHARGER_INPUT_CURRENT=9230 + +# Set CPU power limits in watts +CFLAGS+=\ + -DPOWER_LIMIT_AC=180 \ + -DPOWER_LIMIT_DC=28 + # Custom fan curve CLFAGS+=-DBOARD_HEATUP=5 CFLAGS+=-DBOARD_COOLDOWN=20 @@ -36,12 +35,6 @@ CFLAGS+=-DBOARD_FAN_POINTS="\ FAN_POINT(80, 100) \ " -# Set smart charger parameters -CFLAGS+=\ - -DCHARGER_CHARGE_CURRENT=1536 \ - -DCHARGER_CHARGE_VOLTAGE=16800 \ - -DCHARGER_INPUT_CURRENT=9230 - # Enable DGPU support CFLAGS+=-DHAVE_DGPU=1 CLFAGS+=-DBOARD_DGPU_HEATUP=5 @@ -54,13 +47,5 @@ CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\ FAN_POINT(80, 100) \ " -# Set CPU power limits in watts -CFLAGS+=\ - -DPOWER_LIMIT_AC=180 \ - -DPOWER_LIMIT_DC=28 - -# Enable debug logging over keyboard parallel port -#CFLAGS+=-DPARPORT_DEBUG - # Add system76 common code include src/board/system76/common/common.mk diff --git a/src/board/system76/lemp9/board.mk b/src/board/system76/lemp9/board.mk index 99fa1dc..43b2b53 100644 --- a/src/board/system76/lemp9/board.mk +++ b/src/board/system76/lemp9/board.mk @@ -4,18 +4,6 @@ EC=it5570e KEYMAP?=default SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c -# Set log level -# 0 - NONE -# 1 - ERROR -# 2 - WARN -# 3 - INFO -# 4 - DEBUG -# 5 - TRACE -CFLAGS+=-DLEVEL=4 - -# Enable I2C debug on 0x76 -#CFLAGS+=-DI2C_DEBUGGER=0x76 - # Set battery I2C bus CFLAGS+=-DI2C_SMBUS=I2C_4 @@ -29,8 +17,5 @@ CFLAGS+=\ -DCHARGER_CHARGE_VOLTAGE=8800 \ -DCHARGER_INPUT_CURRENT=1600 -# Enable debug logging over keyboard parallel port -#CFLAGS+=-DPARPORT_DEBUG - # Add system76 common code include src/board/system76/common/common.mk diff --git a/src/board/system76/oryp6/board.mk b/src/board/system76/oryp6/board.mk index 59e48ad..4e00af8 100644 --- a/src/board/system76/oryp6/board.mk +++ b/src/board/system76/oryp6/board.mk @@ -4,18 +4,6 @@ EC=it5570e KEYMAP?=default SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c -# Set log level -# 0 - NONE -# 1 - ERROR -# 2 - WARN -# 3 - INFO -# 4 - DEBUG -# 5 - TRACE -CFLAGS+=-DLEVEL=4 - -# Enable I2C debug on 0x76 -#CFLAGS+=-DI2C_DEBUGGER=0x76 - # Set discrete GPU I2C bus CFLAGS+=-DI2C_DGPU=I2C_1 @@ -25,6 +13,17 @@ CFLAGS+=-DI2C_SMBUS=I2C_4 # Set touchpad PS2 bus CFLAGS+=-DPS2_TOUCHPAD=PS2_3 +# Set smart charger parameters +CFLAGS+=\ + -DCHARGER_CHARGE_CURRENT=1536 \ + -DCHARGER_CHARGE_VOLTAGE=16800 \ + -DCHARGER_INPUT_CURRENT=13050 + +# Set CPU power limits in watts +CFLAGS+=\ + -DPOWER_LIMIT_AC=180 \ + -DPOWER_LIMIT_DC=28 + # Custom fan curve CLFAGS+=-DBOARD_HEATUP=5 CFLAGS+=-DBOARD_COOLDOWN=20 @@ -36,12 +35,6 @@ CFLAGS+=-DBOARD_FAN_POINTS="\ FAN_POINT(80, 100) \ " -# Set smart charger parameters -CFLAGS+=\ - -DCHARGER_CHARGE_CURRENT=1536 \ - -DCHARGER_CHARGE_VOLTAGE=16800 \ - -DCHARGER_INPUT_CURRENT=13050 - # Enable DGPU support CFLAGS+=-DHAVE_DGPU=1 CLFAGS+=-DBOARD_DGPU_HEATUP=5 @@ -54,13 +47,5 @@ CFLAGS+=-DBOARD_DGPU_FAN_POINTS="\ FAN_POINT(80, 100) \ " -# Set CPU power limits in watts -CFLAGS+=\ - -DPOWER_LIMIT_AC=180 \ - -DPOWER_LIMIT_DC=28 - -# Enable debug logging over keyboard parallel port -#CFLAGS+=-DPARPORT_DEBUG - # Add system76 common code include src/board/system76/common/common.mk diff --git a/src/ec/it5570e/include/ec/parallel.h b/src/ec/it5570e/include/ec/parallel.h deleted file mode 100644 index 3a0110a..0000000 --- a/src/ec/it5570e/include/ec/parallel.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _EC_PARALLEL_H -#define _EC_PARALLEL_H - -#include - -void parport_init(void); -int parport_write(uint8_t * data, int length); - -#endif // _EC_PARALLEL_H diff --git a/src/ec/it8587e/include/ec/parallel.h b/src/ec/it8587e/include/ec/parallel.h deleted file mode 100644 index 3a0110a..0000000 --- a/src/ec/it8587e/include/ec/parallel.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _EC_PARALLEL_H -#define _EC_PARALLEL_H - -#include - -void parport_init(void); -int parport_write(uint8_t * data, int length); - -#endif // _EC_PARALLEL_H diff --git a/src/ec/it8587e/parallel.c b/src/ec/it8587e/parallel.c deleted file mode 100644 index 0094653..0000000 --- a/src/ec/it8587e/parallel.c +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include -#include -#include - -#include - -/* - * nWRITE = KSI[0] - * nDATASTB = KSI[1] - * nRESET = KSI[2] - * nADDRSTB = KSI[3] - * - * AD[8:1] = KSOL[7:0] - * nINTR = KSOH[0] - * nWAIT = KSOH[1] - */ - -#define CTL_WRITE (1 << 0) -#define CTL_DATA (1 << 1) -#define CTL_RESET (1 << 2) -#define CTL_ADDR (1 << 3) - -#define STS_WAIT (1 << 1) - -// Maximum peripheral response time in ms -#define PARPORT_TIMEOUT 35 - -void parport_init(void) { - // XXX: Needed? Pull-ups, open-drain are always disabled in GPIO mode - KSOCTRL = 0; - // XXX: Needed? OVRPPK is for KBS mode, pull-ups are always disabled in GPIO mode - KSICTRLR = 0; - - // Set all outputs to GPIO mode, low, and inputs - KSOL = 0; - KSOLGCTRL = 0xFF; - KSOLGOEN = 0; - KSOH1 = 0; - KSOHGCTRL = 0xFF; - KSOHGOEN = 0; - KSOH2 = 0; - - // Set control lines as outputs, low - KSIGCTRL = 0xFF; - KSIGOEN = 0x0F; - KSIGDAT = 0; - - // Assert nRESET - KSIGDAT &= ~CTL_RESET; - - // Deassert nWRITE, nDATASTB, nADDRSTB - KSIGDAT |= CTL_WRITE | CTL_DATA | CTL_ADDR; - - // Set nWAIT high - KSOH1 |= STS_WAIT; - - // Pull up data lines - KSOL = 0xFF; - - // Deassert nRESET - KSIGDAT |= CTL_RESET; -} - -bool parport_wait_peripheral(uint8_t mask, uint8_t value) { - uint32_t start = time_get(); - - while (time_get() < start + PARPORT_TIMEOUT) { - if ((KSOHGDMRR & mask) == value) { - return true; - } - } - - return false; -} - -int parport_write(uint8_t * data, int length) { - // Assert nWRITE - KSIGDAT &= ~CTL_WRITE; - - // Set data lines as outputs - KSOLGOEN = 0xFF; - - int i; - for (i = 0; i < length; i++) { - // Wait for peripheral to indicate it's ready for next cycle - if (!parport_wait_peripheral(STS_WAIT, 0)) { - break; - } - - // Write data to port - KSOL = data[i]; - - // Assert nDATASTB - KSIGDAT &= ~CTL_DATA; - - // Wait for peripheral to indicate it's processing - if (!parport_wait_peripheral(STS_WAIT, STS_WAIT)) { - KSIGDAT |= CTL_DATA; - break; - } - - // Deassert nDATASTB - KSIGDAT |= CTL_DATA; - - // Wait for peripheral to indicate it's ready for next cycle - if (!parport_wait_peripheral(STS_WAIT, 0)) { - break; - } - - // Reset data lines to high - KSOL = 0xFF; - } - - // Set data lines back to inputs - KSOLGOEN = 0; - - // Deassert nWRITE - KSIGDAT |= CTL_WRITE; - - return i; -}