Refactor of smbus
This commit is contained in:
		@@ -1,14 +1,7 @@
 | 
			
		||||
#include <board/gpio.h>
 | 
			
		||||
#include <board/smbus.h>
 | 
			
		||||
#include <common/debug.h>
 | 
			
		||||
#include <ec/i2c.h>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -4,5 +4,7 @@
 | 
			
		||||
#include <ec/smbus.h>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
@@ -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))
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,7 @@
 | 
			
		||||
#include <board/gpio.h>
 | 
			
		||||
#include <board/smbus.h>
 | 
			
		||||
#include <common/debug.h>
 | 
			
		||||
#include <ec/i2c.h>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -4,5 +4,7 @@
 | 
			
		||||
#include <ec/smbus.h>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
@@ -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))
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,6 @@
 | 
			
		||||
#include <board/smbus.h>
 | 
			
		||||
#include <common/debug.h>
 | 
			
		||||
#include <ec/i2c.h>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -4,5 +4,7 @@
 | 
			
		||||
#include <ec/smbus.h>
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
@@ -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))
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user