diff --git a/src/board/system76/darp5/battery.c b/src/board/system76/darp5/battery.c index 9defbd5..28b813e 100644 --- a/src/board/system76/darp5/battery.c +++ b/src/board/system76/darp5/battery.c @@ -1,14 +1,7 @@ #include +#include #include -#include -int smbus_read(uint8_t address, uint8_t command, uint16_t * data) { - return i2c_get(&I2C_0, address, command, (uint8_t *)data, 2); -} - -int smbus_write(uint8_t address, uint8_t command, uint16_t data) { - return i2c_set(&I2C_0, address, command, (uint8_t *)&data, 2); -} // ChargeOption0 flags // Low Power Mode Enable diff --git a/src/board/system76/darp5/board.mk b/src/board/system76/darp5/board.mk index 7820e8d..89f530b 100644 --- a/src/board/system76/darp5/board.mk +++ b/src/board/system76/darp5/board.mk @@ -16,6 +16,9 @@ CFLAGS+=-DLEVEL=2 # Enable I2C debug on 0x76 CFLAGS+=-DI2C_DEBUGGER=0x76 +# Set battery I2C bus +CFLAGS+=-DI2C_SMBUS=I2C_0 + # Add scratch ROM source SCRATCH_DIR=$(BOARD_DIR)/scratch SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c) diff --git a/src/board/system76/darp5/include/board/smbus.h b/src/board/system76/darp5/include/board/smbus.h index 437844a..6b3b141 100644 --- a/src/board/system76/darp5/include/board/smbus.h +++ b/src/board/system76/darp5/include/board/smbus.h @@ -4,5 +4,7 @@ #include void smbus_init(void); +int smbus_read(uint8_t address, uint8_t command, uint16_t * data); +int smbus_write(uint8_t address, uint8_t command, uint16_t data); #endif // _BOARD_SMBUS_H diff --git a/src/board/system76/darp5/scratch/scratch.mk b/src/board/system76/darp5/scratch/scratch.mk index 981642d..5fde8e4 100644 --- a/src/board/system76/darp5/scratch/scratch.mk +++ b/src/board/system76/darp5/scratch/scratch.mk @@ -9,7 +9,11 @@ SCRATCH_CFLAGS+=\ -Isrc/common/include \ -Isrc/ec/$(EC)/include -#SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76 +# Enable I2C debug on 0x76 +SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76 + +# Set battery I2C bus +SCRATCH_CFLAGS+=-DI2C_SMBUS=I2C_0 SCRATCH_BUILD=$(BUILD)/scratch SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC)) diff --git a/src/board/system76/darp5/scratch/stdio.c b/src/board/system76/darp5/scratch/stdio.c index 2a552ab..9bdb177 100644 --- a/src/board/system76/darp5/scratch/stdio.c +++ b/src/board/system76/darp5/scratch/stdio.c @@ -14,7 +14,7 @@ int putchar(int c) { SBUF = byte; #endif #ifdef I2C_DEBUGGER - i2c_send(&I2C_0, I2C_DEBUGGER, &byte, 1); + i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1); #endif return (int)byte; } diff --git a/src/board/system76/darp5/smbus.c b/src/board/system76/darp5/smbus.c index c61c31d..a5dfaec 100644 --- a/src/board/system76/darp5/smbus.c +++ b/src/board/system76/darp5/smbus.c @@ -17,5 +17,13 @@ void smbus_init(void) { SMB45P3USH = 0x01; // Set up for i2c usage - i2c_reset(&I2C_0, true); + i2c_reset(&I2C_SMBUS, true); +} + +int smbus_read(uint8_t address, uint8_t command, uint16_t * data) { + return i2c_get(&I2C_SMBUS, address, command, (uint8_t *)data, 2); +} + +int smbus_write(uint8_t address, uint8_t command, uint16_t data) { + return i2c_set(&I2C_SMBUS, address, command, (uint8_t *)&data, 2); } diff --git a/src/board/system76/darp5/stdio.c b/src/board/system76/darp5/stdio.c index 2a552ab..9bdb177 100644 --- a/src/board/system76/darp5/stdio.c +++ b/src/board/system76/darp5/stdio.c @@ -14,7 +14,7 @@ int putchar(int c) { SBUF = byte; #endif #ifdef I2C_DEBUGGER - i2c_send(&I2C_0, I2C_DEBUGGER, &byte, 1); + i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1); #endif return (int)byte; } diff --git a/src/board/system76/galp3-c/battery.c b/src/board/system76/galp3-c/battery.c index 488599c..f12af07 100644 --- a/src/board/system76/galp3-c/battery.c +++ b/src/board/system76/galp3-c/battery.c @@ -1,14 +1,7 @@ #include +#include #include -#include -int smbus_read(uint8_t address, uint8_t command, uint16_t * data) { - return i2c_get(&I2C_0, address, command, (uint8_t *)data, 2); -} - -int smbus_write(uint8_t address, uint8_t command, uint16_t data) { - return i2c_set(&I2C_0, address, command, (uint8_t *)&data, 2); -} // ChargeOption0 flags // Low Power Mode Enable diff --git a/src/board/system76/galp3-c/board.mk b/src/board/system76/galp3-c/board.mk index 7820e8d..89f530b 100644 --- a/src/board/system76/galp3-c/board.mk +++ b/src/board/system76/galp3-c/board.mk @@ -16,6 +16,9 @@ CFLAGS+=-DLEVEL=2 # Enable I2C debug on 0x76 CFLAGS+=-DI2C_DEBUGGER=0x76 +# Set battery I2C bus +CFLAGS+=-DI2C_SMBUS=I2C_0 + # Add scratch ROM source SCRATCH_DIR=$(BOARD_DIR)/scratch SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c) diff --git a/src/board/system76/galp3-c/include/board/smbus.h b/src/board/system76/galp3-c/include/board/smbus.h index 437844a..6b3b141 100644 --- a/src/board/system76/galp3-c/include/board/smbus.h +++ b/src/board/system76/galp3-c/include/board/smbus.h @@ -4,5 +4,7 @@ #include void smbus_init(void); +int smbus_read(uint8_t address, uint8_t command, uint16_t * data); +int smbus_write(uint8_t address, uint8_t command, uint16_t data); #endif // _BOARD_SMBUS_H diff --git a/src/board/system76/galp3-c/scratch/scratch.mk b/src/board/system76/galp3-c/scratch/scratch.mk index 981642d..5fde8e4 100644 --- a/src/board/system76/galp3-c/scratch/scratch.mk +++ b/src/board/system76/galp3-c/scratch/scratch.mk @@ -9,7 +9,11 @@ SCRATCH_CFLAGS+=\ -Isrc/common/include \ -Isrc/ec/$(EC)/include -#SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76 +# Enable I2C debug on 0x76 +SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76 + +# Set battery I2C bus +SCRATCH_CFLAGS+=-DI2C_SMBUS=I2C_0 SCRATCH_BUILD=$(BUILD)/scratch SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC)) diff --git a/src/board/system76/galp3-c/scratch/stdio.c b/src/board/system76/galp3-c/scratch/stdio.c index 2a552ab..9bdb177 100644 --- a/src/board/system76/galp3-c/scratch/stdio.c +++ b/src/board/system76/galp3-c/scratch/stdio.c @@ -14,7 +14,7 @@ int putchar(int c) { SBUF = byte; #endif #ifdef I2C_DEBUGGER - i2c_send(&I2C_0, I2C_DEBUGGER, &byte, 1); + i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1); #endif return (int)byte; } diff --git a/src/board/system76/galp3-c/smbus.c b/src/board/system76/galp3-c/smbus.c index c61c31d..a5dfaec 100644 --- a/src/board/system76/galp3-c/smbus.c +++ b/src/board/system76/galp3-c/smbus.c @@ -17,5 +17,13 @@ void smbus_init(void) { SMB45P3USH = 0x01; // Set up for i2c usage - i2c_reset(&I2C_0, true); + i2c_reset(&I2C_SMBUS, true); +} + +int smbus_read(uint8_t address, uint8_t command, uint16_t * data) { + return i2c_get(&I2C_SMBUS, address, command, (uint8_t *)data, 2); +} + +int smbus_write(uint8_t address, uint8_t command, uint16_t data) { + return i2c_set(&I2C_SMBUS, address, command, (uint8_t *)&data, 2); } diff --git a/src/board/system76/galp3-c/stdio.c b/src/board/system76/galp3-c/stdio.c index 2a552ab..9bdb177 100644 --- a/src/board/system76/galp3-c/stdio.c +++ b/src/board/system76/galp3-c/stdio.c @@ -14,7 +14,7 @@ int putchar(int c) { SBUF = byte; #endif #ifdef I2C_DEBUGGER - i2c_send(&I2C_0, I2C_DEBUGGER, &byte, 1); + i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1); #endif return (int)byte; } diff --git a/src/board/system76/lemp9/battery.c b/src/board/system76/lemp9/battery.c index 223c428..af89f9d 100644 --- a/src/board/system76/lemp9/battery.c +++ b/src/board/system76/lemp9/battery.c @@ -1,13 +1,6 @@ +#include #include -#include -int smbus_read(uint8_t address, uint8_t command, uint16_t * data) { - return i2c_get(&I2C_4, address, command, (uint8_t *)data, 2); -} - -int smbus_write(uint8_t address, uint8_t command, uint16_t data) { - return i2c_set(&I2C_4, address, command, (uint8_t *)&data, 2); -} // ChargeOption0 flags // Low Power Mode Enable diff --git a/src/board/system76/lemp9/board.mk b/src/board/system76/lemp9/board.mk index bb19bee..7773bec 100644 --- a/src/board/system76/lemp9/board.mk +++ b/src/board/system76/lemp9/board.mk @@ -16,6 +16,9 @@ CFLAGS+=-DLEVEL=2 # Enable I2C debug on 0x76 CFLAGS+=-DI2C_DEBUGGER=0x76 +# Set battery I2C bus +CFLAGS+=-DI2C_SMBUS=I2C_4 + # Add scratch ROM source SCRATCH_DIR=$(BOARD_DIR)/scratch SCRATCH_SRC=$(wildcard $(SCRATCH_DIR)/*.c) diff --git a/src/board/system76/lemp9/include/board/smbus.h b/src/board/system76/lemp9/include/board/smbus.h index 437844a..6b3b141 100644 --- a/src/board/system76/lemp9/include/board/smbus.h +++ b/src/board/system76/lemp9/include/board/smbus.h @@ -4,5 +4,7 @@ #include void smbus_init(void); +int smbus_read(uint8_t address, uint8_t command, uint16_t * data); +int smbus_write(uint8_t address, uint8_t command, uint16_t data); #endif // _BOARD_SMBUS_H diff --git a/src/board/system76/lemp9/scratch/scratch.mk b/src/board/system76/lemp9/scratch/scratch.mk index 981642d..e0949f3 100644 --- a/src/board/system76/lemp9/scratch/scratch.mk +++ b/src/board/system76/lemp9/scratch/scratch.mk @@ -9,7 +9,11 @@ SCRATCH_CFLAGS+=\ -Isrc/common/include \ -Isrc/ec/$(EC)/include -#SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76 +# Enable I2C debug on 0x76 +SCRATCH_CFLAGS+=-DI2C_DEBUGGER=0x76 + +# Set battery I2C bus +SCRATCH_CFLAGS+=-DI2C_SMBUS=I2C_4 SCRATCH_BUILD=$(BUILD)/scratch SCRATCH_OBJ=$(patsubst src/%.c,$(SCRATCH_BUILD)/%.rel,$(SCRATCH_SRC)) diff --git a/src/board/system76/lemp9/scratch/stdio.c b/src/board/system76/lemp9/scratch/stdio.c index bd5e99e..9bdb177 100644 --- a/src/board/system76/lemp9/scratch/stdio.c +++ b/src/board/system76/lemp9/scratch/stdio.c @@ -14,7 +14,7 @@ int putchar(int c) { SBUF = byte; #endif #ifdef I2C_DEBUGGER - i2c_send(&I2C_4, I2C_DEBUGGER, &byte, 1); + i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1); #endif return (int)byte; } diff --git a/src/board/system76/lemp9/smbus.c b/src/board/system76/lemp9/smbus.c index 7808cbe..a5dfaec 100644 --- a/src/board/system76/lemp9/smbus.c +++ b/src/board/system76/lemp9/smbus.c @@ -17,5 +17,13 @@ void smbus_init(void) { SMB45P3USH = 0x01; // Set up for i2c usage - i2c_reset(&I2C_4, true); + i2c_reset(&I2C_SMBUS, true); +} + +int smbus_read(uint8_t address, uint8_t command, uint16_t * data) { + return i2c_get(&I2C_SMBUS, address, command, (uint8_t *)data, 2); +} + +int smbus_write(uint8_t address, uint8_t command, uint16_t data) { + return i2c_set(&I2C_SMBUS, address, command, (uint8_t *)&data, 2); } diff --git a/src/board/system76/lemp9/stdio.c b/src/board/system76/lemp9/stdio.c index bd5e99e..9bdb177 100644 --- a/src/board/system76/lemp9/stdio.c +++ b/src/board/system76/lemp9/stdio.c @@ -14,7 +14,7 @@ int putchar(int c) { SBUF = byte; #endif #ifdef I2C_DEBUGGER - i2c_send(&I2C_4, I2C_DEBUGGER, &byte, 1); + i2c_send(&I2C_SMBUS, I2C_DEBUGGER, &byte, 1); #endif return (int)byte; }