diff options
Diffstat (limited to 'board/host')
-rw-r--r-- | board/host/battery.c | 46 | ||||
-rw-r--r-- | board/host/board.c | 13 |
2 files changed, 34 insertions, 25 deletions
diff --git a/board/host/battery.c b/board/host/battery.c index a5c447f5d7..e2c4b26b85 100644 --- a/board/host/battery.c +++ b/board/host/battery.c @@ -14,38 +14,34 @@ static uint16_t mock_smart_battery[SB_MANUFACTURER_DATA + 1]; -int sb_i2c_read16(int port, int slave_addr, int offset, int *data) +int sb_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size, + uint8_t *in, int in_size, int flags) { - if (port != I2C_PORT_BATTERY || slave_addr != BATTERY_ADDR) - return EC_ERROR_INVAL; - if (offset >= ARRAY_SIZE(mock_smart_battery)) - return EC_ERROR_UNIMPLEMENTED; - if (offset < 0 || data == NULL) - return EC_ERROR_INVAL; - *data = mock_smart_battery[offset]; - return EC_SUCCESS; -} -DECLARE_TEST_I2C_READ16(sb_i2c_read16); + if (out_size == 0 && in_size == 0) + return EC_SUCCESS; -int sb_i2c_write16(int port, int slave_addr, int offset, int data) -{ if (port != I2C_PORT_BATTERY || slave_addr != BATTERY_ADDR) return EC_ERROR_INVAL; - if (offset >= ARRAY_SIZE(mock_smart_battery)) + if (out[0] >= ARRAY_SIZE(mock_smart_battery)) return EC_ERROR_UNIMPLEMENTED; - if (offset < 0) - return EC_ERROR_INVAL; - mock_smart_battery[offset] = data; - return EC_SUCCESS; -} -DECLARE_TEST_I2C_WRITE16(sb_i2c_write16); - -int sb_i2c_read_string(int port, int slave_addr, int offset, uint8_t *data, - int len) -{ + if (out_size == 1) { + /* Read */ + if (in_size != 2) + /* We are not doing a read16, assume read string */ + return EC_SUCCESS; + else + *(uint16_t *)in = mock_smart_battery[out[0]]; + } else { + /* write */ + if (out_size != 3) + /* We are only expecting write 16 */ + return EC_ERROR_UNIMPLEMENTED; + else + mock_smart_battery[out[0]] = (out[2] << 8) | out[1]; + } return EC_SUCCESS; } -DECLARE_TEST_I2C_READ_STRING(sb_i2c_read_string); +DECLARE_TEST_I2C_XFER(sb_i2c_xfer); int battery_time_at_rate(int rate, int *minutes) { diff --git a/board/host/board.c b/board/host/board.c index 7ed0e37f28..c101ad08f8 100644 --- a/board/host/board.c +++ b/board/host/board.c @@ -8,6 +8,7 @@ #include "extpower.h" #include "gpio.h" #include "host_command.h" +#include "i2c.h" #include "inductive_charging.h" #include "lid_switch.h" #include "motion_sense.h" @@ -70,3 +71,15 @@ const struct accel_orientation acc_orient = { .hinge_axis = {0, 1, 0}, }; +#ifdef CONFIG_I2C +/* I2C ports */ +const struct i2c_port_t i2c_ports[] = { +#ifdef I2C_PORT_BATTERY + {"battery", I2C_PORT_BATTERY, 100, 0, 0}, +#elif defined I2C_PORT_LIGHTBAR + {"lightbar", I2C_PORT_LIGHTBAR, 100, 0, 0}, +#endif +}; + +const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); +#endif |