diff options
Diffstat (limited to 'chip/npcx/i2c.c')
-rw-r--r-- | chip/npcx/i2c.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/chip/npcx/i2c.c b/chip/npcx/i2c.c index 0b99f24270..23023abf1d 100644 --- a/chip/npcx/i2c.c +++ b/chip/npcx/i2c.c @@ -84,7 +84,7 @@ struct i2c_status { uint16_t sz_txbuf; /* Size of Tx buffer in bytes */ uint16_t sz_rxbuf; /* Size of rx buffer in bytes */ uint16_t idx_buf; /* Current index of Tx/Rx buffer */ - uint8_t slave_addr;/* Target slave address */ + uint8_t slave_addr__7bf;/* Target slave address */ enum smb_oper_state_t oper_state;/* Smbus operation state */ enum smb_error err_code; /* Error code */ int task_waiting; /* Task waiting on controller */ @@ -344,10 +344,10 @@ void i2c_done(int controller) static void i2c_handle_sda_irq(int controller) { volatile struct i2c_status *p_status = i2c_stsobjs + controller; + uint8_t addr__8b = I2C_GET_ADDR__7b(p_status->slave_addr__7bf) << 1; /* 1 Issue Start is successful ie. write address byte */ if (p_status->oper_state == SMB_MASTER_START || p_status->oper_state == SMB_REPEAT_START) { - uint8_t addr = p_status->slave_addr; /* Prepare address byte */ if (p_status->sz_txbuf == 0) {/* Receive mode */ p_status->oper_state = SMB_READ_OPER; @@ -360,12 +360,12 @@ static void i2c_handle_sda_irq(int controller) I2C_STALL(controller); /* Write the address to the bus R bit*/ - I2C_WRITE_BYTE(controller, (addr | 0x1)); + I2C_WRITE_BYTE(controller, (addr__8b | 0x1)); CPRINTS("-ARR-0x%02x", addr); } else {/* Transmit mode */ p_status->oper_state = SMB_WRITE_OPER; /* Write the address to the bus W bit*/ - I2C_WRITE_BYTE(controller, addr); + I2C_WRITE_BYTE(controller, addr__8b); CPRINTS("-ARW-0x%02x", addr); } /* Completed handling START condition */ @@ -380,7 +380,6 @@ static void i2c_handle_sda_irq(int controller) i2c_done(controller); /* need to restart & send slave address immediately */ else { - uint8_t addr_byte = p_status->slave_addr; /* * Prepare address byte * and start to receive bytes @@ -405,7 +404,8 @@ static void i2c_handle_sda_irq(int controller) CPUTS("-GNA"); } /* Write the address to the bus R bit*/ - I2C_WRITE_BYTE(controller, (addr_byte | 0x1)); + I2C_WRITE_BYTE(controller, + (addr__8b | 0x1)); CPUTS("-ARR"); } } @@ -609,7 +609,9 @@ void i2c_set_timeout(int port, uint32_t timeout) timeout ? timeout : I2C_TIMEOUT_DEFAULT_US; } -int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size, +int chip_i2c_xfer__7bf(const int port, + const uint16_t slave_addr__7bf, + const uint8_t *out, int out_size, uint8_t *in, int in_size, int flags) { volatile struct i2c_status *p_status; @@ -637,13 +639,8 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size, p_status->sz_txbuf = out_size; p_status->rx_buf = in; p_status->sz_rxbuf = in_size; -#if I2C_7BITS_ADDR - /* Set slave address from 7-bits to 8-bits */ - p_status->slave_addr = (slave_addr<<1); -#else - /* Set slave address (8-bits) */ - p_status->slave_addr = slave_addr; -#endif + p_status->slave_addr__7bf = slave_addr__7bf; + /* Reset index & error */ p_status->idx_buf = 0; p_status->err_code = SMB_OK; |