summaryrefslogtreecommitdiff
path: root/chip/stm32
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-06-25 12:44:16 -0600
committerCommit Bot <commit-bot@chromium.org>2019-07-19 21:11:02 +0000
commitd1a18f82ed831d4e640336ff5571f5fa64bc7b36 (patch)
treec46aeb6136de1c27c66e3d5f662e9620161bef7b /chip/stm32
parent1f14229fa7e499dfcee07d17add187598ff0a46c (diff)
downloadchrome-ec-d1a18f82ed831d4e640336ff5571f5fa64bc7b36.tar.gz
Use 7bit I2C/SPI slave addresses in EC
Opt for 7bit slave addresses in EC code. If 8bit is expected by a driver, make it local and show this in the naming. Use __7b, __7bf and __8b as name extensions for i2c/spi addresses used in the EC codebase. __7b indicates a 7bit address by itself. __7bf indicates a 7bit address with optional flags attached. __8b indicates a 8bit address by itself. Allow space for 10bit addresses, even though this is not currently being used by any of our attached devices. These extensions are for verification purposes only and will be removed in the last pass of this ticket. I want to make sure the variable names reflect the type to help eliminate future 7/8/7-flags confusion. BUG=chromium:971296 BRANCH=none TEST=make buildall -j Change-Id: I2fc3d1b52ce76184492b2aaff3060f486ca45f45 Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1699893 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'chip/stm32')
-rw-r--r--chip/stm32/i2c-stm32f0.c26
-rw-r--r--chip/stm32/i2c-stm32f4.c73
-rw-r--r--chip/stm32/i2c-stm32l.c13
-rw-r--r--chip/stm32/i2c-stm32l4.c17
-rw-r--r--chip/stm32/usb_power.c78
-rw-r--r--chip/stm32/usb_power.h4
6 files changed, 125 insertions, 86 deletions
diff --git a/chip/stm32/i2c-stm32f0.c b/chip/stm32/i2c-stm32f0.c
index 9a63fbaf5b..e2aa3f8af9 100644
--- a/chip/stm32/i2c-stm32f0.c
+++ b/chip/stm32/i2c-stm32f0.c
@@ -27,7 +27,7 @@
/* Transmit timeout in microseconds */
#define I2C_TX_TIMEOUT_MASTER (10 * MSEC)
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
+#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF
#if (I2C_PORT_EC == STM32_I2C1_PORT)
#define IRQ_SLAVE STM32_IRQ_I2C1
#else
@@ -146,7 +146,7 @@ static void i2c_init_port(const struct i2c_port_t *p)
STM32_RCC_APB1ENR |= 1 << (21 + port);
if (port == STM32_I2C1_PORT) {
-#if defined(CONFIG_HOSTCMD_I2C_SLAVE_ADDR) && \
+#if defined(CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF) && \
defined(CONFIG_LOW_POWER_IDLE) && \
(I2C_PORT_EC == STM32_I2C1_PORT)
/*
@@ -189,7 +189,7 @@ defined(CONFIG_LOW_POWER_IDLE) && \
}
/*****************************************************************************/
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
+#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF
/* Host command slave */
/*
* Buffer for received host command packets (including prefix byte on request,
@@ -426,9 +426,11 @@ DECLARE_IRQ(IRQ_SLAVE, i2c2_event_interrupt, 2);
/*****************************************************************************/
/* Interface */
-int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
+int chip_i2c_xfer__7bf(const int port, const uint16_t slave_addr__7bf,
+ const uint8_t *out, int out_bytes,
uint8_t *in, int in_bytes, int flags)
{
+ int addr__8b = I2C_GET_ADDR__7b(slave_addr__7bf) << 1;
int rv = EC_SUCCESS;
int i;
int xfer_start = flags & I2C_XFER_START;
@@ -436,7 +438,7 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
#if defined(CONFIG_I2C_SCL_GATE_ADDR) && defined(CONFIG_I2C_SCL_GATE_PORT)
if (port == CONFIG_I2C_SCL_GATE_PORT &&
- slave_addr == CONFIG_I2C_SCL_GATE_ADDR)
+ slave_addr__7bf == CONFIG_I2C_SCL_GATE_ADDR__7BF)
gpio_set_level(CONFIG_I2C_SCL_GATE_GPIO, 1);
#endif
@@ -457,7 +459,7 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
* NBYTES again. if we are starting, then set START bit.
*/
STM32_I2C_CR2(port) = ((out_bytes & 0xFF) << 16)
- | slave_addr
+ | addr__8b
| ((in_bytes == 0 && xfer_stop) ?
STM32_I2C_CR2_AUTOEND : 0)
| ((in_bytes == 0 && !xfer_stop) ?
@@ -486,7 +488,7 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
* set START bit to send (re)start and begin read transaction.
*/
STM32_I2C_CR2(port) = ((in_bytes & 0xFF) << 16)
- | STM32_I2C_CR2_RD_WRN | slave_addr
+ | STM32_I2C_CR2_RD_WRN | addr__8b
| (xfer_stop ? STM32_I2C_CR2_AUTOEND : 0)
| (!xfer_stop ? STM32_I2C_CR2_RELOAD : 0)
| (out_bytes || xfer_start ? STM32_I2C_CR2_START : 0);
@@ -543,7 +545,7 @@ xfer_exit:
#ifdef CONFIG_I2C_SCL_GATE_ADDR
if (port == CONFIG_I2C_SCL_GATE_PORT &&
- slave_addr == CONFIG_I2C_SCL_GATE_ADDR)
+ slave_addr__7bf == CONFIG_I2C_SCL_GATE_ADDR__7BF)
gpio_set_level(CONFIG_I2C_SCL_GATE_GPIO, 0);
#endif
@@ -586,7 +588,7 @@ static void i2c_init(void)
for (i = 0; i < i2c_ports_used; i++, p++)
i2c_init_port(p);
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
+#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF
STM32_I2C_CR1(I2C_PORT_EC) |= STM32_I2C_CR1_RXIE | STM32_I2C_CR1_ERRIE
| STM32_I2C_CR1_ADDRIE | STM32_I2C_CR1_STOPIE
| STM32_I2C_CR1_NACKIE;
@@ -598,13 +600,15 @@ static void i2c_init(void)
*/
STM32_I2C_CR1(I2C_PORT_EC) |= STM32_I2C_CR1_WUPEN;
#endif
- STM32_I2C_OAR1(I2C_PORT_EC) = 0x8000 | CONFIG_HOSTCMD_I2C_SLAVE_ADDR;
+ STM32_I2C_OAR1(I2C_PORT_EC) = 0x8000
+ | (I2C_GET_ADDR__7b(CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF) << 1);
#ifdef TCPCI_I2C_SLAVE
/*
* 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 | CONFIG_TCPC_I2C_BASE_ADDR;
+ STM32_I2C_OAR2(I2C_PORT_EC) = 0x8100
+ | (I2C_GET_ADDR__7b(CONFIG_TCPC_I2C_BASE_ADDR__7BF) << 1);
#endif
task_enable_irq(IRQ_SLAVE);
#endif
diff --git a/chip/stm32/i2c-stm32f4.c b/chip/stm32/i2c-stm32f4.c
index ee6460936c..6b774e829b 100644
--- a/chip/stm32/i2c-stm32f4.c
+++ b/chip/stm32/i2c-stm32f4.c
@@ -25,7 +25,7 @@
/* Transmit timeout in microseconds */
#define I2C_TX_TIMEOUT_MASTER (10 * MSEC)
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
+#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF
#if (I2C_PORT_EC == STM32_I2C1_PORT)
#define IRQ_SLAVE_EV STM32_IRQ_I2C1_EV
#define IRQ_SLAVE_ER STM32_IRQ_I2C1_ER
@@ -171,7 +171,7 @@ static int wait_sr1(int port, int mask)
*
* @return Non-zero if error.
*/
-static int send_start(int port, int slave_addr)
+static int send_start__8b(const int port, const uint16_t slave_addr__8b)
{
int rv;
@@ -182,7 +182,7 @@ static int send_start(int port, int slave_addr)
return I2C_ERROR_FAILED_START;
/* Write slave address */
- STM32_I2C_DR(port) = slave_addr & 0xff;
+ STM32_I2C_DR(port) = slave_addr__8b;
rv = wait_sr1_poll(port, STM32_I2C_SR1_ADDR, SET, 1);
if (rv)
return rv;
@@ -263,7 +263,8 @@ static int wait_fmpi2c_isr(int port, int mask)
*
* @return Non-zero if error.
*/
-static int send_fmpi2c_start(int port, int slave_addr, int size, int is_read)
+static int send_fmpi2c_start__8b(const int port, const uint16_t slave_addr__8b,
+ int size, int is_read)
{
uint32_t reg;
@@ -273,7 +274,7 @@ static int send_fmpi2c_start(int port, int slave_addr, int size, int is_read)
FMPI2C_CR2_RELOAD | FMPI2C_CR2_AUTOEND |
FMPI2C_CR2_RD_WRN | FMPI2C_CR2_START | FMPI2C_CR2_STOP);
reg |= FMPI2C_CR2_START | FMPI2C_CR2_AUTOEND |
- FMPI2C_CR2_SADD(slave_addr) | FMPI2C_CR2_SIZE(size) |
+ slave_addr__8b | FMPI2C_CR2_SIZE(size) |
(is_read ? FMPI2C_CR2_RD_WRN : 0);
STM32_FMPI2C_CR2(port) = reg;
@@ -400,8 +401,9 @@ static void fmpi2c_clear_regs(int port)
*
* @return EC_SUCCESS on success.
*/
-static int chip_fmpi2c_xfer(int port, int slave_addr, const uint8_t *out,
- int out_bytes, uint8_t *in, int in_bytes, int flags)
+static int chip_fmpi2c_xfer__8b(const int port, const uint16_t slave_addr__8b,
+ const uint8_t *out, int out_bytes,
+ uint8_t *in, int in_bytes, int flags)
{
int started = (flags & I2C_XFER_START) ? 0 : 1;
int rv = EC_SUCCESS;
@@ -420,8 +422,8 @@ static int chip_fmpi2c_xfer(int port, int slave_addr, const uint8_t *out,
/* No out bytes and no in bytes means just check for active */
if (out_bytes || !in_bytes) {
- rv = send_fmpi2c_start(
- port, slave_addr, out_bytes, FMPI2C_WRITE);
+ rv = send_fmpi2c_start__8b(
+ port, slave_addr__8b, out_bytes, FMPI2C_WRITE);
if (rv)
goto xfer_exit;
@@ -446,8 +448,8 @@ static int chip_fmpi2c_xfer(int port, int slave_addr, const uint8_t *out,
dma_start_rx(dma, in_bytes, in);
i2c_dma_enable_tc_interrupt(dma->channel, port);
- rv_start = send_fmpi2c_start(
- port, slave_addr, in_bytes, FMPI2C_READ);
+ rv_start = send_fmpi2c_start__8b(
+ port, slave_addr__8b, in_bytes, FMPI2C_READ);
if (rv_start)
goto xfer_exit;
@@ -551,9 +553,11 @@ static void i2c_clear_regs(int port)
*/
/* Perform an i2c transaction. */
-int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
+int chip_i2c_xfer__7bf(const int port, const uint16_t slave_addr__7bf,
+ const uint8_t *out, int out_bytes,
uint8_t *in, int in_bytes, int flags)
{
+ int addr__8b = I2C_GET_ADDR__7b(slave_addr__7bf) << 1;
int started = (flags & I2C_XFER_START) ? 0 : 1;
int rv = EC_SUCCESS;
int i;
@@ -564,15 +568,16 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
ASSERT(!started);
if (p->port == STM32F4_FMPI2C_PORT) {
- return chip_fmpi2c_xfer(port, slave_addr, out, out_bytes,
- in, in_bytes, flags);
+ return chip_fmpi2c_xfer__8b(port, addr__8b,
+ out, out_bytes,
+ in, in_bytes, flags);
}
i2c_clear_regs(port);
/* No out bytes and no in bytes means just check for active */
if (out_bytes || !in_bytes) {
- rv = send_start(port, slave_addr);
+ rv = send_start__8b(port, addr__8b);
if (rv)
goto xfer_exit;
@@ -611,7 +616,7 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
STM32_I2C_CR2(port) |= STM32_I2C_CR2_LAST;
STM32_I2C_CR2(port) |= STM32_I2C_CR2_DMAEN;
- rv_start = send_start(port, slave_addr | 0x01);
+ rv_start = send_start__8b(port, addr__8b | 0x01);
if ((in_bytes == 1) && (flags & I2C_XFER_STOP))
STM32_I2C_CR1(port) |= STM32_I2C_CR1_STOP;
@@ -755,7 +760,7 @@ DECLARE_HOOK(HOOK_FREQ_CHANGE, i2c_freq_change_hook, HOOK_PRIO_DEFAULT);
/*****************************************************************************/
/* Slave */
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
+#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF
/* Host command slave */
/*
* Buffer for received host command packets (including prefix byte on request,
@@ -834,7 +839,7 @@ static void i2c_process_command(void)
host_packet_receive(&i2c_packet);
}
-#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR
+#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR__7BF
static void i2c_send_board_response(int len)
{
/* host_buffer data range, beyond this length, will return 0xec */
@@ -858,7 +863,7 @@ static void i2c_event_handler(int port)
volatile uint32_t i2c_sr2;
volatile uint32_t i2c_sr1;
static int rx_pending, buf_idx;
- static uint16_t addr;
+ static uint16_t addr__8b;
volatile uint32_t dummy __attribute__((unused));
@@ -883,15 +888,15 @@ static void i2c_event_handler(int port)
/* Transfer matched our slave address */
if (i2c_sr1 & STM32_I2C_SR1_ADDR) {
- addr = ((i2c_sr2 & STM32_I2C_SR2_DUALF) ?
+ addr__8b = ((i2c_sr2 & STM32_I2C_SR2_DUALF) ?
STM32_I2C_OAR2(port) : STM32_I2C_OAR1(port)) & 0xfe;
if (i2c_sr2 & STM32_I2C_SR2_TRA) {
/* Transmitter slave */
i2c_sr1 |= STM32_I2C_SR1_TXE;
-#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR
+#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR__7BF
if (!rx_pending && !tx_pending) {
tx_pending = 1;
- i2c_process_board_command(1, addr, 0);
+ i2c_process_board_command(1, addr__8b, 0);
}
#endif
} else {
@@ -926,9 +931,11 @@ static void i2c_event_handler(int port)
host_i2c_resp_port = port;
/* Disable buffer interrupt */
STM32_I2C_CR2(port) &= ~STM32_I2C_CR2_ITBUFEN;
-#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR
- if (addr == CONFIG_BOARD_I2C_SLAVE_ADDR)
- i2c_process_board_command(1, addr,
+#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR__7BF
+ if ((addr__8b >> 1) ==
+ I2C_GET_ADDR__7b(
+ CONFIG_BOARD_I2C_SLAVE_ADDR__7BF))
+ i2c_process_board_command(1, addr__8b,
buf_idx);
else
#endif
@@ -950,9 +957,11 @@ static void i2c_event_handler(int port)
/* Disable buffer interrupt */
STM32_I2C_CR2(port) &= ~STM32_I2C_CR2_ITBUFEN;
-#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR
- if (rx_pending && addr == CONFIG_BOARD_I2C_SLAVE_ADDR)
- i2c_process_board_command(0, addr, buf_idx);
+#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR__7BF
+ if (rx_pending &&
+ (addr__8b >> 1) ==
+ I2C_GET_ADDR__7b(CONFIG_BOARD_I2C_SLAVE_ADDR__7BF))
+ i2c_process_board_command(0, addr__8b, buf_idx);
#endif
rx_pending = 0;
tx_pending = 0;
@@ -987,7 +996,7 @@ static void i2c_init(void)
i2c_init_port(p);
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
+#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF
/* Enable ACK */
STM32_I2C_CR1(I2C_PORT_EC) |= STM32_I2C_CR1_ACK;
/* Enable interrupts */
@@ -995,10 +1004,10 @@ static void i2c_init(void)
| STM32_I2C_CR2_ITERREN;
/* Setup host command slave */
STM32_I2C_OAR1(I2C_PORT_EC) = STM32_I2C_OAR1_B14
- | CONFIG_HOSTCMD_I2C_SLAVE_ADDR;
-#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR
+ | (I2C_GET_ADDR__7b(CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF) << 1);
+#ifdef CONFIG_BOARD_I2C_SLAVE_ADDR__7BF
STM32_I2C_OAR2(I2C_PORT_EC) = STM32_I2C_OAR2_ENDUAL
- | CONFIG_BOARD_I2C_SLAVE_ADDR;
+ | (I2C_GET_ADDR__7b(CONFIG_BOARD_I2C_SLAVE_ADDR__7BF) << 1);
#endif
task_enable_irq(IRQ_SLAVE_EV);
task_enable_irq(IRQ_SLAVE_ER);
diff --git a/chip/stm32/i2c-stm32l.c b/chip/stm32/i2c-stm32l.c
index 42fe3513a9..d56d78d8eb 100644
--- a/chip/stm32/i2c-stm32l.c
+++ b/chip/stm32/i2c-stm32l.c
@@ -98,7 +98,7 @@ static int wait_sr1(int port, int mask)
*
* @return Non-zero if error.
*/
-static int send_start(int port, int slave_addr)
+static int send_start__8b(int port, uint16_t slave_addr__8b)
{
int rv;
@@ -110,7 +110,7 @@ static int send_start(int port, int slave_addr)
return I2C_ERROR_FAILED_START;
/* Write slave address */
- STM32_I2C_DR(port) = slave_addr & 0xff;
+ STM32_I2C_DR(port) = slave_addr__8b & 0xff;
rv = wait_sr1(port, STM32_I2C_SR1_ADDR);
if (rv)
return rv;
@@ -164,9 +164,12 @@ static void i2c_init_port(const struct i2c_port_t *p)
/*****************************************************************************/
/* Interface */
-int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
+int chip_i2c_xfer__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ const uint8_t *out, int out_bytes,
uint8_t *in, int in_bytes, int flags)
{
+ int addr__8b == I2C_GET_ADDR__7b(slave_addr__7bf) << 1;
int started = (flags & I2C_XFER_START) ? 0 : 1;
int rv = EC_SUCCESS;
int i;
@@ -193,7 +196,7 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
/* No out bytes and no in bytes means just check for active */
if (out_bytes || !in_bytes) {
if (!started) {
- rv = send_start(port, slave_addr);
+ rv = send_start__8b(port, addr__8b);
if (rv)
goto xfer_exit;
}
@@ -225,7 +228,7 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
STM32_I2C_CR1(port) |= STM32_I2C_CR1_ACK;
if (!started) {
- rv = send_start(port, slave_addr | 0x01);
+ rv = send_start__8b(port, addr__8b | 0x01);
if (rv)
goto xfer_exit;
}
diff --git a/chip/stm32/i2c-stm32l4.c b/chip/stm32/i2c-stm32l4.c
index 06836dd547..e263394880 100644
--- a/chip/stm32/i2c-stm32l4.c
+++ b/chip/stm32/i2c-stm32l4.c
@@ -26,7 +26,7 @@
/* Transmit timeout in microseconds */
#define I2C_TX_TIMEOUT_MASTER (10 * MSEC)
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
+#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF
#define I2C_SLAVE_ERROR_CODE 0xec
#if (I2C_PORT_EC == STM32_I2C1_PORT)
#define IRQ_SLAVE STM32_IRQ_I2C1
@@ -177,7 +177,7 @@ static void i2c_init_port(const struct i2c_port_t *p)
/*****************************************************************************/
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
+#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF
static void i2c_event_handler(int port)
{
@@ -303,9 +303,11 @@ DECLARE_IRQ(IRQ_SLAVE, i2c_event_interrupt, 2);
/*****************************************************************************/
/* Interface */
-int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
+int chip_i2c_xfer__7bf(const int port, const uint16_t slave_addr__7bf,
+ const uint8_t *out, int out_bytes,
uint8_t *in, int in_bytes, int flags)
{
+ int addr__8b = I2C_GET_ADDR__7b(slave_addr__7bf) << 1;
int rv = EC_SUCCESS;
int i;
int xfer_start = flags & I2C_XFER_START;
@@ -328,7 +330,7 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
* NBYTES again. if we are starting, then set START bit.
*/
STM32_I2C_CR2(port) = ((out_bytes & 0xFF) << 16)
- | slave_addr
+ | addr__8b
| ((in_bytes == 0 && xfer_stop) ?
STM32_I2C_CR2_AUTOEND : 0)
| ((in_bytes == 0 && !xfer_stop) ?
@@ -357,7 +359,7 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
* set START bit to send (re)start and begin read transaction.
*/
STM32_I2C_CR2(port) = ((in_bytes & 0xFF) << 16)
- | STM32_I2C_CR2_RD_WRN | slave_addr
+ | STM32_I2C_CR2_RD_WRN | addr__8b
| (xfer_stop ? STM32_I2C_CR2_AUTOEND : 0)
| (!xfer_stop ? STM32_I2C_CR2_RELOAD : 0)
| (out_bytes || xfer_start ? STM32_I2C_CR2_START : 0);
@@ -451,11 +453,12 @@ static void i2c_init(void)
for (i = 0; i < i2c_ports_used; i++, p++)
i2c_init_port(p);
-#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
+#ifdef CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF
STM32_I2C_CR1(I2C_PORT_EC) |= STM32_I2C_CR1_RXIE | STM32_I2C_CR1_ERRIE
| STM32_I2C_CR1_ADDRIE | STM32_I2C_CR1_STOPIE
| STM32_I2C_CR1_NACKIE;
- STM32_I2C_OAR1(I2C_PORT_EC) = 0x8000 | CONFIG_HOSTCMD_I2C_SLAVE_ADDR;
+ STM32_I2C_OAR1(I2C_PORT_EC) = 0x8000
+ | (I2C_GET_ADDR__7b(CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF) << 1);
task_enable_irq(IRQ_SLAVE);
#endif
}
diff --git a/chip/stm32/usb_power.c b/chip/stm32/usb_power.c
index 7e4206e83b..4cf8bac99e 100644
--- a/chip/stm32/usb_power.c
+++ b/chip/stm32/usb_power.c
@@ -249,7 +249,7 @@ static int usb_power_state_addina(struct usb_power_config const *config,
ina = state->ina_cfg + state->ina_count;
ina->port = cmd->addina.port;
- ina->addr = (cmd->addina.addr) << 1; /* 7 to 8 bit addr. */
+ ina->addr__7bf = cmd->addina.addr__7bf;
ina->rs = cmd->addina.rs;
ina->type = cmd->addina.type;
@@ -270,7 +270,7 @@ static int usb_power_state_addina(struct usb_power_config const *config,
struct usb_power_ina_cfg *tmp = state->ina_cfg + i;
if ((tmp->port == ina->port) &&
- (tmp->addr == ina->addr)) {
+ (tmp->addr__7bf == ina->addr__7bf)) {
ina->shared = 1;
tmp->shared = 1;
}
@@ -406,42 +406,46 @@ int reg_type_mapping(enum usb_power_ina_type ina_type)
}
}
-uint16_t ina2xx_readagain(uint8_t port, uint8_t addr)
+uint16_t ina2xx_readagain__7bf(uint8_t port, uint16_t slave_addr__7bf)
{
int res;
uint16_t val;
- res = i2c_xfer(port, addr, NULL, 0, (uint8_t *)&val, sizeof(uint16_t));
+ res = i2c_xfer__7bf(port, slave_addr__7bf,
+ NULL, 0, (uint8_t *)&val, sizeof(uint16_t));
if (res) {
CPRINTS("INA2XX I2C readagain failed p:%d a:%02x",
- (int)port, (int)addr);
+ (int)port, (int)I2C_GET_ADDR__7b(slave_addr__7bf));
return 0x0bad;
}
return (val >> 8) | ((val & 0xff) << 8);
}
-uint16_t ina2xx_read(uint8_t port, uint8_t addr, uint8_t reg)
+uint16_t ina2xx_read__7bf(uint8_t port, uint16_t slave_addr__7bf,
+ uint8_t reg)
{
int res;
int val;
- res = i2c_read16(port, addr, reg, &val);
+ res = i2c_read16__7bf(port, slave_addr__7bf, reg, &val);
if (res) {
CPRINTS("INA2XX I2C read failed p:%d a:%02x, r:%02x",
- (int)port, (int)addr, (int)reg);
+ (int)port, (int)I2C_GET_ADDR__7b(slave_addr__7bf),
+ (int)reg);
return 0x0bad;
}
return (val >> 8) | ((val & 0xff) << 8);
}
-int ina2xx_write(uint8_t port, uint8_t addr, uint8_t reg, uint16_t val)
+int ina2xx_write__7bf(uint8_t port, uint16_t slave_addr__7bf,
+ uint8_t reg, uint16_t val)
{
int res;
uint16_t be_val = (val >> 8) | ((val & 0xff) << 8);
- res = i2c_write16(port, addr, reg, be_val);
+ res = i2c_write16__7bf(port, slave_addr__7bf, reg, be_val);
if (res)
CPRINTS("INA2XX I2C write failed");
return res;
@@ -505,10 +509,13 @@ static int usb_power_init_inas(struct usb_power_config const *config)
{
int conf, cal;
- conf = ina2xx_read(ina->port, ina->addr, INA231_REG_CONF);
- cal = ina2xx_read(ina->port, ina->addr, INA231_REG_CAL);
+ conf = ina2xx_read__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_CONF);
+ cal = ina2xx_read__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_CAL);
CPRINTS("[CAP] %d (%d,0x%02x): conf:%x, cal:%x",
- i, ina->port, ina->addr, conf, cal);
+ i, ina->port, I2C_GET_ADDR__7b(ina->addr__7bf),
+ conf, cal);
}
#endif
/*
@@ -529,7 +536,8 @@ static int usb_power_init_inas(struct usb_power_config const *config)
if (ina->scale == 0)
return -1;
value = (5120000 * 100) / (ina->scale * ina->rs);
- ret = ina2xx_write(ina->port, ina->addr, INA231_REG_CAL, value);
+ ret = ina2xx_write__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_CAL, value);
if (ret != EC_SUCCESS) {
CPRINTS("[CAP] usb_power_init_inas CAL FAIL: %d", ret);
return ret;
@@ -538,7 +546,8 @@ static int usb_power_init_inas(struct usb_power_config const *config)
{
int actual;
- actual = ina2xx_read(ina->port, ina->addr, INA231_REG_CAL);
+ actual = ina2xx_read__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_CAL);
CPRINTS("[CAP] scale: %d uA/div, %d uW/div, cal:%x act:%x",
ina->scale / 100, ina->scale*25/100, value, actual);
}
@@ -548,8 +557,8 @@ static int usb_power_init_inas(struct usb_power_config const *config)
INA231_CONF_SHUNT_TIME(shunt_time) |
INA231_CONF_BUS_TIME(shunt_time) |
INA231_CONF_AVG(avg);
- ret = ina2xx_write(
- ina->port, ina->addr, INA231_REG_CONF, value);
+ ret = ina2xx_write__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_CONF, value);
if (ret != EC_SUCCESS) {
CPRINTS("[CAP] usb_power_init_inas CONF FAIL: %d", ret);
return ret;
@@ -558,26 +567,31 @@ static int usb_power_init_inas(struct usb_power_config const *config)
{
int actual;
- actual = ina2xx_read(ina->port, ina->addr, INA231_REG_CONF);
+ actual = ina2xx_read__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_CONF);
CPRINTS("[CAP] %d (%d,0x%02x): conf:%x, act:%x",
- i, ina->port, ina->addr, value, actual);
+ i, ina->port, I2C_GET_ADDR__7b(ina->addr__7bf),
+ value, actual);
}
#endif
#ifdef USB_POWER_VERBOSE
{
int busv_mv =
- (ina2xx_read(ina->port, ina->addr, INA231_REG_BUSV)
+ (ina2xx_read__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_BUSV)
* 125) / 100;
CPRINTS("[CAP] %d (%d,0x%02x): busv:%dmv",
- i, ina->port, ina->addr, busv_mv);
+ i, ina->port, I2C_GET_ADDR__7b(ina->addr__7bf),
+ busv_mv);
}
#endif
/* Initialize read from power register. This register address
* will be cached and all ina2xx_readagain() calls will read
* from the same address.
*/
- ina2xx_read(ina->port, ina->addr, reg_type_mapping(ina->type));
+ ina2xx_read__7bf(ina->port, ina->addr__7bf,
+ reg_type_mapping(ina->type));
#ifdef USB_POWER_VERBOSE
CPRINTS("[CAP] %d (%d,0x%02x): type:%d", (int)(ina->type));
#endif
@@ -635,10 +649,11 @@ static int usb_power_get_samples(struct usb_power_config const *config)
* transaction.
*/
if (ina->shared)
- regval = ina2xx_read(ina->port, ina->addr,
+ regval = ina2xx_read__7bf(ina->port, ina->addr__7bf,
reg_type_mapping(ina->type));
else
- regval = ina2xx_readagain(ina->port, ina->addr);
+ regval = ina2xx_readagain__7bf(ina->port,
+ ina->addr__7bf);
r->power[i] = regval;
#ifdef USB_POWER_VERBOSE
{
@@ -647,10 +662,14 @@ static int usb_power_get_samples(struct usb_power_config const *config)
int voltage;
int bvoltage;
- voltage = ina2xx_read(ina->port, ina->addr, INA231_REG_RSHV);
- bvoltage = ina2xx_read(ina->port, ina->addr, INA231_REG_BUSV);
- current = ina2xx_read(ina->port, ina->addr, INA231_REG_CURR);
- power = ina2xx_read(ina->port, ina->addr, INA231_REG_PWR);
+ voltage = ina2xx_read__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_RSHV);
+ bvoltage = ina2xx_read__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_BUSV);
+ current = ina2xx_read__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_CURR);
+ power = ina2xx_read__7bf(ina->port, ina->addr__7bf,
+ INA231_REG_PWR);
{
int uV = ((int)voltage * 25) / 10;
int mV = ((int)bvoltage * 125) / 100;
@@ -659,7 +678,8 @@ 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, ina->addr, uV/1000, ina->rs, uA/1000);
+ i, ina->port, I2C_GET_ADDR__7b(ina->addr__7bf),
+ uV/1000, ina->rs, uA/1000);
CPRINTS("[CAP] %duV %dmV %duA %dCuA "
"%duW v:%04x, b:%04x, p:%04x",
uV, mV, uA, CuA, uW, voltage, bvoltage, power);
diff --git a/chip/stm32/usb_power.h b/chip/stm32/usb_power.h
index ff76603e63..f2f1426691 100644
--- a/chip/stm32/usb_power.h
+++ b/chip/stm32/usb_power.h
@@ -138,7 +138,7 @@ struct usb_power_ina_cfg {
/* i2c bus. TODO(nsanders): specify what kind of index. */
int port;
/* 7-bit i2c addr */
- int addr;
+ uint16_t addr__7bf;
/* Base voltage. mV */
int mv;
@@ -243,7 +243,7 @@ struct __attribute__ ((__packed__)) usb_power_command_addina {
uint16_t command;
uint8_t port;
uint8_t type;
- uint8_t addr;
+ uint16_t addr__7bf;
uint8_t extra;
uint32_t rs;
};