summaryrefslogtreecommitdiff
path: root/include
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 /include
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 'include')
-rw-r--r--include/battery_smart.h4
-rw-r--r--include/charge_state_v2.h2
-rw-r--r--include/config.h20
-rw-r--r--include/ec_commands.h12
-rw-r--r--include/i2c.h162
-rw-r--r--include/motion_sense.h21
-rw-r--r--include/test_util.h13
-rw-r--r--include/usb_i2c.h2
-rw-r--r--include/usb_mux.h20
-rw-r--r--include/usb_pd_tcpc.h6
-rw-r--r--include/usbc_ppc.h2
-rw-r--r--include/virtual_battery.h2
12 files changed, 180 insertions, 86 deletions
diff --git a/include/battery_smart.h b/include/battery_smart.h
index ceec42719c..84b80fd162 100644
--- a/include/battery_smart.h
+++ b/include/battery_smart.h
@@ -11,8 +11,8 @@
#include "common.h"
/* Smart battery and charger I2C address */
-#define BATTERY_ADDR 0x16
-#define CHARGER_ADDR 0x12
+#define BATTERY_ADDR__7bf (0x0B)
+#define CHARGER_ADDR__7bf (0x09)
/* Charger functions */
#define SB_CHARGER_SPEC_INFO 0x11
diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h
index f44fd3d8f7..1a7f698cc4 100644
--- a/include/charge_state_v2.h
+++ b/include/charge_state_v2.h
@@ -14,7 +14,7 @@
#define __CROS_EC_CHARGE_STATE_V2_H
#if defined(CONFIG_I2C_VIRTUAL_BATTERY) && defined(CONFIG_BATTERY_SMART)
-#define VIRTUAL_BATTERY_ADDR BATTERY_ADDR
+#define VIRTUAL_BATTERY_ADDR__7bf BATTERY_ADDR__7bf
#endif
/*
* The values exported by charge_get_state() and charge_get_flags() are used
diff --git a/include/config.h b/include/config.h
index a798f0eac1..95258abd54 100644
--- a/include/config.h
+++ b/include/config.h
@@ -139,7 +139,7 @@
#undef CONFIG_KX022_ORIENTATION_SENSOR
/* Define the i2c address of the sensor behind the main sensor, if present. */
-#undef CONFIG_ACCELGYRO_SEC_ADDR
+#undef CONFIG_ACCELGYRO_SEC_ADDR__7BF
/*
* Define if either CONFIG_BMI160_ORIENTATION_SUPPORT or
@@ -601,7 +601,7 @@
#undef CONFIG_BOARD_VERSION_GPIO
/* EC responses to a board defined I2C slave address */
-#undef CONFIG_BOARD_I2C_SLAVE_ADDR
+#undef CONFIG_BOARD_I2C_SLAVE_ADDR__7BF
/*
* The board is unable to distinguish EC reset from power-on so it should treat
@@ -2030,7 +2030,7 @@
* For ECs where the host command interface is I2C, slave
* address which the EC will respond to.
*/
-#undef CONFIG_HOSTCMD_I2C_SLAVE_ADDR
+#undef CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF
/*
* Accept EC host commands over the SPI slave (SPS) interface.
@@ -2199,7 +2199,7 @@
* transaction is done, the pin is set back to low.
*/
#undef CONFIG_I2C_SCL_GATE_PORT
-#undef CONFIG_I2C_SCL_GATE_ADDR
+#undef CONFIG_I2C_SCL_GATE_ADDR__7BF
#undef CONFIG_I2C_SCL_GATE_GPIO
/*
@@ -3411,9 +3411,9 @@
/* Enable Elan driver */
#undef CONFIG_TOUCHPAD_ELAN
-/* Set I2C port and address (8-bit) */
+/* Set I2C port and address (7-bit) */
#undef CONFIG_TOUCHPAD_I2C_PORT
-#undef CONFIG_TOUCHPAD_I2C_ADDR
+#undef CONFIG_TOUCHPAD_I2C_ADDR__7BF
/*
* Enable touchpad FW update over USB update protocol, and define touchpad
@@ -3624,7 +3624,7 @@
#undef CONFIG_USB_PD_IDENTITY_SW_VERS
/* USB PD MCU slave address for host commands */
-#define CONFIG_USB_PD_I2C_SLAVE_ADDR 0x3c
+#define CONFIG_USB_PD_I2C_SLAVE_ADDR__7BF 0x1E
/* Define if using internal comparator for PD receive */
#undef CONFIG_USB_PD_INTERNAL_COMP
@@ -3736,7 +3736,7 @@
#undef CONFIG_USB_PD_VBUS_MEASURE_NOT_PRESENT
/* Define the type-c port controller I2C base address. */
-#define CONFIG_TCPC_I2C_BASE_ADDR 0x9c
+#define CONFIG_TCPC_I2C_BASE_ADDR__7BF 0x4E
/* Use this option to enable Try.SRC mode for Dual Role devices */
#undef CONFIG_USB_PD_TRY_SRC
@@ -4713,7 +4713,7 @@
#if defined(CONFIG_MAG_BMI160_LIS2MDL) || \
defined(CONFIG_MAG_LSM6DSM_LIS2MDL)
#define CONFIG_MAG_LIS2MDL
-#ifndef CONFIG_ACCELGYRO_SEC_ADDR
+#ifndef CONFIG_ACCELGYRO_SEC_ADDR__7BF
#error "The i2c address of the magnetometer is not set."
#endif
#endif
@@ -4722,7 +4722,7 @@
#if defined(CONFIG_MAG_BMI160_BMM150) || \
defined(CONFIG_MAG_LSM6DSM_BMM150)
#define CONFIG_MAG_BMM150
-#ifndef CONFIG_ACCELGYRO_SEC_ADDR
+#ifndef CONFIG_ACCELGYRO_SEC_ADDR__7BF
#error "The i2c address of the magnetometer is not set."
#endif
#endif
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 5e78cae51c..fb1523b479 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -4008,7 +4008,10 @@ struct ec_response_power_info {
#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
struct ec_params_i2c_passthru_msg {
- uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
+ union {
+ uint16_t addr_flags; /* I2C slave address and flags */
+ uint16_t addr_flags__7bf; /* remove before final merge */
+ };
uint16_t len; /* Number of bytes to read or write */
} __ec_align2;
@@ -5402,8 +5405,11 @@ enum ec_bus_type {
};
struct ec_i2c_info {
- uint16_t port; /* Physical port for device */
- uint16_t addr; /* 7-bit (or 10-bit) address */
+ uint16_t port; /* Physical port for device */
+ union {
+ uint16_t addr_flags; /* 7-bit (or 10-bit) address */
+ uint16_t addr__7bf; /* remove before final merge */
+ };
};
struct ec_params_locate_chip {
diff --git a/include/i2c.h b/include/i2c.h
index 566ae7b402..1281b8280d 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -13,8 +13,35 @@
#include "host_command.h"
#include "stddef.h"
-/* Flags for slave address field, in addition to the 8-bit address */
-#define I2C_FLAG_BIG_ENDIAN 0x100 /* 16 byte values are MSB-first */
+/*
+ * I2C Slave Address encoding
+ *
+ * EC will favor 7bit I2C/SPI address encoding. The variable/define
+ * naming should follow the pattern, if it is just the 7 bit address
+ * then end the variable as "addr". This can be addr, i2c_addr,
+ * slave_addr, etc. If the 7 bit address contains flags for BIG
+ * ENDIAN or overloading the address to be a SPI address, then it
+ * will be customary to end the variable as "addr_flags". This can
+ * be addr_flags, i2c_addr_flags, slave_addr_flags, etc.
+ *
+ * Some of the drivers use an 8bit left shifted 7bit address. Since
+ * this is driver specific, it will be up to the driver to make this
+ * clear. I suggest, since this is a very small amount of usage, that
+ * ending the variable as "addr__8bit" would make this clear.
+ *
+ * NOTE: Slave addresses are always 16 bit values. The least significant
+ * 10 bits are available as an address. More significant bits are
+ * used here and in motion_sense to give specific meaning to the
+ * address that is pertinent to its use.
+ */
+#define I2C_ADDR_MASK 0x03FF
+#define I2C_FLAG_BIG_ENDIAN BIT(14)
+/* BIT(15) SPI_FLAG - used in motion_sense to overload address */
+#define I2C_FLAG_ADDR_IS_SPI BIT(15)
+
+#define I2C_GET_ADDR(x) (I2C_GET_ADDR__7b(x))
+#define I2C_GET_ADDR__7b(x__7bf) ((x__7bf) & I2C_ADDR_MASK)
+#define I2C_IS_BIG_ENDIAN(x__7bf) ((x__7bf) & I2C_FLAG_BIG_ENDIAN)
/*
* Max data size for a version 3 request/response packet. This is
@@ -35,7 +62,16 @@ enum i2c_freq {
struct i2c_info_t {
uint16_t port; /* Physical port for device */
- uint16_t addr; /* 8-bit (or 11-bit) address */
+
+ /*
+ * union is temporary to accommodate ec_tools
+ * and will be reduced to the non-__7bf version
+ * before the final merge
+ */
+ union {
+ uint16_t addr_flags;
+ uint16_t addr__7bf;
+ };
};
/* Data structure to define I2C port configuration. */
@@ -47,8 +83,8 @@ struct i2c_port_t {
enum gpio_signal sda; /* Port SDA GPIO line */
/* When bus is protected, returns true if passthru allowed for address.
* If the function is not defined, the default value is true. */
- int (*passthru_allowed)(const struct i2c_port_t *port,
- uint16_t address);
+ int (*passthru_allowed__7bf)(const struct i2c_port_t *port,
+ uint16_t addr__7bf);
};
extern const struct i2c_port_t i2c_ports[];
@@ -72,17 +108,19 @@ struct i2c_test_results {
struct i2c_stress_test_dev {
struct i2c_test_reg_info reg_info;
struct i2c_test_results test_results;
- int (*i2c_read)(const int port, const int addr,
- const int reg, int *data);
- int (*i2c_write)(const int port, const int addr,
- const int reg, int data);
+ int (*i2c_read__7bf)(const int port,
+ const uint16_t slave_addr__7bf,
+ const int reg, int *data);
+ int (*i2c_write__7bf)(const int port,
+ const uint16_t slave_addr__7bf,
+ const int reg, int data);
int (*i2c_read_dev)(const int reg, int *data);
int (*i2c_write_dev)(const int reg, int data);
};
struct i2c_stress_test {
int port;
- int addr;
+ uint16_t addr__7bf;
struct i2c_stress_test_dev *i2c_test;
};
@@ -109,7 +147,9 @@ extern const int i2c_test_dev_used;
* @param in_size Number of bytes to receive
* @return EC_SUCCESS, or non-zero if error.
*/
-int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
+int 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);
/**
@@ -118,7 +158,8 @@ int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
*
* @param flags Flags (see I2C_XFER_* above)
*/
-int i2c_xfer_unlocked(int port, int slave_addr,
+int i2c_xfer_unlocked__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);
@@ -142,7 +183,9 @@ int i2c_xfer_unlocked(int port, int slave_addr,
* @param flags Flags (see I2C_XFER_* above)
* @return EC_SUCCESS, or non-zero if error.
*/
-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);
/**
@@ -236,68 +279,84 @@ void i2c_prepare_sysjump(void);
void i2c_set_timeout(int port, uint32_t timeout);
/**
- * Read a 32-bit register from the slave at 8-bit slave address <slaveaddr>, at
+ * Read a 32-bit register from the slave at 7-bit slave address <slaveaddr>, at
* the specified 8-bit <offset> in the slave's address space.
*/
-int i2c_read32(int port, int slave_addr, int offset, int *data);
+int i2c_read32__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ int offset, int *data);
/**
- * Write a 32-bit register to the slave at 8-bit slave address <slaveaddr>, at
+ * Write a 32-bit register to the slave at 7-bit slave address <slaveaddr>, at
* the specified 8-bit <offset> in the slave's address space.
*/
-int i2c_write32(int port, int slave_addr, int offset, int data);
+int i2c_write32__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ int offset, int data);
/**
- * Read a 16-bit register from the slave at 8-bit slave address <slaveaddr>, at
+ * Read a 16-bit register from the slave at 7-bit slave address <slaveaddr>, at
* the specified 8-bit <offset> in the slave's address space.
*/
-int i2c_read16(int port, int slave_addr, int offset, int *data);
+int i2c_read16__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ int offset, int *data);
/**
- * Write a 16-bit register to the slave at 8-bit slave address <slaveaddr>, at
+ * Write a 16-bit register to the slave at 7-bit slave address <slaveaddr>, at
* the specified 8-bit <offset> in the slave's address space.
*/
-int i2c_write16(int port, int slave_addr, int offset, int data);
+int i2c_write16__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ int offset, int data);
/**
- * Read an 8-bit register from the slave at 8-bit slave address <slaveaddr>, at
+ * Read an 8-bit register from the slave at 7-bit slave address <slaveaddr>, at
* the specified 8-bit <offset> in the slave's address space.
*/
-int i2c_read8(int port, int slave_addr, int offset, int *data);
+int i2c_read8__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ int offset, int *data);
/**
- * Write an 8-bit register to the slave at 8-bit slave address <slaveaddr>, at
+ * Write an 8-bit register to the slave at 7-bit slave address <slaveaddr>, at
* the specified 8-bit <offset> in the slave's address space.
*/
-int i2c_write8(int port, int slave_addr, int offset, int data);
+int i2c_write8__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ int offset, int data);
/**
- * Read one or two bytes data from the slave at 8-bit slave address
+ * Read one or two bytes data from the slave at 7-bit slave address
* * <slaveaddr>, at 16-bit <offset> in the slave's address space.
*/
-int i2c_read_offset16(int port, int slave_addr, uint16_t offset, int *data,
- int len);
+int i2c_read_offset16__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ uint16_t offset, int *data, int len);
/**
- * Write one or two bytes data to the slave at 8-bit slave address
+ * Write one or two bytes data to the slave at 7-bit slave address
* <slaveaddr>, at 16-bit <offset> in the slave's address space.
*/
-int i2c_write_offset16(int port, int slave_addr, uint16_t offset, int data,
- int len);
+int i2c_write_offset16__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ uint16_t offset, int data, int len);
/**
- * Read <len> bytes block data from the slave at 8-bit slave address
+ * Read <len> bytes block data from the slave at 7-bit slave address
* * <slaveaddr>, at 16-bit <offset> in the slave's address space.
*/
-int i2c_read_offset16_block(int port, int slave_addr, uint16_t offset,
- uint8_t *data, int len);
+int i2c_read_offset16_block__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ uint16_t offset, uint8_t *data, int len);
/**
- * Write <len> bytes block data to the slave at 8-bit slave address
+ * Write <len> bytes block data to the slave at 7-bit slave address
* <slaveaddr>, at 16-bit <offset> in the slave's address space.
*/
-int i2c_write_offset16_block(int port, int slave_addr, uint16_t offset,
- const uint8_t *data, int len);
+int i2c_write_offset16_block__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ uint16_t offset, const uint8_t *data, int len);
/**
* @return non-zero if i2c bus is busy
@@ -324,24 +383,27 @@ int i2c_unwedge(int port);
* always written into the output buffer.
* <len> == 0 : buffer size > 255
*/
-int i2c_read_string(int port, int slave_addr, int offset, uint8_t *data,
- int len);
+int i2c_read_string__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ int offset, uint8_t *data, int len);
/**
- * Read a data block of <len> 8-bit transfers from the slave at 8-bit slave
+ * Read a data block of <len> 8-bit transfers from the slave at 7-bit slave
* address <slaveaddr>, at the specified 8-bit <offset> in the slave's address
* space.
*/
-int i2c_read_block(int port, int slave_addr, int offset, uint8_t *data,
- int len);
+int i2c_read_block__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ int offset, uint8_t *data, int len);
/**
- * Write a data block of <len> 8-bit transfers to the slave at 8-bit slave
+ * Write a data block of <len> 8-bit transfers to the slave at 7-bit slave
* address <slaveaddr>, at the specified 8-bit <offset> in the slave's address
* space.
*/
-int i2c_write_block(int port, int slave_addr, int offset, const uint8_t *data,
- int len);
+int i2c_write_block__7bf(const int port,
+ const uint16_t slave_addr__7bf,
+ int offset, const uint8_t *data, int len);
/**
* Convert port number to controller number, for multi-port controllers.
@@ -414,7 +476,8 @@ int board_is_i2c_port_powered(int port);
* @param slave_addr: Slave device address
*
*/
-void i2c_start_xfer_notify(int port, int slave_addr);
+void i2c_start_xfer_notify__7bf(const int port,
+ const uint16_t slave_addr__7bf);
/**
* Function to allow board to take any action after an i2c transaction on a
@@ -425,7 +488,8 @@ void i2c_start_xfer_notify(int port, int slave_addr);
* @param slave_addr: Slave device address
*
*/
-void i2c_end_xfer_notify(int port, int slave_addr);
+void i2c_end_xfer_notify__7bf(const int port,
+ const uint16_t slave_addr__7bf);
/**
* Defined in common/i2c_trace.c, used by i2c master to notify tracing
@@ -438,7 +502,7 @@ void i2c_end_xfer_notify(int port, int slave_addr);
* @param data: pointer to data read or written
* @param size: size of data read or written
*/
-void i2c_trace_notify(int port, int slave_addr, int direction,
- const uint8_t *data, size_t size);
+void i2c_trace_notify__7bf(int port, uint16_t slave_addr__7bf,
+ int direction, const uint8_t *data, size_t size);
#endif /* __CROS_EC_I2C_H */
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 34da3f9ea5..0e9f79e422 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -12,6 +12,7 @@
#include "common.h"
#include "ec_commands.h"
#include "gpio.h"
+#include "i2c.h"
#include "math_util.h"
#include "queue.h"
#include "timer.h"
@@ -81,6 +82,24 @@ enum sensor_config {
#endif
/*
+ * I2C/SPI Slave Address encoding for motion sensors
+ * - The generic defines, I2C_ADDR_MASK and I2C_IS_BIG_ENDIAN_MASK
+ * are defined in i2c.h.
+ * - Motion sensors support some sensors on the SPI bus, so this
+ * overloads the I2C Address to use a single bit to indicate
+ * it is a SPI address instead of an I2C. Since SPI does not
+ * use slave addressing, it is up to the driver to use this
+ * field as it sees fit
+ */
+#define SLAVE_MK_I2C_ADDR__7bf(x__7b) (x__7b)
+#define SLAVE_MK_SPI_ADDR__7bf(x__7b) ((x__7b) | I2C_FLAG_ADDR_IS_SPI)
+
+#define SLAVE_GET_I2C_ADDR__7b(x__7bf) (I2C_GET_ADDR__7b(x__7bf))
+#define SLAVE_GET_SPI_ADDR__7b(x__7bf) ((x__7bf) & I2C_ADDR_MASK)
+
+#define SLAVE_IS_SPI(x__7bf) ((x__7bf) & I2C_FLAG_ADDR_IS_SPI)
+
+/*
* Define the frequency to use in max_frequency based on the maximal frequency
* the sensor support and what the EC can provide.
* Return a frequency the sensor supports.
@@ -131,7 +150,7 @@ struct motion_sensor_t {
/* i2c port */
uint8_t port;
/* i2c address or SPI slave logic GPIO. */
- uint8_t addr;
+ uint16_t i2c_spi_addr__7bf;
/*
* Various flags, see MOTIONSENSE_FLAG_*
diff --git a/include/test_util.h b/include/test_util.h
index 098700d67b..a812817b8f 100644
--- a/include/test_util.h
+++ b/include/test_util.h
@@ -218,20 +218,21 @@ void test_reboot_to_next_step(enum test_state_t step);
struct test_i2c_read_string_dev {
/* I2C string read handler */
- int (*routine)(int port, int slave_addr, int offset, uint8_t *data,
- int len);
+ int (*routine__7bf)(const int port, const uint16_t i2c_addr__7bf,
+ int offset, uint8_t *data, int len);
};
struct test_i2c_xfer {
/* I2C xfer handler */
- int (*routine)(int port, int slave_addr,
+ int (*routine__7bf)(const int port, const uint16_t i2c_addr__7bf,
const uint8_t *out, int out_size,
uint8_t *in, int in_size, int flags);
};
struct test_i2c_write_dev {
/* I2C write handler */
- int (*routine)(int port, int slave_addr, int offset, int data);
+ int (*routine__7bf)(const int port, const uint16_t i2c_addr__7bf,
+ int offset, int data);
};
/**
@@ -258,7 +259,7 @@ struct test_i2c_write_dev {
* @return EC_SUCCESS if detached; EC_ERROR_OVERFLOW if too many devices are
* detached.
*/
-int test_detach_i2c(int port, int slave_addr);
+int test_detach_i2c__7bf(const int port, const uint16_t slave_addr__7bf);
/*
* Re-attach an I2C device.
@@ -268,6 +269,6 @@ int test_detach_i2c(int port, int slave_addr);
* @return EC_SUCCESS if re-attached; EC_ERROR_INVAL if the specified device
* is not a detached device.
*/
-int test_attach_i2c(int port, int slave_addr);
+int test_attach_i2c__7bf(const int port, const uint16_t slave_addr__7bf);
#endif /* __CROS_EC_TEST_UTIL_H */
diff --git a/include/usb_i2c.h b/include/usb_i2c.h
index 2f09076eb9..629f495b69 100644
--- a/include/usb_i2c.h
+++ b/include/usb_i2c.h
@@ -218,7 +218,7 @@ int usb_i2c_board_is_enabled(void);
* Special i2c address to use when the client is required to execute some
* command which does not directly involve the i2c master driver.
*/
-#define USB_I2C_CMD_ADDR 0xf0
+#define USB_I2C_CMD_ADDR__7bf 0x78
/*
* Function to call to register a handler for commands sent to the special i2c
diff --git a/include/usb_mux.h b/include/usb_mux.h
index ff2704d2b6..94e2d6dbac 100644
--- a/include/usb_mux.h
+++ b/include/usb_mux.h
@@ -27,7 +27,7 @@ typedef uint8_t mux_state_t;
*/
#define MUX_PORT_AND_ADDR(port, addr) ((port << 8) | (addr & 0xFF))
#define MUX_PORT(port) (usb_muxes[port].port_addr >> 8)
-#define MUX_ADDR(port) (usb_muxes[port].port_addr & 0xFF)
+#define MUX_ADDR__7bf(port) (usb_muxes[port].port_addr & 0xFF)
/* Mux state attributes */
/* TODO: Directly use USB_PD_MUX_* everywhere and remove these 3 defines */
@@ -143,29 +143,31 @@ extern struct usb_mux usb_muxes[];
static inline int mux_write(int port, int reg, int val)
{
return usb_muxes[port].flags & USB_MUX_FLAG_NOT_TCPC
- ? i2c_write8(MUX_PORT(port), MUX_ADDR(port), reg, val)
- : tcpc_write(port, reg, val);
+ ? i2c_write8__7bf(MUX_PORT(port), MUX_ADDR__7bf(port), reg, val)
+ : tcpc_write(port, reg, val);
}
static inline int mux_read(int port, int reg, int *val)
{
return usb_muxes[port].flags & USB_MUX_FLAG_NOT_TCPC
- ? i2c_read8(MUX_PORT(port), MUX_ADDR(port), reg, val)
- : tcpc_read(port, reg, val);
+ ? i2c_read8__7bf(MUX_PORT(port), MUX_ADDR__7bf(port), reg, val)
+ : tcpc_read(port, reg, val);
}
static inline int mux_write16(int port, int reg, int val)
{
return usb_muxes[port].flags & USB_MUX_FLAG_NOT_TCPC
- ? i2c_write16(MUX_PORT(port), MUX_ADDR(port), reg, val)
- : tcpc_write16(port, reg, val);
+ ? i2c_write16__7bf(MUX_PORT(port), MUX_ADDR__7bf(port),
+ reg, val)
+ : tcpc_write16(port, reg, val);
}
static inline int mux_read16(int port, int reg, int *val)
{
return usb_muxes[port].flags & USB_MUX_FLAG_NOT_TCPC
- ? i2c_read16(MUX_PORT(port), MUX_ADDR(port), reg, val)
- : tcpc_read16(port, reg, val);
+ ? i2c_read16__7bf(MUX_PORT(port), MUX_ADDR__7bf(port),
+ reg, val)
+ : tcpc_read16(port, reg, val);
}
#endif /* CONFIG_USB_PD_TCPM_MUX */
diff --git a/include/usb_pd_tcpc.h b/include/usb_pd_tcpc.h
index f5785921a4..ba911f00ad 100644
--- a/include/usb_pd_tcpc.h
+++ b/include/usb_pd_tcpc.h
@@ -18,9 +18,11 @@
#ifdef TCPCI_I2C_SLAVE
/* Convert TCPC address to type-C port number */
-#define TCPC_ADDR_TO_PORT(addr) (((addr) - CONFIG_TCPC_I2C_BASE_ADDR) >> 1)
+#define TCPC_ADDR_TO_PORT(addr) ((addr) \
+ - I2C_GET_ADDR__7b(CONFIG_TCPC_I2C_BASE_ADDR__7BF))
/* Check if the i2c address belongs to TCPC */
-#define ADDR_IS_TCPC(addr) (((addr) & 0xfc) == CONFIG_TCPC_I2C_BASE_ADDR)
+#define ADDR_IS_TCPC(addr) (((addr) & 0x7E) \
+ == I2C_GET_ADDR__7b(CONFIG_TCPC_I2C_BASE_ADDR__7BF))
#endif
/**
diff --git a/include/usbc_ppc.h b/include/usbc_ppc.h
index fbd4385afc..3e74f37956 100644
--- a/include/usbc_ppc.h
+++ b/include/usbc_ppc.h
@@ -141,7 +141,7 @@ struct ppc_drv {
struct ppc_config_t {
int i2c_port;
- int i2c_addr;
+ uint16_t i2c_addr__7bf;
const struct ppc_drv *drv;
};
diff --git a/include/virtual_battery.h b/include/virtual_battery.h
index c686a76172..99fb30e03b 100644
--- a/include/virtual_battery.h
+++ b/include/virtual_battery.h
@@ -7,7 +7,7 @@
#define __CROS_EC_VIRTUAL_BATTERY_H
#if defined(CONFIG_I2C_VIRTUAL_BATTERY) && defined(CONFIG_BATTERY_SMART)
-#define VIRTUAL_BATTERY_ADDR BATTERY_ADDR
+#define VIRTUAL_BATTERY_ADDR__7bf BATTERY_ADDR__7bf
#endif
/**