summaryrefslogtreecommitdiff
path: root/board/nautilus/board.c
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 /board/nautilus/board.c
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 'board/nautilus/board.c')
-rw-r--r--board/nautilus/board.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/board/nautilus/board.c b/board/nautilus/board.c
index 5dc1df0328..bf89d0edad 100644
--- a/board/nautilus/board.c
+++ b/board/nautilus/board.c
@@ -151,7 +151,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = NPCX_I2C_PORT0_0,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -159,7 +159,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = NPCX_I2C_PORT0_1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -268,7 +268,7 @@ static void board_report_pmic_fault(const char *str)
uint32_t info;
/* RESETIRQ1 -- Bit 4: VRFAULT */
- if (i2c_read8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x8, &vrfault)
+ if (i2c_read8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x8, &vrfault)
!= EC_SUCCESS)
return;
@@ -278,19 +278,19 @@ static void board_report_pmic_fault(const char *str)
/* VRFAULT has occurred, print VRFAULT status bits. */
/* PWRSTAT1 */
- i2c_read8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x16, &pwrstat1);
+ i2c_read8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x16, &pwrstat1);
/* PWRSTAT2 */
- i2c_read8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x17, &pwrstat2);
+ i2c_read8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x17, &pwrstat2);
CPRINTS("PMIC VRFAULT: %s", str);
CPRINTS("PMIC VRFAULT: PWRSTAT1=0x%02x PWRSTAT2=0x%02x", pwrstat1,
pwrstat2);
/* Clear all faults -- Write 1 to clear. */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x8, BIT(4));
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x16, pwrstat1);
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x17, pwrstat2);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x8, BIT(4));
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x16, pwrstat1);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x17, pwrstat2);
/*
* Status of the fault registers can be checked in the OS by looking at
@@ -309,7 +309,7 @@ static void board_pmic_disable_slp_s0_vr_decay(void)
* Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
* Bits 1:0 (10) - VR set to AUTO operating mode
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x30, 0x3a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x30, 0x3a);
/*
* V18ACNT:
@@ -318,7 +318,7 @@ static void board_pmic_disable_slp_s0_vr_decay(void)
* Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
* Bits 1:0 (10) - VR set to AUTO operating mode
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x34, 0x2a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x34, 0x2a);
/*
* V100ACNT:
@@ -327,7 +327,7 @@ static void board_pmic_disable_slp_s0_vr_decay(void)
* Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
* Bits 1:0 (10) - VR set to AUTO operating mode
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x37, 0x1a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x37, 0x1a);
/*
* V085ACNT:
@@ -336,7 +336,7 @@ static void board_pmic_disable_slp_s0_vr_decay(void)
* Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
* Bits 1:0 (10) - VR set to AUTO operating mode
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x38, 0x3a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x38, 0x3a);
}
static void board_pmic_enable_slp_s0_vr_decay(void)
@@ -348,7 +348,7 @@ static void board_pmic_enable_slp_s0_vr_decay(void)
* Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
* Bits 1:0 (10) - VR set to AUTO operating mode
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x30, 0x7a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x30, 0x7a);
/*
* V18ACNT:
@@ -357,7 +357,7 @@ static void board_pmic_enable_slp_s0_vr_decay(void)
* Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
* Bits 1:0 (10) - VR set to AUTO operating mode
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x34, 0x6a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x34, 0x6a);
/*
* V100ACNT:
@@ -366,7 +366,7 @@ static void board_pmic_enable_slp_s0_vr_decay(void)
* Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
* Bits 1:0 (10) - VR set to AUTO operating mode
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x37, 0x5a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x37, 0x5a);
/*
* V085ACNT:
@@ -375,7 +375,7 @@ static void board_pmic_enable_slp_s0_vr_decay(void)
* Bits 3:2 (10) - VR set to AUTO on SLP_S0# de-assertion
* Bits 1:0 (10) - VR set to AUTO operating mode
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x38, 0x7a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x38, 0x7a);
}
void power_board_handle_host_sleep_event(enum host_sleep_event state)
@@ -394,12 +394,12 @@ static void board_pmic_init(void)
return;
/* DISCHGCNT3 - enable 100 ohm discharge on V1.00A */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x3e, 0x04);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x3e, 0x04);
board_pmic_disable_slp_s0_vr_decay();
/* VRMODECTRL - disable low-power mode for all rails */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x3b, 0x1f);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x3b, 0x1f);
}
DECLARE_DEFERRED(board_pmic_init);
@@ -535,7 +535,7 @@ void board_hibernate(void)
uart_flush_output();
/* Trigger PMIC shutdown. */
- if (i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x49, 0x01)) {
+ if (i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x49, 0x01)) {
/*
* If we can't tell the PMIC to shutdown, instead reset
* and don't start the AP. Hopefully we'll be able to
@@ -611,7 +611,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_bma255_data,
.port = I2C_PORT_ACCEL,
- .addr = BMA2x2_I2C_ADDR1,
+ .i2c_spi_addr__7bf = BMA2x2_I2C_ADDR1__7bf,
.rot_standard_ref = &lid_standard_ref,
.min_frequency = BMA255_ACCEL_MIN_FREQ,
.max_frequency = BMA255_ACCEL_MAX_FREQ,
@@ -637,7 +637,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_ACCEL,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = &base_standard_ref,
.min_frequency = BMI160_ACCEL_MIN_FREQ,
.max_frequency = BMI160_ACCEL_MAX_FREQ,
@@ -664,7 +664,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_ACCEL,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.default_range = 1000, /* dps */
.rot_standard_ref = &base_standard_ref,
.min_frequency = BMI160_GYRO_MIN_FREQ,
@@ -747,16 +747,17 @@ int board_has_working_reset_flags(void)
#define BATTERY_FREE_MIN_DELTA_US (5 * MSEC)
static timestamp_t battery_last_i2c_time;
-static int is_battery_i2c(int port, int slave_addr)
+static int is_battery_i2c__7bf(const int port, const uint16_t slave_addr__7bf)
{
- return (port == I2C_PORT_BATTERY) && (slave_addr == BATTERY_ADDR);
+ return (port == I2C_PORT_BATTERY)
+ && (slave_addr__7bf == BATTERY_ADDR__7bf);
}
-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)
{
unsigned int time_delta_us;
- if (!is_battery_i2c(port, slave_addr))
+ if (!is_battery_i2c__7bf(port, slave_addr__7bf))
return;
time_delta_us = time_since32(battery_last_i2c_time);
@@ -766,9 +767,9 @@ void i2c_start_xfer_notify(int port, int slave_addr)
usleep(BATTERY_FREE_MIN_DELTA_US - time_delta_us);
}
-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)
{
- if (!is_battery_i2c(port, slave_addr))
+ if (!is_battery_i2c__7bf(port, slave_addr__7bf))
return;
battery_last_i2c_time = get_time();