Replace I2C_GET_ADDR with I2C_STRIP_FLAGS

The new I2C_STRIP_FLAGS macro was added to avoid conflict with
Zephyr's macro. This CL performs the migration to that new API.

BRANCH=none
BUG=b:172067439
TEST=make runtests -j and built for various boards: eve, volteer,
     arcada_ish, atlas, hatch, kohaku, nocturne, samus, and scarlet

Change-Id: I0583b647435db96ec268f186252b367bdc4118a6
Signed-off-by: Yuval Peress <peress@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2511097
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Commit-Queue: Jett Rink <jettrink@chromium.org>
This commit is contained in:
Yuval Peress 2020-10-30 13:16:22 -06:00 committed by Commit Bot
parent f0e84c2df2
commit 13323e77ff
24 changed files with 42 additions and 45 deletions

View File

@ -96,7 +96,7 @@ BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
int anx7688_passthru_allowed(const struct i2c_port_t *port,
const uint16_t addr_flags)
{
uint16_t addr = I2C_GET_ADDR(addr_flags);
uint16_t addr = I2C_STRIP_FLAGS(addr_flags);
/* Allow access to 0x2c (TCPC) */
if (addr == 0x2c)

View File

@ -302,7 +302,7 @@ int chip_i2c_xfer(const int port, const uint16_t slave_addr_flags,
uint64_t expire_ts;
struct i2c_context *ctx;
ssize_t curr_index = 0;
uint16_t addr = I2C_GET_ADDR(slave_addr_flags);
uint16_t addr = I2C_STRIP_FLAGS(slave_addr_flags);
int begin_indx;
uint8_t repeat_start = 0;

View File

@ -665,7 +665,7 @@ int chip_i2c_xfer(int port, uint16_t slave_addr_flags,
pd->widx = 0;
pd->ridx = 0;
pd->err = 0;
pd->addr_8bit = I2C_GET_ADDR(slave_addr_flags) << 1;
pd->addr_8bit = I2C_STRIP_FLAGS(slave_addr_flags) << 1;
/* Make sure we're in a good state to start */
if ((flags & I2C_XFER_START) && (i2c_is_busy(port)

View File

@ -193,7 +193,7 @@ int chip_i2c_xfer(const int port, const uint16_t slave_addr_flags,
CPRINTS("I2C%d Addr:%02X bad status 0x%02x, SCL=%d, SDA=%d",
port,
I2C_GET_ADDR(slave_addr_flags),
I2C_STRIP_FLAGS(slave_addr_flags),
reg_mcs,
i2c_get_line_levels(port) & I2C_LINE_SCL_HIGH,
i2c_get_line_levels(port) & I2C_LINE_SDA_HIGH);
@ -219,7 +219,7 @@ int chip_i2c_xfer(const int port, const uint16_t slave_addr_flags,
}
/* Set slave address for transmit */
LM4_I2C_MSA(port) = (I2C_GET_ADDR(slave_addr_flags) << 1) & 0xff;
LM4_I2C_MSA(port) = (I2C_STRIP_FLAGS(slave_addr_flags) << 1) & 0xff;
/* Enable interrupts */
pd->task_waiting = task_get_current();

View File

@ -741,7 +741,7 @@ int chip_i2c_xfer(int port, uint16_t slave_addr_flags,
cdata[ctrl].hwsts3 = 0;
cdata[ctrl].hwsts4 = 0;
cdata[ctrl].port = port & 0xff;
cdata[ctrl].slv_addr_8bit = I2C_GET_ADDR(slave_addr_flags) << 1;
cdata[ctrl].slv_addr_8bit = I2C_STRIP_FLAGS(slave_addr_flags) << 1;
cdata[ctrl].out_size = out_size;
cdata[ctrl].outp = out;
cdata[ctrl].in_size = in_size;

View File

@ -287,7 +287,7 @@ int chip_i2c_xfer(const int port,
if (out_size) {
if (send_start) {
MEC1322_I2C_DATA(controller) =
(uint8_t)(I2C_GET_ADDR(slave_addr_flags)
(uint8_t)(I2C_STRIP_FLAGS(slave_addr_flags)
<< 1);
/* Clock out the slave address, sending START bit */
@ -332,7 +332,7 @@ int chip_i2c_xfer(const int port,
CTRL_ENI;
MEC1322_I2C_DATA(controller) =
(uint8_t)(I2C_GET_ADDR(slave_addr_flags)
(uint8_t)(I2C_STRIP_FLAGS(slave_addr_flags)
<< 1)
| 0x01;

View File

@ -657,7 +657,7 @@ static void i2c_fifo_handle_receive(int controller)
static void i2c_handle_sda_irq(int controller)
{
volatile struct i2c_status *p_status = i2c_stsobjs + controller;
uint8_t addr_8bit = I2C_GET_ADDR(p_status->slave_addr_flags) << 1;
uint8_t addr_8bit = I2C_STRIP_FLAGS(p_status->slave_addr_flags) << 1;
/* 1 Issue Start is successful ie. write address byte */
if (p_status->oper_state == SMB_MASTER_START

View File

@ -146,7 +146,7 @@ static int i2c_master_write(const int port, const uint16_t slave_addr_flags,
int bytes_sent;
int timeout = I2C_TIMEOUT;
NRF51_TWI_ADDRESS(port) = I2C_GET_ADDR(slave_addr_flags);
NRF51_TWI_ADDRESS(port) = I2C_STRIP_FLAGS(slave_addr_flags);
/* Clear the sent bit */
NRF51_TWI_TXDSENT(port) = 0;
@ -192,7 +192,7 @@ static int i2c_master_read(const int port, const uint16_t slave_addr_flags,
int curr_byte;
int timeout = I2C_TIMEOUT;
NRF51_TWI_ADDRESS(port) = I2C_GET_ADDR(slave_addr_flags);
NRF51_TWI_ADDRESS(port) = I2C_STRIP_FLAGS(slave_addr_flags);
if (size == 1) /* Last byte: stop after this one. */
NRF51_PPI_TEP(i2c_ppi_chan[port]) =

View File

@ -450,7 +450,7 @@ int chip_i2c_xfer(const int port, const uint16_t addr_flags,
const uint8_t *out, int out_bytes,
uint8_t *in, int in_bytes, int flags)
{
int addr_8bit = I2C_GET_ADDR(addr_flags) << 1;
int addr_8bit = I2C_STRIP_FLAGS(addr_flags) << 1;
int rv = EC_SUCCESS;
int i;
int xfer_start = flags & I2C_XFER_START;
@ -638,14 +638,14 @@ void i2c_init(void)
STM32_I2C_CR1(I2C_PORT_EC) |= STM32_I2C_CR1_WUPEN;
#endif
STM32_I2C_OAR1(I2C_PORT_EC) = 0x8000
| (I2C_GET_ADDR(CONFIG_HOSTCMD_I2C_ADDR_FLAGS) << 1);
| (I2C_STRIP_FLAGS(CONFIG_HOSTCMD_I2C_ADDR_FLAGS) << 1);
#ifdef TCPCI_I2C_PERIPHERAL
/*
* Configure TCPC address with OA2[1] masked so that we respond
* to CONFIG_TCPC_I2C_BASE_ADDR and CONFIG_TCPC_I2C_BASE_ADDR + 2.
*/
STM32_I2C_OAR2(I2C_PORT_EC) = 0x8100
| (I2C_GET_ADDR(CONFIG_TCPC_I2C_BASE_ADDR_FLAGS) << 1);
| (I2C_STRIP_FLAGS(CONFIG_TCPC_I2C_BASE_ADDR_FLAGS) << 1);
#endif
task_enable_irq(IRQ_PERIPHERAL);
#endif

View File

@ -552,7 +552,7 @@ int chip_i2c_xfer(const int port, const uint16_t slave_addr_flags,
const uint8_t *out, int out_bytes,
uint8_t *in, int in_bytes, int flags)
{
int addr_8bit = I2C_GET_ADDR(slave_addr_flags) << 1;
int addr_8bit = I2C_STRIP_FLAGS(slave_addr_flags) << 1;
int started = (flags & I2C_XFER_START) ? 0 : 1;
int rv = EC_SUCCESS;
int i;
@ -928,7 +928,7 @@ static void i2c_event_handler(int port)
STM32_I2C_CR2(port) &= ~STM32_I2C_CR2_ITBUFEN;
#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR_FLAGS
if ((addr_8bit >> 1) ==
I2C_GET_ADDR(
I2C_STRIP_FLAGS(
CONFIG_BOARD_I2C_SLAVE_ADDR_FLAGS))
i2c_process_board_command(1, addr_8bit,
buf_idx);
@ -955,7 +955,7 @@ static void i2c_event_handler(int port)
#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR_FLAGS
if (rx_pending &&
(addr_8b >> 1) ==
I2C_GET_ADDR(CONFIG_BOARD_I2C_SLAVE_ADDR_FLAGS))
I2C_STRIP_FLAGS(CONFIG_BOARD_I2C_SLAVE_ADDR_FLAGS))
i2c_process_board_command(0, addr_8bit, buf_idx);
#endif
rx_pending = 0;
@ -999,10 +999,10 @@ void i2c_init(void)
| STM32_I2C_CR2_ITERREN;
/* Setup host command slave */
STM32_I2C_OAR1(I2C_PORT_EC) = STM32_I2C_OAR1_B14
| (I2C_GET_ADDR(CONFIG_HOSTCMD_I2C_ADDR_FLAGS) << 1);
| (I2C_STRIP_ADDR(CONFIG_HOSTCMD_I2C_ADDR_FLAGS) << 1);
#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR_FLAGS
STM32_I2C_OAR2(I2C_PORT_EC) = STM32_I2C_OAR2_ENDUAL
| (I2C_GET_ADDR(CONFIG_BOARD_I2C_SLAVE_ADDR_FLAGS) << 1);
| (I2C_STRIP_FLAGS(CONFIG_BOARD_I2C_SLAVE_ADDR_FLAGS) << 1);
#endif
task_enable_irq(IRQ_SLAVE_EV);
task_enable_irq(IRQ_SLAVE_ER);

View File

@ -264,7 +264,7 @@ int chip_i2c_xfer(const int port, const uint16_t slave_addr_flags,
const uint8_t *out, int out_bytes,
uint8_t *in, int in_bytes, int flags)
{
int addr_8bit = I2C_GET_ADDR(slave_addr_flags) << 1;
int addr_8bit = I2C_STRIP_FLAGS(slave_addr_flags) << 1;
int rv = EC_SUCCESS;
int i;
int xfer_start = flags & I2C_XFER_START;

View File

@ -169,7 +169,7 @@ int chip_i2c_xfer(const int port,
const uint8_t *out, int out_bytes,
uint8_t *in, int in_bytes, int flags)
{
int addr_8bit = I2C_GET_ADDR(slave_addr_flags) << 1;
int addr_8bit = I2C_STRIP_FLAGS(slave_addr_flags) << 1;
int started = (flags & I2C_XFER_START) ? 0 : 1;
int rv = EC_SUCCESS;
int i;

View File

@ -307,7 +307,7 @@ int chip_i2c_xfer(const int port, const uint16_t slave_addr_flags,
const uint8_t *out, int out_bytes,
uint8_t *in, int in_bytes, int flags)
{
int addr_8bit = I2C_GET_ADDR(slave_addr_flags) << 1;
int addr_8bit = I2C_STRIP_FLAGS(slave_addr_flags) << 1;
int rv = EC_SUCCESS;
int i;
int xfer_start = flags & I2C_XFER_START;
@ -458,7 +458,7 @@ void i2c_init(void)
| STM32_I2C_CR1_ADDRIE | STM32_I2C_CR1_STOPIE
| STM32_I2C_CR1_NACKIE;
STM32_I2C_OAR1(I2C_PORT_EC) = 0x8000
| (I2C_GET_ADDR(CONFIG_HOSTCMD_I2C_ADDR_FLAGS) << 1);
| (I2C_STRIP_FLAGS(CONFIG_HOSTCMD_I2C_ADDR_FLAGS) << 1);
task_enable_irq(IRQ_SLAVE);
#endif
}

View File

@ -416,7 +416,7 @@ uint16_t ina2xx_readagain(uint8_t port, uint16_t slave_addr_flags)
if (res) {
CPRINTS("INA2XX I2C readagain failed p:%d a:%02x",
(int)port, (int)I2C_GET_ADDR(slave_addr_flags));
(int)port, (int)I2C_STRIP_FLAGS(slave_addr_flags));
return 0x0bad;
}
return (val >> 8) | ((val & 0xff) << 8);
@ -432,7 +432,7 @@ uint16_t ina2xx_read(uint8_t port, uint16_t slave_addr_flags,
res = i2c_read16(port, slave_addr_flags, reg, &val);
if (res) {
CPRINTS("INA2XX I2C read failed p:%d a:%02x, r:%02x",
(int)port, (int)I2C_GET_ADDR(slave_addr_flags),
(int)port, (int)I2C_STRIP_FLAGS(slave_addr_flags),
(int)reg);
return 0x0bad;
}
@ -514,7 +514,7 @@ static int usb_power_init_inas(struct usb_power_config const *config)
cal = ina2xx_read(ina->port, ina->addr_flags,
INA231_REG_CAL);
CPRINTS("[CAP] %d (%d,0x%02x): conf:%x, cal:%x",
i, ina->port, I2C_GET_ADDR(ina->addr_flags),
i, ina->port, I2C_STRIP_FLAGS(ina->addr_flags),
conf, cal);
}
#endif
@ -570,7 +570,7 @@ static int usb_power_init_inas(struct usb_power_config const *config)
actual = ina2xx_read(ina->port, ina->addr_flags,
INA231_REG_CONF);
CPRINTS("[CAP] %d (%d,0x%02x): conf:%x, act:%x",
i, ina->port, I2C_GET_ADDR(ina->addr_flags),
i, ina->port, I2C_STRIP_FLAGS(ina->addr_flags),
value, actual);
}
#endif
@ -582,7 +582,7 @@ static int usb_power_init_inas(struct usb_power_config const *config)
* 125) / 100;
CPRINTS("[CAP] %d (%d,0x%02x): busv:%dmv",
i, ina->port, I2C_GET_ADDR(ina->addr_flags),
i, ina->port, I2C_STRIP_FLAGS(ina->addr_flags),
busv_mv);
}
#endif
@ -678,7 +678,7 @@ static int usb_power_get_samples(struct usb_power_config const *config)
int uW = (((int)power * ina->scale*25)/100);
CPRINTS("[CAP] %d (%d,0x%02x): %dmV / %dmO = %dmA",
i, ina->port, I2C_GET_ADDR(ina->addr_flags),
i, ina->port, I2C_STRIP_FLAGS(ina->addr_flags),
uV/1000, ina->rs, uA/1000);
CPRINTS("[CAP] %duV %dmV %duA %dCuA "
"%duW v:%04x, b:%04x, p:%04x",

View File

@ -28,7 +28,7 @@ void i2c_trace_notify(int port, uint16_t slave_addr_flags,
const uint8_t *in_data, size_t in_size)
{
size_t i;
uint16_t addr = I2C_GET_ADDR(slave_addr_flags);
uint16_t addr = I2C_STRIP_FLAGS(slave_addr_flags);
for (i = 0; i < ARRAY_SIZE(trace_entries); i++)
if (trace_entries[i].enabled

View File

@ -1742,7 +1742,7 @@ static int command_display_accel_info(int argc, char **argv)
ccprintf("type: %d\n", motion_sensors[i].type);
ccprintf("location: %d\n", motion_sensors[i].location);
ccprintf("port: %d\n", motion_sensors[i].port);
ccprintf("addr: %d\n", I2C_GET_ADDR(motion_sensors[i]
ccprintf("addr: %d\n", I2C_STRIP_FLAGS(motion_sensors[i]
.i2c_spi_addr_flags));
ccprintf("range: %d\n", motion_sensors[i].default_range);
ccprintf("min_freq: %d\n", motion_sensors[i].min_frequency);

View File

@ -556,7 +556,7 @@ static int init(const struct motion_sensor_t *s)
*/
if (!SLAVE_IS_SPI(s->i2c_spi_addr_flags)) {
const uint16_t i2c_alt_addr_flags =
I2C_GET_ADDR(
I2C_STRIP_FLAGS(
s->i2c_spi_addr_flags)
& ~2;
ret = raw_write8(s->port,

View File

@ -673,7 +673,7 @@ static int init(const struct motion_sensor_t *s)
/* Set the i2c address of the compass */
ret = bmi_write8(s->port, s->i2c_spi_addr_flags,
BMI160_MAG_IF_0,
I2C_GET_ADDR(
I2C_STRIP_FLAGS(
CONFIG_ACCELGYRO_SEC_ADDR_FLAGS)
<< 1);

View File

@ -165,7 +165,7 @@ static int config_slv0_read(const struct motion_sensor_t *s,
uint16_t reg, uint8_t len)
{
int ret;
uint16_t addr_8bit = I2C_GET_ADDR(slv_addr_flags) << 1;
uint16_t addr_8bit = I2C_STRIP_FLAGS(slv_addr_flags) << 1;
ret = st_raw_write8(s->port, s->i2c_spi_addr_flags,
LSM6DSM_SLV0_ADD_ADDR,

View File

@ -300,17 +300,17 @@ static int anx7447_init(int port)
* specified TCPC slave address
*/
for (i = 0; i < ARRAY_SIZE(anx7447_i2c_addrs_flags); i++) {
if (I2C_GET_ADDR(tcpc_config[port].i2c_info.addr_flags) ==
I2C_GET_ADDR(
if (I2C_STRIP_FLAGS(tcpc_config[port].i2c_info.addr_flags) ==
I2C_STRIP_FLAGS(
anx7447_i2c_addrs_flags[i].tcpc_slave_addr_flags)) {
anx[port].i2c_slave_addr_flags =
anx7447_i2c_addrs_flags[i].spi_slave_addr_flags;
break;
}
}
if (!I2C_GET_ADDR(anx[port].i2c_slave_addr_flags)) {
if (!I2C_STRIP_FLAGS(anx[port].i2c_slave_addr_flags)) {
ccprintf("TCPC I2C slave addr 0x%x is invalid for ANX7447\n",
I2C_GET_ADDR(tcpc_config[port]
I2C_STRIP_FLAGS(tcpc_config[port]
.i2c_info.addr_flags));
return EC_ERROR_UNKNOWN;
}

View File

@ -41,9 +41,6 @@
#define I2C_FLAG_ADDR_IS_SPI BIT(15)
#define I2C_STRIP_FLAGS(addr_flags) ((addr_flags) & I2C_ADDR_MASK)
#ifndef CONFIG_ZEPHYR
#define I2C_GET_ADDR(addr_flags) I2C_STRIP_FLAGS(addr_flags)
#endif /* !CONFIG_ZEPHYR */
#define I2C_USE_PEC(addr_flags) ((addr_flags) & I2C_FLAG_PEC)
#define I2C_IS_BIG_ENDIAN(addr_flags) ((addr_flags) & I2C_FLAG_BIG_ENDIAN)

View File

@ -95,7 +95,7 @@ enum sensor_config {
#define SLAVE_MK_I2C_ADDR_FLAGS(addr) (addr)
#define SLAVE_MK_SPI_ADDR_FLAGS(addr) ((addr) | I2C_FLAG_ADDR_IS_SPI)
#define SLAVE_GET_I2C_ADDR(addr_flags) (I2C_GET_ADDR(addr_flags))
#define SLAVE_GET_I2C_ADDR(addr_flags) (I2C_STRIP_FLAGS(addr_flags))
#define SLAVE_GET_SPI_ADDR(addr_flags) ((addr_flags) & I2C_ADDR_MASK)
#define SLAVE_IS_SPI(addr_flags) ((addr_flags) & I2C_FLAG_ADDR_IS_SPI)

View File

@ -19,10 +19,10 @@
#ifdef TCPCI_I2C_PERIPHERAL
/* Convert TCPC address to type-C port number */
#define TCPC_ADDR_TO_PORT(addr) ((addr) \
- I2C_GET_ADDR(CONFIG_TCPC_I2C_BASE_ADDR_FLAGS))
- I2C_STRIP_FLAGS(CONFIG_TCPC_I2C_BASE_ADDR_FLAGS))
/* Check if the i2c address belongs to TCPC */
#define ADDR_IS_TCPC(addr) (((addr) & 0x7E) \
== I2C_GET_ADDR(CONFIG_TCPC_I2C_BASE_ADDR_FLAGS))
== I2C_STRIP_FLAGS(CONFIG_TCPC_I2C_BASE_ADDR_FLAGS))
#endif
/**

View File

@ -7300,7 +7300,7 @@ int cmd_locate_chip(int argc, char *argv[])
*/
printf("Bus: %s; Port: %d; Address: 0x%02x (7-bit format)\n",
bus_type[r.bus_type], r.i2c_info.port,
I2C_GET_ADDR(r.i2c_info.addr_flags));
I2C_STRIP_FLAGS(r.i2c_info.addr_flags));
printf("reserved: 0x%x\n", r.reserved);