summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-06-25 12:44:16 -0600
committerCommit Bot <commit-bot@chromium.org>2019-08-23 00:12:30 +0000
commitee8d481a027b78796ce30a48224e043fdf5f7491 (patch)
treebe23edd0a16a6548302c45da04740ba19809a40e
parent220205c8480433cb72f7c738ba141d5afa6d1968 (diff)
downloadchrome-ec-ee8d481a027b78796ce30a48224e043fdf5f7491.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> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1767525 Reviewed-by: Edward Hill <ecgh@chromium.org> Commit-Queue: Edward Hill <ecgh@chromium.org> Tested-by: Edward Hill <ecgh@chromium.org>
-rw-r--r--baseboard/dragonegg/baseboard.c8
-rw-r--r--baseboard/dragonegg/baseboard.h4
-rw-r--r--baseboard/grunt/baseboard.c14
-rw-r--r--baseboard/hatch/baseboard.c4
-rw-r--r--baseboard/hatch/baseboard.h186
-rw-r--r--baseboard/kalista/baseboard.c8
-rw-r--r--baseboard/kalista/baseboard.h239
-rw-r--r--baseboard/octopus/baseboard.h4
-rw-r--r--baseboard/octopus/variant_usbc_ec_tcpcs.c8
-rw-r--r--baseboard/octopus/variant_usbc_standalone_tcpcs.c10
-rw-r--r--baseboard/zork/baseboard.c14
-rw-r--r--board/ampton/board.c57
-rw-r--r--board/arcada_ish/board.c203
-rw-r--r--board/atlas/board.c213
-rw-r--r--board/atlas/board.h8
-rw-r--r--board/bloog/board.c329
-rw-r--r--board/bobba/board.c6
-rw-r--r--board/casta/board.c154
-rw-r--r--board/chell/board.c25
-rw-r--r--board/cheza/board.c39
-rw-r--r--board/cheza/board.h36
-rw-r--r--board/coral/board.c20
-rw-r--r--board/elm/board.c15
-rw-r--r--board/elm/board.h4
-rw-r--r--board/eve/board.c98
-rw-r--r--board/eve/board.h22
-rw-r--r--board/fizz/board.c8
-rw-r--r--board/fizz/board.h4
-rw-r--r--board/flapjack/battery.c468
-rw-r--r--board/flapjack/board.c20
-rw-r--r--board/flapjack/board.h331
-rw-r--r--board/fleex/board.c129
-rw-r--r--board/fluffy/board.c405
-rw-r--r--board/garg/board.c337
-rw-r--r--board/glados/battery.c8
-rw-r--r--board/glados/board.c18
-rw-r--r--board/glados/board.h2
-rw-r--r--board/glados_pd/board.h2
-rw-r--r--board/glkrvp/battery.c6
-rw-r--r--board/glkrvp/board.c16
-rw-r--r--board/glkrvp/chg_usb_pd.c8
-rw-r--r--board/glkrvp_ite/battery.c4
-rw-r--r--board/glkrvp_ite/board.c41
-rw-r--r--board/glkrvp_ite/board.h2
-rw-r--r--board/glkrvp_ite/chg_usb_pd.c8
-rw-r--r--board/hammer/board.h2
-rw-r--r--board/hatch/board.c82
-rw-r--r--board/helios/board.c49
-rw-r--r--board/helios/board.h146
-rw-r--r--board/host/battery.c7
-rw-r--r--board/kindred/board.c445
-rw-r--r--board/kindred/board.h176
-rw-r--r--board/kohaku/board.c99
-rw-r--r--board/kukui/board.c382
-rw-r--r--board/kukui/board.h4
-rw-r--r--board/mchpevb1/battery.c8
-rw-r--r--board/mchpevb1/board.c34
-rw-r--r--board/mchpevb1/board.h2
-rw-r--r--board/meep/board.c6
-rw-r--r--board/nami/board.c22
-rw-r--r--board/nami/board.h4
-rw-r--r--board/nautilus/board.c96
-rw-r--r--board/nautilus/board.h4
-rw-r--r--board/nocturne/board.c132
-rw-r--r--board/nocturne/board.h29
-rw-r--r--board/nucleo-f411re/board.c4
-rw-r--r--board/oak/battery.c8
-rw-r--r--board/oak/board.c16
-rw-r--r--board/oak/board.h2
-rw-r--r--board/pdeval-stm32f072/board.c4
-rw-r--r--board/pdeval-stm32f072/usb_pd_policy.c2
-rw-r--r--board/phaser/board.c168
-rw-r--r--board/plankton/board.c30
-rw-r--r--board/poppy/board.c125
-rw-r--r--board/poppy/board.h8
-rw-r--r--board/rainier/board.c15
-rw-r--r--board/rammus/board.c147
-rw-r--r--board/rammus/board.h6
-rw-r--r--board/reef/board.c73
-rw-r--r--board/reef/board.h2
-rw-r--r--board/reef_it8320/board.c4
-rw-r--r--board/reef_mchp/board.c97
-rw-r--r--board/reef_mchp/board.h2
-rw-r--r--board/samus/battery.c8
-rw-r--r--board/samus/board.c56
-rw-r--r--board/samus/extpower.c4
-rw-r--r--board/samus/panel.c10
-rw-r--r--board/samus_pd/board.h2
-rw-r--r--board/scarlet/board.c6
-rw-r--r--board/scarlet/board.h2
-rw-r--r--board/servo_micro/board.c17
-rw-r--r--board/servo_v4/board.c18
-rw-r--r--board/strago/board.c8
-rw-r--r--board/sweetberry/board.c2
-rw-r--r--board/yorp/board.c68
-rw-r--r--chip/g/i2cm.c227
-rw-r--r--chip/host/i2c.c23
-rw-r--r--chip/ish/i2c.c292
-rw-r--r--chip/it83xx/i2c.c25
-rw-r--r--chip/lm4/i2c.c15
-rw-r--r--chip/mchp/i2c.c15
-rw-r--r--chip/mec1322/i2c.c14
-rw-r--r--chip/npcx/i2c.c25
-rw-r--r--chip/nrf51/i2c.c22
-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
-rw-r--r--common/cbi.c8
-rw-r--r--common/host_command_master.c19
-rw-r--r--common/i2c_master.c274
-rw-r--r--common/i2c_trace.c11
-rw-r--r--common/lb_common.c13
-rw-r--r--common/motion_sense.c3
-rw-r--r--common/peripheral.c7
-rw-r--r--common/usb_i2c.c9
-rw-r--r--cts/i2c/dut.c20
-rw-r--r--driver/accel_bma2x2.c54
-rw-r--r--driver/accel_bma2x2.h8
-rw-r--r--driver/accel_kionix.c98
-rw-r--r--driver/accel_kionix.h3
-rw-r--r--driver/accel_kx022.h4
-rw-r--r--driver/accel_kxcj9.h4
-rw-r--r--driver/accel_lis2dh.c34
-rw-r--r--driver/accel_lis2dh.h8
-rw-r--r--driver/accelgyro_bmi160.c377
-rw-r--r--driver/accelgyro_bmi160.h16
-rw-r--r--driver/accelgyro_lsm6ds0.c47
-rw-r--r--driver/accelgyro_lsm6ds0.h4
-rw-r--r--driver/accelgyro_lsm6dsm.c82
-rw-r--r--driver/accelgyro_lsm6dsm.h6
-rw-r--r--driver/accelgyro_lsm6dso.c38
-rw-r--r--driver/accelgyro_lsm6dso.h6
-rw-r--r--driver/als_al3010.h6
-rw-r--r--driver/als_bh1730.c14
-rw-r--r--driver/als_bh1730.h2
-rw-r--r--driver/als_isl29035.c10
-rw-r--r--driver/als_opt3001.c46
-rw-r--r--driver/als_opt3001.h8
-rw-r--r--driver/als_si114x.c92
-rw-r--r--driver/als_si114x.h2
-rw-r--r--driver/als_tcs3400.c494
-rw-r--r--driver/als_tcs3400.h121
-rw-r--r--driver/baro_bmp280.c17
-rw-r--r--driver/baro_bmp280.h5
-rw-r--r--driver/battery/bq27541.c2
-rw-r--r--driver/battery/bq27621_g1.c2
-rw-r--r--driver/battery/max17055.c6
-rw-r--r--driver/battery/max17055.h2
-rw-r--r--driver/battery/mm8013.c5
-rw-r--r--driver/battery/mm8013.h40
-rw-r--r--driver/battery/smart.c17
-rw-r--r--driver/bc12/pi3usb9201.c369
-rw-r--r--driver/bc12/pi3usb9201.h52
-rw-r--r--driver/bc12/pi3usb9281.c10
-rw-r--r--driver/charger/bd9995x.c10
-rw-r--r--driver/charger/bd9995x.h4
-rw-r--r--driver/charger/bq24192.h2
-rw-r--r--driver/charger/bq24715.c6
-rw-r--r--driver/charger/bq24773.h20
-rw-r--r--driver/charger/bq25703.h2
-rw-r--r--driver/charger/bq25710.c7
-rw-r--r--driver/charger/bq25710.h2
-rw-r--r--driver/charger/bq2589x.h6
-rw-r--r--driver/charger/isl923x.c27
-rw-r--r--driver/charger/isl923x.h4
-rw-r--r--driver/charger/isl9241.h115
-rw-r--r--driver/charger/rt946x.c7
-rw-r--r--driver/charger/rt946x.h6
-rw-r--r--driver/charger/sy21612.c7
-rw-r--r--driver/charger/sy21612.h4
-rw-r--r--driver/gyro_l3gd20h.h4
-rw-r--r--driver/ina2xx.c12
-rw-r--r--driver/ioexpander_pca9534.c32
-rw-r--r--driver/ioexpander_pca9534.h9
-rw-r--r--driver/ioexpander_pca9555.h12
-rw-r--r--driver/led/lm3509.c6
-rw-r--r--driver/led/lm3509.h3
-rw-r--r--driver/led/lm3630a.c10
-rw-r--r--driver/led/lp5562.c4
-rw-r--r--driver/led/max695x.h44
-rw-r--r--driver/led/oz554.c145
-rw-r--r--driver/mag_bmm150.c49
-rw-r--r--driver/mag_bmm150.h8
-rw-r--r--driver/mag_lis2mdl.c30
-rw-r--r--driver/mag_lis2mdl.h2
-rw-r--r--driver/pmic_tps650x30.h6
-rw-r--r--driver/ppc/nx20p348x.c8
-rw-r--r--driver/ppc/nx20p348x.h13
-rw-r--r--driver/ppc/sn5s330.c92
-rw-r--r--driver/ppc/sn5s330.h10
-rw-r--r--driver/ppc/syv682x.c351
-rw-r--r--driver/ppc/syv682x.h68
-rw-r--r--driver/regulator_ir357x.c4
-rw-r--r--driver/sensorhub_lsm6dsm.c87
-rw-r--r--driver/sensorhub_lsm6dsm.h17
-rw-r--r--driver/stm_mems_common.c22
-rw-r--r--driver/stm_mems_common.h24
-rw-r--r--driver/tcpm/anx7447.c42
-rw-r--r--driver/tcpm/anx7447.h20
-rw-r--r--driver/tcpm/anx74xx.c4
-rw-r--r--driver/tcpm/anx74xx.h8
-rw-r--r--driver/tcpm/anx7688.c6
-rw-r--r--driver/tcpm/fusb302.h8
-rw-r--r--driver/tcpm/mt6370.c4
-rw-r--r--driver/tcpm/mt6370.h2
-rw-r--r--driver/tcpm/nct38xx.h37
-rw-r--r--driver/tcpm/ps8xxx.c4
-rw-r--r--driver/tcpm/ps8xxx.h8
-rw-r--r--driver/tcpm/tcpci.c36
-rw-r--r--driver/tcpm/tcpm.h46
-rw-r--r--driver/tcpm/tusb422.h16
-rw-r--r--driver/temp_sensor/adt7481.c6
-rw-r--r--driver/temp_sensor/adt7481.h2
-rw-r--r--driver/temp_sensor/bd99992gw.c6
-rw-r--r--driver/temp_sensor/bd99992gw.h2
-rw-r--r--driver/temp_sensor/f75303.c3
-rw-r--r--driver/temp_sensor/f75303.h2
-rw-r--r--driver/temp_sensor/g78x.c6
-rw-r--r--driver/temp_sensor/g78x.h2
-rw-r--r--driver/temp_sensor/sb_tsi.c3
-rw-r--r--driver/temp_sensor/sb_tsi.h2
-rw-r--r--driver/temp_sensor/tmp006.c32
-rw-r--r--driver/temp_sensor/tmp006.h10
-rw-r--r--driver/temp_sensor/tmp112.c6
-rw-r--r--driver/temp_sensor/tmp112.h2
-rw-r--r--driver/temp_sensor/tmp411.h2
-rw-r--r--driver/temp_sensor/tmp432.c6
-rw-r--r--driver/temp_sensor/tmp432.h2
-rw-r--r--driver/temp_sensor/tmp468.c101
-rw-r--r--driver/temp_sensor/tmp468.h126
-rw-r--r--driver/touchpad_elan.c23
-rw-r--r--driver/usb_mux_it5205.c4
-rw-r--r--driver/usb_mux_it5205.h4
-rw-r--r--driver/usb_mux_pi3usb30532.c8
-rw-r--r--driver/usb_mux_ps874x.c8
-rw-r--r--driver/wpc/p9221.c806
-rw-r--r--driver/wpc/p9221.h323
-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
-rw-r--r--test/battery_get_params_smart.c6
-rw-r--r--test/sbs_charging_v2.c4
-rw-r--r--util/ectool.c4
255 files changed, 10156 insertions, 2695 deletions
diff --git a/baseboard/dragonegg/baseboard.c b/baseboard/dragonegg/baseboard.c
index dda630e739..fd5bd6fa36 100644
--- a/baseboard/dragonegg/baseboard.c
+++ b/baseboard/dragonegg/baseboard.c
@@ -183,7 +183,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_USBC1C2,
- .addr = TUSB422_I2C_ADDR,
+ .addr__7bf = TUSB422_I2C_ADDR__7bf,
},
.drv = &tusb422_tcpm_drv,
/* Alert is active-low, push-pull */
@@ -196,19 +196,19 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_COUNT] = {
[USB_PD_PORT_ITE_0] = {
.i2c_port = I2C_PORT_USBC0,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
[USB_PD_PORT_ITE_1] = {
.i2c_port = I2C_PORT_USBC1C2,
- .i2c_addr = SYV682X_ADDR0,
+ .i2c_addr__7bf = SYV682X_ADDR0__7bf,
.drv = &syv682x_drv
},
[USB_PD_PORT_TUSB422_2] = {
.i2c_port = I2C_PORT_USBC1C2,
- .i2c_addr = NX20P3481_ADDR2,
+ .i2c_addr__7bf = NX20P3481_ADDR2__7bf,
.drv = &nx20p348x_drv,
},
};
diff --git a/baseboard/dragonegg/baseboard.h b/baseboard/dragonegg/baseboard.h
index 535d1731c7..795ecfce1d 100644
--- a/baseboard/dragonegg/baseboard.h
+++ b/baseboard/dragonegg/baseboard.h
@@ -105,9 +105,9 @@
#define I2C_PORT_CHARGER IT83XX_I2C_CH_F /* Shared bus */
#define I2C_PORT_SENSOR IT83XX_I2C_CH_B
#define I2C_PORT_USBC0 IT83XX_I2C_CH_E
-#define I2C_PORT_USBC1C2 IT83XX_I2C_CH_C
+#define I2C_PORT_USBC1C2 IT83XX_I2C_CH_C
#define I2C_PORT_EEPROM IT83XX_I2C_CH_A
-#define I2C_ADDR_EEPROM 0xA0
+#define I2C_ADDR_EEPROM__7bf 0x50
#ifndef __ASSEMBLER__
diff --git a/baseboard/grunt/baseboard.c b/baseboard/grunt/baseboard.c
index 2ebdbc6591..592c821ca7 100644
--- a/baseboard/grunt/baseboard.c
+++ b/baseboard/grunt/baseboard.c
@@ -82,7 +82,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = ANX74XX_I2C_ADDR1,
+ .addr__7bf = ANX74XX_I2C_ADDR1__7bf,
},
.drv = &anx74xx_tcpm_drv,
/* Alert is active-low, open-drain */
@@ -92,7 +92,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
/* Alert is active-low, push-pull */
@@ -133,12 +133,12 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
struct ppc_config_t ppc_chips[] = {
{
.i2c_port = I2C_PORT_TCPC0,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
{
.i2c_port = I2C_PORT_TCPC1,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
};
@@ -380,7 +380,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kx022_data,
.port = I2C_PORT_SENSOR,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = (const mat33_fp_t *)&lid_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KX022_ACCEL_MIN_FREQ,
@@ -408,7 +408,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_SENSOR,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.default_range = 2, /* g, enough for laptop */
.rot_standard_ref = (const mat33_fp_t *)&grunt_base_standard_ref,
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -436,7 +436,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_SENSOR,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.default_range = 1000, /* dps */
.rot_standard_ref = (const mat33_fp_t *)&grunt_base_standard_ref,
.min_frequency = BMI160_GYRO_MIN_FREQ,
diff --git a/baseboard/hatch/baseboard.c b/baseboard/hatch/baseboard.c
index ba90e10fa2..2e76304eab 100644
--- a/baseboard/hatch/baseboard.c
+++ b/baseboard/hatch/baseboard.c
@@ -168,13 +168,13 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_COUNT] = {
[USB_PD_PORT_TCPC_0] = {
.i2c_port = I2C_PORT_PPC0,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
[USB_PD_PORT_TCPC_1] = {
.i2c_port = I2C_PORT_TCPC1,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
};
diff --git a/baseboard/hatch/baseboard.h b/baseboard/hatch/baseboard.h
new file mode 100644
index 0000000000..4ad634df45
--- /dev/null
+++ b/baseboard/hatch/baseboard.h
@@ -0,0 +1,186 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Hatch baseboard configuration */
+
+#ifndef __CROS_EC_BASEBOARD_H
+#define __CROS_EC_BASEBOARD_H
+
+/*
+ * By default, enable all console messages excepted HC, ACPI and event:
+ * The sensor stack is generating a lot of activity.
+ */
+#define CC_DEFAULT (CC_ALL & ~(CC_MASK(CC_EVENTS) | CC_MASK(CC_LPC)))
+#undef CONFIG_HOSTCMD_DEBUG_MODE
+#define CONFIG_HOSTCMD_DEBUG_MODE HCDEBUG_OFF
+
+/* NPCX7 config */
+#define NPCX7_PWM1_SEL 0 /* GPIO C2 is not used as PWM1. */
+#define NPCX_UART_MODULE2 1 /* GPIO64/65 are used as UART pins. */
+/* Internal SPI flash on NPCX796FC is 512 kB */
+#define CONFIG_FLASH_SIZE (512 * 1024)
+#define CONFIG_SPI_FLASH_REGS
+#define CONFIG_SPI_FLASH_W25Q80 /* Internal SPI flash type. */
+#define CONFIG_I2C
+
+/* Optional console commands */
+#define CONFIG_CMD_CHARGER_DUMP
+
+/* EC Defines */
+#define CONFIG_ADC
+#define CONFIG_BOARD_VERSION_CBI
+#define CONFIG_CRC8
+#define CONFIG_CROS_BOARD_INFO
+#define CONFIG_DPTF
+#define CONFIG_HIBERNATE_PSL
+#define CONFIG_LED_ONOFF_STATES
+#define CONFIG_PWM
+#define CONFIG_VBOOT_HASH
+#define CONFIG_VSTORE
+#define CONFIG_VSTORE_SLOT_COUNT 1
+
+/* Chipset config */
+#define CONFIG_CHIPSET_COMETLAKE
+#define CONFIG_CHIPSET_HAS_PRE_INIT_CALLBACK
+#define CONFIG_CHIPSET_RESET_HOOK
+#define CONFIG_CPU_PROCHOT_ACTIVE_LOW
+#define CONFIG_EXTPOWER_GPIO
+#define CONFIG_POWER_BUTTON
+#define CONFIG_POWER_BUTTON_X86
+#define CONFIG_POWER_COMMON
+#define CONFIG_POWER_PP5000_CONTROL
+#define CONFIG_POWER_S0IX
+#define CONFIG_POWER_S0IX_FAILURE_DETECTION
+#define CONFIG_POWER_TRACK_HOST_SLEEP_STATE
+
+/* Common Keyboard Defines */
+#define CONFIG_CMD_KEYBOARD
+#define CONFIG_KEYBOARD_BOARD_CONFIG
+#define CONFIG_KEYBOARD_COL2_INVERTED
+#define CONFIG_KEYBOARD_KEYPAD
+#define CONFIG_KEYBOARD_PROTOCOL_8042
+#define CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI2
+
+/* Sensors */
+#define CONFIG_MKBP_EVENT
+#define CONFIG_MKBP_USE_GPIO
+#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT
+/* I2C_PORT_ACCEL needs to be defined for i2c transactions */
+#define I2C_PORT_ACCEL I2C_PORT_SENSOR
+
+/* FIFO size is in power of 2. */
+#define CONFIG_ACCEL_FIFO 256
+/* Depends on how fast the AP boots and typical ODRs */
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+
+/* Sensor console commands */
+#define CONFIG_CMD_ACCELS
+#define CONFIG_CMD_ACCEL_INFO
+
+/* Common charger defines */
+#define CONFIG_CHARGE_MANAGER
+#define CONFIG_CHARGER
+#define CONFIG_CHARGER_BQ25710
+#define CONFIG_CHARGER_DISCHARGE_ON_AC
+#define CONFIG_CHARGER_INPUT_CURRENT 512 /* Allow low-current USB charging */
+#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1
+#define CONFIG_CHARGER_NARROW_VDC
+#define CONFIG_CHARGER_SENSE_RESISTOR 10
+#define CONFIG_CHARGER_SENSE_RESISTOR_AC 10
+#define CONFIG_CHARGER_V2
+
+/* Common battery defines */
+#define CONFIG_BATTERY_CUT_OFF
+#define CONFIG_BATTERY_DEVICE_CHEMISTRY "LION"
+#define CONFIG_BATTERY_FUEL_GAUGE
+#define CONFIG_BATTERY_HW_PRESENT_CUSTOM
+#define CONFIG_BATTERY_PRESENT_CUSTOM
+#define CONFIG_BATTERY_REVIVE_DISCONNECT
+#define CONFIG_BATTERY_SMART
+#undef CONFIG_BATT_HOST_FULL_FACTOR
+#define CONFIG_BATT_HOST_FULL_FACTOR 100
+
+/* USB Type C and USB PD defines */
+#define CONFIG_USB_POWER_DELIVERY
+#define CONFIG_USB_PD_PORT_COUNT 2
+#define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0
+#define CONFIG_USB_PD_TCPC_LOW_POWER
+#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
+#define CONFIG_USB_PD_DUAL_ROLE
+#define CONFIG_USB_PD_LOGGING
+#define CONFIG_USB_PD_ALT_MODE
+#define CONFIG_USB_PD_ALT_MODE_DFP
+#define CONFIG_USB_PD_DISCHARGE_PPC
+#define CONFIG_USB_PD_TRY_SRC
+#define CONFIG_USB_PD_VBUS_DETECT_PPC
+#define CONFIG_USB_PD_TCPM_TCPCI
+#define CONFIG_USBC_PPC_SN5S330
+#define CONFIG_USBC_PPC_VCONN
+#define CONFIG_USBC_SS_MUX
+#define CONFIG_USB_PD_TCPM_MUX
+#define CONFIG_USBC_VCONN
+#define CONFIG_USBC_VCONN_SWAP
+
+#define CONFIG_CMD_PD_CONTROL
+#define CONFIG_CMD_PPC_DUMP
+
+#define USB_PD_PORT_TCPC_0 0
+#define USB_PD_PORT_TCPC_1 1
+
+/* BC 1.2 */
+#define CONFIG_USB_CHARGER
+
+/* Common Sensor Defines */
+#define CONFIG_TABLET_MODE
+
+/* TODO(b/122273953): Use correct PD delay values */
+#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
+#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */
+#define PD_VCONN_SWAP_DELAY 5000 /* us */
+
+/* TODO(b/122273953): Use correct PD power values */
+#define PD_OPERATING_POWER_MW 15000
+#define PD_MAX_POWER_MW 60000
+#define PD_MAX_CURRENT_MA 3000
+#define PD_MAX_VOLTAGE_MV 20000
+
+/* I2C Bus Configuration */
+#define CONFIG_I2C
+#define CONFIG_I2C_MASTER
+#define I2C_PORT_SENSOR NPCX_I2C_PORT0_0
+#define I2C_PORT_PPC0 NPCX_I2C_PORT1_0
+#define I2C_PORT_TCPC1 NPCX_I2C_PORT2_0
+#define I2C_PORT_TCPC0 NPCX_I2C_PORT3_0
+#define I2C_PORT_POWER NPCX_I2C_PORT5_0
+#define I2C_PORT_EEPROM NPCX_I2C_PORT7_0
+#define I2C_ADDR_EEPROM__7bf 0x50
+#define I2C_PORT_BATTERY I2C_PORT_POWER
+#define I2C_PORT_CHARGER I2C_PORT_POWER
+
+/* Other common defines */
+#define CONFIG_BACKLIGHT_LID
+#define GPIO_ENABLE_BACKLIGHT GPIO_EDP_BKLTEN_OD
+
+#define PP5000_PGOOD_POWER_SIGNAL_MASK POWER_SIGNAL_MASK(PP5000_A_PGOOD)
+
+#ifndef __ASSEMBLER__
+
+enum mst_source {
+ MST_TYPE_C0,
+ MST_TYPE_C1,
+ MST_HDMI,
+};
+
+/* Forward declare common (within Hatch) board-specific functions */
+void board_reset_pd_mcu(void);
+void baseboard_mst_enable_control(enum mst_source, int level);
+
+
+/* Check with variant about battery presence. */
+enum battery_present variant_battery_present(void);
+
+#endif /* !__ASSEMBLER__ */
+
+#endif /* __CROS_EC_BASEBOARD_H */
diff --git a/baseboard/kalista/baseboard.c b/baseboard/kalista/baseboard.c
index 5956223f48..6646a63763 100644
--- a/baseboard/kalista/baseboard.c
+++ b/baseboard/kalista/baseboard.c
@@ -155,7 +155,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = I2C_ADDR_TCPC0,
+ .addr__7bf = I2C_ADDR_TCPC0__7bf,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -204,7 +204,7 @@ void board_tcpc_init(void)
* TCPM_INIT will fail due to not able to access PS8751.
* Note PS8751 A3 will wake on any I2C access.
*/
- i2c_read8(I2C_PORT_TCPC0, I2C_ADDR_TCPC0, 0xA0, &reg);
+ i2c_read8__7bf(I2C_PORT_TCPC0, I2C_ADDR_TCPC0__7bf, 0xA0, &reg);
/* Enable TCPC interrupts */
gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
@@ -260,10 +260,10 @@ BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT);
/* Initialize PMIC */
#define I2C_PMIC_READ(reg, data) \
- i2c_read8(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1, (reg), (data))
+ i2c_read8__7bf(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1__7bf, (reg), (data))
#define I2C_PMIC_WRITE(reg, data) \
- i2c_write8(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1, (reg), (data))
+ i2c_write8__7bf(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1__7bf, (reg), (data))
static void board_pmic_init(void)
{
diff --git a/baseboard/kalista/baseboard.h b/baseboard/kalista/baseboard.h
new file mode 100644
index 0000000000..2cb8a06481
--- /dev/null
+++ b/baseboard/kalista/baseboard.h
@@ -0,0 +1,239 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Kalista baseboard configuration */
+
+#ifndef __CROS_EC_BASEBOARD_H
+#define __CROS_EC_BASEBOARD_H
+
+/*
+ * Allow dangerous commands.
+ * TODO: Remove this config before production.
+ */
+#undef CONFIG_SYSTEM_UNLOCKED
+#define CONFIG_USB_PD_COMM_LOCKED
+
+/* EC */
+#define CONFIG_ADC
+#define CONFIG_BOARD_VERSION_CBI
+#define CONFIG_BOARD_HAS_RTC_RESET
+#define CONFIG_CRC8
+#define CONFIG_CEC
+#define CONFIG_CROS_BOARD_INFO
+#define CONFIG_DEDICATED_RECOVERY_BUTTON
+#define CONFIG_EMULATED_SYSRQ
+#define CONFIG_LED_COMMON
+#define CONFIG_KEYBOARD_PROTOCOL_MKBP
+#define CONFIG_MKBP_USE_HOST_EVENT
+#define CONFIG_DPTF
+#define CONFIG_FLASH_SIZE 0x80000
+#define CONFIG_FPU
+#define CONFIG_I2C
+#define CONFIG_I2C_MASTER
+#undef CONFIG_LID_SWITCH
+#define CONFIG_POWER_BUTTON_IGNORE_LID
+#define CONFIG_PWM
+#define CONFIG_LTO
+#define CONFIG_CHIP_PANIC_BACKUP
+#define CONFIG_SPI_FLASH_REGS
+#define CONFIG_SPI_FLASH_W25X40
+#define CONFIG_WATCHDOG_HELP
+#define CONFIG_WIRELESS
+#define CONFIG_WIRELESS_SUSPEND \
+ (EC_WIRELESS_SWITCH_WLAN | EC_WIRELESS_SWITCH_WLAN_POWER)
+#define WIRELESS_GPIO_WLAN GPIO_WLAN_OFF_L
+#define WIRELESS_GPIO_WLAN_POWER GPIO_PP3300_DX_WLAN
+#define WIRELESS_GPIO_WWAN GPIO_PP3300_DX_LTE
+#define CEC_GPIO_OUT GPIO_CEC_OUT
+#define CEC_GPIO_IN GPIO_CEC_IN
+#define CEC_GPIO_PULL_UP GPIO_CEC_PULL_UP
+#define CONFIG_FANS 1
+#define CONFIG_FAN_RPM_CUSTOM
+#define CONFIG_THROTTLE_AP
+#define CONFIG_CHIPSET_CAN_THROTTLE
+#define CONFIG_PWM
+#define CONFIG_SUPPRESSED_HOST_COMMANDS \
+ EC_CMD_CONSOLE_SNAPSHOT, EC_CMD_CONSOLE_READ, EC_CMD_PD_GET_LOG_ENTRY
+
+/* EC console commands */
+#define CONFIG_CMD_BUTTON
+
+/* SOC */
+#define CONFIG_CHIPSET_SKYLAKE
+#define CONFIG_CHIPSET_HAS_PLATFORM_PMIC_RESET
+#define CONFIG_CHIPSET_HAS_PRE_INIT_CALLBACK
+#define CONFIG_CHIPSET_RESET_HOOK
+#define CONFIG_HOSTCMD_ESPI
+/*
+ * Eve and Poppy all have wires from GPIO to PCH but
+ * CONFIG_HOSTCMD_ESPI_VW_SLP_SIGNALS is defined. So, those GPIOs are not used
+ * by EC.
+ */
+#define CONFIG_HOSTCMD_ESPI_VW_SLP_SIGNALS
+
+#define CONFIG_CMD_PD_CONTROL
+#define CONFIG_EXTPOWER_GPIO
+#undef CONFIG_EXTPOWER_DEBOUNCE_MS
+#define CONFIG_EXTPOWER_DEBOUNCE_MS 1000
+#define CONFIG_POWER_BUTTON
+#define CONFIG_POWER_BUTTON_X86
+#define CONFIG_POWER_BUTTON_INIT_IDLE
+#define CONFIG_POWER_COMMON
+#define CONFIG_POWER_SIGNAL_INTERRUPT_STORM_DETECT_THRESHOLD 30
+#define CONFIG_DELAY_DSW_PWROK_TO_PWRBTN
+
+/* Sensor */
+#define CONFIG_TEMP_SENSOR
+#define CONFIG_TEMP_SENSOR_TMP432
+
+/* USB */
+#define CONFIG_USB_PD_ALT_MODE
+#define CONFIG_USB_PD_ALT_MODE_DFP
+#define CONFIG_USB_PD_DISCHARGE_TCPC
+#define CONFIG_USB_PD_LOGGING
+#define CONFIG_USB_PD_PORT_COUNT 1
+#define CONFIG_USB_PD_VBUS_DETECT_GPIO
+#define CONFIG_USB_PD_TCPM_MUX
+#define CONFIG_USB_PD_TCPM_TCPCI
+#define CONFIG_USB_PD_TCPM_PS8751
+#define CONFIG_USB_POWER_DELIVERY
+#define CONFIG_USBC_SS_MUX
+#define CONFIG_USBC_SS_MUX_DFP_ONLY
+#define CONFIG_USBC_VCONN
+
+/* USB-A config */
+#define CONFIG_USB_PORT_POWER_DUMB
+#define USB_PORT_COUNT 4
+
+/* Optional feature to configure npcx chip */
+#define NPCX_UART_MODULE2 1 /* 1:GPIO64/65 as UART */
+#define NPCX_JTAG_MODULE2 0 /* 0:GPIO21/17/16/20 as JTAG */
+#define NPCX_TACH_SEL2 1 /* 0:GPIO40/73 1:GPIO93/A6 as TACH */
+
+/* I2C ports */
+#define I2C_PORT_TCPC0 NPCX_I2C_PORT0_0
+#define I2C_PORT_EEPROM NPCX_I2C_PORT0_1
+#define I2C_PORT_BACKLIGHT NPCX_I2C_PORT1
+#define I2C_PORT_PMIC NPCX_I2C_PORT2
+#define I2C_PORT_THERMAL NPCX_I2C_PORT3
+
+/* I2C addresses */
+#define I2C_ADDR_TCPC0__7bf 0x0b
+#define I2C_ADDR_EEPROM__7bf 0x50
+
+/* Verify and jump to RW image on boot */
+#define CONFIG_VBOOT_EFS
+#define CONFIG_VBOOT_HASH
+#define CONFIG_VSTORE
+#define CONFIG_VSTORE_SLOT_COUNT 1
+
+/*
+ * LED backlight controller
+ */
+#define CONFIG_LED_DRIVER_OZ554
+
+/*
+ * Flash layout. Since config_flash_layout.h is included before board.h,
+ * we can only overwrite (=undef/define) these parameters here.
+ *
+ * Flash stores 3 images: RO, RW_A, RW_B. We divide the flash by 4.
+ * A public key is stored at the end of RO. Signatures are stored at the
+ * end of RW_A and RW_B, respectively.
+ */
+#define CONFIG_RW_B
+#define CONFIG_RW_B_MEM_OFF CONFIG_RO_MEM_OFF
+#undef CONFIG_RO_SIZE
+#define CONFIG_RO_SIZE (CONFIG_FLASH_SIZE / 4)
+#undef CONFIG_RW_SIZE
+#define CONFIG_RW_SIZE CONFIG_RO_SIZE
+#define CONFIG_RW_A_STORAGE_OFF CONFIG_RW_STORAGE_OFF
+#define CONFIG_RW_B_STORAGE_OFF (CONFIG_RW_A_STORAGE_OFF + \
+ CONFIG_RW_SIZE)
+#define CONFIG_RW_A_SIGN_STORAGE_OFF (CONFIG_RW_A_STORAGE_OFF + \
+ CONFIG_RW_SIZE - CONFIG_RW_SIG_SIZE)
+#define CONFIG_RW_B_SIGN_STORAGE_OFF (CONFIG_RW_B_STORAGE_OFF + \
+ CONFIG_RW_SIZE - CONFIG_RW_SIG_SIZE)
+
+#define CONFIG_RWSIG
+#define CONFIG_RWSIG_TYPE_RWSIG
+#define CONFIG_RSA
+#ifdef SECTION_IS_RO
+#define CONFIG_RSA_OPTIMIZED
+#endif
+#define CONFIG_SHA256
+#ifdef SECTION_IS_RO
+#define CONFIG_SHA256_UNROLLED
+#endif
+#define CONFIG_RSA_KEY_SIZE 3072
+#define CONFIG_RSA_EXPONENT_3
+
+#ifndef __ASSEMBLER__
+
+#include "gpio_signal.h"
+#include "registers.h"
+
+enum charge_port {
+ CHARGE_PORT_TYPEC0,
+ CHARGE_PORT_BARRELJACK,
+};
+
+enum temp_sensor_id {
+ TEMP_SENSOR_CHARGER, /* BD99992GW SYSTHERM1 */
+ TEMP_SENSOR_DRAM, /* BD99992GW SYSTHERM2 */
+ TEMP_SENSOR_COUNT
+};
+
+enum adc_channel {
+ ADC_VBUS,
+ ADC_CH_COUNT
+};
+
+enum pwm_channel {
+ PWM_CH_LED_RED,
+ PWM_CH_LED_BLUE,
+ PWM_CH_FAN,
+ /* Number of PWM channels */
+ PWM_CH_COUNT
+};
+
+enum fan_channel {
+ FAN_CH_0,
+ /* Number of FAN channels */
+ FAN_CH_COUNT
+};
+
+enum mft_channel {
+ MFT_CH_0,
+ /* Number of MFT channels */
+ MFT_CH_COUNT
+};
+
+enum OEM_ID {
+ OEM_KARMA = 7,
+ /* Number of OEM IDs */
+ OEM_COUNT
+};
+
+/* TODO(crosbug.com/p/61098): Verify the numbers below. */
+/*
+ * delay to turn on the power supply max is ~16ms.
+ * delay to turn off the power supply max is about ~180ms.
+ */
+#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
+#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */
+
+/* delay to turn on/off vconn */
+#define PD_VCONN_SWAP_DELAY 5000 /* us */
+
+/* Board specific handlers */
+void board_reset_pd_mcu(void);
+void board_set_tcpc_power_mode(int port, int mode);
+int board_get_battery_soc(void);
+void led_alert(int enable);
+void led_critical(void);
+
+#endif /* !__ASSEMBLER__ */
+
+#endif /* __CROS_EC_BASEBOARD_H */
diff --git a/baseboard/octopus/baseboard.h b/baseboard/octopus/baseboard.h
index 1d01f09bce..b48080f829 100644
--- a/baseboard/octopus/baseboard.h
+++ b/baseboard/octopus/baseboard.h
@@ -37,7 +37,7 @@
#define I2C_PORT_EEPROM NPCX_I2C_PORT3_0
#define I2C_PORT_CHARGER NPCX_I2C_PORT4_1
#define I2C_PORT_SENSOR NPCX_I2C_PORT7_0
- #define I2C_ADDR_EEPROM 0xA0
+ #define I2C_ADDR_EEPROM__7bf 0x50
/* EC variant determines USB-C variant */
#define VARIANT_OCTOPUS_USBC_STANDALONE_TCPCS
@@ -56,7 +56,7 @@
#define I2C_PORT_USBC1 IT83XX_I2C_CH_E
#define I2C_PORT_USB_MUX I2C_PORT_USBC0 /* For MUX driver */
#define I2C_PORT_EEPROM IT83XX_I2C_CH_F
- #define I2C_ADDR_EEPROM 0xA0
+ #define I2C_ADDR_EEPROM__7bf 0x50
/* EC variant determines USB-C variant */
#define VARIANT_OCTOPUS_USBC_ITE_EC_TCPCS
diff --git a/baseboard/octopus/variant_usbc_ec_tcpcs.c b/baseboard/octopus/variant_usbc_ec_tcpcs.c
index 27f1f99ede..50f7842c82 100644
--- a/baseboard/octopus/variant_usbc_ec_tcpcs.c
+++ b/baseboard/octopus/variant_usbc_ec_tcpcs.c
@@ -67,14 +67,14 @@ static void board_it83xx_hpd_status(int port, int hpd_lvl, int hpd_irq)
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
[USB_PD_PORT_ITE_0] = {
/* Driver uses I2C_PORT_USB_MUX as I2C port */
- .port_addr = IT5205_I2C_ADDR1,
+ .port_addr = IT5205_I2C_ADDR1__7bf,
.driver = &it5205_usb_mux_driver,
.hpd_update = &board_it83xx_hpd_status,
},
[USB_PD_PORT_ITE_1] = {
/* Use PS8751 as mux only */
.port_addr = MUX_PORT_AND_ADDR(
- I2C_PORT_USBC1, PS8751_I2C_ADDR1),
+ I2C_PORT_USBC1, PS8751_I2C_ADDR1__7bf),
.flags = USB_MUX_FLAG_NOT_TCPC,
.driver = &ps8xxx_usb_mux_driver,
.hpd_update = &ps8xxx_tcpc_update_hpd_status,
@@ -86,12 +86,12 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_COUNT] = {
[USB_PD_PORT_ITE_0] = {
.i2c_port = I2C_PORT_USBC0,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
[USB_PD_PORT_ITE_1] = {
.i2c_port = I2C_PORT_USBC1,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
};
diff --git a/baseboard/octopus/variant_usbc_standalone_tcpcs.c b/baseboard/octopus/variant_usbc_standalone_tcpcs.c
index cc47633586..c9921b8a4b 100644
--- a/baseboard/octopus/variant_usbc_standalone_tcpcs.c
+++ b/baseboard/octopus/variant_usbc_standalone_tcpcs.c
@@ -35,14 +35,14 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
#else
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = AN7447_TCPC0_I2C_ADDR,
+ .addr__7bf = AN7447_TCPC0_I2C_ADDR__7bf,
},
.drv = &anx7447_tcpm_drv,
#endif
@@ -51,7 +51,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -91,12 +91,12 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_COUNT] = {
[USB_PD_PORT_TCPC_0] = {
.i2c_port = I2C_PORT_TCPC0,
- .i2c_addr = NX20P3483_ADDR2,
+ .i2c_addr__7bf = NX20P3483_ADDR2__7bf,
.drv = &nx20p348x_drv,
},
[USB_PD_PORT_TCPC_1] = {
.i2c_port = I2C_PORT_TCPC1,
- .i2c_addr = NX20P3483_ADDR2,
+ .i2c_addr__7bf = NX20P3483_ADDR2__7bf,
.drv = &nx20p348x_drv,
},
};
diff --git a/baseboard/zork/baseboard.c b/baseboard/zork/baseboard.c
index eca652210f..1014b1dec5 100644
--- a/baseboard/zork/baseboard.c
+++ b/baseboard/zork/baseboard.c
@@ -89,7 +89,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = ANX74XX_I2C_ADDR1,
+ .addr__7bf = ANX74XX_I2C_ADDR1__7bf,
},
.drv = &anx74xx_tcpm_drv,
/* Alert is active-low, open-drain */
@@ -99,7 +99,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
/* Alert is active-low, push-pull */
@@ -140,12 +140,12 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
struct ppc_config_t ppc_chips[] = {
{
.i2c_port = I2C_PORT_TCPC0,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
{
.i2c_port = I2C_PORT_TCPC1,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
};
@@ -387,7 +387,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kx022_data,
.port = I2C_PORT_SENSOR,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = (const mat33_fp_t *)&lid_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KX022_ACCEL_MIN_FREQ,
@@ -415,7 +415,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_SENSOR,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.default_range = 2, /* g, enough for laptop */
.rot_standard_ref = (const mat33_fp_t *)&zork_base_standard_ref,
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -443,7 +443,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_SENSOR,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.default_range = 1000, /* dps */
.rot_standard_ref = (const mat33_fp_t *)&zork_base_standard_ref,
.min_frequency = BMI160_GYRO_MIN_FREQ,
diff --git a/board/ampton/board.c b/board/ampton/board.c
index 941aab7f00..15b3af652a 100644
--- a/board/ampton/board.c
+++ b/board/ampton/board.c
@@ -17,7 +17,7 @@
#include "driver/sync.h"
#include "driver/tcpm/it83xx_pd.h"
#include "driver/tcpm/ps8xxx.h"
-#include "driver/usb_mux_it5205.h"
+#include "driver/usb_mux/it5205.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
@@ -66,25 +66,41 @@ int ppc_get_alert_status(int port)
#define USB_PD_PORT_ITE_0 0
#define USB_PD_PORT_ITE_1 1
+static int tune_mux(int port);
+
struct usb_mux ampton_usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
[USB_PD_PORT_ITE_0] = {
/* Use PS8751 as mux only */
.port_addr = MUX_PORT_AND_ADDR(
- I2C_PORT_USBC0, PS8751_I2C_ADDR1),
+ I2C_PORT_USBC0, PS8751_I2C_ADDR1__7bf),
.flags = USB_MUX_FLAG_NOT_TCPC,
- .driver = &tcpci_tcpm_usb_mux_driver,
+ .driver = &ps8xxx_usb_mux_driver,
.hpd_update = &ps8xxx_tcpc_update_hpd_status,
+ .board_init = &tune_mux,
},
[USB_PD_PORT_ITE_1] = {
/* Use PS8751 as mux only */
.port_addr = MUX_PORT_AND_ADDR(
- I2C_PORT_USBC1, PS8751_I2C_ADDR1),
+ I2C_PORT_USBC1, PS8751_I2C_ADDR1__7bf),
.flags = USB_MUX_FLAG_NOT_TCPC,
- .driver = &tcpci_tcpm_usb_mux_driver,
+ .driver = &ps8xxx_usb_mux_driver,
.hpd_update = &ps8xxx_tcpc_update_hpd_status,
+ .board_init = &tune_mux,
}
};
+/* Some external monitors can't display content normally (eg. ViewSonic VX2880).
+ * We need to turn the mux for monitors to function normally.
+ */
+static int tune_mux(int port)
+{
+ /* Auto EQ disabled, compensate for channel lost up to 3.6dB */
+ mux_write(port, PS8XXX_REG_MUX_DP_EQ_CONFIGURATION, 0x98);
+ /* DP output swing adjustment +15% */
+ mux_write(port, PS8XXX_REG_MUX_DP_OUTPUT_CONFIGURATION, 0xc0);
+
+ return EC_SUCCESS;
+}
/******************************************************************************/
/* ADC channels */
const struct adc_t adc_channels[] = {
@@ -115,13 +131,6 @@ const struct adc_t adc_channels[] = {
};
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
-static int read_charger_temp(int idx, int *temp_ptr)
-{
- if (!gpio_get_level(GPIO_AC_PRESENT))
- return EC_ERROR_NOT_POWERED;
- return get_temp_3v3_13k7_47k_4050b(idx, temp_ptr);
-}
-
const struct temp_sensor_t temp_sensors[] = {
[TEMP_SENSOR_BATTERY] = {.name = "Battery",
.type = TEMP_SENSOR_TYPE_BATTERY,
@@ -134,7 +143,7 @@ const struct temp_sensor_t temp_sensors[] = {
.action_delay_sec = 5},
[TEMP_SENSOR_CHARGER] = {.name = "Charger",
.type = TEMP_SENSOR_TYPE_BOARD,
- .read = read_charger_temp,
+ .read = get_temp_3v3_13k7_47k_4050b,
.idx = ADC_TEMP_SENSOR_CHARGER,
.action_delay_sec = 1},
};
@@ -151,6 +160,18 @@ const mat33_fp_t lid_standard_ref = {
{ 0, 0, FLOAT_TO_FP(1)}
};
+const mat33_fp_t base_standard_ref = {
+ { 0, FLOAT_TO_FP(-1), 0},
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
+const mat33_fp_t gyro_standard_ref = {
+ { 0, FLOAT_TO_FP(-1), 0},
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
/* sensor private data */
static struct kionix_accel_data g_kx022_data;
static struct bmi160_drv_data_t g_bmi160_data;
@@ -167,7 +188,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kx022_data,
.port = I2C_PORT_SENSOR,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = &lid_standard_ref,
.default_range = 4, /* g */
.config = {
@@ -191,8 +212,8 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_SENSOR,
- .addr = BMI160_ADDR0,
- .rot_standard_ref = NULL, /* Identity matrix. */
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
+ .rot_standard_ref = &base_standard_ref,
.default_range = 4, /* g */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
.max_frequency = BMI160_ACCEL_MAX_FREQ,
@@ -219,9 +240,9 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_SENSOR,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.default_range = 1000, /* dps */
- .rot_standard_ref = NULL, /* Identity matrix. */
+ .rot_standard_ref = &gyro_standard_ref,
.min_frequency = BMI160_GYRO_MIN_FREQ,
.max_frequency = BMI160_GYRO_MAX_FREQ,
},
diff --git a/board/arcada_ish/board.c b/board/arcada_ish/board.c
new file mode 100644
index 0000000000..f18a530568
--- /dev/null
+++ b/board/arcada_ish/board.c
@@ -0,0 +1,203 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Arcada ISH board-specific configuration */
+
+#include "console.h"
+#include "driver/accel_lis2dh.h"
+#include "driver/accelgyro_lsm6dsm.h"
+#include "driver/mag_lis2mdl.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "i2c.h"
+#include "lid_switch.h"
+#include "motion_sense.h"
+#include "power.h"
+#include "tablet_mode.h"
+#include "task.h"
+
+#include "gpio_list.h" /* has to be included last */
+
+/* I2C port map */
+const struct i2c_port_t i2c_ports[] = {
+ {
+ .name = "sensor",
+ .port = I2C_PORT_SENSOR,
+ .kbps = 400,
+ },
+};
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+
+/* Sensor config */
+static struct mutex g_lid_mutex;
+static struct mutex g_lid_mag_mutex;
+static struct mutex g_base_mutex;
+
+/* sensor private data */
+static struct lsm6dsm_data lsm6dsm_a_data;
+static struct stprivate_data g_lis2dh_data;
+static struct lis2mdl_private_data lis2mdl_a_data;
+
+/* Matrix to rotate lid sensor into standard reference frame */
+const mat33_fp_t lid_rot_ref = {
+ { FLOAT_TO_FP(-1), 0, 0},
+ { 0, FLOAT_TO_FP(-1), 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
+/* Drivers */
+struct motion_sensor_t motion_sensors[] = {
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .chip = MOTIONSENSE_CHIP_LSM6DS3,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &lsm6dsm_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = LSM6DSM_ST_DATA(lsm6dsm_a_data,
+ MOTIONSENSE_TYPE_ACCEL),
+ .int_signal = GPIO_ACCEL_GYRO_INT_L,
+ .flags = MOTIONSENSE_FLAG_INT_SIGNAL,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR1__7bf,
+ .rot_standard_ref = &lid_rot_ref,
+ .default_range = 4, /* g */
+ .min_frequency = LSM6DSM_ODR_MIN_VAL,
+ .max_frequency = LSM6DSM_ODR_MAX_VAL,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 13000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 13000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+
+ [LID_GYRO] = {
+ .name = "Lid Gyro",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .chip = MOTIONSENSE_CHIP_LSM6DS3,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &lsm6dsm_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = LSM6DSM_ST_DATA(lsm6dsm_a_data,
+ MOTIONSENSE_TYPE_GYRO),
+ .int_signal = GPIO_ACCEL_GYRO_INT_L,
+ .flags = MOTIONSENSE_FLAG_INT_SIGNAL,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR1__7bf,
+ .default_range = 1000 | ROUND_UP_FLAG, /* dps */
+ .rot_standard_ref = &lid_rot_ref,
+ .min_frequency = LSM6DSM_ODR_MIN_VAL,
+ .max_frequency = LSM6DSM_ODR_MAX_VAL,
+ },
+
+ [BASE_ACCEL] = {
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .chip = MOTIONSENSE_CHIP_LNG2DM,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &lis2dh_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_lis2dh_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = LNG2DM_ADDR0__7bf,
+ .rot_standard_ref = NULL, /* Identity matrix */
+ /* We only use 2g because its resolution is only 8-bits */
+ .default_range = 2, /* g */
+ .min_frequency = LIS2DH_ODR_MIN_VAL,
+ .max_frequency = LIS2DH_ODR_MAX_VAL,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+
+ [LID_MAG] = {
+ .name = "Lid Mag",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .chip = MOTIONSENSE_CHIP_LIS2MDL,
+ .type = MOTIONSENSE_TYPE_MAG,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &lis2mdl_drv,
+ .mutex = &g_lid_mag_mutex,
+ .drv_data = LIS2MDL_ST_DATA(lis2mdl_a_data),
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = LIS2MDL_ADDR__7bf,
+ .default_range = 1 << 11, /* 16LSB / uT, fixed */
+ .rot_standard_ref = &lid_rot_ref,
+ .min_frequency = LIS2MDL_ODR_MIN_VAL,
+ .max_frequency = LIS2MDL_ODR_MAX_VAL,
+ },
+};
+
+const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+int board_sensor_at_360(void)
+{
+ /*
+ * The 360 degree sensor is too sensitive and is active when the lid is
+ * closed at 0 degrees. Ignore the hall sensor when the lid close is
+ * also active.
+ */
+ return lid_is_open() &&
+ !gpio_get_level(HALL_SENSOR_GPIO_L);
+}
+
+/* Initialize board. */
+static void board_init(void)
+{
+ /* Enable interrupt for LSM6DS3 sensor */
+ gpio_enable_interrupt(GPIO_ACCEL_GYRO_INT_L);
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+
+/*
+ * The only use for chipset state is sensors, so we hard code the AP state to on
+ * and make the sensor on in S0. The sensors are always on when the ISH is
+ * powered.
+ */
+int chipset_in_state(int state_mask)
+{
+ return state_mask & CHIPSET_STATE_ON;
+}
+
+int chipset_in_or_transitioning_to_state(int state_mask)
+{
+ return chipset_in_state(state_mask);
+}
+
+void chipset_force_shutdown(enum chipset_shutdown_reason reason)
+{
+ /* Required, but nothing to do */
+}
+
+/* Needed for empty chipset task */
+int board_idle_task(void *unused)
+{
+ while (1)
+ task_wait_event(-1);
+}
+
+static void board_tablet_mode_change(void)
+{
+ /* Update GPIO to EC letting it know that we entered tablet mode */
+ gpio_set_level(GPIO_NB_MODE_L, tablet_get_mode());
+}
+DECLARE_HOOK(HOOK_TABLET_MODE_CHANGE, board_tablet_mode_change,
+ HOOK_PRIO_DEFAULT);
diff --git a/board/atlas/board.c b/board/atlas/board.c
index 85b2e0bb93..3d6e52ed89 100644
--- a/board/atlas/board.c
+++ b/board/atlas/board.c
@@ -51,34 +51,24 @@
static void tcpc_alert_event(enum gpio_signal signal)
{
- if ((signal == GPIO_USB_C0_PD_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C0_PD_RST_L))
- return;
- else if ((signal == GPIO_USB_C1_PD_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C1_PD_RST_L))
+ int port = -1;
+
+ switch (signal) {
+ case GPIO_USB_C0_PD_INT_ODL:
+ port = 0;
+ break;
+ case GPIO_USB_C1_PD_INT_ODL:
+ port = 1;
+ break;
+ default:
return;
+ }
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
+ schedule_deferred_pd_interrupt(port);
}
#include "gpio_list.h"
-/* power signal list. Must match order of enum power_signal. */
-const struct power_signal_info power_signal_list[] = {
- {GPIO_SLP_S0_L,
- POWER_SIGNAL_ACTIVE_HIGH | POWER_SIGNAL_DISABLE_AT_BOOT,
- "SLP_S0_DEASSERTED"},
- {VW_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
- {VW_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
- {GPIO_PCH_SLP_SUS_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_SUS_DEASSERTED"},
- {GPIO_RSMRST_L_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "RSMRST_L_PGOOD"},
- {GPIO_PMIC_DPWROK, POWER_SIGNAL_ACTIVE_HIGH, "PMIC_DPWROK"},
-};
-BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
-
/* Keyboard scan. Increase output_settle_us to 80us from default 50us. */
struct keyboard_scan_config keyscan_config = {
.output_settle_us = 80,
@@ -151,16 +141,14 @@ BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
const struct i2c_port_t i2c_ports[] = {
{"power", I2C_PORT_POWER, 100,
GPIO_EC_I2C0_POWER_SCL, GPIO_EC_I2C0_POWER_SDA},
- {"tcpc0", I2C_PORT_TCPC0, 400,
+ {"tcpc0", I2C_PORT_TCPC0, 1000,
GPIO_EC_I2C1_USB_C0_SCL, GPIO_EC_I2C1_USB_C0_SDA},
- {"tcpc1", I2C_PORT_TCPC1, 400,
+ {"tcpc1", I2C_PORT_TCPC1, 1000,
GPIO_EC_I2C2_USB_C1_SCL, GPIO_EC_I2C2_USB_C1_SDA},
{"sensor", I2C_PORT_SENSOR, 100,
GPIO_EC_I2C3_SENSOR_3V3_SCL, GPIO_EC_I2C3_SENSOR_3V3_SDA},
{"battery", I2C_PORT_BATTERY, 100,
GPIO_EC_I2C4_BATTERY_SCL, GPIO_EC_I2C4_BATTERY_SDA},
- {"gyro", I2C_PORT_GYRO, 100,
- GPIO_EC_I2C5_GYRO_SCL, GPIO_EC_I2C5_GYRO_SDA},
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
@@ -171,7 +159,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = I2C_ADDR_TCPC,
+ .addr__7bf = I2C_ADDR_TCPC__7bf,
},
.drv = &ps8xxx_tcpm_drv,
/* Alert is active-low, push-pull */
@@ -182,7 +170,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC1,
- .addr = I2C_ADDR_TCPC,
+ .addr__7bf = I2C_ADDR_TCPC__7bf,
},
.drv = &ps8xxx_tcpm_drv,
/* Alert is active-low, push-pull */
@@ -259,7 +247,6 @@ const struct temp_sensor_t temp_sensors[] = {
BD99992GW_ADC_CHANNEL_SYSTHERM2, 4},
{"eMMC", TEMP_SENSOR_TYPE_BOARD, bd99992gw_get_val,
BD99992GW_ADC_CHANNEL_SYSTHERM3, 4},
- {"gyro", TEMP_SENSOR_TYPE_BOARD, bmi160_get_sensor_temp, BASE_GYRO, 1},
};
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
@@ -275,29 +262,34 @@ 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)
- != EC_SUCCESS)
+ if (i2c_read8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_RESETIRQ1, &vrfault) != EC_SUCCESS)
return;
- if (!(vrfault & (1 << 4)))
+ if (!(vrfault & BIT(4)))
return;
/* 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,
+ BD99992GW_REG_PWRSTAT1, &pwrstat1);
/* PWRSTAT2 */
- i2c_read8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x17, &pwrstat2);
+ i2c_read8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_PWRSTAT2, &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, (1 << 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,
+ BD99992GW_REG_RESETIRQ1, BIT(4));
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_PWRSTAT1, pwrstat1);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_PWRSTAT2, pwrstat2);
/*
* Status of the fault registers can be checked in the OS by looking at
@@ -312,11 +304,12 @@ static void board_pmic_disable_slp_s0_vr_decay(void)
/*
* VCCIOCNT:
* Bit 6 (0) - Disable decay of VCCIO on SLP_S0# assertion
- * Bits 5:4 (00) - Nominal output voltage: 0.850V
+ * Bits 5:4 (11) - Nominal output voltage: 0.850V
* 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,
+ BD99992GW_REG_VCCIOCNT, 0x3a);
/*
* V18ACNT:
@@ -325,25 +318,18 @@ 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);
-
- /*
- * V100ACNT:
- * Bits 7:6 (00) - Disable low power mode on SLP_S0# assertion
- * Bits 5:4 (01) - Nominal voltage 1.0V
- * 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,
+ BD99992GW_REG_V18ACNT, 0x2a);
/*
* V085ACNT:
* Bits 7:6 (00) - Disable low power mode on SLP_S0# assertion
- * Bits 5:4 (11) - Nominal voltage 0.85V
+ * Bits 5:4 (10) - Nominal voltage 0.85V
* 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, 0x2a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_V085ACNT, 0x2a);
}
static void board_pmic_enable_slp_s0_vr_decay(void)
@@ -351,11 +337,12 @@ static void board_pmic_enable_slp_s0_vr_decay(void)
/*
* VCCIOCNT:
* Bit 6 (1) - Enable decay of VCCIO on SLP_S0# assertion
- * Bits 5:4 (00) - Nominal output voltage: 0.850V
+ * Bits 5:4 (11) - Nominal output voltage: 0.850V
* 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,
+ BD99992GW_REG_VCCIOCNT, 0x7a);
/*
* V18ACNT:
@@ -364,25 +351,18 @@ 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);
-
- /*
- * V100ACNT:
- * Bits 7:6 (01) - Enable low power mode on SLP_S0# assertion
- * Bits 5:4 (01) - Nominal voltage 1.0V
- * 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,
+ BD99992GW_REG_V18ACNT, 0x6a);
/*
* V085ACNT:
* Bits 7:6 (01) - Enable low power mode on SLP_S0# assertion
- * Bits 5:4 (11) - Nominal voltage 0.85V
+ * Bits 5:4 (10) - Nominal voltage 0.85V
* 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, 0x6a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_V085ACNT, 0x6a);
}
void power_board_handle_host_sleep_event(enum host_sleep_event state)
@@ -398,34 +378,49 @@ static void board_pmic_init(void)
board_report_pmic_fault("SYSJUMP");
/* Clear power source events */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992,
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
BD99992GW_REG_PWRSRCINT, 0xff);
/* Disable power button shutdown timer */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992,
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
BD99992GW_REG_PBCONFIG, 0x00);
if (system_jumped_to_this_image())
return;
- /* DISCHGCNT2 - enable 100 ohm discharge on V5.0A, V3.3A and V1.8A */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992,
- BD99992GW_REG_DISCHGCNT2, 0x45);
+ /* DISCHGCNT1 - enable 100 ohm discharge on VCCIO */
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_DISCHGCNT1, 0x01);
- /* DISCHGCNT3 - enable 100 ohm discharge on V1.00A */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992,
- BD99992GW_REG_DISCHGCNT3, 0x04);
+ /*
+ * DISCHGCNT2 - enable 100 ohm discharge on
+ * V5.0A, V3.3DSW, V3.3A and V1.8A
+ */
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_DISCHGCNT2, 0x55);
/*
- * Set V085ACNT / V0.85A Control Register:
- * Nominal output = 0.85V.
+ * DISCHGCNT3 - enable 500 ohm discharge on
+ * V1.8U_2.5U
+ * DISCHGCNT3 - enable 100 ohm discharge on
+ * V12U, V1.00A, V0.85A
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992,
- BD99992GW_REG_V085ACNT, 0x2a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_DISCHGCNT3, 0xd5);
+
+ /* DISCHGCNT4 - enable 100 ohm discharge on V33S, V18S, V100S */
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_DISCHGCNT4, 0x15);
/* VRMODECTRL - disable low-power mode for all rails */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992,
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
BD99992GW_REG_VRMODECTRL, 0x1f);
+
+ /* V5ADS3CNT - boost V5A_DS3 by 2% */
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ BD99992GW_REG_V5ADS3CNT, 0x1a);
+
+ board_pmic_disable_slp_s0_vr_decay();
}
DECLARE_HOOK(HOOK_INIT, board_pmic_init, HOOK_PRIO_DEFAULT);
@@ -445,7 +440,7 @@ void board_hibernate(void)
system_enter_psl_mode();
/* Cut off DSW power via the ROP PMIC. */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992,
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
BD99992GW_REG_SDWNCTRL, BD99992GW_SDWNCTRL_SWDN);
/* Wait for power to be cut. */
@@ -456,11 +451,16 @@ void board_hibernate(void)
/* Initialize board. */
static void board_init(void)
{
+ if (system_get_board_version() < ATLAS_REV_FIXED_EC_WP) {
+ int dflags;
+
+ CPRINTS("Applying EC_WP_L workaround");
+ dflags = gpio_get_default_flags(GPIO_EC_WP_L);
+ gpio_set_flags(GPIO_EC_WP_L, dflags | GPIO_PULL_UP);
+ }
+
/* Provide AC status to the PCH */
gpio_set_level(GPIO_PCH_ACOK, extpower_is_present());
-
- /* Enable interrupts from BMI160 sensor. */
- gpio_enable_interrupt(GPIO_ACCELGYRO3_INT_L);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
@@ -532,14 +532,12 @@ void board_set_charge_limit(int port, int supplier, int charge_ma,
static void board_chipset_suspend(void)
{
- gpio_set_level(GPIO_ENABLE_BACKLIGHT, 0);
gpio_set_level(GPIO_KBD_BL_EN, 0);
}
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT);
static void board_chipset_resume(void)
{
- gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);
gpio_set_level(GPIO_KBD_BL_EN, 1);
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT);
@@ -572,10 +570,6 @@ int board_get_version(void)
return ver;
}
-/* Base Sensor mutex */
-static struct mutex g_base_mutex;
-
-static struct bmi160_drv_data_t g_bmi160_data;
static struct opt3001_drv_data_t g_opt3001_data = {
.scale = 1,
.uscale = 0,
@@ -590,47 +584,6 @@ const mat33_fp_t base_standard_ref = {
};
struct motion_sensor_t motion_sensors[] = {
- [BASE_ACCEL] = {
- .name = "Base Accel",
- .active_mask = SENSOR_ACTIVE_S0_S3_S5,
- .chip = MOTIONSENSE_CHIP_BMI160,
- .type = MOTIONSENSE_TYPE_ACCEL,
- .location = MOTIONSENSE_LOC_BASE,
- .drv = &bmi160_drv,
- .mutex = &g_base_mutex,
- .drv_data = &g_bmi160_data,
- .port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
- .rot_standard_ref = &base_standard_ref,
- .default_range = 2, /* g, enough for laptop. */
- .min_frequency = BMI160_ACCEL_MIN_FREQ,
- .max_frequency = BMI160_ACCEL_MAX_FREQ,
- .config = {
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 10000 | ROUND_UP_FLAG,
- .ec_rate = 100 * MSEC,
- },
- [SENSOR_CONFIG_EC_S3] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- },
- },
- [BASE_GYRO] = {
- .name = "Base Gyro",
- .active_mask = SENSOR_ACTIVE_S0_S3_S5,
- .chip = MOTIONSENSE_CHIP_BMI160,
- .type = MOTIONSENSE_TYPE_GYRO,
- .location = MOTIONSENSE_LOC_BASE,
- .drv = &bmi160_drv,
- .mutex = &g_base_mutex,
- .drv_data = &g_bmi160_data,
- .port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
- .default_range = 1000, /* dps */
- .rot_standard_ref = &base_standard_ref,
- .min_frequency = BMI160_GYRO_MIN_FREQ,
- .max_frequency = BMI160_GYRO_MAX_FREQ,
- },
[LID_ALS] = {
.name = "Light",
.active_mask = SENSOR_ACTIVE_S0,
@@ -640,7 +593,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &opt3001_drv,
.drv_data = &g_opt3001_data,
.port = I2C_PORT_SENSOR,
- .addr = OPT3001_I2C_ADDR,
+ .i2c_spi_addr__7bf = OPT3001_I2C_ADDR__7bf,
.rot_standard_ref = NULL,
.default_range = 0x2b11a1, /* from nocturne */
.min_frequency = OPT3001_LIGHT_MIN_FREQ,
diff --git a/board/atlas/board.h b/board/atlas/board.h
index 07f6debc60..a6c6bd6396 100644
--- a/board/atlas/board.h
+++ b/board/atlas/board.h
@@ -119,7 +119,7 @@
#define CONFIG_ALS
#define CONFIG_ALS_OPT3001
#define ALS_COUNT 1
-#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
+#define OPT3001_I2C_ADDR__7bf OPT3001_I2C_ADDR1__7bf
#define CONFIG_ACCEL_FIFO 1024
#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
#define CONFIG_ACCEL_INTERRUPTS
@@ -174,9 +174,9 @@
#define I2C_PORT_THERMAL I2C_PORT_POWER
/* I2C addresses */
-#define I2C_ADDR_TCPC 0x16
-#define I2C_ADDR_MP2949 0x40
-#define I2C_ADDR_BD99992 0x60
+#define I2C_ADDR_TCPC__7bf 0x0B
+#define I2C_ADDR_MP2949__7bf 0x20
+#define I2C_ADDR_BD99992__7bf 0x30
#ifndef __ASSEMBLER__
diff --git a/board/bloog/board.c b/board/bloog/board.c
new file mode 100644
index 0000000000..f14989ad73
--- /dev/null
+++ b/board/bloog/board.c
@@ -0,0 +1,329 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Bloog/Blooguard board-specific configuration */
+
+#include "adc.h"
+#include "adc_chip.h"
+#include "battery.h"
+#include "button.h"
+#include "charge_manager.h"
+#include "charge_state.h"
+#include "common.h"
+#include "console.h"
+#include "cros_board_info.h"
+#include "driver/accel_kionix.h"
+#include "driver/accelgyro_lsm6dsm.h"
+#include "driver/charger/bd9995x.h"
+#include "driver/ppc/nx20p348x.h"
+#include "driver/tcpm/anx7447.h"
+#include "driver/tcpm/ps8xxx.h"
+#include "driver/tcpm/tcpci.h"
+#include "driver/tcpm/tcpm.h"
+#include "extpower.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "keyboard_scan.h"
+#include "lid_switch.h"
+#include "motion_sense.h"
+#include "power.h"
+#include "power_button.h"
+#include "switch.h"
+#include "system.h"
+#include "tablet_mode.h"
+#include "tcpci.h"
+#include "temp_sensor.h"
+#include "thermistor.h"
+#include "usb_mux.h"
+#include "usbc_ppc.h"
+#include "util.h"
+
+#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
+
+#define USB_PD_PORT_ANX7447 0
+#define USB_PD_PORT_PS8751 1
+
+static uint8_t sku_id;
+
+static void ppc_interrupt(enum gpio_signal signal)
+{
+ switch (signal) {
+ case GPIO_USB_PD_C0_INT_ODL:
+ nx20p348x_interrupt(0);
+ break;
+
+ case GPIO_USB_PD_C1_INT_ODL:
+ nx20p348x_interrupt(1);
+ break;
+
+ default:
+ break;
+ }
+}
+
+/* Must come after other header files and GPIO interrupts*/
+#include "gpio_list.h"
+
+/* ADC channels */
+const struct adc_t adc_channels[] = {
+ [ADC_TEMP_SENSOR_AMB] = {
+ "TEMP_AMB", NPCX_ADC_CH0, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+ [ADC_TEMP_SENSOR_CHARGER] = {
+ "TEMP_CHARGER", NPCX_ADC_CH1, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+ /* Vbus C0 sensing (10x voltage divider). PPVAR_USB_C0_VBUS */
+ [ADC_VBUS_C0] = {
+ "VBUS_C0", NPCX_ADC_CH9, ADC_MAX_VOLT*10, ADC_READ_MAX+1, 0},
+ /* Vbus C1 sensing (10x voltage divider). PPVAR_USB_C1_VBUS */
+ [ADC_VBUS_C1] = {
+ "VBUS_C1", NPCX_ADC_CH4, ADC_MAX_VOLT*10, ADC_READ_MAX+1, 0},
+};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
+
+const struct temp_sensor_t temp_sensors[] = {
+ [TEMP_SENSOR_BATTERY] = {.name = "Battery",
+ .type = TEMP_SENSOR_TYPE_BATTERY,
+ .read = charge_get_battery_temp,
+ .idx = 0,
+ .action_delay_sec = 1},
+ [TEMP_SENSOR_AMBIENT] = {.name = "Ambient",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_AMB,
+ .action_delay_sec = 5},
+ [TEMP_SENSOR_CHARGER] = {.name = "Charger",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_13k7_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_CHARGER,
+ .action_delay_sec = 1},
+};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
+
+/* Motion sensors */
+/* Mutexes */
+static struct mutex g_lid_mutex;
+static struct mutex g_base_mutex;
+
+/* Matrix to rotate accelrator into standard reference frame */
+const mat33_fp_t lid_standrd_ref = {
+ { FLOAT_TO_FP(-1), 0, 0},
+ { 0, FLOAT_TO_FP(1), 0},
+ { 0, 0, FLOAT_TO_FP(-1)}
+};
+
+const mat33_fp_t base_standard_ref = {
+ { FLOAT_TO_FP(-1), 0, 0},
+ { 0, FLOAT_TO_FP(-1), 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
+/* sensor private data */
+static struct kionix_accel_data kx022_data;
+static struct lsm6dsm_data lsm6dsm_data;
+
+/* Drivers */
+struct motion_sensor_t motion_sensors[] = {
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_KX022,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &kionix_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &kx022_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
+ .rot_standard_ref = &lid_standrd_ref,
+ .default_range = 2, /* g */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+
+ [BASE_ACCEL] = {
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_LSM6DSM,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &lsm6dsm_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = LSM6DSM_ST_DATA(lsm6dsm_data,
+ MOTIONSENSE_TYPE_ACCEL),
+ .int_signal = GPIO_BASE_SIXAXIS_INT_L,
+ .flags = MOTIONSENSE_FLAG_INT_SIGNAL,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR0__7bf,
+ .rot_standard_ref = &base_standard_ref,
+ .default_range = 2, /* g */
+ .min_frequency = LSM6DSM_ODR_MIN_VAL,
+ .max_frequency = LSM6DSM_ODR_MAX_VAL,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 13000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on for angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ },
+ },
+
+ [BASE_GYRO] = {
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_LSM6DSM,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &lsm6dsm_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = LSM6DSM_ST_DATA(lsm6dsm_data,
+ MOTIONSENSE_TYPE_GYRO),
+ .int_signal = GPIO_BASE_SIXAXIS_INT_L,
+ .flags = MOTIONSENSE_FLAG_INT_SIGNAL,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR0__7bf,
+ .default_range = 1000 | ROUND_UP_FLAG, /* dps */
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = LSM6DSM_ODR_MIN_VAL,
+ .max_frequency = LSM6DSM_ODR_MAX_VAL,
+ },
+};
+
+unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+/*
+ * Returns 1 for boards that are convertible into tablet mode, and zero for
+ * clamshells.
+ */
+int board_is_convertible(void)
+{
+ /*
+ * Bloog: 33, 34, 35, 36
+ * Blooguard: 49, 50, 51, 52
+ * Unprovisioned: 255
+ */
+ return sku_id == 33 || sku_id == 34 || sku_id == 35 || sku_id == 36
+ || sku_id == 49 || sku_id == 50 || sku_id == 51 || sku_id == 52
+ || sku_id == 255;
+}
+
+static void board_update_sensor_config_from_sku(void)
+{
+ if (board_is_convertible()) {
+ motion_sensor_count = ARRAY_SIZE(motion_sensors);
+ /* Enable Base Accel interrupt */
+ gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
+ } else {
+ motion_sensor_count = 0;
+ hall_sensor_disable();
+ /* Base accel is not stuffed, don't allow line to float */
+ gpio_set_flags(GPIO_BASE_SIXAXIS_INT_L,
+ GPIO_INPUT | GPIO_PULL_DOWN);
+ }
+}
+
+static void cbi_init(void)
+{
+ uint32_t val;
+
+ if (cbi_get_sku_id(&val) == EC_SUCCESS)
+ sku_id = val;
+ ccprints("SKU: 0x%04x", sku_id);
+
+ board_update_sensor_config_from_sku();
+}
+DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_INIT_I2C + 1);
+
+void board_hibernate_late(void)
+{
+ int i;
+
+ const uint32_t hibernate_pins[][2] = {
+ /* Turn off LEDs before going to hibernate */
+ {GPIO_LED_WHITE_C0_L, GPIO_INPUT | GPIO_PULL_UP},
+ {GPIO_LED_AMBER_C0_L, GPIO_INPUT | GPIO_PULL_UP},
+ {GPIO_LED_WHITE_C1_L, GPIO_INPUT | GPIO_PULL_UP},
+ {GPIO_LED_AMBER_C1_L, GPIO_INPUT | GPIO_PULL_UP},
+ };
+
+ for (i = 0; i < ARRAY_SIZE(hibernate_pins); ++i)
+ gpio_set_flags(hibernate_pins[i][0], hibernate_pins[i][1]);
+}
+
+#ifndef TEST_BUILD
+/* This callback disables keyboard when convertibles are fully open */
+void lid_angle_peripheral_enable(int enable)
+{
+ /*
+ * If the lid is in tablet position via other sensors,
+ * ignore the lid angle, which might be faulty then
+ * disable keyboard.
+ */
+ if (tablet_get_mode())
+ enable = 0;
+
+ if (board_is_convertible())
+ keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE);
+}
+#endif
+
+#ifdef CONFIG_KEYBOARD_FACTORY_TEST
+/*
+ * Map keyboard connector pins to EC GPIO pins for factory test.
+ * Pins mapped to {-1, -1} are skipped.
+ * The connector has 24 pins total, and there is no pin 0.
+ */
+const int keyboard_factory_scan_pins[][2] = {
+ {-1, -1}, {0, 5}, {1, 1}, {1, 0}, {0, 6},
+ {0, 7}, {1, 4}, {1, 3}, {1, 6}, {1, 7},
+ {3, 1}, {2, 0}, {1, 5}, {2, 6}, {2, 7},
+ {2, 1}, {2, 4}, {2, 5}, {1, 2}, {2, 3},
+ {2, 2}, {3, 0}, {-1, -1}, {-1, -1}, {-1, -1},
+};
+
+const int keyboard_factory_scan_pins_used =
+ ARRAY_SIZE(keyboard_factory_scan_pins);
+#endif
+
+void board_overcurrent_event(int port, int is_overcurrented)
+{
+ /* Sanity check the port. */
+ if ((port < 0) || (port >= CONFIG_USB_PD_PORT_COUNT))
+ return;
+
+ /* Note that the level is inverted because the pin is active low. */
+ gpio_set_level(GPIO_USB_C_OC, !is_overcurrented);
+}
+
+uint32_t board_override_feature_flags0(uint32_t flags0)
+{
+ /*
+ * Remove keyboard backlight feature for devices that don't support it.
+ */
+ if (sku_id == 33 || sku_id == 36 || sku_id == 51 || sku_id == 52)
+ return (flags0 & ~EC_FEATURE_MASK_0(EC_FEATURE_PWM_KEYB));
+ else
+ return flags0;
+}
+
+uint32_t board_override_feature_flags1(uint32_t flags1)
+{
+ return flags1;
+}
diff --git a/board/bobba/board.c b/board/bobba/board.c
index 4cc3d3f678..aaf31187a7 100644
--- a/board/bobba/board.c
+++ b/board/bobba/board.c
@@ -130,7 +130,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kx022_data,
.port = I2C_PORT_SENSOR,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 4, /* g */
.config = {
@@ -154,7 +154,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_SENSOR,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = &base_standard_ref,
.default_range = 4, /* g */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -182,7 +182,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_SENSOR,
- .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,
diff --git a/board/casta/board.c b/board/casta/board.c
new file mode 100644
index 0000000000..ae3f61e0c1
--- /dev/null
+++ b/board/casta/board.c
@@ -0,0 +1,154 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Casta board-specific configuration */
+
+#include "adc.h"
+#include "adc_chip.h"
+#include "battery.h"
+#include "charge_manager.h"
+#include "charge_state.h"
+#include "common.h"
+#include "cros_board_info.h"
+#include "driver/charger/bd9995x.h"
+#include "driver/ppc/nx20p348x.h"
+#include "driver/tcpm/anx7447.h"
+#include "driver/tcpm/ps8xxx.h"
+#include "driver/tcpm/tcpci.h"
+#include "driver/tcpm/tcpm.h"
+#include "extpower.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "keyboard_scan.h"
+#include "lid_switch.h"
+#include "power.h"
+#include "power_button.h"
+#include "switch.h"
+#include "system.h"
+#include "tcpci.h"
+#include "temp_sensor.h"
+#include "thermistor.h"
+#include "usb_mux.h"
+#include "usbc_ppc.h"
+#include "util.h"
+
+#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
+
+static void ppc_interrupt(enum gpio_signal signal)
+{
+ switch (signal) {
+ case GPIO_USB_PD_C0_INT_ODL:
+ nx20p348x_interrupt(0);
+ break;
+
+ case GPIO_USB_PD_C1_INT_ODL:
+ nx20p348x_interrupt(1);
+ break;
+
+ default:
+ break;
+ }
+}
+
+/* Must come after other header files and GPIO interrupts*/
+#include "gpio_list.h"
+
+/* ADC channels */
+const struct adc_t adc_channels[] = {
+ [ADC_TEMP_SENSOR_AMB] = {
+ "TEMP_AMB", NPCX_ADC_CH0, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+ [ADC_TEMP_SENSOR_CHARGER] = {
+ "TEMP_CHARGER", NPCX_ADC_CH1, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
+
+/* TODO(b/119872005): Casta: confirm thermistor parts */
+const struct temp_sensor_t temp_sensors[] = {
+ [TEMP_SENSOR_BATTERY] = {.name = "Battery",
+ .type = TEMP_SENSOR_TYPE_BATTERY,
+ .read = charge_get_battery_temp,
+ .idx = 0,
+ .action_delay_sec = 1},
+ [TEMP_SENSOR_AMBIENT] = {.name = "Ambient",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_AMB,
+ .action_delay_sec = 5},
+ [TEMP_SENSOR_CHARGER] = {.name = "Charger",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_13k7_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_CHARGER,
+ .action_delay_sec = 1},
+};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
+
+/*
+ * I2C callbacks to ensure bus free time for battery I2C transactions is at
+ * least 5ms.
+ */
+#define BATTERY_FREE_MIN_DELTA_US (5 * MSEC)
+static timestamp_t battery_last_i2c_time;
+
+static int is_battery_i2c__7bf(const int port, const uint16_t slave_addr__7bf)
+{
+ return (port == I2C_PORT_BATTERY)
+ && (slave_addr__7bf == BATTERY_ADDR__7bf);
+}
+
+static int is_battery_port(int port)
+{
+ return (port == I2C_PORT_BATTERY);
+}
+
+void i2c_start_xfer_notify__7bf(const int port, const uint16_t slave_addr__7bf)
+{
+ unsigned int time_delta_us;
+
+ if (!is_battery_i2c__7bf(port, slave_addr__7bf))
+ return;
+
+ time_delta_us = time_since32(battery_last_i2c_time);
+ if (time_delta_us >= BATTERY_FREE_MIN_DELTA_US)
+ return;
+
+ usleep(BATTERY_FREE_MIN_DELTA_US - time_delta_us);
+}
+
+void i2c_end_xfer_notify__7bf(const int port, const uint16_t slave_addr__7bf)
+{
+ /*
+ * The bus free time needs to be maintained from last transaction
+ * on I2C bus to any device on it to the next transaction to battery.
+ */
+ if (!is_battery_port(port))
+ return;
+
+ battery_last_i2c_time = get_time();
+}
+
+/* TODO: Casta: remove this routine after rev0 is not supported */
+static void board_init(void)
+{
+ uint32_t val;
+ if (cbi_get_board_version(&val) == EC_SUCCESS && val > 0)
+ return;
+
+ gpio_set_flags(GPIO_USB_C0_MUX_INT_ODL, GPIO_INT_FALLING | GPIO_PULL_UP);
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+
+void board_overcurrent_event(int port, int is_overcurrented)
+{
+ /* Sanity check the port. */
+ if ((port < 0) || (port >= CONFIG_USB_PD_PORT_COUNT))
+ return;
+
+ /* Note that the level is inverted because the pin is active low. */
+ gpio_set_level(GPIO_USB_C_OC, !is_overcurrented);
+}
diff --git a/board/chell/board.c b/board/chell/board.c
index 14b1e56d2c..659f3ecb02 100644
--- a/board/chell/board.c
+++ b/board/chell/board.c
@@ -42,7 +42,7 @@
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
-#define I2C_ADDR_BD99992 0x60
+#define I2C_ADDR_BD99992__7bf 0x30
/* Exchange status with PD MCU. */
static void pd_mcu_interrupt(enum gpio_signal signal)
@@ -126,7 +126,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC,
- .addr = CONFIG_TCPC_I2C_BASE_ADDR,
+ .addr__7bf = CONFIG_TCPC_I2C_BASE_ADDR__7BF,
},
.drv = &tcpci_tcpm_drv,
},
@@ -134,7 +134,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC,
- .addr = CONFIG_TCPC_I2C_BASE_ADDR + 2,
+ .addr__7bf = CONFIG_TCPC_I2C_BASE_ADDR__7BF + 1,
},
.drv = &tcpci_tcpm_drv,
@@ -198,12 +198,12 @@ static int ps874x_tune_mux(int port)
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
{
- .port_addr = 0x34,
+ .port_addr = 0x1A,
.driver = &ps874x_usb_mux_driver,
.board_init = &ps874x_tune_mux,
},
{
- .port_addr = 0x20,
+ .port_addr = 0x10,
.driver = &ps874x_usb_mux_driver,
.board_init = &ps874x_tune_mux,
}
@@ -245,7 +245,7 @@ BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
static void board_pmic_init(void)
{
/* 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);
/*
* No need to re-init below settings since they are present on all MP
@@ -255,23 +255,23 @@ static void board_pmic_init(void)
return;
/* Set CSDECAYEN / VCCIO decays to 0V at assertion of SLP_S0# */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x30, 0x4a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x30, 0x4a);
/*
* Set V100ACNT / V1.00A Control Register:
* Nominal output = 1.0V.
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x37, 0x1a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x37, 0x1a);
/*
* Set V085ACNT / V0.85A Control Register:
* Lower power mode = 0.7V.
* Nominal output = 1.0V.
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x38, 0x7a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x38, 0x7a);
/* VRMODECTRL - enable low-power mode for VCCIO and V0.85A */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x3b, 0x18);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x3b, 0x18);
}
DECLARE_HOOK(HOOK_INIT, board_pmic_init, HOOK_PRIO_DEFAULT);
@@ -409,7 +409,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
@@ -481,7 +481,8 @@ void chipset_set_pmic_slp_sus_l(int level)
if (!level)
msleep(25);
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x43, val);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ 0x43, val);
previous_level = level;
}
}
diff --git a/board/cheza/board.c b/board/cheza/board.c
index be505d1a0e..8f11d0150b 100644
--- a/board/cheza/board.c
+++ b/board/cheza/board.c
@@ -6,12 +6,14 @@
/* Cheza board-specific configuration */
#include "adc_chip.h"
+#include "als.h"
#include "button.h"
#include "charge_manager.h"
#include "charge_state.h"
#include "chipset.h"
#include "extpower.h"
#include "driver/accelgyro_bmi160.h"
+#include "driver/als_opt3001.h"
#include "driver/ppc/sn5s330.h"
#include "driver/tcpm/anx74xx.h"
#include "driver/tcpm/ps8xxx.h"
@@ -129,7 +131,7 @@ static void ppc_interrupt(enum gpio_signal signal)
static void usb1_oc_evt_deferred(void)
{
/* Only port-1 has overcurrent GPIO interrupt */
- board_overcurrent_event(0, 1);
+ board_overcurrent_event(1, 1);
}
DECLARE_DEFERRED(usb1_oc_evt_deferred);
@@ -240,7 +242,7 @@ const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
struct ppc_config_t ppc_chips[] = {
{
.i2c_port = I2C_PORT_TCPC0,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
/*
@@ -259,7 +261,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = 0x50,
+ .addr__7bf = 0x28,
},
.drv = &anx74xx_tcpm_drv,
.flags = TCPC_FLAGS_ALERT_OD,
@@ -268,7 +270,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC1,
- .addr = 0x16,
+ .addr__7bf = 0x0B,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -618,6 +620,11 @@ uint16_t tcpc_get_alert_status(void)
static struct mutex g_lid_mutex;
static struct bmi160_drv_data_t g_bmi160_data;
+static struct opt3001_drv_data_t g_opt3001_data = {
+ .scale = 1,
+ .uscale = 0,
+ .offset = 0,
+};
/* Matrix to rotate accelerometer into standard reference frame */
const mat33_fp_t base_standard_ref = {
@@ -642,7 +649,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_SENSOR,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = &base_standard_ref,
.default_range = 4, /* g */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -663,11 +670,31 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_SENSOR,
- .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,
.max_frequency = BMI160_GYRO_MAX_FREQ,
},
+ [LID_ALS] = {
+ .name = "Light",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .chip = MOTIONSENSE_CHIP_OPT3001,
+ .type = MOTIONSENSE_TYPE_LIGHT,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &opt3001_drv,
+ .drv_data = &g_opt3001_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = OPT3001_I2C_ADDR__7bf,
+ .rot_standard_ref = NULL,
+ .default_range = 0x10000, /* scale = 1; uscale = 0 */
+ .min_frequency = OPT3001_LIGHT_MIN_FREQ,
+ .max_frequency = OPT3001_LIGHT_MAX_FREQ,
+ .config = {
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 1000,
+ },
+ },
+ },
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
diff --git a/board/cheza/board.h b/board/cheza/board.h
index ed1dcd9c72..e35502fa57 100644
--- a/board/cheza/board.h
+++ b/board/cheza/board.h
@@ -12,6 +12,8 @@
#define CONFIG_BRINGUP
#define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands. */
#define CONFIG_USB_PD_DEBUG_LEVEL 3
+#define CONFIG_CMD_AP_RESET_LOG
+#define CONFIG_HOSTCMD_AP_RESET
/*
* By default, enable all console messages excepted event and HC:
@@ -26,20 +28,26 @@
#define NPCX7_PWM1_SEL 0 /* GPIO C2 is not used as PWM1. */
/* Internal SPI flash on NPCX7 */
-#define CONFIG_FLASH_SIZE (512 * 1024) /* It's really 1MB. */
+#define CONFIG_FLASH_SIZE (1024 * 1024) /* 1MB internal spi flash */
#define CONFIG_SPI_FLASH_REGS
#define CONFIG_SPI_FLASH_W25Q80 /* Internal SPI flash type. */
+#define CONFIG_HOSTCMD_FLASH_SPI_INFO
/* EC Modules */
#define CONFIG_I2C
#define CONFIG_I2C_MASTER
#define CONFIG_LED_COMMON
+#define CONFIG_LOW_POWER_IDLE
#define CONFIG_ADC
#define CONFIG_BACKLIGHT_LID
#define CONFIG_FPU
#define CONFIG_PWM
#define CONFIG_PWM_DISPLIGHT
+#define CONFIG_VBOOT_HASH
+
+#define CONFIG_DETACHABLE_BASE
+
#undef CONFIG_PECI
#define CONFIG_HOSTCMD_SPS
@@ -79,7 +87,6 @@
#define CONFIG_CHARGER_PSYS_READ
#define CONFIG_CHARGER_DISCHARGE_ON_AC
-/* TODO(b/79163120): Use correct charger values, copied from Lux for rev-0 */
#define CONFIG_CHARGER_INPUT_CURRENT 512
#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2
#define CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON 7500
@@ -109,11 +116,16 @@
#define CONFIG_USB_PD_TRY_SRC
#define CONFIG_USB_PD_VBUS_DETECT_CHARGER
#define CONFIG_USB_PD_5V_EN_CUSTOM
+#define CONFIG_USB_MUX_VIRTUAL
#define CONFIG_USBC_PPC_SN5S330
#define CONFIG_USBC_SS_MUX
#define CONFIG_USBC_VCONN
#define CONFIG_USBC_VCONN_SWAP
+/* RTC */
+#define CONFIG_CMD_RTC
+#define CONFIG_HOSTCMD_RTC
+
/* Sensors */
#define CONFIG_ACCELGYRO_BMI160
#define CONFIG_ACCEL_INTERRUPTS
@@ -123,25 +135,29 @@
#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
#define CONFIG_CMD_ACCELS
#define CONFIG_CMD_ACCEL_INFO
+#define CONFIG_ALS
+#define CONFIG_ALS_OPT3001
+#define ALS_COUNT 1
+#define OPT3001_I2C_ADDR__7bf OPT3001_I2C_ADDR1__7bf
-/* TODO(b/79163120): Use correct PD delay values, copied from Lux for rev-0 */
+/* PD */
#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */
#define PD_VCONN_SWAP_DELAY 5000 /* us */
-/* TODO(b/79163120): Use correct PD power values, copied from Lux for rev-0 */
#define PD_OPERATING_POWER_MW 15000
-#define PD_MAX_POWER_MW 45000
+#define PD_MAX_POWER_MW ((PD_MAX_VOLTAGE_MV * PD_MAX_CURRENT_MA) / 1000)
#define PD_MAX_CURRENT_MA 3000
#define PD_MAX_VOLTAGE_MV 20000
+/* Chipset */
#define CONFIG_CHIPSET_SDM845
#define CONFIG_CHIPSET_RESET_HOOK
#define CONFIG_POWER_COMMON
#define CONFIG_POWER_PP5000_CONTROL
-/* TODO(b/79348203): Enable EC hibernate */
-#undef CONFIG_HIBERNATE
+/* NPCX Features */
+#define CONFIG_HIBERNATE_PSL
/* I2C Ports */
#define I2C_PORT_BATTERY I2C_PORT_POWER
@@ -159,10 +175,11 @@
#include "registers.h"
enum power_signal {
- SDM845_AP_RST_L = 0,
+ SDM845_AP_RST_ASSERTED = 0,
SDM845_PS_HOLD,
SDM845_PMIC_FAULT_L,
SDM845_POWER_GOOD,
+ SDM845_WARM_RESET,
/* Number of power signals */
POWER_SIGNAL_COUNT
};
@@ -197,6 +214,9 @@ void board_reset_pd_mcu(void);
/* Base detection interrupt handler */
void base_detect_interrupt(enum gpio_signal signal);
+/* Sensors without hardware FIFO are in forced mode */
+#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ALS)
+
#endif /* !defined(__ASSEMBLER__) */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/coral/board.c b/board/coral/board.c
index 012e3a8038..8a027e73d9 100644
--- a/board/coral/board.c
+++ b/board/coral/board.c
@@ -191,7 +191,7 @@ struct i2c_stress_test i2c_stress_tests[] = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_TCPC
{
.port = NPCX_I2C_PORT0_0,
- .addr = ANX74XX_I2C_ADDR1,
+ .addr__7bf = ANX74XX_I2C_ADDR1__7bf,
.i2c_test = &anx74xx_i2c_stress_test_dev,
},
#endif
@@ -200,7 +200,7 @@ struct i2c_stress_test i2c_stress_tests[] = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_TCPC
{
.port = NPCX_I2C_PORT0_1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
.i2c_test = &ps8xxx_i2c_stress_test_dev,
},
#endif
@@ -209,7 +209,7 @@ struct i2c_stress_test i2c_stress_tests[] = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL
{
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .addr__7bf = BMI160_ADDR0__7bf,
.i2c_test = &bmi160_i2c_stress_test_dev,
},
#endif
@@ -218,7 +218,7 @@ struct i2c_stress_test i2c_stress_tests[] = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL
{
.port = I2C_PORT_LID_ACCEL,
- .addr = KX022_ADDR1,
+ .addr__7bf = KX022_ADDR1__7bf,
.i2c_test = &kionix_i2c_stress_test_dev,
},
#endif
@@ -243,7 +243,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 = ANX74XX_I2C_ADDR1,
+ .addr__7bf = ANX74XX_I2C_ADDR1__7bf,
},
.drv = &anx74xx_tcpm_drv,
},
@@ -251,7 +251,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,
},
@@ -390,7 +390,7 @@ static void board_tcpc_init(void)
*
* NOTE: PS8751 A3 will wake on any I2C access.
*/
- i2c_read8(NPCX_I2C_PORT0_1, 0x10, 0xA0, &reg);
+ i2c_read8__7bf(NPCX_I2C_PORT0_1, 0x08, 0xA0, &reg);
/* Enable TCPC0 interrupt */
gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
@@ -740,7 +740,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kx022_data,
.port = I2C_PORT_LID_ACCEL,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 2, /* g, enough for laptop. */
.config = {
@@ -765,7 +765,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.config = {
@@ -792,7 +792,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.default_range = 1000, /* dps */
.rot_standard_ref = &base_standard_ref,
},
diff --git a/board/elm/board.c b/board/elm/board.c
index 5f00866350..b92aa14c7d 100644
--- a/board/elm/board.c
+++ b/board/elm/board.c
@@ -95,13 +95,14 @@ const struct adc_t adc_channels[] = {
};
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
-int anx7688_passthru_allowed(const struct i2c_port_t *port, uint16_t address)
+int anx7688_passthru_allowed__7bf(const struct i2c_port_t *port,
+ const uint16_t addr__7bf)
{
/* Allow access to 0x2c (TCPC) */
- if (address == 0x2c)
+ if (I2C_GET_ADDR__7b(addr__7bf) == 0x2c)
return 1;
- CPRINTF("Passthru rejected on %x", address);
+ CPRINTF("Passthru rejected on %x", I2C_GET_ADDR__7b(addr__7bf));
return 0;
}
@@ -110,7 +111,7 @@ int anx7688_passthru_allowed(const struct i2c_port_t *port, uint16_t address)
const struct i2c_port_t i2c_ports[] = {
{"battery", I2C_PORT_BATTERY, 100, GPIO_I2C0_SCL, GPIO_I2C0_SDA},
{"pd", I2C_PORT_PD_MCU, 1000, GPIO_I2C1_SCL, GPIO_I2C1_SDA,
- anx7688_passthru_allowed}
+ anx7688_passthru_allowed__7bf}
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
@@ -128,7 +129,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC,
- .addr = CONFIG_TCPC_I2C_BASE_ADDR,
+ .addr__7bf = CONFIG_TCPC_I2C_BASE_ADDR__7BF,
},
.drv = &anx7688_tcpm_drv,
},
@@ -469,7 +470,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &kionix_accel_drv,
.mutex = &g_kx022_mutex[0],
.drv_data = &g_kx022_data[0],
- .addr = 1, /* SPI, device ID 0 */
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(0),
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KX022_ACCEL_MIN_FREQ,
@@ -492,7 +493,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &kionix_accel_drv,
.mutex = &g_kx022_mutex[1],
.drv_data = &g_kx022_data[1],
- .addr = 3, /* SPI, device ID 1 */
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(1),
.rot_standard_ref = &lid_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KX022_ACCEL_MIN_FREQ,
diff --git a/board/elm/board.h b/board/elm/board.h
index 0de9730454..359bd7e279 100644
--- a/board/elm/board.h
+++ b/board/elm/board.h
@@ -99,8 +99,8 @@
#define CONFIG_USB_PD_TCPM_TCPCI
#define CONFIG_USB_PD_TRY_SRC
#define CONFIG_USB_PD_VBUS_DETECT_TCPC
-#undef CONFIG_TCPC_I2C_BASE_ADDR
-#define CONFIG_TCPC_I2C_BASE_ADDR 0x58
+#undef CONFIG_TCPC_I2C_BASE_ADDR__7BF
+#define CONFIG_TCPC_I2C_BASE_ADDR__7BF 0x2C
#define CONFIG_USB_PD_ANX7688
/* UART DMA */
diff --git a/board/eve/board.c b/board/eve/board.c
index 4c5fa8ce89..72877fd100 100644
--- a/board/eve/board.c
+++ b/board/eve/board.c
@@ -5,6 +5,7 @@
/* Eve board-specific configuration */
+#include "acpi.h"
#include "adc_chip.h"
#include "bd99992gw.h"
#include "board_config.h"
@@ -62,17 +63,20 @@
static void tcpc_alert_event(enum gpio_signal signal)
{
- if ((signal == GPIO_USB_C0_PD_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C0_PD_RST_L))
- return;
- else if ((signal == GPIO_USB_C1_PD_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C1_PD_RST_L))
+ int port = -1;
+
+ switch (signal) {
+ case GPIO_USB_C0_PD_INT_ODL:
+ port = 0;
+ break;
+ case GPIO_USB_C1_PD_INT_ODL:
+ port = 1;
+ break;
+ default:
return;
+ }
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
+ schedule_deferred_pd_interrupt(port);
}
/*
@@ -153,17 +157,6 @@ void anx74xx_cable_det_interrupt(enum gpio_signal signal)
#include "gpio_list.h"
-/* power signal list. Must match order of enum power_signal. */
-const struct power_signal_info power_signal_list[] = {
- {GPIO_PCH_SLP_S0_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S0_DEASSERTED"},
- {VW_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
- {VW_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
- {GPIO_PCH_SLP_SUS_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_SUS_DEASSERTED"},
- {GPIO_RSMRST_L_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "RSMRST_L_PGOOD"},
- {GPIO_PMIC_DPWROK, POWER_SIGNAL_ACTIVE_HIGH, "PMIC_DPWROK"},
-};
-BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
-
/* Keyboard scan. Increase output_settle_us to 80us from default 50us. */
struct keyboard_scan_config keyscan_config = {
.output_settle_us = 80,
@@ -214,7 +207,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = ANX74XX_I2C_ADDR1,
+ .addr__7bf = ANX74XX_I2C_ADDR1__7bf,
},
.drv = &anx74xx_tcpm_drv,
},
@@ -222,7 +215,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC1,
- .addr = ANX74XX_I2C_ADDR1,
+ .addr__7bf = ANX74XX_I2C_ADDR1__7bf,
},
.drv = &anx74xx_tcpm_drv,
},
@@ -370,29 +363,29 @@ 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;
- if (!(vrfault & (1 << 4)))
+ if (!(vrfault & BIT(4)))
return;
/* 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, (1 << 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
@@ -410,38 +403,46 @@ static void board_pmic_init(void)
return;
/* DISCHGCNT2 - enable 100 ohm discharge on V3.3A and V1.8A */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x3d, 0x05);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x3d, 0x05);
/* 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);
/* Set CSDECAYEN / VCCIO decays to 0V at assertion of SLP_S0# */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x30, 0x7a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x30, 0x7a);
/*
* Set V100ACNT / V1.00A Control Register:
* Nominal output = 1.0V.
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x37, 0x1a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x37, 0x1a);
/*
* Set V085ACNT / V0.85A Control Register:
* Lower power mode = 0.7V.
* Nominal output = 1.0V.
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x38, 0x7a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x38, 0x7a);
/* 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);
/* Clear power source events */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x04, 0xff);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x04, 0xff);
}
DECLARE_HOOK(HOOK_INIT, board_pmic_init, HOOK_PRIO_DEFAULT);
static void board_set_tablet_mode(void)
{
- tablet_set_mode(!gpio_get_level(GPIO_TABLET_MODE_L));
+ int flipped_360_mode = !gpio_get_level(GPIO_TABLET_MODE_L);
+
+ tablet_set_mode(flipped_360_mode);
+
+ /* Update DPTF profile based on mode */
+ if (flipped_360_mode)
+ acpi_dptf_set_profile_num(DPTF_PROFILE_FLIPPED_360_MODE);
+ else
+ acpi_dptf_set_profile_num(DPTF_PROFILE_CLAMSHELL);
}
int board_has_working_reset_flags(void)
@@ -491,7 +492,10 @@ static void board_init(void)
if (board_get_version() == 4) {
/* Set F13 to new defined key on EVT */
CPRINTS("Overriding F13 scan code");
- scancode_set2[3][9] = 0xe007;
+ scancode_set2[9][3] = 0xe007;
+#ifdef CONFIG_KEYBOARD_DEBUG
+ keycap_label[9][3] = KLLI_F13;
+#endif
}
#endif
}
@@ -718,7 +722,7 @@ void board_hibernate(void)
/* Shut down PMIC */
CPRINTS("Triggering PMIC shutdown");
uart_flush_output();
- 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
@@ -811,7 +815,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kxcj9_data,
.port = I2C_PORT_LID_ACCEL,
- .addr = KXCJ9_ADDR0,
+ .i2c_spi_addr__7bf = KXCJ9_ADDR0__7bf,
.rot_standard_ref = &lid_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KXCJ9_ACCEL_MIN_FREQ,
@@ -838,7 +842,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = NULL,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -864,7 +868,7 @@ struct motion_sensor_t motion_sensors[] = {
[BASE_GYRO] = {
.name = "Base Gyro",
- .active_mask = SENSOR_ACTIVE_S0,
+ .active_mask = SENSOR_ACTIVE_S0_S3_S5,
.chip = MOTIONSENSE_CHIP_BMI160,
.type = MOTIONSENSE_TYPE_GYRO,
.location = MOTIONSENSE_LOC_BASE,
@@ -872,7 +876,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.default_range = 1000, /* dps */
.rot_standard_ref = NULL,
.min_frequency = BMI160_GYRO_MIN_FREQ,
@@ -881,7 +885,7 @@ struct motion_sensor_t motion_sensors[] = {
[BASE_MAG] = {
.name = "Base Mag",
- .active_mask = SENSOR_ACTIVE_S0,
+ .active_mask = SENSOR_ACTIVE_S0_S3_S5,
.chip = MOTIONSENSE_CHIP_BMI160,
.type = MOTIONSENSE_TYPE_MAG,
.location = MOTIONSENSE_LOC_BASE,
@@ -889,8 +893,8 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
- .default_range = 1 << 11, /* 16LSB / uT, fixed */
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
+ .default_range = BIT(11), /* 16LSB / uT, fixed */
.rot_standard_ref = &mag_standard_ref,
.min_frequency = BMM150_MAG_MIN_FREQ,
.max_frequency = BMM150_MAG_MAX_FREQ(SPECIAL),
@@ -906,7 +910,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_si114x_data,
.port = I2C_PORT_ALS,
- .addr = SI114X_ADDR,
+ .i2c_spi_addr__7bf = SI114X_ADDR__7bf,
.rot_standard_ref = NULL,
.default_range = 3088, /* 30.88%: int = 0 - frac = 3088/10000 */
.min_frequency = SI114X_LIGHT_MIN_FREQ,
diff --git a/board/eve/board.h b/board/eve/board.h
index f329cb2557..88938e9719 100644
--- a/board/eve/board.h
+++ b/board/eve/board.h
@@ -29,6 +29,7 @@
#define CONFIG_BOARD_FORCE_RESET_PIN
#define CONFIG_DEVICE_EVENT
#define CONFIG_DPTF
+#define CONFIG_DPTF_MULTI_PROFILE
#define CONFIG_FLASH_SIZE 0x80000
#define CONFIG_FPU
#define CONFIG_I2C
@@ -127,7 +128,8 @@
#define CONFIG_ACCEL_INTERRUPTS
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
-#define CONFIG_ACCELGYRO_SEC_ADDR BMM150_ADDR0 /* 8-bit address */
+#define CONFIG_ACCELGYRO_SEC_ADDR__7BF BMM150_ADDR0__7bf
+#define CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT /* Unused */
#define CONFIG_MAG_CALIBRATE
#define CONFIG_LID_ANGLE
#define CONFIG_LID_ANGLE_UPDATE
@@ -148,7 +150,7 @@
#define CONFIG_GESTURE_TAP_THRES_MG 100
#define CONFIG_GESTURE_TAP_MAX_INTERSTICE_T 500
#define CONFIG_GESTURE_DETECTION_MASK \
- (1 << CONFIG_GESTURE_SENSOR_BATTERY_TAP)
+ BIT(CONFIG_GESTURE_SENSOR_BATTERY_TAP)
/* USB */
#define CONFIG_USB_CHARGER
@@ -193,8 +195,8 @@
#define I2C_PORT_MP2949 NPCX_I2C_PORT3
/* I2C addresses */
-#define I2C_ADDR_BD99992 0x60
-#define I2C_ADDR_MP2949 0x40
+#define I2C_ADDR_BD99992__7bf 0x30
+#define I2C_ADDR_MP2949__7bf 0x20
#ifndef __ASSEMBLER__
@@ -211,16 +213,6 @@ enum board_version_list {
BOARD_VERSION_PVT,
};
-enum power_signal {
- X86_SLP_S0_DEASSERTED,
- X86_SLP_S3_DEASSERTED,
- X86_SLP_S4_DEASSERTED,
- X86_SLP_SUS_DEASSERTED,
- X86_RSMRST_L_PGOOD,
- X86_PMIC_DPWROK,
- POWER_SIGNAL_COUNT
-};
-
enum temp_sensor_id {
TEMP_SENSOR_BATTERY, /* BD99956GW TSENSE */
TEMP_SENSOR_AMBIENT, /* BD99992GW SYSTHERM0 */
@@ -298,7 +290,7 @@ void led_register_double_tap(void);
void board_update_ac_status(void);
/* Sensors without hardware FIFO are in forced mode */
-#define CONFIG_ACCEL_FORCE_MODE_MASK ((1 << LID_ACCEL) | (1 << LID_LIGHT))
+#define CONFIG_ACCEL_FORCE_MODE_MASK (BIT(LID_ACCEL) | BIT(LID_LIGHT))
#endif /* !__ASSEMBLER__ */
diff --git a/board/fizz/board.c b/board/fizz/board.c
index f278da3107..069c6450e8 100644
--- a/board/fizz/board.c
+++ b/board/fizz/board.c
@@ -201,7 +201,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 = I2C_ADDR_TCPC0,
+ .addr__7bf = I2C_ADDR_TCPC0__7bf,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -251,7 +251,7 @@ void board_tcpc_init(void)
* TCPM_INIT will fail due to not able to access PS8751.
* Note PS8751 A3 will wake on any I2C access.
*/
- i2c_read8(I2C_PORT_TCPC0, I2C_ADDR_TCPC0, 0xA0, &reg);
+ i2c_read8__7bf(I2C_PORT_TCPC0, I2C_ADDR_TCPC0__7bf, 0xA0, &reg);
/* Enable TCPC interrupts */
gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
@@ -312,10 +312,10 @@ BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT);
/* Initialize PMIC */
#define I2C_PMIC_READ(reg, data) \
- i2c_read8(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1, (reg), (data))
+ i2c_read8__7bf(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1__7bf, (reg), (data))
#define I2C_PMIC_WRITE(reg, data) \
- i2c_write8(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1, (reg), (data))
+ i2c_write8__7bf(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1__7bf, (reg), (data))
static void board_pmic_init(void)
{
diff --git a/board/fizz/board.h b/board/fizz/board.h
index fd6646fec1..8009b1cdbd 100644
--- a/board/fizz/board.h
+++ b/board/fizz/board.h
@@ -137,8 +137,8 @@
#define I2C_PORT_THERMAL NPCX_I2C_PORT3
/* I2C addresses */
-#define I2C_ADDR_TCPC0 0x16
-#define I2C_ADDR_EEPROM 0xa0
+#define I2C_ADDR_TCPC0__7bf 0x0b
+#define I2C_ADDR_EEPROM__7bf 0x50
/* Verify and jump to RW image on boot */
#define CONFIG_VBOOT_EFS
diff --git a/board/flapjack/battery.c b/board/flapjack/battery.c
new file mode 100644
index 0000000000..5bb6b07a9f
--- /dev/null
+++ b/board/flapjack/battery.c
@@ -0,0 +1,468 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Battery pack vendor provided charging profile
+ */
+
+#include "battery.h"
+#include "battery_smart.h"
+#include "charge_state.h"
+#include "console.h"
+#include "driver/battery/max17055.h"
+#include "driver/charger/rt946x.h"
+#include "driver/tcpm/mt6370.h"
+#include "ec_commands.h"
+#include "extpower.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "usb_pd.h"
+#include "util.h"
+#include "board.h"
+#include "adc.h"
+#include "adc_chip.h"
+#include "math_util.h"
+#include "p9221.h"
+
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
+#define BAT_LEVEL_PD_LIMIT 85
+
+#define BATTERY_ATL_CHARGE_MIN_TEMP 0
+#define BATTERY_ATL_CHARGE_MAX_TEMP 60
+
+#define BATTERY_SUNWODA_CHARGE_MIN_TEMP 0
+#define BATTERY_SUNWODA_CHARGE_MAX_TEMP 60
+
+static const uint16_t full_model_ocv_table[][MAX17055_OCV_TABLE_SIZE] = {
+ [BATTERY_C18_ATL] = {
+ 0x8fc0, 0xb6c0, 0xb910, 0xbb30, 0xbcb0, 0xbdd0, 0xbef0, 0xc050,
+ 0xc1a0, 0xc460, 0xc750, 0xca40, 0xcd10, 0xd070, 0xd560, 0xda20,
+ 0x0060, 0x0f20, 0x0f40, 0x16c0, 0x17f0, 0x15c0, 0x1050, 0x10e0,
+ 0x09f0, 0x0850, 0x0730, 0x07a0, 0x0730, 0x0700, 0x0710, 0x0710,
+ 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800,
+ 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800,
+ },
+ [BATTERY_C19_ATL] = {
+ 0xa260, 0xb5d0, 0xb840, 0xb940, 0xbbb0, 0xbcb0, 0xbdb0, 0xbf80,
+ 0xc0a0, 0xc1e0, 0xc520, 0xc840, 0xcdb0, 0xd150, 0xd590, 0xd9e0,
+ 0x0030, 0x0cd0, 0x1100, 0x0f30, 0x19e0, 0x19f0, 0x14f0, 0x1160,
+ 0x0dc0, 0x0980, 0x0850, 0x0780, 0x0730, 0x0700, 0x0710, 0x0710,
+ 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800,
+ 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800,
+ },
+ [BATTERY_C18_SUNWODA] = {
+ 0x9d70, 0xaf80, 0xb6b0, 0xb830, 0xb990, 0xbc00, 0xbcd0, 0xbea0,
+ 0xc080, 0xc2e0, 0xc5f0, 0xc890, 0xcb90, 0xcf10, 0xd270, 0xd9e0,
+ 0x0060, 0x0240, 0x0b20, 0x1210, 0x0f20, 0x2200, 0x1650, 0x14f0,
+ 0x0980, 0x09c0, 0x07b0, 0x07f0, 0x06f0, 0x07e0, 0x05c0, 0x05c0,
+ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+ },
+ [BATTERY_C19_SUNWODA] = {
+ 0x8590, 0xb1d0, 0xb810, 0xbae0, 0xbc30, 0xbd70, 0xbeb0, 0xbfa0,
+ 0xc0f0, 0xc330, 0xc640, 0xc890, 0xcb50, 0xce20, 0xd370, 0xd950,
+ 0x0020, 0x0520, 0x0d80, 0x1860, 0x1910, 0x2040, 0x0be0, 0x0dd0,
+ 0x0cb0, 0x07b0, 0x08f0, 0x07c0, 0x0790, 0x06e0, 0x0620, 0x0620,
+ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+ 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(full_model_ocv_table) == BATTERY_COUNT);
+
+/*
+ * TODO: Only precharge_current is different. We should consolidate these
+ * and apply 294 or 327 at run-time.when we need more rom space later.
+ */
+static const struct battery_info info[] = {
+ [BATTERY_C18_ATL] = {
+ .voltage_max = 4400,
+ .voltage_normal = 3850,
+ .voltage_min = 3000,
+ .precharge_current = 294,
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 60,
+ .discharging_min_c = -20,
+ .discharging_max_c = 60,
+ },
+ [BATTERY_C19_ATL] = {
+ .voltage_max = 4400,
+ .voltage_normal = 3850,
+ .voltage_min = 3000,
+ .precharge_current = 327,
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 60,
+ .discharging_min_c = -20,
+ .discharging_max_c = 60,
+ },
+ [BATTERY_C18_SUNWODA] = {
+ .voltage_max = 4400,
+ .voltage_normal = 3850,
+ .voltage_min = 3000,
+ .precharge_current = 294,
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 60,
+ .discharging_min_c = -20,
+ .discharging_max_c = 60,
+ },
+ [BATTERY_C19_SUNWODA] = {
+ .voltage_max = 4400,
+ .voltage_normal = 3850,
+ .voltage_min = 3000,
+ .precharge_current = 327,
+ .start_charging_min_c = 0,
+ .start_charging_max_c = 45,
+ .charging_min_c = 0,
+ .charging_max_c = 60,
+ .discharging_min_c = -20,
+ .discharging_max_c = 60,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(info) == BATTERY_COUNT);
+
+static const struct max17055_batt_profile batt_profile[] = {
+ [BATTERY_C18_ATL] = {
+ .is_ez_config = 0,
+ .design_cap = 0x2e78, /* 5948mAh */
+ .ichg_term = 0x03c0, /* 150 mA */
+ /* Empty voltage = 3400mV, Recovery voltage = 4000mV */
+ .v_empty_detect = 0xaa64,
+ .learn_cfg = 0x4402,
+ .dpacc = 0x0c7d,
+ .rcomp0 = 0x0011,
+ .tempco = 0x0209,
+ .qr_table00 = 0x5a00,
+ .qr_table10 = 0x2980,
+ .qr_table20 = 0x1100,
+ .qr_table30 = 0x1000,
+ .ocv_table = full_model_ocv_table[BATTERY_C18_ATL],
+ },
+ [BATTERY_C19_ATL] = {
+ .is_ez_config = 0,
+ .design_cap = 0x3407, /* 6659mAh */
+ .ichg_term = 0x03c0, /* 150 mA */
+ /* Empty voltage = 3400mV, Recovery voltage = 4000mV */
+ .v_empty_detect = 0xaa64,
+ .learn_cfg = 0x4402,
+ .dpacc = 0x0c7e,
+ .rcomp0 = 0x000f,
+ .tempco = 0x000b,
+ .qr_table00 = 0x5800,
+ .qr_table10 = 0x2680,
+ .qr_table20 = 0x0d00,
+ .qr_table30 = 0x0b00,
+ .ocv_table = full_model_ocv_table[BATTERY_C19_ATL],
+ },
+ [BATTERY_C18_SUNWODA] = {
+ .is_ez_config = 0,
+ .design_cap = 0x2fcc, /* 6118mAh */
+ .ichg_term = 0x03c0, /* 150 mA */
+ /* Empty voltage = 3400mV, Recovery voltage = 4000mV */
+ .v_empty_detect = 0xaa64,
+ .learn_cfg = 0x4402,
+ .dpacc = 0x0c7c,
+ .rcomp0 = 0x0024,
+ .tempco = 0x0c1f,
+ .qr_table00 = 0x9f00,
+ .qr_table10 = 0x4480,
+ .qr_table20 = 0x1600,
+ .qr_table30 = 0x1400,
+ .ocv_table = full_model_ocv_table[BATTERY_C18_SUNWODA],
+ },
+ [BATTERY_C19_SUNWODA] = {
+ .is_ez_config = 0,
+ .design_cap = 0x34b1, /* 6744mAh */
+ .ichg_term = 0x03c0, /* 150 mA */
+ /* Empty voltage = 3400mV, Recovery voltage = 4000mV */
+ .v_empty_detect = 0xaa64,
+ .learn_cfg = 0x4402,
+ .dpacc = 0x0c80,
+ .rcomp0 = 0x001f,
+ .tempco = 0x051f,
+ .qr_table00 = 0x9100,
+ .qr_table10 = 0x3d00,
+ .qr_table20 = 0x1200,
+ .qr_table30 = 0x1002,
+ .ocv_table = full_model_ocv_table[BATTERY_C19_SUNWODA],
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(batt_profile) == BATTERY_COUNT);
+
+static const struct max17055_alert_profile alert_profile[] = {
+ [BATTERY_C18_ATL] = {
+ .v_alert_mxmn = VALRT_DISABLE,
+ .t_alert_mxmn = MAX17055_TALRTTH_REG(
+ BATTERY_ATL_CHARGE_MAX_TEMP,
+ BATTERY_ATL_CHARGE_MIN_TEMP),
+ .s_alert_mxmn = SALRT_DISABLE,
+ .i_alert_mxmn = IALRT_DISABLE,
+ },
+ [BATTERY_C19_ATL] = {
+ .v_alert_mxmn = VALRT_DISABLE,
+ .t_alert_mxmn = MAX17055_TALRTTH_REG(
+ BATTERY_ATL_CHARGE_MAX_TEMP,
+ BATTERY_ATL_CHARGE_MIN_TEMP),
+ .s_alert_mxmn = SALRT_DISABLE,
+ .i_alert_mxmn = IALRT_DISABLE,
+ },
+ [BATTERY_C18_SUNWODA] = {
+ .v_alert_mxmn = VALRT_DISABLE,
+ .t_alert_mxmn = MAX17055_TALRTTH_REG(
+ BATTERY_SUNWODA_CHARGE_MIN_TEMP,
+ BATTERY_SUNWODA_CHARGE_MAX_TEMP),
+ .s_alert_mxmn = SALRT_DISABLE,
+ .i_alert_mxmn = IALRT_DISABLE,
+ },
+ [BATTERY_C19_SUNWODA] = {
+ .v_alert_mxmn = VALRT_DISABLE,
+ .t_alert_mxmn = MAX17055_TALRTTH_REG(
+ BATTERY_SUNWODA_CHARGE_MIN_TEMP,
+ BATTERY_SUNWODA_CHARGE_MAX_TEMP),
+ .s_alert_mxmn = SALRT_DISABLE,
+ .i_alert_mxmn = IALRT_DISABLE,
+ },
+
+};
+BUILD_ASSERT(ARRAY_SIZE(alert_profile) == BATTERY_COUNT);
+
+enum temp_zone {
+ TEMP_ZONE_0, /* t0 <= bat_temp_c < t1 */
+ TEMP_ZONE_1, /* t1 <= bat_temp_c < t2 */
+ TEMP_ZONE_2, /* t2 <= bat_temp_c < t3 */
+ TEMP_ZONE_3, /* t3 <= bat_temp_c < t4 */
+ TEMP_ZONE_COUNT,
+ TEMP_OUT_OF_RANGE = TEMP_ZONE_COUNT,
+};
+
+/*
+ * TODO: Many value in temp_zones are pretty similar, we should consolidate
+ * these and modify the value when we need more rom space later.
+ */
+static const struct {
+ int temp_min; /* 0.1 deg C */
+ int temp_max; /* 0.1 deg C */
+ int desired_current; /* mA */
+ int desired_voltage; /* mV */
+} temp_zones[BATTERY_COUNT][TEMP_ZONE_COUNT] = {
+ [BATTERY_C18_ATL] = {
+ {BATTERY_ATL_CHARGE_MIN_TEMP * 10, 100, 1170, 4400},
+ {100, 200, 1755, 4400},
+ {200, 450, 2925, 4400},
+ {450, BATTERY_ATL_CHARGE_MAX_TEMP * 10, 2925, 4100},
+ },
+ [BATTERY_C19_ATL] = {
+ {BATTERY_ATL_CHARGE_MIN_TEMP * 10, 100, 1300, 4400},
+ {100, 200, 1950, 4400},
+ {200, 450, 3250, 4400},
+ {450, BATTERY_ATL_CHARGE_MAX_TEMP * 10, 3250, 4100},
+ },
+ [BATTERY_C18_SUNWODA] = {
+ {BATTERY_SUNWODA_CHARGE_MIN_TEMP * 10, 100, 1170, 4400},
+ {100, 200, 1755, 4400},
+ {200, 450, 2925, 4400},
+ {450, BATTERY_SUNWODA_CHARGE_MAX_TEMP * 10, 2925, 4100},
+ },
+ [BATTERY_C19_SUNWODA] = {
+ {BATTERY_SUNWODA_CHARGE_MIN_TEMP * 10, 100, 1300, 4400},
+ {100, 200, 1950, 4400},
+ {200, 450, 3250, 4400},
+ {450, BATTERY_SUNWODA_CHARGE_MAX_TEMP * 10, 3250, 4100},
+ },
+};
+
+/* BOARD_VERSION < 5: Pull-up = 1800 mV. */
+static const struct mv_to_id batteries0[] = {
+ { BATTERY_C18_ATL, 900 }, /* 100K ohm */
+ { BATTERY_C19_ATL, 576 }, /* 47K ohm */
+ { BATTERY_C18_SUNWODA, 1484 }, /* 470K ohm */
+ { BATTERY_C19_SUNWODA, 1200 }, /* 200K ohm */
+};
+BUILD_ASSERT(ARRAY_SIZE(batteries0) < BATTERY_COUNT);
+
+/* BOARD_VERSION >= 5: Pull-up = 3300 mV. */
+static const struct mv_to_id batteries1[] = {
+ { BATTERY_C18_ATL, 1650 }, /* 100K ohm */
+ { BATTERY_C19_ATL, 1055 }, /* 47K ohm */
+ { BATTERY_C18_SUNWODA, 2721 }, /* 470K ohm */
+ { BATTERY_C19_SUNWODA, 2200 }, /* 200K ohm */
+};
+BUILD_ASSERT(ARRAY_SIZE(batteries1) < BATTERY_COUNT);
+
+static enum battery_type batt_type = BATTERY_UNKNOWN;
+
+static void board_get_battery_type(void)
+{
+ const struct mv_to_id *table = batteries0;
+ int size = ARRAY_SIZE(batteries0);
+ int id;
+
+ if (board_version >= 5) {
+ table = batteries1;
+ size = ARRAY_SIZE(batteries1);
+ }
+ id = board_read_id(ADC_BATT_ID, table, size);
+ if (id != ADC_READ_ERROR)
+ batt_type = id;
+ CPRINTS("Battery Type: %d", batt_type);
+}
+/* It has to run after BOARD_VERSION is read */
+DECLARE_HOOK(HOOK_INIT, board_get_battery_type, HOOK_PRIO_INIT_I2C + 2);
+
+const struct battery_info *battery_get_info(void)
+{
+ return &info[batt_type];
+}
+
+const struct max17055_batt_profile *max17055_get_batt_profile(void)
+{
+ return &batt_profile[batt_type];
+}
+
+const struct max17055_alert_profile *max17055_get_alert_profile(void)
+{
+ return &alert_profile[batt_type];
+}
+
+int get_battery_manufacturer_name(char *dest, int size)
+{
+ static const char * const name[] = {
+ [BATTERY_UNKNOWN] = "UNKNOWN",
+ [BATTERY_C18_ATL] = "C18_ATL",
+ [BATTERY_C19_ATL] = "C19_ATL",
+ [BATTERY_C18_SUNWODA] = "C18_SWD",
+ [BATTERY_C19_SUNWODA] = "C19_SWD",
+ };
+ ASSERT(dest);
+ strzcpy(dest, name[batt_type], size);
+ return EC_SUCCESS;
+}
+
+int board_cut_off_battery(void)
+{
+ /* The cut-off procedure is recommended by Richtek. b/116682788 */
+ rt946x_por_reset();
+ mt6370_vconn_discharge(0);
+ rt946x_cutoff_battery();
+
+ return EC_SUCCESS;
+}
+
+enum battery_disconnect_state battery_get_disconnect_state(void)
+{
+ if (battery_is_present() == BP_YES)
+ return BATTERY_NOT_DISCONNECTED;
+ return BATTERY_DISCONNECTED;
+}
+
+int charger_profile_override(struct charge_state_data *curr)
+{
+ /* battery temp in 0.1 deg C */
+ int temp = curr->batt.temperature - 2731;
+ enum temp_zone zone;
+ int usb_mv, wpc_mv;
+ static int previous_usb_mv;
+ int val;
+
+ if (curr->state != ST_CHARGE)
+ return 0;
+
+ /* Limit input (=VBUS) to 5V when soc > 85% and charge current < 1A. */
+ if (!(curr->batt.flags & BATT_FLAG_BAD_CURRENT) &&
+ charge_get_percent() > BAT_LEVEL_PD_LIMIT &&
+ curr->batt.current < 1000 &&
+ curr->batt.current > 0) {
+ usb_mv = 5500;
+ wpc_mv = 5500;
+ } else {
+ usb_mv = PD_MAX_VOLTAGE_MV;
+ wpc_mv = P9221_DC_IVL_EPP_MV;
+ }
+
+ if (usb_mv != previous_usb_mv)
+ CPRINTS("VBUS limited to %dmV", usb_mv);
+ previous_usb_mv = usb_mv;
+
+ /* Pull down USB VBUS */
+ if (pd_get_max_voltage() != usb_mv)
+ pd_set_external_voltage_limit(0, usb_mv);
+
+ /*
+ * Pull down WPC VBUS. Need to use raw i2c APIs because RO
+ * doesn't have p9221 driver. If WPC is off, this is a no-op.
+ */
+ if (i2c_read_offset16__7bf(I2C_PORT_WPC, P9221_R7_ADDR__7bf,
+ P9221R7_VOUT_SET_REG, &val, 1) == EC_SUCCESS
+ && val * 100 != wpc_mv)
+ i2c_write_offset16__7bf(I2C_PORT_WPC, P9221_R7_ADDR__7bf,
+ P9221R7_VOUT_SET_REG, wpc_mv / 100, 1);
+
+ if ((curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE) ||
+ (temp < temp_zones[batt_type][TEMP_ZONE_0].temp_min)) {
+ zone = TEMP_OUT_OF_RANGE;
+ } else {
+ for (zone = TEMP_ZONE_0; zone < TEMP_ZONE_COUNT; zone++) {
+ if (temp < temp_zones[batt_type][zone].temp_max)
+ break;
+ }
+ }
+
+ if (zone == TEMP_OUT_OF_RANGE || zone >= TEMP_ZONE_COUNT) {
+ curr->requested_current = curr->requested_voltage = 0;
+ curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE;
+ curr->state = ST_IDLE;
+ } else {
+ curr->requested_current =
+ temp_zones[batt_type][zone].desired_current;
+ curr->requested_voltage =
+ temp_zones[batt_type][zone].desired_voltage;
+ }
+
+ /*
+ * When the charger says it's done charging, even if fuel gauge says
+ * SOC < BATTERY_LEVEL_NEAR_FULL, we'll overwrite SOC with
+ * BATTERY_LEVEL_NEAR_FULL. So we can ensure both Chrome OS UI
+ * and battery LED indicate full charge.
+ */
+ if (rt946x_is_charge_done()) {
+ curr->batt.state_of_charge = MAX(BATTERY_LEVEL_NEAR_FULL,
+ curr->batt.state_of_charge);
+ }
+
+ return 0;
+}
+
+static void board_charge_termination(void)
+{
+ static uint8_t te;
+ /* Enable charge termination when we are sure battery is present. */
+ if (!te && battery_is_present() == BP_YES) {
+ if (!rt946x_enable_charge_termination(1))
+ te = 1;
+ }
+}
+DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE,
+ board_charge_termination,
+ HOOK_PRIO_DEFAULT);
+
+/* Customs options controllable by host command. */
+#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0)
+
+enum ec_status charger_profile_override_get_param(uint32_t param,
+ uint32_t *value)
+{
+ return EC_RES_INVALID_PARAM;
+}
+
+enum ec_status charger_profile_override_set_param(uint32_t param,
+ uint32_t value)
+{
+ return EC_RES_INVALID_PARAM;
+}
diff --git a/board/flapjack/board.c b/board/flapjack/board.c
index c8524dca4e..b5be3ff1d6 100644
--- a/board/flapjack/board.c
+++ b/board/flapjack/board.c
@@ -138,12 +138,12 @@ static void board_setup_panel(void)
dim = sku & SKU_ID_PANEL_SIZE_MASK ? 0xc4 : 0xc8;
}
- rv |= i2c_write8(I2C_PORT_CHARGER, RT946X_ADDR, MT6370_BACKLIGHT_BLEN,
- channel);
- rv |= i2c_write8(I2C_PORT_CHARGER, RT946X_ADDR, MT6370_BACKLIGHT_BLDIM,
- dim);
- rv |= i2c_write8(I2C_PORT_CHARGER, RT946X_ADDR, MT6370_BACKLIGHT_BLPWM,
- 0xac);
+ rv |= i2c_write8__7bf(I2C_PORT_CHARGER, RT946X_ADDR__7bf,
+ MT6370_BACKLIGHT_BLEN, channel);
+ rv |= i2c_write8__7bf(I2C_PORT_CHARGER, RT946X_ADDR__7bf,
+ MT6370_BACKLIGHT_BLDIM, dim);
+ rv |= i2c_write8__7bf(I2C_PORT_CHARGER, RT946X_ADDR__7bf,
+ MT6370_BACKLIGHT_BLPWM, 0xac);
if (rv)
CPRINTS("Board setup panel failed\n");
}
@@ -287,7 +287,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = MT6370_TCPC_I2C_ADDR,
+ .addr__7bf = MT6370_TCPC_I2C_ADDR__7bf,
},
.drv = &mt6370_tcpm_drv},
};
@@ -499,7 +499,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_ACCEL,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = &lid_standard_ref,
.default_range = 4, /* g */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -522,7 +522,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_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 = &lid_standard_ref,
.min_frequency = BMI160_GYRO_MIN_FREQ,
@@ -537,7 +537,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &tcs3400_drv,
.drv_data = &g_tcs3400_data,
.port = I2C_PORT_ALS,
- .addr = TCS3400_I2C_ADDR,
+ .i2c_spi_addr__7bf = TCS3400_I2C_ADDR__7bf,
.rot_standard_ref = NULL,
.default_range = 0x10000, /* scale = 1x, uscale = 0 */
.min_frequency = TCS3400_LIGHT_MIN_FREQ,
diff --git a/board/flapjack/board.h b/board/flapjack/board.h
new file mode 100644
index 0000000000..13a010f416
--- /dev/null
+++ b/board/flapjack/board.h
@@ -0,0 +1,331 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Configuration for Kukui */
+
+#ifndef __CROS_EC_BOARD_H
+#define __CROS_EC_BOARD_H
+
+/* Optional modules */
+#define CONFIG_ADC
+#undef CONFIG_ADC_WATCHDOG
+#define CONFIG_BOARD_VERSION_CBI
+#define CONFIG_CHIPSET_MT8183
+#define CONFIG_CMD_ACCELS
+#define CONFIG_CRC8
+#define CONFIG_CROS_BOARD_INFO
+#define CONFIG_EMULATED_SYSRQ
+#undef CONFIG_HIBERNATE
+#define CONFIG_I2C
+#define CONFIG_I2C_MASTER
+#define CONFIG_I2C_VIRTUAL_BATTERY
+#define CONFIG_I2C_PASSTHRU_RESTRICTED
+#define CONFIG_LED_COMMON
+#define CONFIG_LOW_POWER_IDLE
+#define CONFIG_POWER_COMMON
+#define CONFIG_SPI
+#define CONFIG_SPI_MASTER
+#define CONFIG_STM_HWTIMER32
+#define CONFIG_SWITCH
+#define CONFIG_WATCHDOG_HELP
+
+#define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands for testing */
+
+#undef CONFIG_UART_CONSOLE
+#define CONFIG_UART_CONSOLE 1
+#define CONFIG_UART_RX_DMA
+
+/* Bootblock */
+#ifdef SECTION_IS_RO
+#define CONFIG_BOOTBLOCK
+
+#define EMMC_SPI_PORT 2
+#endif
+
+/* Optional features */
+#define CONFIG_BOARD_PRE_INIT
+#define CONFIG_BUTTON_TRIGGERED_RECOVERY
+#define CONFIG_CHARGER_ILIM_PIN_DISABLED
+#define CONFIG_FORCE_CONSOLE_RESUME
+#define CONFIG_HOST_COMMAND_STATUS
+#define CONFIG_CMD_AP_RESET_LOG
+
+/* Required for FAFT */
+#define CONFIG_CMD_BUTTON
+
+/* By default, set hcdebug to off */
+#undef CONFIG_HOSTCMD_DEBUG_MODE
+#define CONFIG_HOSTCMD_DEBUG_MODE HCDEBUG_OFF
+#define CONFIG_LTO
+#define CONFIG_POWER_BUTTON
+#define CONFIG_POWER_BUTTON_IGNORE_LID
+#define CONFIG_POWER_TRACK_HOST_SLEEP_STATE
+#define CONFIG_SOFTWARE_PANIC
+#define CONFIG_VBOOT_HASH
+#define CONFIG_VOLUME_BUTTONS
+
+#define CONFIG_CHARGER
+#define CONFIG_CHARGER_MT6370
+#define CONFIG_CHARGER_INPUT_CURRENT 512
+#define CONFIG_CHARGER_V2
+#define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2
+#define CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT 2
+#define CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW 15000
+#define CONFIG_CHARGER_PROFILE_OVERRIDE
+#define CONFIG_CHARGER_DISCHARGE_ON_AC
+#define CONFIG_CHARGER_OTG
+#define CONFIG_USB_CHARGER
+#define CONFIG_USB_MUX_VIRTUAL
+
+/* Increase tx buffer size, as we'd like to stream EC log to AP. */
+#undef CONFIG_UART_TX_BUF_SIZE
+#define CONFIG_UART_TX_BUF_SIZE 4096
+
+/* Motion Sensors */
+#ifdef SECTION_IS_RW
+#define CONFIG_ACCELGYRO_BMI160
+#define CONFIG_ACCEL_INTERRUPTS
+#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL)
+
+#define CONFIG_ALS
+#define ALS_COUNT 1
+
+/* TSC3400 ALS */
+#define CONFIG_ALS_TCS3400
+#define CONFIG_ALS_TCS3400_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(CLEAR_ALS)
+
+/* ALS needs to be polled */
+#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(CLEAR_ALS)
+
+/* Camera VSYNC */
+#define CONFIG_SYNC
+#define CONFIG_SYNC_COMMAND
+#define CONFIG_SYNC_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(VSYNC)
+#endif /* SECTION_IS_RW */
+
+/* To be able to indicate the device is in tablet mode. */
+#define CONFIG_TABLET_MODE
+#define CONFIG_TABLET_MODE_SWITCH
+
+/* FIFO size is in power of 2. */
+#define CONFIG_ACCEL_FIFO 256
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
+
+/* Wireless Power Charger Config */
+#ifdef SECTION_IS_RW
+#define CONFIG_WIRELESS_CHARGER_P9221_R7
+#endif
+
+
+/* USB PD config */
+#define CONFIG_CHARGE_MANAGER
+#define CONFIG_USB_POWER_DELIVERY
+#define CONFIG_USB_PD_ALT_MODE
+#define CONFIG_USB_PD_ALT_MODE_DFP
+#define CONFIG_USB_PD_DISCHARGE_TCPC
+#define CONFIG_USB_PD_DUAL_ROLE
+#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
+#define CONFIG_USB_PD_LOGGING
+#define CONFIG_USB_PD_PORT_COUNT 1
+#define CONFIG_USB_PD_TCPC_LOW_POWER
+#define CONFIG_USB_PD_TCPM_MT6370
+#define CONFIG_USB_PD_TCPM_TCPCI
+#define CONFIG_USB_PD_VBUS_DETECT_TCPC
+#define CONFIG_USB_PD_5V_CHARGER_CTRL
+#define CONFIG_USBC_SS_MUX
+#define CONFIG_USBC_VCONN
+#define CONFIG_USBC_VCONN_SWAP
+#define CONFIG_USB_PD_COMM_LOCKED
+#define CONFIG_USBC_DISABLE_CHARGE_FROM_RP_DEF
+#ifdef SECTION_IS_RO
+#define CONFIG_USB_PD_DEBUG_LEVEL 0
+#endif
+
+#define CONFIG_BATTERY_CUT_OFF
+#define CONFIG_BATTERY_PRESENT_CUSTOM
+#define CONFIG_BATTERY_REVIVE_DISCONNECT
+#define CONFIG_BATTERY_MAX17055
+#define CONFIG_BATTERY_MAX17055_ALERT
+#define CONFIG_BATTERY_MAX17055_FULL_MODEL
+
+/* Battery parameters for max17055 ModelGauge m5 algorithm. */
+#define BATTERY_MAX17055_RSENSE 10 /* m-ohm */
+#define BATTERY_DESIRED_CHARGING_CURRENT 2000 /* mA */
+
+#define PD_OPERATING_POWER_MW 15000
+#define PD_MAX_VOLTAGE_MV 9000
+#define PD_MAX_CURRENT_MA 3000
+#define PD_MAX_POWER_MW 18000
+
+#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
+#define PD_POWER_SUPPLY_TURN_OFF_DELAY 50000 /* us */
+#define PD_VCONN_SWAP_DELAY 5000 /* us */
+
+/* Timer selection */
+#define TIM_CLOCK32 2
+#define TIM_WATCHDOG 7
+
+/* 48 MHz SYSCLK clock frequency */
+#define CPU_CLOCK 48000000
+
+/* Optional for testing */
+#undef CONFIG_PECI
+#undef CONFIG_PSTORE
+
+/* Modules we want to exclude */
+#undef CONFIG_CMD_ACCELSPOOF
+#undef CONFIG_CMD_APTHROTTLE
+#undef CONFIG_CMD_BATTFAKE
+#undef CONFIG_CMD_DEVICE_EVENT
+#undef CONFIG_CMD_FASTCHARGE
+#undef CONFIG_CMD_FLASH
+#undef CONFIG_CMD_GETTIME
+#undef CONFIG_CMD_HASH
+#undef CONFIG_CMD_HCDEBUG
+#undef CONFIG_CMD_MD
+#undef CONFIG_CMD_MEM
+#undef CONFIG_CMD_POWERINDEBUG
+#undef CONFIG_CMD_TIMERINFO
+
+#ifdef SECTION_IS_RO
+#undef CONFIG_CMD_ADC
+#undef CONFIG_CMD_APTHROTTLE
+#undef CONFIG_CMD_CBI
+#undef CONFIG_CMD_I2C_SCAN
+#undef CONFIG_CMD_I2C_XFER
+#undef CONFIG_CMD_IDLE_STATS
+#undef CONFIG_CMD_INA
+#undef CONFIG_CMD_MMAPINFO
+#undef CONFIG_CMD_PD
+#undef CONFIG_CMD_PWR_AVG
+#undef CONFIG_CMD_REGULATOR
+#undef CONFIG_CMD_RW
+#undef CONFIG_CMD_SHMEM
+/* TODO: Consider put these back when FSI is (about to be) done. */
+#undef CONFIG_CMD_SLEEPMASK
+#undef CONFIG_CMD_SLEEPMASK_SET
+#undef CONFIG_CMD_SYSLOCK
+#endif
+
+#define CONFIG_TASK_PROFILING
+
+/* I2C ports */
+#define I2C_PORT_CHARGER 0
+#define I2C_PORT_TCPC0 0
+#define I2C_PORT_WPC 0
+#define I2C_PORT_BATTERY 1
+#define I2C_PORT_VIRTUAL_BATTERY I2C_PORT_BATTERY
+#define I2C_PORT_ACCEL 1
+#define I2C_PORT_ALS 1
+#define I2C_PORT_EEPROM 1
+
+/* I2C addresses */
+#define I2C_ADDR_EEPROM__7bf 0x50
+
+/* Route sbs host requests to virtual battery driver */
+#define VIRTUAL_BATTERY_ADDR__7bf 0x0B
+
+/* Enable Accel over SPI */
+#define CONFIG_SPI_ACCEL_PORT 0 /* The first SPI master port (SPI2) */
+
+#define CONFIG_KEYBOARD_PROTOCOL_MKBP
+#define CONFIG_MKBP_EVENT
+#define CONFIG_MKBP_USE_GPIO
+/* Define the host events which are allowed to wakeup AP in S3. */
+#define CONFIG_MKBP_HOST_EVENT_WAKEUP_MASK \
+ (EC_HOST_EVENT_MASK(EC_HOST_EVENT_POWER_BUTTON) |\
+ EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC))
+
+/* Define panel size mask according to skuid */
+#define SKU_ID_PANEL_SIZE_MASK BIT(1)
+
+#ifndef __ASSEMBLER__
+
+enum oem_id {
+ PROJECT_FLAPJACK = 0,
+ PROJECT_COUNT,
+};
+
+enum adc_channel {
+ /* Real ADC channels begin here */
+ ADC_LCM_ID = 0,
+ ADC_EC_SKU_ID,
+ ADC_BATT_ID,
+ ADC_USBC_THERM,
+ ADC_CH_COUNT
+};
+
+/* Panel ID bit position inside sku_id */
+#define PANEL_ID_BIT_POSITION 16
+
+/* Refer to coreboot/src/mainboard/google/kukui/display.h */
+enum panel_id {
+ PANEL_DEFAULT = 0,
+ PANEL_BOE_TV101WUM_NG0,
+ PANEL_BOE_TV080WUM_NG0,
+ PANEL_STA_10P,
+ PANEL_STA_08P,
+ PANEL_COUNT,
+ PANEL_UNINITIALIZED = 0xf,
+};
+
+/* power signal definitions */
+enum power_signal {
+ AP_IN_S3_L,
+ PMIC_PWR_GOOD,
+
+ /* Number of signals */
+ POWER_SIGNAL_COUNT,
+};
+
+/* Motion sensors */
+enum sensor_id {
+ LID_ACCEL = 0,
+ LID_GYRO,
+ CLEAR_ALS,
+ RGB_ALS,
+ VSYNC,
+ SENSOR_COUNT,
+};
+
+/* Batteries */
+enum battery_type {
+ BATTERY_UNKNOWN = 0,
+ BATTERY_C18_ATL,
+ BATTERY_C19_ATL,
+ BATTERY_C18_SUNWODA,
+ BATTERY_C19_SUNWODA,
+ BATTERY_COUNT,
+};
+
+#include "gpio_signal.h"
+#include "registers.h"
+
+#ifdef SECTION_IS_RO
+/* Interrupt handler for emmc task */
+void emmc_cmd_interrupt(enum gpio_signal signal);
+#endif
+
+void board_reset_pd_mcu(void);
+
+#define ADC_MARGIN_MV 56 /* Simply assume 1800/16/2 */
+
+struct mv_to_id {
+ int id;
+ int median_mv;
+};
+
+int board_read_id(enum adc_channel, const struct mv_to_id *table, int size);
+
+extern uint8_t board_version;
+extern uint8_t oem;
+extern uint32_t sku;
+
+#endif /* !__ASSEMBLER__ */
+
+#endif /* __CROS_EC_BOARD_H */
diff --git a/board/fleex/board.c b/board/fleex/board.c
index 9406e1b2c9..444d585308 100644
--- a/board/fleex/board.c
+++ b/board/fleex/board.c
@@ -48,17 +48,7 @@
#define USB_PD_PORT_ANX7447 0
#define USB_PD_PORT_PS8751 1
-static void tcpc_alert_event(enum gpio_signal signal)
-{
- if ((signal == GPIO_USB_C1_MUX_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C1_PD_RST_ODL))
- return;
-
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
-}
+static uint8_t sku_id;
static void ppc_interrupt(enum gpio_signal signal)
{
@@ -90,15 +80,6 @@ const struct adc_t adc_channels[] = {
};
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
-enum adc_channel board_get_vbus_adc(int port)
-{
- if (port == USB_PD_PORT_ANX7447)
- return ADC_VBUS_C0;
- if (port == USB_PD_PORT_PS8751)
- return ADC_VBUS_C1;
- return ADC_VBUS_C0;
-}
-
const struct temp_sensor_t temp_sensors[] = {
[TEMP_SENSOR_BATTERY] = {.name = "Battery",
.type = TEMP_SENSOR_TYPE_BATTERY,
@@ -140,35 +121,34 @@ const mat33_fp_t lid_standard_ref = {
static struct stprivate_data g_lis2dh_data;
static struct lsm6dsm_data lsm6dsm_data;
-static uint16_t sku_id;
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
- .name = "Lid Accel",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_LIS2DE,
- .type = MOTIONSENSE_TYPE_ACCEL,
- .location = MOTIONSENSE_LOC_LID,
- .drv = &lis2dh_drv,
- .mutex = &g_lid_mutex,
- .drv_data = &g_lis2dh_data,
- .port = I2C_PORT_SENSOR,
- .addr = LIS2DH_ADDR1,
- .rot_standard_ref = &lid_standard_ref,
- .default_range = 2, /* g */
- /* We only use 2g because its resolution is only 8-bits */
- .min_frequency = LIS2DH_ODR_MIN_VAL,
- .max_frequency = LIS2DH_ODR_MAX_VAL,
- .config = {
- /* EC use accel for angle detection */
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- /* Sensor on for lid angle detection */
- [SENSOR_CONFIG_EC_S3] = {
- .odr = 10000 | ROUND_UP_FLAG,
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_LIS2DE,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &lis2dh_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_lis2dh_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = LIS2DH_ADDR1__7bf,
+ .rot_standard_ref = &lid_standard_ref,
+ .default_range = 2, /* g */
+ /* We only use 2g because its resolution is only 8-bits */
+ .min_frequency = LIS2DH_ODR_MIN_VAL,
+ .max_frequency = LIS2DH_ODR_MAX_VAL,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
},
- },
},
[BASE_ACCEL] = {
@@ -184,7 +164,7 @@ struct motion_sensor_t motion_sensors[] = {
.int_signal = GPIO_BASE_SIXAXIS_INT_L,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
.port = I2C_PORT_SENSOR,
- .addr = LSM6DSM_ADDR0,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR0__7bf,
.rot_standard_ref = &base_standard_ref,
.default_range = 4, /* g */
.min_frequency = LSM6DSM_ODR_MIN_VAL,
@@ -216,7 +196,7 @@ struct motion_sensor_t motion_sensors[] = {
.int_signal = GPIO_BASE_SIXAXIS_INT_L,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
.port = I2C_PORT_SENSOR,
- .addr = LSM6DSM_ADDR0,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR0__7bf,
.default_range = 1000 | ROUND_UP_FLAG, /* dps */
.rot_standard_ref = &base_standard_ref,
.min_frequency = LSM6DSM_ODR_MIN_VAL,
@@ -231,12 +211,19 @@ static int board_is_convertible(void)
return sku_id == 0x21 || sku_id == 0x22 || sku_id == 0xff;
}
-static void board_set_motion_sensor_count(void)
+static void board_update_sensor_config_from_sku(void)
{
- if (board_is_convertible())
+ if (board_is_convertible()) {
motion_sensor_count = ARRAY_SIZE(motion_sensors);
- else
+ /* Enable Base Accel interrupt */
+ gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
+ } else {
motion_sensor_count = 0;
+ hall_sensor_disable();
+ /* Base accel is not stuffed, don't allow line to float */
+ gpio_set_flags(GPIO_BASE_SIXAXIS_INT_L,
+ GPIO_INPUT | GPIO_PULL_DOWN);
+ }
}
static void cbi_init(void)
@@ -247,18 +234,10 @@ static void cbi_init(void)
sku_id = val;
ccprints("SKU: 0x%04x", sku_id);
- board_set_motion_sensor_count();
+ board_update_sensor_config_from_sku();
}
DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_INIT_I2C + 1);
-/* Initialize board. */
-static void board_init(void)
-{
- /* Enable Base Accel interrupt */
- gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
-}
-DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
-
#ifndef TEST_BUILD
/* This callback disables keyboard when convertibles are fully open */
void lid_angle_peripheral_enable(int enable)
@@ -275,32 +254,12 @@ void lid_angle_peripheral_enable(int enable)
}
#endif
-/*
- * Set gpio flags based on board ID, can be removed when proto is no longer
- * supported
- */
-static void update_gpios_from_board_id(void)
+void board_overcurrent_event(int port, int is_overcurrented)
{
- uint32_t board_id = 0;
-
- /* Errors will count as board_id 0 */
- cbi_get_board_version(&board_id);
-
- if (board_id == 0) {
- /*
- * USB2_OTG_ID is a 1.8V pin on the SoC side with an internal
- * pull-up. However, it is 3.3V on the EC side. So, configure
- * it as ODR so that the EC never drives it high.
- */
- gpio_set_flags(GPIO_USB_C0_PD_RST, GPIO_ODR_LOW);
- } else {
- int flags = GPIO_OUTPUT;
-
- if (!system_is_reboot_warm() && !system_jumped_to_this_image())
- flags |= GPIO_LOW;
+ /* Sanity check the port. */
+ if ((port < 0) || (port >= CONFIG_USB_PD_PORT_COUNT))
+ return;
- gpio_set_flags(GPIO_USB_C0_PD_RST, flags);
- }
+ /* Note that the level is inverted because the pin is active low. */
+ gpio_set_level(GPIO_USB_C_OC, !is_overcurrented);
}
-
-DECLARE_HOOK(HOOK_INIT, update_gpios_from_board_id, HOOK_PRIO_INIT_I2C + 1);
diff --git a/board/fluffy/board.c b/board/fluffy/board.c
new file mode 100644
index 0000000000..4631b4a851
--- /dev/null
+++ b/board/fluffy/board.c
@@ -0,0 +1,405 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Fluffy configuration */
+
+#include "adc.h"
+#include "adc_chip.h"
+#include "common.h"
+#include "console.h"
+#include "ec_version.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "usb_descriptor.h"
+#include "registers.h"
+#include "timer.h"
+#include "usb_pd.h"
+#include "util.h"
+
+#include "gpio_list.h"
+
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args)
+
+/******************************************************************************
+ * Define the strings used in our USB descriptors.
+ */
+
+const void *const usb_strings[] = {
+ [USB_STR_DESC] = usb_string_desc,
+ [USB_STR_VENDOR] = USB_STRING_DESC("Google Inc."),
+ [USB_STR_PRODUCT] = USB_STRING_DESC("Fluffy"),
+ /* This gets filled in at runtime. */
+ [USB_STR_SERIALNO] = USB_STRING_DESC(""),
+ [USB_STR_VERSION] = USB_STRING_DESC(CROS_EC_VERSION32),
+ [USB_STR_CONSOLE_NAME] = USB_STRING_DESC("Fluffy Shell"),
+};
+
+BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT);
+
+/* ADC channels */
+const struct adc_t adc_channels[] = {
+ /* Sensing the VBUS voltage at the DUT side. Converted to mV. */
+ [ADC_PPVAR_VBUS_DUT] = {
+ .name = "PPVAR_VBUS_DUT",
+ .factor_mul = 3300,
+ .factor_div = 4096,
+ .shift = 0,
+ .channel = STM32_AIN(0),
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
+
+/* I2C ports */
+const struct i2c_port_t i2c_ports[] = {
+ {
+ .name = "master",
+ .port = 1,
+ .kbps = 400,
+ .scl = GPIO_I2C_SCL,
+ .sda = GPIO_I2C_SDA,
+ },
+};
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+
+static enum gpio_signal enabled_port = GPIO_EN_C0;
+static uint8_t output_en;
+
+static void print_port_status(void)
+{
+ if (!output_en)
+ CPRINTS("No ports enabled. zZZ");
+ else
+ CPRINTS("Port %d is ON", enabled_port - GPIO_EN_C0);
+
+ CPRINTS("CC Flip: %s", gpio_get_level(GPIO_EN_CC_FLIP) ? "YES" : "NO");
+ CPRINTS("USB MUX: %s", gpio_get_level(GPIO_EN_USB_MUX2) ? "ON" : "OFF");
+}
+
+static int command_cc_flip(int argc, char *argv[])
+{
+ int enable;
+
+ if (argc != 2)
+ return EC_ERROR_PARAM_COUNT;
+
+ if (!parse_bool(argv[1], &enable))
+ return EC_ERROR_INVAL;
+
+ if (output_en) {
+ gpio_set_level(enabled_port, 0);
+ gpio_set_level(GPIO_EN_USB_MUX2, 0);
+ /* Wait long enough for CC to discharge. */
+ usleep(500 * MSEC);
+ }
+
+ gpio_set_level(GPIO_EN_CC_FLIP, enable);
+ /* Allow some time for new CC configuration to settle. */
+ usleep(500 * MSEC);
+
+ if (output_en) {
+ gpio_set_level(enabled_port, 1);
+ gpio_set_level(GPIO_EN_USB_MUX2, 1);
+ }
+
+ print_port_status();
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(ccflip, command_cc_flip,
+ "<enable/disable>",
+ "enable or disable flipping CC orientation");
+/*
+ * Support tca6416 I2C ioexpander.
+ */
+#define GPIOX_I2C_ADDR__7bf 0x20
+#define GPIOX_IN_PORT_A 0x0
+#define GPIOX_IN_PORT_B 0x1
+#define GPIOX_OUT_PORT_A 0x2
+#define GPIOX_OUT_PORT_B 0x3
+#define GPIOX_DIR_PORT_A 0x6
+#define GPIOX_DIR_PORT_B 0x7
+#define I2C_PORT_MASTER 1
+
+static void i2c_expander_init(void)
+{
+ gpio_set_level(GPIO_XP_RESET_L, 1);
+
+ /*
+ * Setup P00, P02, P04, P10, and P12 on the I/O expander as an output.
+ */
+ i2c_write8__7bf(I2C_PORT_MASTER, GPIOX_I2C_ADDR__7bf,
+ GPIOX_DIR_PORT_A, 0xea);
+ i2c_write8__7bf(I2C_PORT_MASTER, GPIOX_I2C_ADDR__7bf,
+ GPIOX_DIR_PORT_B, 0xfa);
+}
+DECLARE_HOOK(HOOK_INIT, i2c_expander_init, HOOK_PRIO_INIT_I2C+1);
+
+/* Write to a GPIO register on the tca6416 I2C ioexpander. */
+static void write_ioexpander(int bank, int gpio, int reg, int val)
+{
+ int tmp;
+
+ /* Read output port register */
+ i2c_read8__7bf(I2C_PORT_MASTER, GPIOX_I2C_ADDR__7bf,
+ reg + bank, &tmp);
+ if (val)
+ tmp |= BIT(gpio);
+ else
+ tmp &= ~BIT(gpio);
+ /* Write back modified output port register */
+ i2c_write8__7bf(I2C_PORT_MASTER, GPIOX_I2C_ADDR__7bf,
+ reg + bank, tmp);
+}
+
+enum led_ch {
+ LED_5V = 0,
+ LED_9V,
+ LED_12V,
+ LED_15V,
+ LED_20V,
+ LED_COUNT,
+};
+
+static void set_led(enum led_ch led, int enable)
+{
+ int bank;
+ int gpio;
+
+ switch (led) {
+ case LED_5V:
+ bank = 0;
+ gpio = 0;
+ break;
+
+ case LED_9V:
+ bank = 0;
+ gpio = 2;
+ break;
+
+ case LED_12V:
+ bank = 0;
+ gpio = 4;
+ break;
+
+ case LED_15V:
+ bank = 1;
+ gpio = 0;
+ break;
+
+ case LED_20V:
+ bank = 1;
+ gpio = 2;
+ break;
+
+ default:
+ return;
+ }
+
+ /*
+ * Setup the LED as an output if enabled, otherwise as an input to keep
+ * the LEDs off.
+ */
+ write_ioexpander(bank, gpio, GPIOX_DIR_PORT_A, !enable);
+
+ /* The LEDs are active low. */
+ if (enable)
+ write_ioexpander(bank, gpio, GPIOX_OUT_PORT_A, 0);
+}
+
+void show_output_voltage_on_leds(void);
+DECLARE_DEFERRED(show_output_voltage_on_leds);
+
+static void board_init(void)
+{
+ /* Do a sweeping LED dance. */
+ for (enum led_ch led = 0; led < LED_COUNT; led++) {
+ set_led(led, 1);
+ msleep(100);
+ }
+
+ msleep(500);
+
+ for (enum led_ch led = 0; led < LED_COUNT; led++)
+ set_led(led, 0);
+
+ show_output_voltage_on_leds();
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+
+
+enum usb_mux {
+ USB_MUX0 = 0,
+ USB_MUX1,
+ USB_MUX2,
+ USB_MUX_COUNT,
+};
+
+static void set_mux(enum usb_mux mux, uint8_t val)
+{
+ enum gpio_signal c0;
+ enum gpio_signal c1;
+ enum gpio_signal c2;
+
+ switch (mux) {
+ case USB_MUX0:
+ c0 = GPIO_USB_MUX0_C0;
+ c1 = GPIO_USB_MUX0_C1;
+ c2 = GPIO_USB_MUX0_C2;
+ break;
+
+ case USB_MUX1:
+ c0 = GPIO_USB_MUX1_C0;
+ c1 = GPIO_USB_MUX1_C1;
+ c2 = GPIO_USB_MUX1_C2;
+ break;
+
+ case USB_MUX2:
+ c0 = GPIO_USB_MUX2_C0;
+ c1 = GPIO_USB_MUX2_C1;
+ c2 = GPIO_USB_MUX2_C2;
+ break;
+
+ default:
+ break;
+ }
+
+ val &= 0x7;
+
+ gpio_set_level(c0, val & BIT(0));
+ gpio_set_level(c1, val & BIT(1));
+ gpio_set_level(c2, val & BIT(2));
+}
+
+/* This function assumes only 1 port works at a time. */
+static int command_portctl(int argc, char **argv)
+{
+ int port;
+ int enable;
+
+ if (argc < 2)
+ return EC_ERROR_PARAM_COUNT;
+
+ port = atoi(argv[1]);
+ if ((port < 0) || (port > 19) || !parse_bool(argv[2], &enable))
+ return EC_ERROR_INVAL;
+
+ gpio_set_level(GPIO_EN_USB_MUX2, 0);
+
+ /*
+ * For each port, we must configure the USB 2.0 muxes and make sure that
+ * the power enables are configured as desired.
+ */
+
+ gpio_set_level(enabled_port, 0);
+ if (enabled_port != GPIO_EN_C0 + port)
+ CPRINTS("Port %d: disabled", enabled_port-GPIO_EN_C0);
+
+ /* Allow time for an "unplug" to allow VBUS and CC to fall. */
+ usleep(1 * SECOND);
+
+ /*
+ * The USB 2.0 lines are arranged using 3x 8:1 muxes. Ports 0-7 are
+ * handled by the first mux, ports 8-15 are handled by the 2nd mux, then
+ * the outputs of those muxes are fed into the third mux along with
+ * ports 16-19. The schematic contains the truth table.
+ */
+ if (enable) {
+ enabled_port = GPIO_EN_C0 + port;
+ gpio_set_level(enabled_port, 1);
+
+ if (port < 8) {
+ set_mux(USB_MUX0, 7-port);
+ set_mux(USB_MUX2, 3);
+ } else if (port < 16) {
+ if (port < 14)
+ set_mux(USB_MUX1, 5-(port-8));
+ else
+ set_mux(USB_MUX1, 7-(port-14));
+
+ set_mux(USB_MUX2, 1);
+ } else {
+ set_mux(USB_MUX2, 7-(port-16));
+ }
+
+ gpio_set_level(GPIO_EN_USB_MUX2, 1);
+ output_en = 1;
+ } else {
+ gpio_set_level(enabled_port, 0);
+ output_en = 0;
+ }
+
+ print_port_status();
+ return EC_SUCCESS;
+}
+
+DECLARE_CONSOLE_COMMAND(portctl, command_portctl,
+ "<port# 0-19> <enable/disable>",
+ "enable or disable a port");
+
+static int command_status(int argc, char **argv)
+{
+ int vbus_mv = adc_read_channel(ADC_PPVAR_VBUS_DUT);
+
+ CPRINTS("PPVAR_VBUS_DUT: %dmV (raw: %d)", vbus_mv*7692/1000,
+ vbus_mv);
+ print_port_status();
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(status, command_status, NULL, "show current status");
+
+/*
+ * According to the USB PD Spec, the minimum voltage for a fixed source is 95%
+ * of the new source voltage with an additional 500mV drop.
+ *
+ * vSrcNew | min | vSrcNew(min) + vSrcValid
+ * 5V | 4.75V | 4.25V | 553mV
+ * 9V | 8.55V | 8.05V | 1047mV
+ * 12V | 11.4V | 10.9V | 1417mV
+ * 15V | 14.25V | 13.75V | 1788mV
+ * 20V | 19V | 18.5V | 2405mV
+ *
+ * With the resistor divider that fluffy has, the ADC is only seeing 0.13 of the
+ * actual voltage.
+ */
+void show_output_voltage_on_leds(void)
+{
+ int vbus_mv = adc_read_channel(ADC_PPVAR_VBUS_DUT);
+ static int prev_vbus_mv;
+ int i;
+ int act;
+ enum led_ch max_on_exclusive = LED_5V;
+
+ if (vbus_mv != ADC_READ_ERROR) {
+ if (vbus_mv >= 2405)
+ max_on_exclusive = LED_COUNT;
+ else if (vbus_mv >= 1788)
+ max_on_exclusive = LED_20V;
+ else if (vbus_mv >= 1417)
+ max_on_exclusive = LED_15V;
+ else if (vbus_mv >= 1047)
+ max_on_exclusive = LED_12V;
+ else if (vbus_mv >= 553)
+ max_on_exclusive = LED_9V;
+
+ for (i = 0; i < LED_COUNT; i++)
+ set_led(i, i < max_on_exclusive);
+
+ act = (vbus_mv * 7692) / 1000;
+ if ((vbus_mv > prev_vbus_mv+2) || (vbus_mv < prev_vbus_mv-2)) {
+ CPRINTS("PPVAR_VBUS_DUT: %d mV (raw: %d)", act,
+ vbus_mv);
+ prev_vbus_mv = vbus_mv;
+ }
+ }
+
+ /*
+ * The reason we reschedule this ourselves as opposed to declaring it as
+ * a hook with a HOOK_TICK period is to allow the LED sweep sequence
+ * when the board boots up.
+ */
+ hook_call_deferred(&show_output_voltage_on_leds_data,
+ 500 * MSEC);
+}
diff --git a/board/garg/board.c b/board/garg/board.c
new file mode 100644
index 0000000000..b0ec0ef955
--- /dev/null
+++ b/board/garg/board.c
@@ -0,0 +1,337 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Garg board-specific configuration */
+
+#include "adc.h"
+#include "adc_chip.h"
+#include "battery.h"
+#include "button.h"
+#include "charge_manager.h"
+#include "charge_state.h"
+#include "common.h"
+#include "cros_board_info.h"
+#include "driver/accel_kionix.h"
+#include "driver/accelgyro_bmi160.h"
+#include "driver/charger/bd9995x.h"
+#include "driver/ppc/nx20p348x.h"
+#include "driver/sync.h"
+#include "driver/tcpm/anx7447.h"
+#include "driver/tcpm/ps8xxx.h"
+#include "driver/tcpm/tcpci.h"
+#include "driver/tcpm/tcpm.h"
+#include "extpower.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "keyboard_scan.h"
+#include "lid_switch.h"
+#include "motion_sense.h"
+#include "power.h"
+#include "power_button.h"
+#include "switch.h"
+#include "system.h"
+#include "tablet_mode.h"
+#include "tcpci.h"
+#include "temp_sensor.h"
+#include "thermistor.h"
+#include "usb_mux.h"
+#include "usbc_ppc.h"
+#include "util.h"
+
+#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
+#define USB_PD_PORT_ANX7447 0
+#define USB_PD_PORT_PS8751 1
+
+static uint8_t sku_id;
+
+/*
+ * We have total 30 pins for keyboard connecter {-1, -1} mean
+ * the N/A pin that don't consider it and reserve index 0 area
+ * that we don't have pin 0.
+ */
+const int keyboard_factory_scan_pins[][2] = {
+ {-1, -1}, {0, 5}, {1, 1}, {1, 0}, {0, 6},
+ {0, 7}, {-1, -1}, {-1, -1}, {1, 4}, {1, 3},
+ {-1, -1}, {1, 6}, {1, 7}, {3, 1}, {2, 0},
+ {1, 5}, {2, 6}, {2, 7}, {2, 1}, {2, 4},
+ {2, 5}, {1, 2}, {2, 3}, {2, 2}, {3, 0},
+ {-1, -1}, {0, 4}, {-1, -1}, {8, 2}, {-1, -1},
+ {-1, -1},
+};
+
+const int keyboard_factory_scan_pins_used =
+ ARRAY_SIZE(keyboard_factory_scan_pins);
+
+static void ppc_interrupt(enum gpio_signal signal)
+{
+ switch (signal) {
+ case GPIO_USB_PD_C0_INT_ODL:
+ nx20p348x_interrupt(0);
+ break;
+
+ case GPIO_USB_PD_C1_INT_ODL:
+ nx20p348x_interrupt(1);
+ break;
+
+ default:
+ break;
+ }
+}
+
+/* Must come after other header files and GPIO interrupts*/
+#include "gpio_list.h"
+
+/* ADC channels */
+const struct adc_t adc_channels[] = {
+ [ADC_TEMP_SENSOR_AMB] = {
+ "TEMP_AMB", NPCX_ADC_CH0, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+ [ADC_TEMP_SENSOR_CHARGER] = {
+ "TEMP_CHARGER", NPCX_ADC_CH1, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+ /* Vbus sensing (1/10 voltage divider). */
+ [ADC_VBUS_C0] = {
+ "VBUS_C0", NPCX_ADC_CH9, ADC_MAX_VOLT*10, ADC_READ_MAX+1, 0},
+ [ADC_VBUS_C1] = {
+ "VBUS_C1", NPCX_ADC_CH4, ADC_MAX_VOLT*10, ADC_READ_MAX+1, 0},
+};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
+
+const struct temp_sensor_t temp_sensors[] = {
+ [TEMP_SENSOR_BATTERY] = {.name = "Battery",
+ .type = TEMP_SENSOR_TYPE_BATTERY,
+ .read = charge_get_battery_temp,
+ .idx = 0,
+ .action_delay_sec = 1},
+ [TEMP_SENSOR_AMBIENT] = {.name = "Ambient",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_AMB,
+ .action_delay_sec = 5},
+ [TEMP_SENSOR_CHARGER] = {.name = "Charger",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_13k7_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_CHARGER,
+ .action_delay_sec = 1},
+};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
+
+/* Motion sensors */
+/* Mutexes */
+static struct mutex g_lid_mutex;
+static struct mutex g_base_mutex;
+
+/* Matrix to rotate accelrator into standard reference frame */
+const mat33_fp_t base_standard_ref = {
+ { 0, FLOAT_TO_FP(-1), 0},
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
+/* TODO: Tune the rot_standard_ref values after got mockup or system */
+const mat33_fp_t base_ar_cam_ref = {
+ { 0, FLOAT_TO_FP(-0.96126), FLOAT_TO_FP(0.27564)},
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, FLOAT_TO_FP(0.27564), FLOAT_TO_FP(0.96126)}
+};
+
+/* sensor private data */
+static struct kionix_accel_data g_kx022_data;
+static struct bmi160_drv_data_t g_bmi160_data;
+
+/* Drivers */
+struct motion_sensor_t motion_sensors[] = {
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_KX022,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &kionix_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_kx022_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
+ .rot_standard_ref = NULL, /* Identity matrix. */
+ .default_range = 4, /* g */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+ [BASE_ACCEL] = {
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi160_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
+ .rot_standard_ref = &base_standard_ref,
+ .default_range = 4, /* g */
+ .min_frequency = BMI160_ACCEL_MIN_FREQ,
+ .max_frequency = BMI160_ACCEL_MAX_FREQ,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 13000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on for angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ },
+ },
+ [BASE_GYRO] = {
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi160_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = BMI160_GYRO_MIN_FREQ,
+ .max_frequency = BMI160_GYRO_MAX_FREQ,
+ },
+ [VSYNC] = {
+ .name = "Camera VSYNC",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .chip = MOTIONSENSE_CHIP_GPIO,
+ .type = MOTIONSENSE_TYPE_SYNC,
+ .location = MOTIONSENSE_LOC_CAMERA,
+ .drv = &sync_drv,
+ .default_range = 0,
+ .min_frequency = 0,
+ .max_frequency = 1,
+ },
+};
+
+unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+static int board_is_convertible(void)
+{
+ /* Garg: TBD */
+ return sku_id == 255;
+}
+
+static int board_with_ar_cam(void)
+{
+ /* SKU ID of Garg with AR Cam: TBD */
+ return 255;
+}
+
+static void board_update_sensor_config_from_sku(void)
+{
+ if (board_is_convertible()) {
+ motion_sensor_count = ARRAY_SIZE(motion_sensors);
+ /* Enable Base Accel interrupt */
+ gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
+ } else {
+ motion_sensor_count = 0;
+ hall_sensor_disable();
+ /* Base accel is not stuffed, don't allow line to float */
+ gpio_set_flags(GPIO_BASE_SIXAXIS_INT_L,
+ GPIO_INPUT | GPIO_PULL_DOWN);
+ }
+
+ /* TODO: Garg has AR camera? Remove it if not support */
+ if (board_with_ar_cam()) {
+ /* Enable interrupt from camera */
+ gpio_enable_interrupt(GPIO_WFCAM_VSYNC);
+
+ motion_sensors[BASE_ACCEL].rot_standard_ref = &base_ar_cam_ref;
+ motion_sensors[BASE_GYRO].rot_standard_ref = &base_ar_cam_ref;
+ } else {
+ /* Camera isn't stuffed, don't allow line to float */
+ gpio_set_flags(GPIO_WFCAM_VSYNC, GPIO_INPUT | GPIO_PULL_DOWN);
+ }
+}
+
+/* Read CBI from i2c eeprom and initialize variables for board variants */
+static void cbi_init(void)
+{
+ uint32_t val;
+
+ if (cbi_get_sku_id(&val) != EC_SUCCESS || val > UINT8_MAX)
+ return;
+ sku_id = val;
+ CPRINTSUSB("SKU: %d", sku_id);
+
+ board_update_sensor_config_from_sku();
+}
+DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_INIT_I2C + 1);
+
+uint32_t board_override_feature_flags0(uint32_t flags0)
+{
+ /*
+ * Remove keyboard backlight feature for devices that don't support it.
+ */
+ if (sku_id == 255)
+ return flags0;
+ else
+ return (flags0 & ~EC_FEATURE_MASK_0(EC_FEATURE_PWM_KEYB));
+}
+
+uint32_t board_override_feature_flags1(uint32_t flags1)
+{
+ return flags1;
+}
+
+void board_hibernate_late(void)
+{
+ int i;
+
+ const uint32_t hibernate_pins[][2] = {
+ /* Turn off LEDs before going to hibernate */
+ {GPIO_BAT_LED_BLUE_L, GPIO_INPUT | GPIO_PULL_UP},
+ {GPIO_BAT_LED_ORANGE_L, GPIO_INPUT | GPIO_PULL_UP},
+ };
+
+ for (i = 0; i < ARRAY_SIZE(hibernate_pins); ++i)
+ gpio_set_flags(hibernate_pins[i][0], hibernate_pins[i][1]);
+}
+
+#ifndef TEST_BUILD
+/* This callback disables keyboard when convertibles are fully open */
+void lid_angle_peripheral_enable(int enable)
+{
+ /*
+ * If the lid is in tablet position via other sensors,
+ * ignore the lid angle, which might be faulty then
+ * disable keyboard.
+ */
+ if (tablet_get_mode())
+ enable = 0;
+ if (board_is_convertible())
+ keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE);
+}
+#endif
+
+void board_overcurrent_event(int port, int is_overcurrented)
+{
+ /* Sanity check the port. */
+ if ((port < 0) || (port >= CONFIG_USB_PD_PORT_COUNT))
+ return;
+
+ /* Note that the level is inverted because the pin is active low. */
+ gpio_set_level(GPIO_USB_C_OC, !is_overcurrented);
+}
diff --git a/board/glados/battery.c b/board/glados/battery.c
index 016d225950..d6c702127e 100644
--- a/board/glados/battery.c
+++ b/board/glados/battery.c
@@ -47,10 +47,10 @@ int board_cut_off_battery(void)
buf[2] = PARAM_CUT_OFF_HIGH;
i2c_lock(I2C_PORT_BATTERY, 1);
- rv = i2c_xfer_unlocked(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
- I2C_XFER_SINGLE);
- rv |= i2c_xfer_unlocked(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
- I2C_XFER_SINGLE);
+ rv = i2c_xfer_unlocked__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ buf, 3, NULL, 0, I2C_XFER_SINGLE);
+ rv |= i2c_xfer_unlocked__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ buf, 3, NULL, 0, I2C_XFER_SINGLE);
i2c_lock(I2C_PORT_BATTERY, 0);
return rv;
diff --git a/board/glados/board.c b/board/glados/board.c
index c24c3ebef6..46dd4de814 100644
--- a/board/glados/board.c
+++ b/board/glados/board.c
@@ -48,7 +48,7 @@
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
-#define I2C_ADDR_BD99992 0x60
+#define I2C_ADDR_BD99992__7bf 0x30
/* Exchange status with PD MCU. */
static void pd_mcu_interrupt(enum gpio_signal signal)
@@ -133,7 +133,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC,
- .addr = CONFIG_TCPC_I2C_BASE_ADDR,
+ .addr__7bf = CONFIG_TCPC_I2C_BASE_ADDR__7BF,
},
.drv = &tcpci_tcpm_drv,
},
@@ -141,7 +141,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC,
- .addr = CONFIG_TCPC_I2C_BASE_ADDR + 2,
+ .addr__7bf = CONFIG_TCPC_I2C_BASE_ADDR__7BF + 1,
},
.drv = &tcpci_tcpm_drv,
},
@@ -176,11 +176,11 @@ BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) ==
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
{
- .port_addr = 0xa8,
+ .port_addr = 0x54,
.driver = &pi3usb30532_usb_mux_driver,
},
{
- .port_addr = 0x20,
+ .port_addr = 0x10,
.driver = &ps874x_usb_mux_driver,
}
};
@@ -223,23 +223,23 @@ static void board_pmic_init(void)
return;
/* Set CSDECAYEN / VCCIO decays to 0V at assertion of SLP_S0# */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x30, 0x4a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x30, 0x4a);
/*
* Set V100ACNT / V1.00A Control Register:
* Nominal output = 1.0V.
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x37, 0x1a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x37, 0x1a);
/*
* Set V085ACNT / V0.85A Control Register:
* Lower power mode = 0.7V.
* Nominal output = 1.0V.
*/
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x38, 0x7a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x38, 0x7a);
/* VRMODECTRL - enable low-power mode for VCCIO and V0.85A */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x3b, 0x18);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x3b, 0x18);
}
DECLARE_HOOK(HOOK_INIT, board_pmic_init, HOOK_PRIO_DEFAULT);
diff --git a/board/glados/board.h b/board/glados/board.h
index 0cff78ba60..7393952873 100644
--- a/board/glados/board.h
+++ b/board/glados/board.h
@@ -134,7 +134,7 @@
#define I2C_PORT_THERMAL I2C_PORT_PMIC
/* Ambient Light Sensor address */
-#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
+#define OPT3001_I2C_ADDR__7bf OPT3001_I2C_ADDR1__7bf
/* Modules we want to exclude */
#undef CONFIG_CMD_HASH
diff --git a/board/glados_pd/board.h b/board/glados_pd/board.h
index 9310ee8715..0d513b6e67 100644
--- a/board/glados_pd/board.h
+++ b/board/glados_pd/board.h
@@ -97,7 +97,7 @@
/* slave address for host commands */
#ifdef HAS_TASK_HOSTCMD
-#define CONFIG_HOSTCMD_I2C_SLAVE_ADDR CONFIG_USB_PD_I2C_SLAVE_ADDR
+#define CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF CONFIG_USB_PD_I2C_SLAVE_ADDR__7BF
#endif
#ifndef __ASSEMBLER__
diff --git a/board/glkrvp/battery.c b/board/glkrvp/battery.c
index bb49336ecf..36dec46702 100644
--- a/board/glkrvp/battery.c
+++ b/board/glkrvp/battery.c
@@ -14,10 +14,10 @@
#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
#define I2C_PORT_PCA555_BATT_PRESENT_GPIO NPCX_I2C_PORT0_0
-#define I2C_ADDR_PCA555_BATT_PRESENT_GPIO 0x42
+#define I2C_ADDR_PCA555_BATT_PRESENT_GPIO__7bf 0x21
#define PCA555_BATT_PRESENT_GPIO_READ(reg, data) \
- pca9555_read(I2C_PORT_PCA555_BATT_PRESENT_GPIO, \
- I2C_ADDR_PCA555_BATT_PRESENT_GPIO, (reg), (data))
+ pca9555_read__7bf(I2C_PORT_PCA555_BATT_PRESENT_GPIO, \
+ I2C_ADDR_PCA555_BATT_PRESENT_GPIO__7bf, (reg), (data))
/* Shutdown mode parameter to write to manufacturer access register */
#define SB_SHUTDOWN_DATA 0x0010
diff --git a/board/glkrvp/board.c b/board/glkrvp/board.c
index 898c53971c..1ee956f522 100644
--- a/board/glkrvp/board.c
+++ b/board/glkrvp/board.c
@@ -29,19 +29,19 @@
#include "gpio_list.h"
#define I2C_PORT_PCA555_PMIC_GPIO NPCX_I2C_PORT0_0
-#define I2C_ADDR_PCA555_PMIC_GPIO 0x42
+#define I2C_ADDR_PCA555_PMIC_GPIO__7bf 0x21
#define PCA555_PMIC_GPIO_WRITE(reg, data) \
- pca9555_write(I2C_PORT_PCA555_PMIC_GPIO, \
- I2C_ADDR_PCA555_PMIC_GPIO, (reg), (data))
+ pca9555_write__7bf(I2C_PORT_PCA555_PMIC_GPIO, \
+ I2C_ADDR_PCA555_PMIC_GPIO__7bf, (reg), (data))
#define PCA555_PMIC_GPIO_READ(reg, data) \
- pca9555_read(I2C_PORT_PCA555_PMIC_GPIO, \
- I2C_ADDR_PCA555_PMIC_GPIO, (reg), (data))
+ pca9555_read__7bf(I2C_PORT_PCA555_PMIC_GPIO, \
+ I2C_ADDR_PCA555_PMIC_GPIO__7bf, (reg), (data))
#define I2C_PORT_PCA555_BOARD_ID_GPIO NPCX_I2C_PORT0_0
-#define I2C_ADDR_PCA555_BOARD_ID_GPIO 0x40
+#define I2C_ADDR_PCA555_BOARD_ID_GPIO__7bf 0x20
#define PCA555_BOARD_ID_GPIO_READ(reg, data) \
- pca9555_read(I2C_PORT_PCA555_BOARD_ID_GPIO, \
- I2C_ADDR_PCA555_BOARD_ID_GPIO, (reg), (data))
+ pca9555_read__7bf(I2C_PORT_PCA555_BOARD_ID_GPIO, \
+ I2C_ADDR_PCA555_BOARD_ID_GPIO__7bf, (reg), (data))
/* power signal list. Must match order of enum power_signal. */
const struct power_signal_info power_signal_list[] = {
diff --git a/board/glkrvp/chg_usb_pd.c b/board/glkrvp/chg_usb_pd.c
index f1b5b810e5..ac32349cff 100644
--- a/board/glkrvp/chg_usb_pd.c
+++ b/board/glkrvp/chg_usb_pd.c
@@ -35,7 +35,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = NPCX_I2C_PORT7_0,
- .addr = 0xa0,
+ .addr__7bf = 0x50,
},
.drv = &tcpci_tcpm_drv,
},
@@ -43,7 +43,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = NPCX_I2C_PORT7_0,
- .addr = 0xa4,
+ .addr__7bf = 0x52,
},
.drv = &tcpci_tcpm_drv,
},
@@ -52,11 +52,11 @@ BUILD_ASSERT(ARRAY_SIZE(tcpc_config) == CONFIG_USB_PD_PORT_COUNT);
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
{
- .port_addr = 0x20,
+ .port_addr = 0x10,
.driver = &ps874x_usb_mux_driver,
},
{
- .port_addr = 0x22,
+ .port_addr = 0x11,
.driver = &ps874x_usb_mux_driver,
},
};
diff --git a/board/glkrvp_ite/battery.c b/board/glkrvp_ite/battery.c
index d9d4bf9bf3..5665b1f557 100644
--- a/board/glkrvp_ite/battery.c
+++ b/board/glkrvp_ite/battery.c
@@ -199,8 +199,8 @@ enum battery_present battery_hw_present(void)
int data;
int rv;
- rv = pca9555_read(I2C_PORT_PCA555_PMIC_BATT_GPIO,
- I2C_ADDR_PCA555_PMIC_BATT_GPIO,
+ rv = pca9555_read__7bf(I2C_PORT_PCA555_PMIC_BATT_GPIO,
+ I2C_ADDR_PCA555_PMIC_BATT_GPIO__7bf,
PCA9555_CMD_INPUT_PORT_0, &data);
/* GPIO is low when the battery is physically present */
diff --git a/board/glkrvp_ite/board.c b/board/glkrvp_ite/board.c
index fab4e8dde7..21e712b266 100644
--- a/board/glkrvp_ite/board.c
+++ b/board/glkrvp_ite/board.c
@@ -31,7 +31,7 @@
#include "gpio_list.h"
#define I2C_PORT_PCA555_BOARD_ID_GPIO IT83XX_I2C_CH_C
-#define I2C_ADDR_PCA555_BOARD_ID_GPIO 0x40
+#define I2C_ADDR_PCA555_BOARD_ID_GPIO__7bf 0x20
/* power signal list. Must match order of enum power_signal. */
const struct power_signal_info power_signal_list[] = {
@@ -70,8 +70,8 @@ void chipset_pre_init_callback(void)
{
int data;
- if (pca9555_read(I2C_PORT_PCA555_PMIC_BATT_GPIO,
- I2C_ADDR_PCA555_PMIC_BATT_GPIO,
+ if (pca9555_read__7bf(I2C_PORT_PCA555_PMIC_BATT_GPIO,
+ I2C_ADDR_PCA555_PMIC_BATT_GPIO__7bf,
PCA9555_CMD_OUTPUT_PORT_0, &data))
return;
@@ -85,16 +85,17 @@ void chipset_pre_init_callback(void)
/* Enable SOC_3P3_EN_L: Set the Output port O0.1 to low level */
data &= ~PCA9555_IO_1;
- pca9555_write(I2C_PORT_PCA555_PMIC_BATT_GPIO,
- I2C_ADDR_PCA555_PMIC_BATT_GPIO,
+ pca9555_write__7bf(I2C_PORT_PCA555_PMIC_BATT_GPIO,
+ I2C_ADDR_PCA555_PMIC_BATT_GPIO__7bf,
PCA9555_CMD_OUTPUT_PORT_0, data);
/* TODO: Find out from the spec */
msleep(10);
/* Enable PMIC_EN: Set the Output port O0.0 to high level */
- pca9555_write(I2C_PORT_PCA555_PMIC_BATT_GPIO,
- I2C_ADDR_PCA555_PMIC_BATT_GPIO, PCA9555_CMD_OUTPUT_PORT_0,
+ pca9555_write__7bf(I2C_PORT_PCA555_PMIC_BATT_GPIO,
+ I2C_ADDR_PCA555_PMIC_BATT_GPIO__7bf,
+ PCA9555_CMD_OUTPUT_PORT_0,
data | PCA9555_IO_0);
}
@@ -120,23 +121,24 @@ void chipset_do_shutdown(void)
{
int data;
- if (pca9555_read(I2C_PORT_PCA555_PMIC_BATT_GPIO,
- I2C_ADDR_PCA555_PMIC_BATT_GPIO,
+ if (pca9555_read__7bf(I2C_PORT_PCA555_PMIC_BATT_GPIO,
+ I2C_ADDR_PCA555_PMIC_BATT_GPIO__7bf,
PCA9555_CMD_OUTPUT_PORT_0, &data))
return;
/* Disable SOC_3P3_EN_L: Set the Output port O0.1 to high level */
data |= PCA9555_IO_1;
- pca9555_write(I2C_PORT_PCA555_PMIC_BATT_GPIO,
- I2C_ADDR_PCA555_PMIC_BATT_GPIO,
+ pca9555_write__7bf(I2C_PORT_PCA555_PMIC_BATT_GPIO,
+ I2C_ADDR_PCA555_PMIC_BATT_GPIO__7bf,
PCA9555_CMD_OUTPUT_PORT_0, data);
/* TODO: Find out from the spec */
msleep(10);
/* Disable PMIC_EN: Set the Output port O0.0 to low level */
- pca9555_write(I2C_PORT_PCA555_PMIC_BATT_GPIO,
- I2C_ADDR_PCA555_PMIC_BATT_GPIO, PCA9555_CMD_OUTPUT_PORT_0,
+ pca9555_write__7bf(I2C_PORT_PCA555_PMIC_BATT_GPIO,
+ I2C_ADDR_PCA555_PMIC_BATT_GPIO__7bf,
+ PCA9555_CMD_OUTPUT_PORT_0,
data & ~PCA9555_IO_0);
}
@@ -160,8 +162,9 @@ int board_get_version(void)
{
int data;
- if (pca9555_read(I2C_PORT_PCA555_BOARD_ID_GPIO,
- I2C_ADDR_PCA555_BOARD_ID_GPIO, PCA9555_CMD_INPUT_PORT_1, &data))
+ if (pca9555_read__7bf(I2C_PORT_PCA555_BOARD_ID_GPIO,
+ I2C_ADDR_PCA555_BOARD_ID_GPIO__7bf,
+ PCA9555_CMD_INPUT_PORT_1, &data))
return -1;
return data & 0x0f;
@@ -178,8 +181,8 @@ static void pmic_init(void)
* Configure Port O0.0 as Output port - PMIC_EN
* Configure Port O0.1 as Output port - SOC_3P3_EN_L
*/
- pca9555_write(I2C_PORT_PCA555_PMIC_BATT_GPIO,
- I2C_ADDR_PCA555_PMIC_BATT_GPIO,
+ pca9555_write__7bf(I2C_PORT_PCA555_PMIC_BATT_GPIO,
+ I2C_ADDR_PCA555_PMIC_BATT_GPIO__7bf,
PCA9555_CMD_CONFIGURATION_PORT_0, 0xfc);
/*
@@ -189,8 +192,8 @@ static void pmic_init(void)
* POR of PCA9555 port is input with high impedance hence explicitly
* configure the SOC_3P3_EN_L to high level.
*/
- pca9555_write(I2C_PORT_PCA555_PMIC_BATT_GPIO,
- I2C_ADDR_PCA555_PMIC_BATT_GPIO,
+ pca9555_write__7bf(I2C_PORT_PCA555_PMIC_BATT_GPIO,
+ I2C_ADDR_PCA555_PMIC_BATT_GPIO__7bf,
PCA9555_CMD_OUTPUT_PORT_0, 0xfe);
}
DECLARE_HOOK(HOOK_INIT, pmic_init, HOOK_PRIO_INIT_I2C + 1);
diff --git a/board/glkrvp_ite/board.h b/board/glkrvp_ite/board.h
index 4209a06bf8..bc5147045b 100644
--- a/board/glkrvp_ite/board.h
+++ b/board/glkrvp_ite/board.h
@@ -114,7 +114,7 @@
#define I2C_PORT_USB_MUX IT83XX_I2C_CH_B
#define I2C_PORT_PCA555_PMIC_BATT_GPIO IT83XX_I2C_CH_C
-#define I2C_ADDR_PCA555_PMIC_BATT_GPIO 0x42
+#define I2C_ADDR_PCA555_PMIC_BATT_GPIO__7bf 0x21
/* EC exclude modules */
#undef CONFIG_ADC
diff --git a/board/glkrvp_ite/chg_usb_pd.c b/board/glkrvp_ite/chg_usb_pd.c
index 129117614f..dbf20fdbbc 100644
--- a/board/glkrvp_ite/chg_usb_pd.c
+++ b/board/glkrvp_ite/chg_usb_pd.c
@@ -35,7 +35,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = IT83XX_I2C_CH_B,
- .addr = 0xa0,
+ .addr__7bf = 0x50,
},
.drv = &tcpci_tcpm_drv,
},
@@ -43,7 +43,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = IT83XX_I2C_CH_B,
- .addr = 0xa4,
+ .addr__7bf = 0x52,
},
.drv = &tcpci_tcpm_drv,
},
@@ -52,11 +52,11 @@ BUILD_ASSERT(ARRAY_SIZE(tcpc_config) == CONFIG_USB_PD_PORT_COUNT);
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
{
- .port_addr = 0x20,
+ .port_addr = 0x10,
.driver = &ps874x_usb_mux_driver,
},
{
- .port_addr = 0x22,
+ .port_addr = 0x11,
.driver = &ps874x_usb_mux_driver,
},
};
diff --git a/board/hammer/board.h b/board/hammer/board.h
index e9ba1dabb5..81f51fa8a2 100644
--- a/board/hammer/board.h
+++ b/board/hammer/board.h
@@ -275,7 +275,7 @@
#define CONFIG_TOUCHPAD
#define CONFIG_TOUCHPAD_ELAN
#define CONFIG_TOUCHPAD_I2C_PORT I2C_PORT_MASTER
-#define CONFIG_TOUCHPAD_I2C_ADDR (0x15 << 1)
+#define CONFIG_TOUCHPAD_I2C_ADDR__7BF 0x15
#endif /* BOARD_WHISKERS */
#define CONFIG_CURVE25519
diff --git a/board/hatch/board.c b/board/hatch/board.c
index 4737239042..364c9e3d31 100644
--- a/board/hatch/board.c
+++ b/board/hatch/board.c
@@ -12,7 +12,7 @@
#include "cros_board_info.h"
#include "driver/accel_bma2x2.h"
#include "driver/accelgyro_bmi160.h"
-#include "driver/als_opt3001.h"
+#include "driver/als_tcs3400.h"
#include "driver/bc12/pi3usb9201.h"
#include "driver/ppc/sn5s330.h"
#include "driver/tcpm/anx7447.h"
@@ -130,7 +130,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = AN7447_TCPC0_I2C_ADDR,
+ .addr__7bf = AN7447_TCPC0_I2C_ADDR__7bf,
},
.drv = &anx7447_tcpm_drv,
.flags = TCPC_FLAGS_RESET_ACTIVE_HIGH,
@@ -139,7 +139,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -159,12 +159,12 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
const struct pi3usb2901_config_t pi3usb2901_bc12_chips[] = {
[USB_PD_PORT_TCPC_0] = {
.i2c_port = I2C_PORT_PPC0,
- .i2c_addr = PI3USB9201_I2C_ADDR_3,
+ .i2c_addr__7bf = PI3USB9201_I2C_ADDR_3__7bf,
},
[USB_PD_PORT_TCPC_1] = {
.i2c_port = I2C_PORT_TCPC1,
- .i2c_addr = PI3USB9201_I2C_ADDR_3,
+ .i2c_addr__7bf = PI3USB9201_I2C_ADDR_3__7bf,
},
};
@@ -180,10 +180,28 @@ static struct bmi160_drv_data_t g_bmi160_data;
/* BMA255 private data */
static struct accelgyro_saved_data_t g_bma255_data;
-static struct opt3001_drv_data_t g_opt3001_data = {
- .scale = 1,
- .uscale = 0,
- .offset = 0,
+/* ALS private data */
+static struct als_drv_data_t g_tcs3400_data = {
+ .als_cal.scale = 1,
+ .als_cal.uscale = 0,
+ .als_cal.offset = 0,
+};
+
+static struct tcs3400_rgb_drv_data_t g_tcs3400_rgb_data = {
+ .device_scale = 1,
+ .device_uscale = 0,
+ .rgb_cal[X] = {
+ .scale = ALS_CHANNEL_SCALE(1),
+ .offset = 0,
+ },
+ .rgb_cal[Y] = {
+ .scale = ALS_CHANNEL_SCALE(1),
+ .offset = 0,
+ },
+ .rgb_cal[Z] = {
+ .scale = ALS_CHANNEL_SCALE(1),
+ .offset = 0,
+ },
};
/* Matrix to rotate accelrator into standard reference frame */
@@ -215,7 +233,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,
@@ -242,7 +260,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,
@@ -268,27 +286,27 @@ 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,
.max_frequency = BMI160_GYRO_MAX_FREQ,
},
- [LID_ALS] = {
- .name = "Light",
+ [CLEAR_ALS] = {
+ .name = "Clear Light",
.active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_OPT3001,
+ .chip = MOTIONSENSE_CHIP_TCS3400,
.type = MOTIONSENSE_TYPE_LIGHT,
.location = MOTIONSENSE_LOC_LID,
- .drv = &opt3001_drv,
- .drv_data = &g_opt3001_data,
- .port = I2C_PORT_ACCEL,
- .addr = OPT3001_I2C_ADDR,
+ .drv = &tcs3400_drv,
+ .drv_data = &g_tcs3400_data,
+ .port = I2C_PORT_ALS,
+ .i2c_spi_addr__7bf = TCS3400_I2C_ADDR__7bf,
.rot_standard_ref = NULL,
- .default_range = 0x2b11a1,
- .min_frequency = OPT3001_LIGHT_MIN_FREQ,
- .max_frequency = OPT3001_LIGHT_MAX_FREQ,
+ .default_range = 0x10000, /* scale = 1x, uscale = 0 */
+ .min_frequency = TCS3400_LIGHT_MIN_FREQ,
+ .max_frequency = TCS3400_LIGHT_MAX_FREQ,
.config = {
/* Run ALS sensor in S0 */
[SENSOR_CONFIG_EC_S0] = {
@@ -296,12 +314,28 @@ struct motion_sensor_t motion_sensors[] = {
},
},
},
+
+ [RGB_ALS] = {
+ /*
+ * RGB channels read by CLEAR_ALS and so the i2c port and
+ * address do not need to be defined for RGB_ALS.
+ */
+ .name = "RGB Light",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_TCS3400,
+ .type = MOTIONSENSE_TYPE_LIGHT_RGB,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &tcs3400_rgb_drv,
+ .drv_data = &g_tcs3400_rgb_data,
+ .rot_standard_ref = NULL,
+ .default_range = 0x10000, /* scale = 1x, uscale = 0 */
+ },
};
unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
/* ALS instances when LPC mapping is needed. Each entry directs to a sensor. */
const struct motion_sensor_t *motion_als_sensors[] = {
- &motion_sensors[LID_ALS],
+ &motion_sensors[CLEAR_ALS],
};
BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT);
@@ -426,6 +460,8 @@ static void board_init(void)
setup_fans();
/* Enable gpio interrupt for base accelgyro sensor */
gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
+ /* Enable interrupt for the TCS3400 color light sensor */
+ gpio_enable_interrupt(GPIO_TCS3400_INT_ODL);
/* Enable HDMI HPD interrupt. */
gpio_enable_interrupt(GPIO_HDMI_CONN_HPD);
/* Select correct gpio signal for PP5000_A control */
diff --git a/board/helios/board.c b/board/helios/board.c
index 55359affdb..6a47979565 100644
--- a/board/helios/board.c
+++ b/board/helios/board.c
@@ -15,7 +15,6 @@
#include "driver/als_opt3001.h"
#include "driver/bc12/pi3usb9201.h"
#include "driver/ppc/sn5s330.h"
-#include "driver/tcpm/anx7447.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/tcpci.h"
#include "ec_commands.h"
@@ -46,11 +45,6 @@
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
-/* GPIO to enable/disable the USB Type-A port. */
-const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = {
- GPIO_EN_USB_A_5V,
-};
-
static void ppc_interrupt(enum gpio_signal signal)
{
switch (signal) {
@@ -125,16 +119,15 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = AN7447_TCPC0_I2C_ADDR,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
- .drv = &anx7447_tcpm_drv,
- .flags = TCPC_FLAGS_RESET_ACTIVE_HIGH,
+ .drv = &ps8xxx_tcpm_drv,
},
[USB_PD_PORT_TCPC_1] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -142,8 +135,8 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
[USB_PD_PORT_TCPC_0] = {
- .driver = &anx7447_usb_mux_driver,
- .hpd_update = &anx7447_tcpc_update_hpd_status,
+ .driver = &tcpci_tcpm_usb_mux_driver,
+ .hpd_update = &ps8xxx_tcpc_update_hpd_status,
},
[USB_PD_PORT_TCPC_1] = {
.driver = &tcpci_tcpm_usb_mux_driver,
@@ -154,12 +147,12 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
const struct pi3usb2901_config_t pi3usb2901_bc12_chips[] = {
[USB_PD_PORT_TCPC_0] = {
.i2c_port = I2C_PORT_PPC0,
- .i2c_addr = PI3USB9201_I2C_ADDR_3,
+ .i2c_addr__7bf = PI3USB9201_I2C_ADDR_3__7bf,
},
[USB_PD_PORT_TCPC_1] = {
.i2c_port = I2C_PORT_TCPC1,
- .i2c_addr = PI3USB9201_I2C_ADDR_3,
+ .i2c_addr__7bf = PI3USB9201_I2C_ADDR_3__7bf,
},
};
@@ -184,18 +177,13 @@ static struct opt3001_drv_data_t g_opt3001_data = {
/* Matrix to rotate accelrator into standard reference frame */
static const mat33_fp_t base_standard_ref = {
{ 0, FLOAT_TO_FP(1), 0},
- { FLOAT_TO_FP(-1), 0, 0},
- { 0, 0, FLOAT_TO_FP(1)}
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(-1)}
};
-/*
- * TODO(b/124337208): P0 boards don't have this sensor mounted so the rotation
- * matrix can't be tested properly. This needs to be revisited after EVT to make
- * sure the rotaiton matrix for the lid sensor is correct.
- */
static const mat33_fp_t lid_standard_ref = {
- { 0, FLOAT_TO_FP(-1), 0},
- { FLOAT_TO_FP(-1), 0, 0},
+ { 0, FLOAT_TO_FP(1), 0},
+ { FLOAT_TO_FP(1), 0, 0},
{ 0, 0, FLOAT_TO_FP(-1)}
};
@@ -210,7 +198,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,
@@ -237,7 +225,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,
@@ -263,7 +251,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,
@@ -279,7 +267,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &opt3001_drv,
.drv_data = &g_opt3001_data,
.port = I2C_PORT_ACCEL,
- .addr = OPT3001_I2C_ADDR,
+ .i2c_spi_addr__7bf = OPT3001_I2C_ADDR__7bf,
.rot_standard_ref = NULL,
.default_range = 0x2b11a1,
.min_frequency = OPT3001_LIGHT_MIN_FREQ,
@@ -399,3 +387,10 @@ void board_overcurrent_event(int port, int is_overcurrented)
/* Note that the level is inverted because the pin is active low. */
gpio_set_level(GPIO_USB_C_OC_ODL, !is_overcurrented);
}
+
+int board_tcpc_post_init(int port)
+{
+ return port == USB_PD_PORT_TCPC_1 ?
+ tcpc_write(port, PS8XXX_REG_MUX_USB_C2SS_HS_THRESHOLD, 0x80) :
+ EC_SUCCESS;
+}
diff --git a/board/helios/board.h b/board/helios/board.h
new file mode 100644
index 0000000000..b85299e19d
--- /dev/null
+++ b/board/helios/board.h
@@ -0,0 +1,146 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Helios board configuration */
+
+#ifndef __CROS_EC_BOARD_H
+#define __CROS_EC_BOARD_H
+
+/* Baseboard features */
+#include "baseboard.h"
+
+/* Optional features */
+#define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands while in dev. */
+
+#define CONFIG_POWER_BUTTON
+#define CONFIG_KEYBOARD_BOARD_CONFIG
+#define CONFIG_KEYBOARD_PROTOCOL_8042
+#define CONFIG_LED_COMMON
+#define CONFIG_LED_POWER_LED
+#define CONFIG_LOW_POWER_IDLE
+
+#define CONFIG_HOSTCMD_ESPI
+/* #define CONFIG_HOSTCMD_ESPI_VW_SIGNALS */
+
+#undef CONFIG_UART_TX_BUF_SIZE
+#define CONFIG_UART_TX_BUF_SIZE 4096
+
+/* Keyboard features */
+#define CONFIG_PWM_KBLIGHT
+
+/* Sensors */
+/* BMI160 Base accel/gyro */
+#define CONFIG_ACCEL_INTERRUPTS
+#define CONFIG_ACCELGYRO_BMI160
+#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
+#define CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT
+/* BMA253 Lid accel */
+#define CONFIG_ACCEL_BMA255
+#define CONFIG_ACCEL_FORCE_MODE_MASK (BIT(LID_ACCEL) | BIT(LID_ALS))
+#define CONFIG_LID_ANGLE
+#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
+#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
+#define CONFIG_LID_ANGLE_UPDATE
+/* OPT3001 ALS */
+#define CONFIG_ALS
+#define ALS_COUNT 1
+#define CONFIG_ALS_OPT3001
+#define OPT3001_I2C_ADDR__7bf OPT3001_I2C_ADDR1__7bf
+
+/* USB Type C and USB PD defines */
+#define CONFIG_USB_PD_TCPM_PS8751
+#define BOARD_TCPC_C0_RESET_HOLD_DELAY PS8XXX_RESET_DELAY_MS
+#define BOARD_TCPC_C0_RESET_POST_DELAY 0
+#define BOARD_TCPC_C1_RESET_HOLD_DELAY PS8XXX_RESET_DELAY_MS
+#define BOARD_TCPC_C1_RESET_POST_DELAY 0
+#define GPIO_USB_C0_TCPC_RST GPIO_USB_C0_TCPC_RST_ODL
+#define GPIO_USB_C1_TCPC_RST GPIO_USB_C1_TCPC_RST_ODL
+
+/* BC 1.2 */
+#define CONFIG_BC12_DETECT_PI3USB9201
+
+/* Volume Button feature */
+#define CONFIG_VOLUME_BUTTONS
+#define GPIO_VOLUME_UP_L GPIO_EC_VOLUP_BTN_ODL
+#define GPIO_VOLUME_DOWN_L GPIO_EC_VOLDN_BTN_ODL
+
+/* Fan features */
+#define CONFIG_FANS 1
+#undef CONFIG_FAN_INIT_SPEED
+#define CONFIG_FAN_INIT_SPEED 50
+#define CONFIG_TEMP_SENSOR_POWER_GPIO GPIO_EN_A_RAILS
+#define CONFIG_THERMISTOR
+#define CONFIG_THROTTLE_AP
+#define CONFIG_STEINHART_HART_3V3_51K1_47K_4050B
+
+/*
+ * Macros for GPIO signals used in common code that don't match the
+ * schematic names. Signal names in gpio.inc match the schematic and are
+ * then redefined here to so it's more clear which signal is being used for
+ * which purpose.
+ */
+#define GPIO_PCH_RSMRST_L GPIO_EC_PCH_RSMRST_L
+#define GPIO_PCH_SLP_S0_L GPIO_SLP_S0_L
+#define GPIO_CPU_PROCHOT GPIO_EC_PROCHOT_ODL
+#define GPIO_AC_PRESENT GPIO_ACOK_OD
+#define GPIO_RSMRST_L_PGOOD GPIO_PG_EC_RSMRST_L
+#define GPIO_PCH_SLP_S3_L GPIO_SLP_S3_L
+#define GPIO_PCH_SLP_S4_L GPIO_SLP_S4_L
+#define GPIO_EN_PP5000 GPIO_EN_PP5000_A
+
+#ifndef __ASSEMBLER__
+
+#include "gpio_signal.h"
+#include "registers.h"
+
+enum adc_channel {
+ ADC_TEMP_SENSOR_1, /* ADC0 */
+ ADC_TEMP_SENSOR_2, /* ADC1 */
+ ADC_CH_COUNT
+};
+
+enum sensor_id {
+ LID_ACCEL = 0,
+ BASE_ACCEL,
+ BASE_GYRO,
+ LID_ALS,
+ SENSOR_COUNT,
+};
+
+enum pwm_channel {
+ PWM_CH_KBLIGHT,
+ PWM_CH_FAN,
+ PWM_CH_COUNT
+};
+
+enum fan_channel {
+ FAN_CH_0 = 0,
+ /* Number of FAN channels */
+ FAN_CH_COUNT,
+};
+
+enum mft_channel {
+ MFT_CH_0 = 0,
+ /* Number of MFT channels */
+ MFT_CH_COUNT,
+};
+
+enum temp_sensor_id {
+ TEMP_SENSOR_1,
+ TEMP_SENSOR_2,
+ TEMP_SENSOR_COUNT
+};
+
+/* List of possible batteries */
+enum battery_type {
+ BATTERY_SIMPLO_C424,
+ BATTERY_SIMPLO_C436,
+ BATTERY_TYPE_COUNT,
+};
+
+#endif /* !__ASSEMBLER__ */
+
+#endif /* __CROS_EC_BOARD_H */
diff --git a/board/host/battery.c b/board/host/battery.c
index 9dcde241ab..0056c23e6d 100644
--- a/board/host/battery.c
+++ b/board/host/battery.c
@@ -14,13 +14,14 @@
static uint16_t mock_smart_battery[SB_MANUFACTURER_DATA + 1];
-int sb_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
+int sb_i2c_xfer__7bf(int port, uint16_t slave_addr__7bf,
+ const uint8_t *out, int out_size,
uint8_t *in, int in_size, int flags)
{
if (out_size == 0)
return EC_SUCCESS;
- if (port != I2C_PORT_BATTERY || slave_addr != BATTERY_ADDR)
+ if (port != I2C_PORT_BATTERY || slave_addr__7bf != BATTERY_ADDR__7bf)
return EC_ERROR_INVAL;
if (out[0] >= ARRAY_SIZE(mock_smart_battery))
return EC_ERROR_UNIMPLEMENTED;
@@ -41,7 +42,7 @@ int sb_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
}
return EC_SUCCESS;
}
-DECLARE_TEST_I2C_XFER(sb_i2c_xfer);
+DECLARE_TEST_I2C_XFER(sb_i2c_xfer__7bf);
int battery_time_at_rate(int rate, int *minutes)
{
diff --git a/board/kindred/board.c b/board/kindred/board.c
new file mode 100644
index 0000000000..66862f706a
--- /dev/null
+++ b/board/kindred/board.c
@@ -0,0 +1,445 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Hatch board-specific configuration */
+
+#include "adc.h"
+#include "adc_chip.h"
+#include "button.h"
+#include "common.h"
+#include "cros_board_info.h"
+#include "driver/accel_bma2x2.h"
+#include "driver/accelgyro_bmi160.h"
+#include "driver/als_opt3001.h"
+#include "driver/bc12/pi3usb9201.h"
+#include "driver/ppc/sn5s330.h"
+#include "driver/tcpm/anx7447.h"
+#include "driver/tcpm/ps8xxx.h"
+#include "driver/tcpm/tcpci.h"
+#include "ec_commands.h"
+#include "extpower.h"
+#include "fan.h"
+#include "fan_chip.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "lid_switch.h"
+#include "power.h"
+#include "power_button.h"
+#include "pwm.h"
+#include "pwm_chip.h"
+#include "spi.h"
+#include "switch.h"
+#include "system.h"
+#include "task.h"
+#include "temp_sensor.h"
+#include "thermal.h"
+#include "thermistor.h"
+#include "uart.h"
+#include "usb_charge.h"
+#include "usb_pd.h"
+#include "usbc_ppc.h"
+#include "util.h"
+
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
+/* GPIO to enable/disable the USB Type-A port. */
+const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = {
+ GPIO_EN_USB_A_5V,
+};
+
+static void ppc_interrupt(enum gpio_signal signal)
+{
+ switch (signal) {
+ case GPIO_USB_C0_PPC_INT_ODL:
+ sn5s330_interrupt(0);
+ break;
+
+ case GPIO_USB_C1_PPC_INT_ODL:
+ sn5s330_interrupt(1);
+ break;
+
+ default:
+ break;
+ }
+}
+
+static void tcpc_alert_event(enum gpio_signal signal)
+{
+ int port = -1;
+
+ switch (signal) {
+ case GPIO_USB_C0_TCPC_INT_ODL:
+ port = 0;
+ break;
+ case GPIO_USB_C1_TCPC_INT_ODL:
+ port = 1;
+ break;
+ default:
+ return;
+ }
+
+ schedule_deferred_pd_interrupt(port);
+}
+
+static void hdmi_hpd_interrupt(enum gpio_signal signal)
+{
+ baseboard_mst_enable_control(MST_HDMI, gpio_get_level(signal));
+}
+
+static void bc12_interrupt(enum gpio_signal signal)
+{
+ switch (signal) {
+ case GPIO_USB_C0_BC12_INT_ODL:
+ task_set_event(TASK_ID_USB_CHG_P0, USB_CHG_EVENT_BC12, 0);
+ break;
+
+ case GPIO_USB_C1_BC12_INT_ODL:
+ task_set_event(TASK_ID_USB_CHG_P1, USB_CHG_EVENT_BC12, 0);
+ break;
+
+ default:
+ break;
+ }
+}
+
+#include "gpio_list.h" /* Must come after other header files. */
+
+/******************************************************************************/
+/* SPI devices */
+const struct spi_device_t spi_devices[] = {
+};
+const unsigned int spi_devices_used = ARRAY_SIZE(spi_devices);
+
+/******************************************************************************/
+/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */
+const struct pwm_t pwm_channels[] = {
+ [PWM_CH_KBLIGHT] = { .channel = 3, .flags = 0, .freq = 10000 },
+ [PWM_CH_FAN] = {.channel = 5, .flags = PWM_CONFIG_OPEN_DRAIN,
+ .freq = 25000},
+};
+BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
+
+/******************************************************************************/
+/* USB-C TPCP Configuration */
+const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
+ [USB_PD_PORT_TCPC_0] = {
+ .bus_type = EC_BUS_TYPE_I2C,
+ .i2c_info = {
+ .port = I2C_PORT_TCPC0,
+ .addr__7bf = AN7447_TCPC0_I2C_ADDR__7bf,
+ },
+ .drv = &anx7447_tcpm_drv,
+ .flags = TCPC_FLAGS_RESET_ACTIVE_HIGH,
+ },
+ [USB_PD_PORT_TCPC_1] = {
+ .bus_type = EC_BUS_TYPE_I2C,
+ .i2c_info = {
+ .port = I2C_PORT_TCPC1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
+ },
+ .drv = &ps8xxx_tcpm_drv,
+ .flags = 0,
+ },
+};
+
+struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
+ [USB_PD_PORT_TCPC_0] = {
+ .driver = &anx7447_usb_mux_driver,
+ .hpd_update = &anx7447_tcpc_update_hpd_status,
+ },
+ [USB_PD_PORT_TCPC_1] = {
+ .driver = &tcpci_tcpm_usb_mux_driver,
+ .hpd_update = &ps8xxx_tcpc_update_hpd_status,
+ }
+};
+
+const struct pi3usb2901_config_t pi3usb2901_bc12_chips[] = {
+ [USB_PD_PORT_TCPC_0] = {
+ .i2c_port = I2C_PORT_PPC0,
+ .i2c_addr__7bf = PI3USB9201_I2C_ADDR_3__7bf,
+ },
+
+ [USB_PD_PORT_TCPC_1] = {
+ .i2c_port = I2C_PORT_TCPC1,
+ .i2c_addr__7bf = PI3USB9201_I2C_ADDR_3__7bf,
+ },
+};
+
+/******************************************************************************/
+/* Sensors */
+/* Base Sensor mutex */
+static struct mutex g_base_mutex;
+static struct mutex g_lid_mutex;
+
+/* Base accel private data */
+static struct bmi160_drv_data_t g_bmi160_data;
+
+/* BMA255 private data */
+static struct accelgyro_saved_data_t g_bma255_data;
+
+static struct opt3001_drv_data_t g_opt3001_data = {
+ .scale = 1,
+ .uscale = 0,
+ .offset = 0,
+};
+
+/* Matrix to rotate accelrator into standard reference frame */
+static const mat33_fp_t base_standard_ref = {
+ { 0, FLOAT_TO_FP(1), 0},
+ { FLOAT_TO_FP(-1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
+/*
+ * TODO(b/124337208): P0 boards don't have this sensor mounted so the rotation
+ * matrix can't be tested properly. This needs to be revisited after EVT to make
+ * sure the rotaiton matrix for the lid sensor is correct.
+ */
+static const mat33_fp_t lid_standard_ref = {
+ { 0, FLOAT_TO_FP(-1), 0},
+ { FLOAT_TO_FP(-1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(-1)}
+};
+
+struct motion_sensor_t motion_sensors[] = {
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMA255,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &bma2x2_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_bma255_data,
+ .port = I2C_PORT_ACCEL,
+ .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,
+ .default_range = 2, /* g, to support tablet mode */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+
+ [BASE_ACCEL] = {
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi160_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_ACCEL,
+ .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,
+ .default_range = 2, /* g, to support tablet mode */
+ .config = {
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on in S3 */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+
+ [BASE_GYRO] = {
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi160_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = BMI160_GYRO_MIN_FREQ,
+ .max_frequency = BMI160_GYRO_MAX_FREQ,
+ },
+
+ [LID_ALS] = {
+ .name = "Light",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_OPT3001,
+ .type = MOTIONSENSE_TYPE_LIGHT,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &opt3001_drv,
+ .drv_data = &g_opt3001_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr__7bf = OPT3001_I2C_ADDR__7bf,
+ .rot_standard_ref = NULL,
+ .default_range = 0x2b11a1,
+ .min_frequency = OPT3001_LIGHT_MIN_FREQ,
+ .max_frequency = OPT3001_LIGHT_MAX_FREQ,
+ .config = {
+ /* Run ALS sensor in S0 */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 1000,
+ },
+ },
+ },
+};
+unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+/* ALS instances when LPC mapping is needed. Each entry directs to a sensor. */
+const struct motion_sensor_t *motion_als_sensors[] = {
+ &motion_sensors[LID_ALS],
+};
+BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT);
+
+/******************************************************************************/
+/* Physical fans. These are logically separate from pwm_channels. */
+
+const struct fan_conf fan_conf_0 = {
+ .flags = FAN_USE_RPM_MODE,
+ .ch = MFT_CH_0, /* Use MFT id to control fan */
+ .pgood_gpio = -1,
+ .enable_gpio = GPIO_EN_PP5000_FAN,
+};
+
+/* Default */
+const struct fan_rpm fan_rpm_0 = {
+ .rpm_min = 3100,
+ .rpm_start = 3100,
+ .rpm_max = 6900,
+};
+
+struct fan_t fans[FAN_CH_COUNT] = {
+ [FAN_CH_0] = { .conf = &fan_conf_0, .rpm = &fan_rpm_0, },
+};
+
+/******************************************************************************/
+/* MFT channels. These are logically separate from pwm_channels. */
+const struct mft_t mft_channels[] = {
+ [MFT_CH_0] = {NPCX_MFT_MODULE_1, TCKC_LFCLK, PWM_CH_FAN},
+};
+BUILD_ASSERT(ARRAY_SIZE(mft_channels) == MFT_CH_COUNT);
+
+/* ADC channels */
+const struct adc_t adc_channels[] = {
+ [ADC_TEMP_SENSOR_1] = {
+ "TEMP_AMB", NPCX_ADC_CH0, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+ [ADC_TEMP_SENSOR_2] = {
+ "TEMP_CHARGER", NPCX_ADC_CH1, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
+
+const struct temp_sensor_t temp_sensors[] = {
+ [TEMP_SENSOR_1] = {.name = "Temp1",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_1,
+ .action_delay_sec = 1},
+ [TEMP_SENSOR_2] = {.name = "Temp2",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_2,
+ .action_delay_sec = 1},
+};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
+
+
+/* Hatch Temperature sensors */
+/*
+ * TODO(b/124316213): These setting need to be reviewed and set appropriately
+ * for Hatch. They matter when the EC is controlling the fan as opposed to DPTF
+ * control.
+ */
+const static struct ec_thermal_config thermal_a = {
+ .temp_host = {
+ [EC_TEMP_THRESH_WARN] = 0,
+ [EC_TEMP_THRESH_HIGH] = C_TO_K(75),
+ [EC_TEMP_THRESH_HALT] = C_TO_K(80),
+ },
+ .temp_host_release = {
+ [EC_TEMP_THRESH_WARN] = 0,
+ [EC_TEMP_THRESH_HIGH] = C_TO_K(65),
+ [EC_TEMP_THRESH_HALT] = 0,
+ },
+ .temp_fan_off = C_TO_K(25),
+ .temp_fan_max = C_TO_K(50),
+};
+
+struct ec_thermal_config thermal_params[TEMP_SENSOR_COUNT];
+
+static void setup_fans(void)
+{
+ thermal_params[TEMP_SENSOR_1] = thermal_a;
+ thermal_params[TEMP_SENSOR_2] = thermal_a;
+}
+
+/* Sets the gpio flags correct taking into account warm resets */
+static void reset_gpio_flags(enum gpio_signal signal, int flags)
+{
+ /*
+ * If the system was already on, we cannot set the value otherwise we
+ * may change the value from the previous image which could cause a
+ * brownout.
+ */
+ if (system_is_reboot_warm() || system_jumped_to_this_image())
+ flags &= ~(GPIO_LOW | GPIO_HIGH);
+
+ gpio_set_flags(signal, flags);
+}
+
+/* Runtime GPIO defaults */
+enum gpio_signal gpio_en_pp5000_a = GPIO_EN_PP5000_A_V1;
+
+static void board_gpio_set_pp5000(void)
+{
+ uint32_t board_id = 0;
+
+ /* Errors will count as board_id 0 */
+ cbi_get_board_version(&board_id);
+
+ if (board_id == 0) {
+ reset_gpio_flags(GPIO_EN_PP5000_A_V0, GPIO_OUT_LOW);
+ /* Change runtime default for V0 */
+ gpio_en_pp5000_a = GPIO_EN_PP5000_A_V0;
+ } else if (board_id >= 1) {
+ reset_gpio_flags(GPIO_EN_PP5000_A_V1, GPIO_OUT_LOW);
+ }
+
+}
+
+static void board_init(void)
+{
+ /* Initialize Fans */
+ setup_fans();
+ /* Enable gpio interrupt for base accelgyro sensor */
+ gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
+ /* Enable HDMI HPD interrupt. */
+ gpio_enable_interrupt(GPIO_HDMI_CONN_HPD);
+ /* Select correct gpio signal for PP5000_A control */
+ board_gpio_set_pp5000();
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+
+void board_overcurrent_event(int port, int is_overcurrented)
+{
+ /* Sanity check the port. */
+ if ((port < 0) || (port >= CONFIG_USB_PD_PORT_COUNT))
+ return;
+
+ /* Note that the level is inverted because the pin is active low. */
+ gpio_set_level(GPIO_USB_C_OC_ODL, !is_overcurrented);
+}
diff --git a/board/kindred/board.h b/board/kindred/board.h
new file mode 100644
index 0000000000..1d327abbcf
--- /dev/null
+++ b/board/kindred/board.h
@@ -0,0 +1,176 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Hatch board configuration */
+
+#ifndef __CROS_EC_BOARD_H
+#define __CROS_EC_BOARD_H
+
+/* Baseboard features */
+#include "baseboard.h"
+
+/* Optional features */
+#define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands while in dev. */
+
+#define CONFIG_POWER_BUTTON
+#define CONFIG_KEYBOARD_BOARD_CONFIG
+#define CONFIG_KEYBOARD_PROTOCOL_8042
+#define CONFIG_LED_COMMON
+#define CONFIG_LOW_POWER_IDLE
+
+#define CONFIG_HOSTCMD_ESPI
+/* #define CONFIG_HOSTCMD_ESPI_VW_SIGNALS */
+
+#undef CONFIG_UART_TX_BUF_SIZE
+#define CONFIG_UART_TX_BUF_SIZE 4096
+
+/* Keyboard features */
+#define CONFIG_PWM_KBLIGHT
+
+/* Sensors */
+/* BMI160 Base accel/gyro */
+#define CONFIG_ACCEL_INTERRUPTS
+#define CONFIG_ACCELGYRO_BMI160
+#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
+#define CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT
+/* BMA253 Lid accel */
+#define CONFIG_ACCEL_BMA255
+#define CONFIG_ACCEL_FORCE_MODE_MASK (BIT(LID_ACCEL) | BIT(LID_ALS))
+#define CONFIG_LID_ANGLE
+#define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL
+#define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL
+#define CONFIG_LID_ANGLE_UPDATE
+/* OPT3001 ALS */
+#define CONFIG_ALS
+#define ALS_COUNT 1
+#define CONFIG_ALS_OPT3001
+#define OPT3001_I2C_ADDR__7bf OPT3001_I2C_ADDR1__7bf
+
+/* USB Type C and USB PD defines */
+#define CONFIG_USB_PD_TCPM_ANX7447
+#define CONFIG_USB_PD_TCPM_PS8751
+#define BOARD_TCPC_C0_RESET_HOLD_DELAY ANX74XX_RESET_HOLD_MS
+#define BOARD_TCPC_C0_RESET_POST_DELAY ANX74XX_RESET_HOLD_MS
+#define BOARD_TCPC_C1_RESET_HOLD_DELAY PS8XXX_RESET_DELAY_MS
+#define BOARD_TCPC_C1_RESET_POST_DELAY 0
+#define GPIO_USB_C1_TCPC_RST GPIO_USB_C1_TCPC_RST_ODL
+
+/* USB Type A Features */
+#define CONFIG_USB_PORT_POWER_SMART
+#undef CONFIG_USB_PORT_POWER_SMART_PORT_COUNT
+#define CONFIG_USB_PORT_POWER_SMART_PORT_COUNT 1
+#define CONFIG_USB_PORT_POWER_SMART_CDP_SDP_ONLY
+#define GPIO_USB1_ILIM_SEL GPIO_EN_USB_A_LOW_PWR_OD
+
+/* BC 1.2 */
+#define CONFIG_BC12_DETECT_PI3USB9201
+
+/* Charger features */
+/*
+ * The IDCHG current limit is set in 512 mA steps. The value set here is
+ * somewhat specific to the battery pack being currently used. The limit here
+ * was set based on the battery's discharge current limit and what was tested to
+ * prevent the AP rebooting with low charge level batteries.
+ *
+ * TODO(b/133447140): Revisit this threshold once peak power consumption tuning
+ * for the AP is completed.
+ */
+#define CONFIG_CHARGER_BQ25710_IDCHG_LIMIT_MA 8192
+
+/* Volume Button feature */
+#define CONFIG_VOLUME_BUTTONS
+#define GPIO_VOLUME_UP_L GPIO_EC_VOLUP_BTN_ODL
+#define GPIO_VOLUME_DOWN_L GPIO_EC_VOLDN_BTN_ODL
+
+/* Fan features */
+#define CONFIG_FANS 1
+#undef CONFIG_FAN_INIT_SPEED
+#define CONFIG_FAN_INIT_SPEED 50
+#define CONFIG_TEMP_SENSOR_POWER_GPIO GPIO_EN_A_RAILS
+#define CONFIG_THERMISTOR
+#define CONFIG_THROTTLE_AP
+#define CONFIG_STEINHART_HART_3V3_51K1_47K_4050B
+
+/* MST */
+/*
+ * TDOD (b/124068003): This inherently assumes the MST chip is connected to only
+ * one Type C port. This will need to be chagned to support 2 Type C ports
+ * connected to the same MST chip.
+ */
+#define USB_PD_PORT_TCPC_MST USB_PD_PORT_TCPC_1
+
+/*
+ * Macros for GPIO signals used in common code that don't match the
+ * schematic names. Signal names in gpio.inc match the schematic and are
+ * then redefined here to so it's more clear which signal is being used for
+ * which purpose.
+ */
+#define GPIO_PCH_RSMRST_L GPIO_EC_PCH_RSMRST_L
+#define GPIO_PCH_SLP_S0_L GPIO_SLP_S0_L
+#define GPIO_CPU_PROCHOT GPIO_EC_PROCHOT_ODL
+#define GPIO_AC_PRESENT GPIO_ACOK_OD
+#define GPIO_RSMRST_L_PGOOD GPIO_PG_EC_RSMRST_L
+#define GPIO_PCH_SLP_S3_L GPIO_SLP_S3_L
+#define GPIO_PCH_SLP_S4_L GPIO_SLP_S4_L
+#define GPIO_EN_PP5000 GPIO_EN_PP5000_A
+
+#ifndef __ASSEMBLER__
+
+#include "gpio_signal.h"
+#include "registers.h"
+
+/* GPIO signals updated base on board version. */
+#define GPIO_EN_PP5000_A gpio_en_pp5000_a
+extern enum gpio_signal gpio_en_pp5000_a;
+
+enum adc_channel {
+ ADC_TEMP_SENSOR_1, /* ADC0 */
+ ADC_TEMP_SENSOR_2, /* ADC1 */
+ ADC_CH_COUNT
+};
+
+enum sensor_id {
+ LID_ACCEL = 0,
+ BASE_ACCEL,
+ BASE_GYRO,
+ LID_ALS,
+ SENSOR_COUNT,
+};
+
+enum pwm_channel {
+ PWM_CH_KBLIGHT,
+ PWM_CH_FAN,
+ PWM_CH_COUNT
+};
+
+enum fan_channel {
+ FAN_CH_0 = 0,
+ /* Number of FAN channels */
+ FAN_CH_COUNT,
+};
+
+enum mft_channel {
+ MFT_CH_0 = 0,
+ /* Number of MFT channels */
+ MFT_CH_COUNT,
+};
+
+enum temp_sensor_id {
+ TEMP_SENSOR_1,
+ TEMP_SENSOR_2,
+ TEMP_SENSOR_COUNT
+};
+
+/* List of possible batteries */
+enum battery_type {
+ BATTERY_LGC_AP18C8K,
+ BATTERY_MURATA_AP18C4K,
+ BATTERY_TYPE_COUNT,
+};
+
+#endif /* !__ASSEMBLER__ */
+
+#endif /* __CROS_EC_BOARD_H */
diff --git a/board/kohaku/board.c b/board/kohaku/board.c
index 23b6124ad7..0fa7b42ac7 100644
--- a/board/kohaku/board.c
+++ b/board/kohaku/board.c
@@ -13,8 +13,10 @@
#include "driver/accel_bma2x2.h"
#include "driver/accelgyro_bmi160.h"
#include "driver/als_bh1730.h"
+#include "driver/als_tcs3400.h"
#include "driver/ppc/sn5s330.h"
#include "driver/bc12/max14637.h"
+#include "driver/sync.h"
#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/tcpci.h"
#include "ec_commands.h"
@@ -115,7 +117,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -123,7 +125,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -169,6 +171,30 @@ static struct accelgyro_saved_data_t g_bma255_data;
/* BH1730 private data */
struct bh1730_drv_data_t g_bh1730_data;
+/* TCS3400 private data */
+static struct als_drv_data_t g_tcs3400_data = {
+ .als_cal.scale = 1,
+ .als_cal.uscale = 0,
+ .als_cal.offset = 0,
+};
+
+static struct tcs3400_rgb_drv_data_t g_tcs3400_rgb_data = {
+ .device_scale = 1,
+ .device_uscale = 0,
+ .rgb_cal[X] = {
+ .scale = ALS_CHANNEL_SCALE(1),
+ .offset = 0,
+ },
+ .rgb_cal[Y] = {
+ .scale = ALS_CHANNEL_SCALE(1),
+ .offset = 0,
+ },
+ .rgb_cal[Z] = {
+ .scale = ALS_CHANNEL_SCALE(1),
+ .offset = 0,
+ },
+};
+
/* Matrix to rotate accelrator into standard reference frame */
static const mat33_fp_t base_standard_ref = {
{ 0, FLOAT_TO_FP(1), 0},
@@ -182,9 +208,9 @@ static const mat33_fp_t base_standard_ref = {
* sure the rotaiton matrix for the lid sensor is correct.
*/
static const mat33_fp_t lid_standard_ref = {
- { 0, FLOAT_TO_FP(-1), 0},
- { FLOAT_TO_FP(-1), 0, 0},
- { 0, 0, FLOAT_TO_FP(-1)}
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, FLOAT_TO_FP(1), 0},
+ { 0, 0, FLOAT_TO_FP(1)}
};
struct motion_sensor_t motion_sensors[] = {
@@ -198,7 +224,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,
@@ -225,7 +251,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,
@@ -251,7 +277,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,
@@ -267,7 +293,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &bh1730_drv,
.drv_data = &g_bh1730_data,
.port = I2C_PORT_ACCEL,
- .addr = BH1730_I2C_ADDR,
+ .i2c_spi_addr__7bf = BH1730_I2C_ADDR__7bf,
.rot_standard_ref = NULL,
.default_range = 65535,
.min_frequency = 10,
@@ -279,12 +305,63 @@ struct motion_sensor_t motion_sensors[] = {
},
},
},
+
+ [VSYNC] = {
+ .name = "Camera VSYNC",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .chip = MOTIONSENSE_CHIP_GPIO,
+ .type = MOTIONSENSE_TYPE_SYNC,
+ .location = MOTIONSENSE_LOC_CAMERA,
+ .drv = &sync_drv,
+ .default_range = 0,
+ .min_frequency = 0,
+ .max_frequency = 1,
+ },
+
+ [CLEAR_ALS] = {
+ .name = "Clear Light",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_TCS3400,
+ .type = MOTIONSENSE_TYPE_LIGHT,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &tcs3400_drv,
+ .drv_data = &g_tcs3400_data,
+ .port = I2C_PORT_ALS,
+ .i2c_spi_addr__7bf = TCS3400_I2C_ADDR__7bf,
+ .rot_standard_ref = NULL,
+ .default_range = 0x10000, /* scale = 1x, uscale = 0 */
+ .min_frequency = TCS3400_LIGHT_MIN_FREQ,
+ .max_frequency = TCS3400_LIGHT_MAX_FREQ,
+ .config = {
+ /* Run ALS sensor in S0 */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 1000,
+ },
+ },
+ },
+
+ [RGB_ALS] = {
+ /*
+ * RGB channels read by CLEAR_ALS and so the i2c port and
+ * address do not need to be defined for RGB_ALS.
+ */
+ .name = "RGB Light",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_TCS3400,
+ .type = MOTIONSENSE_TYPE_LIGHT_RGB,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &tcs3400_rgb_drv,
+ .drv_data = &g_tcs3400_rgb_data,
+ .rot_standard_ref = NULL,
+ .default_range = 0x10000, /* scale = 1x, uscale = 0 */
+ },
};
unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
/* ALS instances when LPC mapping is needed. Each entry directs to a sensor. */
const struct motion_sensor_t *motion_als_sensors[] = {
&motion_sensors[LID_ALS],
+ &motion_sensors[CLEAR_ALS],
};
BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT);
@@ -320,6 +397,10 @@ static void board_init(void)
{
/* Enable gpio interrupt for base accelgyro sensor */
gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
+ /* Enable gpio interrupt for camera vsync */
+ gpio_enable_interrupt(GPIO_WFCAM_VSYNC);
+ /* Enable interrupt for the TCS3400 color light sensor */
+ gpio_enable_interrupt(GPIO_TCS3400_INT_ODL);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/board/kukui/board.c b/board/kukui/board.c
index 8b6649e288..95f177bf6b 100644
--- a/board/kukui/board.c
+++ b/board/kukui/board.c
@@ -8,35 +8,35 @@
#include "backlight.h"
#include "button.h"
#include "charge_manager.h"
+#include "charge_ramp.h"
#include "charge_state.h"
#include "charger.h"
#include "chipset.h"
#include "common.h"
#include "console.h"
#include "driver/accelgyro_bmi160.h"
+#include "driver/als_tcs3400.h"
+#include "driver/battery/max17055.h"
+#include "driver/bc12/pi3usb9201.h"
#include "driver/charger/rt946x.h"
#include "driver/sync.h"
#include "driver/tcpm/mt6370.h"
-#include "driver/temp_sensor/tmp432.h"
#include "ec_commands.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
#include "i2c.h"
+#include "lid_switch.h"
#include "power.h"
#include "power_button.h"
#include "pwm.h"
#include "pwm_chip.h"
#include "registers.h"
#include "spi.h"
-#include "switch.h"
#include "system.h"
#include "task.h"
#include "tcpm.h"
-#include "temp_sensor.h"
-#include "temp_sensor_chip.h"
-#include "thermal.h"
#include "timer.h"
#include "usb_charge.h"
#include "usb_mux.h"
@@ -48,41 +48,13 @@
static void tcpc_alert_event(enum gpio_signal signal)
{
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
-}
-
-static void warm_reset_request_interrupt(enum gpio_signal signal)
-{
- CPRINTS("AP wants warm reset");
- chipset_reset(CHIPSET_RESET_AP_REQ);
-}
-
-static void ap_watchdog_interrupt(enum gpio_signal signal)
-{
- int level = gpio_get_level(GPIO_AP_EC_WATCHDOG_L);
-
- CPRINTS("AP watchdog level %d", level);
- /*
- * TODO(b:109900671): Handle AP watchdog, when necessary, for now, just
- * mirror input to output.
- */
- gpio_set_level(GPIO_PMIC_WATCHDOG_L, level);
-}
-
-#if BOARD_REV >= 1
-static void hall_interrupt(enum gpio_signal signal)
-{
- /* TODO(b/111378000): Implement hall_interrupt */
+ schedule_deferred_pd_interrupt(0 /* port */);
}
static void gauge_interrupt(enum gpio_signal signal)
{
- /* TODO(b/111378620): Impelement gauge_interrupt */
+ task_wake(TASK_ID_CHARGER);
}
-#endif
#include "gpio_list.h"
@@ -90,6 +62,9 @@ static void gauge_interrupt(enum gpio_signal signal)
/* ADC channels. Must be in the exactly same order as in enum adc_channel. */
const struct adc_t adc_channels[] = {
[ADC_BOARD_ID] = {"BOARD_ID", 3300, 4096, 0, STM32_AIN(10)},
+ [ADC_EC_SKU_ID] = {"EC_SKU_ID", 3300, 4096, 0, STM32_AIN(8)},
+ [ADC_BATT_ID] = {"BATT_ID", 3300, 4096, 0, STM32_AIN(7)},
+ [ADC_POGO_ADC_INT_L] = {"POGO_ADC_INT_L", 3300, 4096, 0, STM32_AIN(6)},
};
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
@@ -100,9 +75,13 @@ const struct i2c_port_t i2c_ports[] = {
{"tcpc0", I2C_PORT_TCPC0, 400, GPIO_I2C1_SCL, GPIO_I2C1_SDA},
{"battery", I2C_PORT_BATTERY, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
{"accelgyro", I2C_PORT_ACCEL, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
+ {"bc12", I2C_PORT_BC12, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
+ {"als", I2C_PORT_ALS, 400, GPIO_I2C2_SCL, GPIO_I2C2_SDA},
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+#define BC12_I2C_ADDR__7bf PI3USB9201_I2C_ADDR_3__7bf
+
/* power signal list. Must match order of enum power_signal. */
const struct power_signal_info power_signal_list[] = {
{GPIO_AP_IN_SLEEP_L, POWER_SIGNAL_ACTIVE_LOW, "AP_IN_S3_L"},
@@ -110,30 +89,6 @@ const struct power_signal_info power_signal_list[] = {
};
BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
-#ifdef CONFIG_TEMP_SENSOR_TMP432
-/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
-const struct temp_sensor_t temp_sensors[] = {
- {"TMP432_Internal", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val,
- TMP432_IDX_LOCAL, 4},
- {"TMP432_Sensor_1", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val,
- TMP432_IDX_REMOTE1, 4},
- {"TMP432_Sensor_2", TEMP_SENSOR_TYPE_BOARD, tmp432_get_val,
- TMP432_IDX_REMOTE2, 4},
-};
-BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
-
-/*
- * Thermal limits for each temp sensor. All temps are in degrees K. Must be in
- * same order as enum temp_sensor_id. To always ignore any temp, use 0.
- */
-struct ec_thermal_config thermal_params[] = {
- {{0, 0, 0}, 0, 0}, /* TMP432_Internal */
- {{0, 0, 0}, 0, 0}, /* TMP432_Sensor_1 */
- {{0, 0, 0}, 0, 0}, /* TMP432_Sensor_2 */
-};
-BUILD_ASSERT(ARRAY_SIZE(thermal_params) == TEMP_SENSOR_COUNT);
-#endif
-
/******************************************************************************/
/* SPI devices */
const struct spi_device_t spi_devices[] = {
@@ -146,7 +101,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = MT6370_TCPC_I2C_ADDR,
+ .addr__7bf = MT6370_TCPC_I2C_ADDR__7bf,
},
.drv = &mt6370_tcpm_drv,
},
@@ -173,15 +128,38 @@ uint16_t tcpc_get_alert_status(void)
return status;
}
+static void board_pogo_charge_init(void)
+{
+ int i;
+
+ /* Initialize all charge suppliers to 0 */
+ for (i = 0; i < CHARGE_SUPPLIER_COUNT; i++)
+ charge_manager_update_charge(i, CHARGE_PORT_POGO, NULL);
+}
+DECLARE_HOOK(HOOK_INIT, board_pogo_charge_init,
+ HOOK_PRIO_CHARGE_MANAGER_INIT + 1);
+
+static int force_discharge;
+
int board_set_active_charge_port(int charge_port)
{
CPRINTS("New chg p%d", charge_port);
+ /* ignore all request when discharge mode is on */
+ if (force_discharge)
+ return EC_SUCCESS;
+
switch (charge_port) {
- case 0:
+ case CHARGE_PORT_USB_C:
/* Don't charge from a source port */
if (board_vbus_source_enabled(charge_port))
return -1;
+ gpio_set_level(GPIO_EN_POGO_CHARGE_L, 1);
+ gpio_set_level(GPIO_EN_USBC_CHARGE_L, 0);
+ break;
+ case CHARGE_PORT_POGO:
+ gpio_set_level(GPIO_EN_USBC_CHARGE_L, 1);
+ gpio_set_level(GPIO_EN_POGO_CHARGE_L, 0);
break;
case CHARGE_PORT_NONE:
/*
@@ -189,6 +167,8 @@ int board_set_active_charge_port(int charge_port)
* even when battery is disconnected, keep VBAT rail on but
* set the charging current to minimum.
*/
+ gpio_set_level(GPIO_EN_POGO_CHARGE_L, 1);
+ gpio_set_level(GPIO_EN_USBC_CHARGE_L, 1);
charger_set_current(0);
break;
default:
@@ -206,16 +186,41 @@ void board_set_charge_limit(int port, int supplier, int charge_ma,
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
+int board_discharge_on_ac(int enable)
+{
+ int ret, port;
+
+ if (enable) {
+ port = CHARGE_PORT_NONE;
+ } else {
+ /* restore the charge port state */
+ port = charge_manager_get_override();
+ if (port == OVERRIDE_OFF)
+ port = charge_manager_get_active_charge_port();
+ }
+
+ ret = board_set_active_charge_port(port);
+ if (ret)
+ return ret;
+ force_discharge = enable;
+
+ return charger_discharge_on_ac(enable);
+}
+
int extpower_is_present(void)
{
/*
* The charger will indicate VBUS presence if we're sourcing 5V,
* so exclude such ports.
*/
- if (board_vbus_source_enabled(0))
- return 0;
+ int usb_c_extpower_present;
+
+ if (board_vbus_source_enabled(CHARGE_PORT_USB_C))
+ usb_c_extpower_present = 0;
else
- return tcpm_get_vbus_level(0);
+ usb_c_extpower_present = tcpm_get_vbus_level(CHARGE_PORT_USB_C);
+
+ return usb_c_extpower_present || gpio_get_level(GPIO_POGO_VBUS_PRESENT);
}
int pd_snk_is_vbus_provided(int port)
@@ -226,8 +231,22 @@ int pd_snk_is_vbus_provided(int port)
return rt946x_is_vbus_ready();
}
+#if defined(BOARD_KUKUI) || defined(BOARD_KODAMA)
+/* dummy interrupt function for kukui */
+void pogo_adc_interrupt(enum gpio_signal signal)
+{
+}
+#endif
+
static void board_init(void)
{
+ /* If the reset cause is external, pulse PMIC force reset. */
+ if (system_get_reset_flags() == RESET_FLAG_RESET_PIN) {
+ gpio_set_level(GPIO_PMIC_FORCE_RESET_ODL, 0);
+ msleep(100);
+ gpio_set_level(GPIO_PMIC_FORCE_RESET_ODL, 1);
+ }
+
/* Set SPI1 PB13/14/15 pins to high speed */
STM32_GPIO_OSPEEDR(GPIO_B) |= 0xfc000000;
@@ -237,11 +256,6 @@ static void board_init(void)
/* Enable charger interrupts */
gpio_enable_interrupt(GPIO_CHARGER_INT_ODL);
- /* Enable reboot / shutdown / sleep control inputs from AP */
- gpio_enable_interrupt(GPIO_WARM_RESET_REQ);
- gpio_enable_interrupt(GPIO_AP_EC_WATCHDOG_L);
- gpio_enable_interrupt(GPIO_AP_IN_SLEEP_L);
-
#ifdef SECTION_IS_RW
/* Enable interrupts from BMI160 sensor. */
gpio_enable_interrupt(GPIO_ACCEL_INT_ODL);
@@ -252,9 +266,51 @@ static void board_init(void)
/* Enable interrupt from PMIC. */
gpio_enable_interrupt(GPIO_PMIC_EC_RESETB);
+
+ /* Enable gauge interrupt from max17055 */
+ gpio_enable_interrupt(GPIO_GAUGE_INT_ODL);
+
+ /* Enable pogo interrupt */
+ gpio_enable_interrupt(GPIO_POGO_ADC_INT_L);
+
+ if (IS_ENABLED(BOARD_KRANE))
+ /* Display bias settings. */
+ mt6370_db_set_voltages(6000, 5800, 5800);
+
+ /* Enable pogo charging signal */
+ gpio_enable_interrupt(GPIO_POGO_VBUS_PRESENT);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+static void board_rev_init(void)
+{
+ /* Board revision specific configs. */
+
+ /*
+ * It's a P1 pin BOOTBLOCK_MUX_OE, also a P2 pin BC12_DET_EN.
+ * Keep this pin defaults to P1 setting since that eMMC enabled with
+ * High-Z stat.
+ */
+ if (IS_ENABLED(BOARD_KUKUI) && board_get_version() == 1)
+ gpio_set_flags(GPIO_BC12_DET_EN, GPIO_ODR_HIGH);
+
+ if (board_get_version() >= 2) {
+ /*
+ * Enable MT6370 DB_POSVOUT/DB_NEGVOUT (controlled by _EN pins).
+ */
+ mt6370_db_external_control(1);
+ }
+
+ if (board_get_version() == 2) {
+ /* configure PI3USB9201 to USB Path ON Mode */
+ i2c_write8__7bf(I2C_PORT_BC12, BC12_I2C_ADDR__7bf,
+ PI3USB9201_REG_CTRL_1,
+ (PI3USB9201_USB_PATH_ON <<
+ PI3USB9201_REG_CTRL_1_MODE_SHIFT));
+ }
+}
+DECLARE_HOOK(HOOK_INIT, board_rev_init, HOOK_PRIO_INIT_ADC + 1);
+
void board_config_pre_init(void)
{
STM32_RCC_AHBENR |= STM32_RCC_HB_DMA1;
@@ -340,30 +396,63 @@ int board_get_version(void)
}
}
- /*
- * Disable ADC module after we detect the board version,
- * since this is the only thing ADC module needs to do
- * for this board.
- */
- if (version != BOARD_VERSION_UNKNOWN)
- adc_disable();
-
return version;
}
/* Motion sensors */
/* Mutexes */
#ifdef SECTION_IS_RW
-static struct mutex g_base_mutex;
+static struct mutex g_lid_mutex;
static struct bmi160_drv_data_t g_bmi160_data;
+static struct als_drv_data_t g_tcs3400_data = {
+ .als_cal.scale = 1,
+ .als_cal.uscale = 0,
+ .als_cal.offset = 0,
+};
+
+static struct tcs3400_rgb_drv_data_t g_tcs3400_rgb_data = {
+ .device_scale = 1,
+ .device_uscale = 0,
+ .rgb_cal[X] = {
+ .scale = ALS_CHANNEL_SCALE(1),
+ .offset = 0,
+ },
+ .rgb_cal[Y] = {
+ .scale = ALS_CHANNEL_SCALE(1),
+ .offset = 0,
+ },
+ .rgb_cal[Z] = {
+ .scale = ALS_CHANNEL_SCALE(1),
+ .offset = 0,
+ },
+};
+
+#ifdef BOARD_KRANE
/* Matrix to rotate accelerometer into standard reference frame */
-const mat33_fp_t base_standard_ref = {
- { FLOAT_TO_FP(-1), 0, 0},
- { 0, FLOAT_TO_FP(-1), 0},
- { 0, 0, FLOAT_TO_FP(1)}
+static const mat33_fp_t lid_standard_ref_rev3 = {
+ {0, FLOAT_TO_FP(-1), 0},
+ {FLOAT_TO_FP(1), 0, 0},
+ {0, 0, FLOAT_TO_FP(1)}
+};
+#endif /* BOARD_KRANE */
+
+/* Matrix to rotate accelerometer into standard reference frame */
+static const mat33_fp_t lid_standard_ref = {
+ {FLOAT_TO_FP(1), 0, 0},
+ {0, FLOAT_TO_FP(1), 0},
+ {0, 0, FLOAT_TO_FP(1)}
+};
+
+#ifdef CONFIG_MAG_BMI160_BMM150
+/* Matrix to rotate accelrator into standard reference frame */
+static const mat33_fp_t mag_standard_ref = {
+ {0, FLOAT_TO_FP(-1), 0},
+ {FLOAT_TO_FP(-1), 0, 0},
+ {0, 0, FLOAT_TO_FP(-1)}
};
+#endif /* CONFIG_MAG_BMI160_BMM150 */
struct motion_sensor_t motion_sensors[] = {
/*
@@ -378,11 +467,11 @@ struct motion_sensor_t motion_sensors[] = {
.type = MOTIONSENSE_TYPE_ACCEL,
.location = MOTIONSENSE_LOC_LID,
.drv = &bmi160_drv,
- .mutex = &g_base_mutex,
+ .mutex = &g_lid_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_ACCEL,
- .addr = BMI160_ADDR0,
- .rot_standard_ref = &base_standard_ref,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
+ .rot_standard_ref = &lid_standard_ref,
.default_range = 4, /* g */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
.max_frequency = BMI160_ACCEL_MAX_FREQ,
@@ -401,15 +490,68 @@ struct motion_sensor_t motion_sensors[] = {
.type = MOTIONSENSE_TYPE_GYRO,
.location = MOTIONSENSE_LOC_LID,
.drv = &bmi160_drv,
- .mutex = &g_base_mutex,
+ .mutex = &g_lid_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,
+ .rot_standard_ref = &lid_standard_ref,
.min_frequency = BMI160_GYRO_MIN_FREQ,
.max_frequency = BMI160_GYRO_MAX_FREQ,
},
+#ifdef CONFIG_MAG_BMI160_BMM150
+ [LID_MAG] = {
+ .name = "Lid Mag",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_MAG,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &bmi160_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
+ .default_range = BIT(11), /* 16LSB / uT, fixed */
+ .rot_standard_ref = &mag_standard_ref,
+ .min_frequency = BMM150_MAG_MIN_FREQ,
+ .max_frequency = BMM150_MAG_MAX_FREQ(SPECIAL),
+ },
+#endif /* CONFIG_MAG_BMI160_BMM150 */
+ [CLEAR_ALS] = {
+ .name = "Clear Light",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_TCS3400,
+ .type = MOTIONSENSE_TYPE_LIGHT,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &tcs3400_drv,
+ .drv_data = &g_tcs3400_data,
+ .port = I2C_PORT_ALS,
+ .i2c_spi_addr__7bf = TCS3400_I2C_ADDR__7bf,
+ .rot_standard_ref = NULL,
+ .default_range = 0x10000, /* scale = 1x, uscale = 0 */
+ .min_frequency = TCS3400_LIGHT_MIN_FREQ,
+ .max_frequency = TCS3400_LIGHT_MAX_FREQ,
+ .config = {
+ /* Run ALS sensor in S0 */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 1000,
+ },
+ },
+ },
+ [RGB_ALS] = {
+ .name = "RGB Light",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_TCS3400,
+ .type = MOTIONSENSE_TYPE_LIGHT_RGB,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &tcs3400_rgb_drv,
+ .drv_data = &g_tcs3400_rgb_data,
+ /*.port = I2C_PORT_ALS,*/ /* Unused. RGB channels read by CLEAR_ALS. */
+ .rot_standard_ref = NULL,
+ .default_range = 0x10000, /* scale = 1x, uscale = 0 */
+ .min_frequency = 0, /* 0 indicates we should not use sensor directly */
+ .max_frequency = 0, /* 0 indicates we should not use sensor directly */
+ },
[VSYNC] = {
.name = "Camera vsync",
.active_mask = SENSOR_ACTIVE_S0,
@@ -423,8 +565,33 @@ struct motion_sensor_t motion_sensors[] = {
},
};
const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+const struct motion_sensor_t *motion_als_sensors[] = {
+ &motion_sensors[CLEAR_ALS],
+};
+
#endif /* SECTION_IS_RW */
+#ifdef BOARD_KRANE
+static void fix_krane(void)
+{
+ if (board_get_version() != 3)
+ return;
+
+ /*
+ * Fix backlight led maximum current: tolerance 120mA * 0.75 = 90mA.
+ * (b/133655155)
+ */
+ mt6370_backlight_set_dim(MT6370_BLDIM_DEFAULT * 3 / 4);
+
+#ifdef SECTION_IS_RW
+ /* Fix reference point */
+ motion_sensors[LID_ACCEL].rot_standard_ref = &lid_standard_ref_rev3;
+ motion_sensors[LID_GYRO].rot_standard_ref = &lid_standard_ref_rev3;
+#endif /* SECTION_IS_RW */
+}
+DECLARE_HOOK(HOOK_INIT, fix_krane, HOOK_PRIO_INIT_ADC + 1);
+#endif /* BOARD_KRANE */
+
int board_allow_i2c_passthru(int port)
{
return (port == I2C_PORT_VIRTUAL_BATTERY);
@@ -433,3 +600,42 @@ int board_allow_i2c_passthru(int port)
void usb_charger_set_switches(int port, enum usb_switch setting)
{
}
+
+/*
+ * Return if VBUS is sagging too low
+ */
+int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state)
+{
+ /*
+ * Though we have a more tolerant range (3.9V~13.4V), setting 4400 to
+ * prevent from a bad charger crashed.
+ *
+ * TODO(b:131284131): mt6370 VBUS reading is not accurate currently.
+ * Vendor will provide a workaround solution to fix the gap between ADC
+ * reading and actual voltage. After the workaround applied, we could
+ * try to raise this value to 4600. (when it says it read 4400, it is
+ * actually close to 4600)
+ */
+ return charger_get_vbus_voltage(port) < 4400;
+}
+
+int board_charge_port_is_sink(int port)
+{
+ /* TODO(b:128386458): Check POGO_ADC_INT_L */
+ return 1;
+}
+
+int board_charge_port_is_connected(int port)
+{
+ return gpio_get_level(GPIO_POGO_VBUS_PRESENT);
+}
+
+void board_fill_source_power_info(int port,
+ struct ec_response_usb_pd_power_info *r)
+{
+ r->meas.voltage_now = 3300;
+ r->meas.voltage_max = 3300;
+ r->meas.current_max = 1500;
+ r->meas.current_lim = 1500;
+ r->max_power = r->meas.voltage_now * r->meas.current_max;
+}
diff --git a/board/kukui/board.h b/board/kukui/board.h
index b0b9396ab5..2ca8428142 100644
--- a/board/kukui/board.h
+++ b/board/kukui/board.h
@@ -91,7 +91,7 @@
/* Motion Sensors */
#ifdef SECTION_IS_RW
#define CONFIG_MAG_BMI160_BMM150
-#define CONFIG_ACCELGYRO_SEC_ADDR BMM150_ADDR0 /* 8-bit address */
+#define CONFIG_ACCELGYRO_SEC_ADDR__7BF BMM150_ADDR0__7bf
#define CONFIG_MAG_CALIBRATE
#define CONFIG_ACCELGYRO_BMI160
#define CONFIG_ACCEL_INTERRUPTS
@@ -184,7 +184,7 @@
#define I2C_PORT_ACCEL 1
/* Route sbs host requests to virtual battery driver */
-#define VIRTUAL_BATTERY_ADDR 0x16
+#define VIRTUAL_BATTERY_ADDR__7bf 0x0B
/* Enable Accel over SPI */
#define CONFIG_SPI_ACCEL_PORT 0 /* The first SPI master port (SPI2) */
diff --git a/board/mchpevb1/battery.c b/board/mchpevb1/battery.c
index 016d225950..d6c702127e 100644
--- a/board/mchpevb1/battery.c
+++ b/board/mchpevb1/battery.c
@@ -47,10 +47,10 @@ int board_cut_off_battery(void)
buf[2] = PARAM_CUT_OFF_HIGH;
i2c_lock(I2C_PORT_BATTERY, 1);
- rv = i2c_xfer_unlocked(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
- I2C_XFER_SINGLE);
- rv |= i2c_xfer_unlocked(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
- I2C_XFER_SINGLE);
+ rv = i2c_xfer_unlocked__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ buf, 3, NULL, 0, I2C_XFER_SINGLE);
+ rv |= i2c_xfer_unlocked__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ buf, 3, NULL, 0, I2C_XFER_SINGLE);
i2c_lock(I2C_PORT_BATTERY, 0);
return rv;
diff --git a/board/mchpevb1/board.c b/board/mchpevb1/board.c
index a87ca3fdcf..cf4f9a8eef 100644
--- a/board/mchpevb1/board.c
+++ b/board/mchpevb1/board.c
@@ -66,14 +66,14 @@
/* NOTE: MEC17xx EVB + SKL RVP3 does not use BD99992 PMIC.
* RVP3 PMIC controlled by RVP3 logic.
*/
-#define I2C_ADDR_BD99992 0x60
+#define I2C_ADDR_BD99992__7bf 0x30
/*
* Maxim DS1624 I2C temperature sensor used for testing I2C.
* DS1624 contains one internal temperature sensor
* and EEPROM. It has no external temperature inputs.
*/
-#define DS1624_I2C_ADDR 0x90 /* 7-bit address is 0x48 */
+#define DS1624_I2C_ADDR__7bf (0x48 | I2C_FLAG_BIG_ENDIAN)
#define DS1624_IDX_LOCAL 0
#define DS1624_READ_TEMP16 0xAA /* read 16-bit temperature */
#define DS1624_ACCESS_CFG 0xAC /* read/write 8-bit config */
@@ -275,8 +275,13 @@ int board_i2c_p2c(int port)
#ifdef CONFIG_USB_POWER_DELIVERY
const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
- {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR, &tcpci_tcpm_drv},
- {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2, &tcpci_tcpm_drv},
+ {I2C_PORT_TCPC,
+ CONFIG_TCPC_I2C_BASE_ADDR__7BF,
+ &tcpci_tcpm_drv},
+
+ {I2C_PORT_TCPC,
+ CONFIG_TCPC_I2C_BASE_ADDR__7BF + 1,
+ &tcpci_tcpm_drv},
};
#endif
@@ -395,11 +400,11 @@ BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) ==
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
{
- .port_addr = 0xa8,
+ .port_addr = 0x54,
.driver = &pi3usb30532_usb_mux_driver,
},
{
- .port_addr = 0x20,
+ .port_addr = 0x10,
.driver = &ps874x_usb_mux_driver,
}
};
@@ -516,14 +521,14 @@ static void board_pmic_init(void)
/* Config DS1624 temperature sensor for continuous conversion */
cfg = 0x66;
- rv = i2c_read8(I2C_PORT_THERMAL, DS1624_I2C_ADDR,
+ rv = i2c_read8__7bf(I2C_PORT_THERMAL, DS1624_I2C_ADDR__7bf,
DS1624_ACCESS_CFG, &cfg);
trace2(0, BRD, 0, "Read DS1624 Config rv = %d cfg = 0x%02X",
rv, cfg);
if ((rv == EC_SUCCESS) && (cfg & (1u << 0))) {
/* one-shot mode switch to continuous */
- rv = i2c_write8(I2C_PORT_THERMAL, DS1624_I2C_ADDR,
+ rv = i2c_write8__7bf(I2C_PORT_THERMAL, DS1624_I2C_ADDR__7bf,
DS1624_ACCESS_CFG, 0);
trace1(0, BRD, 0, "Write DS1624 Config to 0, rv = %d", rv);
/* writes to config require 10ms until next I2C command */
@@ -532,7 +537,7 @@ static void board_pmic_init(void)
}
/* Send start command */
- rv = i2c_write8(I2C_PORT_THERMAL, DS1624_I2C_ADDR,
+ rv = i2c_write8__7bf(I2C_PORT_THERMAL, DS1624_I2C_ADDR__7bf,
DS1624_CMD_START, 1);
trace1(0, BRD, 0, "Send Start command to DS1624 rv = %d", rv);
@@ -875,8 +880,7 @@ static void ds1624_update(void)
int temp;
int rv __attribute__((unused));
- rv = i2c_read16(I2C_PORT_THERMAL,
- (DS1624_I2C_ADDR | I2C_FLAG_BIG_ENDIAN),
+ rv = i2c_read16__7bf(I2C_PORT_THERMAL, DS1624_I2C_ADDR__7bf,
DS1624_READ_TEMP16, &temp);
d = (temp & 0x7FFF) >> 8;
@@ -939,7 +943,8 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = CONFIG_SPI_ACCEL_PORT,
- .addr = BMI160_SET_SPI_ADDRESS(CONFIG_SPI_ACCEL_PORT),
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(
+ CONFIG_SPI_ACCEL_PORT),
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 2, /* g, enough for laptop. */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -963,7 +968,8 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = CONFIG_SPI_ACCEL_PORT,
- .addr = BMI160_SET_SPI_ADDRESS(CONFIG_SPI_ACCEL_PORT),
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(
+ CONFIG_SPI_ACCEL_PORT),
.default_range = 1000, /* dps */
.rot_standard_ref = NULL, /* Identity Matrix. */
.min_frequency = BMI160_GYRO_MIN_FREQ,
@@ -980,7 +986,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kx022_data,
.port = I2C_PORT_ACCEL,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KX022_ACCEL_MIN_FREQ,
diff --git a/board/mchpevb1/board.h b/board/mchpevb1/board.h
index ee6f9d92ba..3445537007 100644
--- a/board/mchpevb1/board.h
+++ b/board/mchpevb1/board.h
@@ -400,7 +400,7 @@
#endif
/* Ambient Light Sensor address */
-#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
+#define OPT3001_I2C_ADDR__7bf OPT3001_I2C_ADDR1__7bf
/* Modules we want to exclude */
#undef CONFIG_CMD_HASH
diff --git a/board/meep/board.c b/board/meep/board.c
index 2bd17d9d5f..19b13eb08d 100644
--- a/board/meep/board.c
+++ b/board/meep/board.c
@@ -153,7 +153,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &kx022_data,
.port = I2C_PORT_SENSOR,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = &lid_standrd_ref,
.default_range = 2, /* g */
.config = {
@@ -186,7 +186,7 @@ struct motion_sensor_t motion_sensors[] = {
.int_signal = GPIO_BASE_SIXAXIS_INT_L,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
.port = I2C_PORT_SENSOR,
- .addr = LSM6DSM_ADDR0,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR0__7bf,
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g */
.min_frequency = LSM6DSM_ODR_MIN_VAL,
@@ -218,7 +218,7 @@ struct motion_sensor_t motion_sensors[] = {
.int_signal = GPIO_BASE_SIXAXIS_INT_L,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
.port = I2C_PORT_SENSOR,
- .addr = LSM6DSM_ADDR0,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR0__7bf,
.default_range = 1000 | ROUND_UP_FLAG, /* dps */
.rot_standard_ref = &base_standard_ref,
.min_frequency = LSM6DSM_ODR_MIN_VAL,
diff --git a/board/nami/board.c b/board/nami/board.c
index 3085db8420..4804c8d2a0 100644
--- a/board/nami/board.c
+++ b/board/nami/board.c
@@ -216,7 +216,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,
/* Alert is active-low, push-pull */
@@ -226,7 +226,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 = AN7447_TCPC3_I2C_ADDR,
+ .addr__7bf = AN7447_TCPC3_I2C_ADDR__7bf,
},
.drv = &anx7447_tcpm_drv,
/* Alert is active-low, push-pull */
@@ -460,9 +460,11 @@ const static struct ec_thermal_config thermal_d2 = {
};
#define I2C_PMIC_READ(reg, data) \
- i2c_read8(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1, (reg), (data))
+ i2c_read8__7bf(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1__7bf,\
+ (reg), (data))
#define I2C_PMIC_WRITE(reg, data) \
- i2c_write8(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1, (reg), (data))
+ i2c_write8__7bf(I2C_PORT_PMIC, TPS650X30_I2C_ADDR1__7bf,\
+ (reg), (data))
static void board_pmic_init(void)
{
@@ -717,7 +719,7 @@ const struct motion_sensor_t lid_accel_1 = {
.mutex = &g_lid_mutex,
.drv_data = &g_kx022_data,
.port = I2C_PORT_ACCEL,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = &rotation_x180_z90,
.min_frequency = KX022_ACCEL_MIN_FREQ,
.max_frequency = KX022_ACCEL_MAX_FREQ,
@@ -745,7 +747,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,
@@ -773,7 +775,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,
@@ -801,7 +803,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,
@@ -930,10 +932,10 @@ static void board_init(void)
gpio_set_level(GPIO_PCH_ACPRESENT, extpower_is_present());
/* Reduce Buck-boost mode switching frequency to reduce heat */
- if (i2c_read16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
+ if (i2c_read16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
ISL9238_REG_CONTROL3, &reg) == EC_SUCCESS) {
reg |= ISL9238_C3_BB_SWITCHING_PERIOD;
- if (i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
+ if (i2c_write16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
ISL9238_REG_CONTROL3, reg))
CPRINTF("Failed to set isl9238\n");
}
diff --git a/board/nami/board.h b/board/nami/board.h
index 5ac9b94666..c7254a281d 100644
--- a/board/nami/board.h
+++ b/board/nami/board.h
@@ -205,8 +205,8 @@
#define I2C_PORT_ALS NPCX_I2C_PORT3
/* I2C addresses */
-#define I2C_ADDR_MP2949 0x40
-#define I2C_ADDR_EEPROM 0xa0
+#define I2C_ADDR_MP2949__7bf 0x20
+#define I2C_ADDR_EEPROM__7bf 0x50
#ifndef __ASSEMBLER__
diff --git a/board/nautilus/board.c b/board/nautilus/board.c
index 2e3d8be848..bf89d0edad 100644
--- a/board/nautilus/board.c
+++ b/board/nautilus/board.c
@@ -112,26 +112,6 @@ void usb1_evt(enum gpio_signal signal)
#include "gpio_list.h"
-/* power signal list. Must match order of enum power_signal. */
-const struct power_signal_info power_signal_list[] = {
-#ifdef CONFIG_POWER_S0IX
- {GPIO_PCH_SLP_S0_L,
- POWER_SIGNAL_ACTIVE_HIGH | POWER_SIGNAL_DISABLE_AT_BOOT,
- "SLP_S0_DEASSERTED"},
-#endif
-#ifdef CONFIG_HOSTCMD_ESPI_VW_SLP_SIGNALS
- {VW_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
- {VW_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
-#else
- {GPIO_PCH_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
- {GPIO_PCH_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
-#endif
- {GPIO_PCH_SLP_SUS_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_SUS_DEASSERTED"},
- {GPIO_RSMRST_L_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "RSMRST_L_PGOOD"},
- {GPIO_PMIC_DPWROK, POWER_SIGNAL_ACTIVE_HIGH, "PMIC_DPWROK"},
-};
-BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
-
/* Hibernate wake configuration */
const enum gpio_signal hibernate_wake_pins[] = {
GPIO_AC_PRESENT,
@@ -171,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,
},
@@ -179,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,
},
@@ -288,29 +268,29 @@ 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;
- if (!(vrfault & (1 << 4)))
+ if (!(vrfault & BIT(4)))
return;
/* 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, (1 << 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
@@ -329,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:
@@ -338,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:
@@ -347,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:
@@ -356,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)
@@ -368,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:
@@ -377,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:
@@ -386,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:
@@ -395,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)
@@ -414,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);
@@ -432,7 +412,7 @@ static void board_init(void)
* floating SPI buffer input (MISO), which causes power leakage (see
* b/64797021).
*/
- NPCX_PUPD_EN1 |= (1 << NPCX_DEVPU1_F_SPI_PUD_EN);
+ NPCX_PUPD_EN1 |= BIT(NPCX_DEVPU1_F_SPI_PUD_EN);
/* Provide AC status to the PCH */
gpio_set_level(GPIO_PCH_ACOK, extpower_is_present());
@@ -532,21 +512,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma,
}
/**
- * Return whether ramping is allowed for given supplier
- */
-int board_is_ramp_allowed(int supplier)
-{
- /* Don't allow ramping in RO when write protected */
- if (!system_is_in_rw() && system_is_locked())
- return 0;
- else
- return (supplier == CHARGE_SUPPLIER_BC12_DCP ||
- supplier == CHARGE_SUPPLIER_BC12_SDP ||
- supplier == CHARGE_SUPPLIER_BC12_CDP ||
- supplier == CHARGE_SUPPLIER_OTHER);
-}
-
-/**
* Return the maximum allowed input current
*/
int board_get_ramp_current_limit(int supplier, int sup_curr)
@@ -570,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
@@ -646,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,
@@ -672,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,
@@ -699,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,
@@ -782,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);
@@ -801,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();
diff --git a/board/nautilus/board.h b/board/nautilus/board.h
index 858247b817..12945e1f98 100644
--- a/board/nautilus/board.h
+++ b/board/nautilus/board.h
@@ -179,8 +179,8 @@
#define I2C_PORT_THERMAL I2C_PORT_PMIC
/* I2C addresses */
-#define I2C_ADDR_BD99992 0x60
-#define I2C_ADDR_MP2949 0x40
+#define I2C_ADDR_BD99992__7bf 0x30
+#define I2C_ADDR_MP2949__7bf 0x20
#ifndef __ASSEMBLER__
diff --git a/board/nocturne/board.c b/board/nocturne/board.c
index 293604c0e3..5df9e338ed 100644
--- a/board/nocturne/board.c
+++ b/board/nocturne/board.c
@@ -26,6 +26,8 @@
#include "hooks.h"
#include "i2c.h"
#include "lid_switch.h"
+#include "lpc.h"
+#include "mkbp_event.h"
#include "motion_sense.h"
#include "power.h"
#include "power_button.h"
@@ -48,10 +50,20 @@
static void tcpc_alert_event(enum gpio_signal s)
{
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
+ int port = -1;
+
+ switch (s) {
+ case GPIO_USB_C0_PD_INT_ODL:
+ port = 0;
+ break;
+ case GPIO_USB_C1_PD_INT_ODL:
+ port = 1;
+ break;
+ default:
+ return;
+ }
+
+ schedule_deferred_pd_interrupt(port);
}
/*
@@ -66,6 +78,21 @@ static void usb_c_interrupt(enum gpio_signal s)
sn5s330_interrupt(port);
}
+static void board_connect_c0_sbu_deferred(void)
+{
+ /*
+ * If CCD_MODE_ODL asserts, it means there's a debug accessory connected
+ * and we should enable the SBU FETs.
+ */
+ ppc_set_sbu(0, 1);
+}
+DECLARE_DEFERRED(board_connect_c0_sbu_deferred);
+
+static void board_connect_c0_sbu(enum gpio_signal s)
+{
+ hook_call_deferred(&board_connect_c0_sbu_deferred_data, 0);
+}
+
#include "gpio_list.h"
const enum gpio_signal hibernate_wake_pins[] = {
@@ -85,19 +112,6 @@ const struct adc_t adc_channels[] = {
},
};
-/* Power signal list. Must match order of enum power_signal. */
-const struct power_signal_info power_signal_list[] = {
- {GPIO_SLP_S0_L,
- POWER_SIGNAL_ACTIVE_HIGH | POWER_SIGNAL_DISABLE_AT_BOOT,
- "SLP_S0_DEASSERTED"},
- {GPIO_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
- {GPIO_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
- {GPIO_PCH_SLP_SUS_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_SUS_DEASSERTED"},
- {GPIO_RSMRST_L_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "RSMRST_L_PGOOD"},
- {GPIO_PMIC_DPWROK, POWER_SIGNAL_ACTIVE_HIGH, "PMIC_DPWROK"},
-};
-BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
-
/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */
const struct pwm_t pwm_channels[] = {
[PWM_CH_DB0_LED_RED] = { 3, PWM_CONFIG_ACTIVE_LOW | PWM_CONFIG_DSLEEP,
@@ -176,7 +190,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_ALS_GYRO,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = &lid_standard_ref,
.default_range = 4, /* g */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -199,7 +213,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_ALS_GYRO,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = &lid_standard_ref,
.default_range = 1000, /* dps */
.min_frequency = BMI160_GYRO_MIN_FREQ,
@@ -215,7 +229,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &opt3001_drv,
.drv_data = &g_opt3001_data,
.port = I2C_PORT_ALS_GYRO,
- .addr = OPT3001_I2C_ADDR,
+ .i2c_spi_addr__7bf = OPT3001_I2C_ADDR__7bf,
.rot_standard_ref = NULL,
/* scale = 43.4513 http://b/111528815#comment14 */
.default_range = 0x2b11a1,
@@ -273,12 +287,12 @@ DECLARE_HOOK(HOOK_CHIPSET_RESUME, enable_sensor_irqs, HOOK_PRIO_DEFAULT);
struct ppc_config_t ppc_chips[] = {
{
.i2c_port = I2C_PORT_USB_C0,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv
},
{
.i2c_port = I2C_PORT_USB_C1,
- .i2c_addr = SN5S330_ADDR0,
+ .i2c_addr__7bf = SN5S330_ADDR0__7bf,
.drv = &sn5s330_drv,
},
};
@@ -289,7 +303,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_USB_C0,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &tcpci_tcpm_drv,
},
@@ -297,7 +311,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_USB_C1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &tcpci_tcpm_drv,
},
@@ -328,7 +342,8 @@ DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_chipset_startup, HOOK_PRIO_DEFAULT);
static void imvp8_tune_deferred(void)
{
/* For the IMVP8, reduce the steps during decay from 3 to 1. */
- if (i2c_write16(I2C_PORT_POWER, I2C_ADDR_MP2949, 0xFA, 0x0AC5))
+ if (i2c_write16__7bf(I2C_PORT_POWER, I2C_ADDR_MP2949__7bf,
+ 0xFA, 0x0AC5))
CPRINTS("Failed to change step decay!");
}
DECLARE_DEFERRED(imvp8_tune_deferred);
@@ -386,7 +401,7 @@ void board_hibernate(void)
system_enter_psl_mode();
/* Cut off DSW power via the ROP PMIC. */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x49, 0x1);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x49, 0x1);
/* Wait for power to be cut. */
while (1)
@@ -436,7 +451,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:
@@ -445,7 +460,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:
@@ -454,7 +469,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:
@@ -463,7 +478,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, 0x2a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x38, 0x2a);
}
static void board_pmic_enable_slp_s0_vr_decay(void)
@@ -475,7 +490,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:
@@ -484,7 +499,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:
@@ -493,7 +508,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:
@@ -502,7 +517,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, 0x6a);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x38, 0x6a);
}
void power_board_handle_host_sleep_event(enum host_sleep_event state)
@@ -518,15 +533,16 @@ static void board_pmic_init(void)
int pgmask1;
/* Mask V5A_DS3_PG from PMIC PGMASK1. */
- if (i2c_read8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x18, &pgmask1))
+ if (i2c_read8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf,
+ 0x18, &pgmask1))
return;
- pgmask1 |= (1 << 2);
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x18, pgmask1);
+ pgmask1 |= BIT(2);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x18, pgmask1);
board_pmic_disable_slp_s0_vr_decay();
/* Enable active discharge (100 ohms) on V33A_PCH and V1.8A. */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x3D, 0x5);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x3D, 0x5);
}
DECLARE_HOOK(HOOK_INIT, board_pmic_init, HOOK_PRIO_DEFAULT);
@@ -540,6 +556,14 @@ static void board_quirks(void)
gpio_set_flags(GPIO_USB_C0_PD_INT_ODL, GPIO_INT_FALLING);
gpio_set_flags(GPIO_USB_C1_PD_INT_ODL, GPIO_INT_FALLING);
}
+
+ /*
+ * Older boards don't have the SBU bypass circuitry needed for CCD, so
+ * enable the CCD_MODE_ODL interrupt such that we can help in making
+ * sure the SBU FETs are connected.
+ */
+ if (board_get_version() < 2)
+ gpio_enable_interrupt(GPIO_CCD_MODE_ODL);
}
DECLARE_HOOK(HOOK_INIT, board_quirks, HOOK_PRIO_DEFAULT);
@@ -609,29 +633,29 @@ 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;
- if (!(vrfault & (1 << 4)))
+ if (!(vrfault & BIT(4)))
return;
/* 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, (1 << 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
@@ -674,10 +698,13 @@ int board_set_active_charge_port(int port)
port < CONFIG_USB_PD_PORT_COUNT);
int i;
int rv;
+ int old_port;
if (!is_real_port && port != CHARGE_PORT_NONE)
return EC_ERROR_INVAL;
+ old_port = charge_manager_get_active_charge_port();
+
CPRINTS("New chg p%d", port);
if (port == CHARGE_PORT_NONE) {
@@ -713,12 +740,23 @@ int board_set_active_charge_port(int port)
CPRINTS("p%d: sink path disable failed.", i);
}
+ /*
+ * Stop the charger IC from switching while changing ports. Otherwise,
+ * we can overcurrent the adapter we're switching to. (crbug.com/926056)
+ */
+ if (old_port != CHARGE_PORT_NONE)
+ charger_discharge_on_ac(1);
+
/* Enable requested charge port. */
if (ppc_vbus_sink_enable(port, 1)) {
CPRINTS("p%d: sink path enable failed.");
+ charger_discharge_on_ac(0);
return EC_ERROR_UNKNOWN;
}
+ /* Allow the charger IC to begin/continue switching. */
+ charger_discharge_on_ac(0);
+
return EC_SUCCESS;
}
@@ -753,7 +791,7 @@ uint16_t tcpc_get_alert_status(void)
if (!gpio_get_level(GPIO_USB_C0_PD_INT_ODL)) {
if (!tcpc_read16(0, TCPC_REG_ALERT, &regval)) {
/* The TCPCI spec says to ignore bits 14:12. */
- regval &= ~((1 << 14) | (1 << 13) | (1 << 12));
+ regval &= ~(BIT(14) | BIT(13) | BIT(12));
if (regval)
status |= PD_STATUS_TCPC_ALERT_0;
@@ -763,7 +801,7 @@ uint16_t tcpc_get_alert_status(void)
if (!gpio_get_level(GPIO_USB_C1_PD_INT_ODL)) {
if (!tcpc_read16(1, TCPC_REG_ALERT, &regval)) {
/* TCPCI spec says to ignore bits 14:12. */
- regval &= ~((1 << 14) | (1 << 13) | (1 << 12));
+ regval &= ~(BIT(14) | BIT(13) | BIT(12));
if (regval)
status |= PD_STATUS_TCPC_ALERT_1;
diff --git a/board/nocturne/board.h b/board/nocturne/board.h
index fc43a119ed..d678f70a3e 100644
--- a/board/nocturne/board.h
+++ b/board/nocturne/board.h
@@ -44,6 +44,8 @@
#define CONFIG_VSTORE
#define CONFIG_VSTORE_SLOT_COUNT 1
+#define CONFIG_DETACHABLE_BASE
+
/* EC console commands */
#define CONFIG_CMD_ACCELS
#define CONFIG_CMD_ACCEL_INFO
@@ -83,18 +85,18 @@
/* MKBP */
#define CONFIG_MKBP_EVENT
-#define CONFIG_MKBP_USE_HOST_EVENT
+#define CONFIG_MKBP_EVENT_WAKEUP_MASK 0
#define CONFIG_KEYBOARD_PROTOCOL_MKBP
-#define CONFIG_MKBP_USE_GPIO
+#define CONFIG_MKBP_USE_GPIO_AND_HOST_EVENT
/* Sensors */
#define CONFIG_ALS
#define ALS_COUNT 1
#define CONFIG_ALS_OPT3001
-#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
-#define CONFIG_ACCEL_FIFO 1024 /* Must be a power of 2 */
+#define OPT3001_I2C_ADDR__7bf OPT3001_I2C_ADDR1__7bf
+#define CONFIG_ACCEL_FIFO 512 /* Must be a power of 2 */
/* Depends on how fast the AP boots and typical ODRs */
-#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 100)
+#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3)
#define CONFIG_ACCEL_INTERRUPTS
#define CONFIG_ACCELGYRO_BMI160
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
@@ -127,7 +129,6 @@
#define CONFIG_USB_PD_DUAL_ROLE
#define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
#define CONFIG_USB_PD_LOGGING
-#define CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT TYPEC_RP_3A0
#define CONFIG_USB_PD_PORT_COUNT 2
#define CONFIG_USB_PD_TCPC_LOW_POWER
#define CONFIG_USB_PD_TCPM_PS8805
@@ -174,8 +175,8 @@
#define GPIO_USB_C1_SCL GPIO_EC_I2C2_USB_C1_SCL
#define GPIO_USB_C1_SDA GPIO_EC_I2C2_USB_C1_SDA
-#define I2C_ADDR_MP2949 0x40
-#define I2C_ADDR_BD99992 0x60
+#define I2C_ADDR_MP2949__7bf 0x20
+#define I2C_ADDR_BD99992__7bf 0x30
/*
* Remapping of schematic GPIO names to common GPIO names expected (hardcoded)
@@ -213,16 +214,6 @@ enum adc_channel {
ADC_CH_COUNT
};
-enum power_signal {
- X86_SLP_S0_DEASSERTED,
- X86_SLP_S3_DEASSERTED,
- X86_SLP_S4_DEASSERTED,
- X86_SLP_SUS_DEASSERTED,
- X86_RSMRST_L_PGOOD,
- X86_PMIC_DPWROK,
- POWER_SIGNAL_COUNT
-};
-
enum temp_sensor_id {
TEMP_SENSOR_BATTERY, /* BD99956GW TSENSE */
TEMP_SENSOR_AMBIENT, /* BD99992GW SYSTHERM0 */
@@ -257,7 +248,7 @@ enum sensor_id {
SENSOR_COUNT,
};
-#define CONFIG_ACCEL_FORCE_MODE_MASK (1 << LID_ALS)
+#define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ALS)
void base_pwr_fault_interrupt(enum gpio_signal s);
int board_get_version(void);
diff --git a/board/nucleo-f411re/board.c b/board/nucleo-f411re/board.c
index 0f7c57f1e3..d2f587321f 100644
--- a/board/nucleo-f411re/board.c
+++ b/board/nucleo-f411re/board.c
@@ -75,7 +75,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 = NULL,
.default_range = 2, /* g, enough for laptop. */
.config = {
@@ -102,7 +102,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 = NULL,
},
diff --git a/board/oak/battery.c b/board/oak/battery.c
index a868e20bc0..25d6b6e46d 100644
--- a/board/oak/battery.c
+++ b/board/oak/battery.c
@@ -57,10 +57,10 @@ static int cutoff(void)
buf[2] = PARAM_CUT_OFF_HIGH;
i2c_lock(I2C_PORT_BATTERY, 1);
- rv = i2c_xfer_unlocked(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
- I2C_XFER_SINGLE);
- rv |= i2c_xfer_unlocked(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
- I2C_XFER_SINGLE);
+ rv = i2c_xfer_unlocked__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ buf, 3, NULL, 0, I2C_XFER_SINGLE);
+ rv |= i2c_xfer_unlocked__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ buf, 3, NULL, 0, I2C_XFER_SINGLE);
i2c_lock(I2C_PORT_BATTERY, 0);
return rv;
diff --git a/board/oak/board.c b/board/oak/board.c
index 476ef90b76..41ad3a5526 100644
--- a/board/oak/board.c
+++ b/board/oak/board.c
@@ -117,7 +117,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC,
- .addr = CONFIG_TCPC_I2C_BASE_ADDR,
+ .addr__7bf = CONFIG_TCPC_I2C_BASE_ADDR__7BF,
},
.drv = &tcpci_tcpm_drv,
},
@@ -125,7 +125,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC,
- .addr = CONFIG_TCPC_I2C_BASE_ADDR + 2,
+ .addr__7bf = CONFIG_TCPC_I2C_BASE_ADDR__7BF + 1,
},
.drv = &tcpci_tcpm_drv,
},
@@ -176,17 +176,17 @@ BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT);
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
{
- .port_addr = 0x54 << 1,
+ .port_addr = 0x54,
.driver = &pi3usb30532_usb_mux_driver,
},
#if (BOARD_REV <= OAK_REV4)
{
- .port_addr = 0x55 << 1,
+ .port_addr = 0x55,
.driver = &pi3usb30532_usb_mux_driver,
},
#else
{
- .port_addr = 0x20,
+ .port_addr = 0x10,
.driver = &ps874x_usb_mux_driver,
},
#endif
@@ -647,7 +647,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_ACCEL,
- .addr = 1,
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(0),
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -671,7 +671,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_ACCEL,
- .addr = 1,
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(0),
.default_range = 1000, /* dps */
.rot_standard_ref = &base_standard_ref,
.min_frequency = BMI160_GYRO_MIN_FREQ,
@@ -689,7 +689,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kx022_data,
.port = I2C_PORT_ACCEL,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KX022_ACCEL_MIN_FREQ,
diff --git a/board/oak/board.h b/board/oak/board.h
index e4ae567b29..af68701ab1 100644
--- a/board/oak/board.h
+++ b/board/oak/board.h
@@ -160,7 +160,7 @@
#define CONFIG_SPI_ACCEL_PORT 0 /* First SPI master port (SPI2) */
/* Ambient Light Sensor address */
-#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
+#define OPT3001_I2C_ADDR__7bf OPT3001_I2C_ADDR1__7bf
/* Timer selection */
#define TIM_CLOCK32 2
diff --git a/board/pdeval-stm32f072/board.c b/board/pdeval-stm32f072/board.c
index 5a632ced06..e2e6bc63b6 100644
--- a/board/pdeval-stm32f072/board.c
+++ b/board/pdeval-stm32f072/board.c
@@ -4,8 +4,8 @@
*/
/* STM32F072-discovery board based USB PD evaluation configuration */
-#include "anx7447.h"
#include "common.h"
+#include "anx7447.h"
#include "ec_version.h"
#include "gpio.h"
#include "hooks.h"
@@ -62,7 +62,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC,
- .addr = AN7447_TCPC3_I2C_ADDR,
+ .addr__7bf = AN7447_TCPC3_I2C_ADDR__7bf,
},
.drv = &anx7447_tcpm_drv,
},
diff --git a/board/pdeval-stm32f072/usb_pd_policy.c b/board/pdeval-stm32f072/usb_pd_policy.c
index ba899f5efb..4b1e7ca6f7 100644
--- a/board/pdeval-stm32f072/usb_pd_policy.c
+++ b/board/pdeval-stm32f072/usb_pd_policy.c
@@ -3,8 +3,8 @@
* found in the LICENSE file.
*/
-#include "anx7447.h"
#include "common.h"
+#include "anx7447.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
diff --git a/board/phaser/board.c b/board/phaser/board.c
index 90f5c3e30a..353eeed9e5 100644
--- a/board/phaser/board.c
+++ b/board/phaser/board.c
@@ -30,20 +30,15 @@
#include "temp_sensor.h"
#include "thermistor.h"
#include "util.h"
+#include "battery_smart.h"
-static uint16_t sku_id;
+#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args)
-static void tcpc_alert_event(enum gpio_signal signal)
-{
- if ((signal == GPIO_USB_C1_MUX_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C1_PD_RST_ODL))
- return;
+#define USB_PD_PORT_ANX7447 0
+#define USB_PD_PORT_PS8751 1
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
-}
+static uint8_t sku_id;
static void ppc_interrupt(enum gpio_signal signal)
{
@@ -70,6 +65,11 @@ const struct adc_t adc_channels[] = {
"TEMP_AMB", NPCX_ADC_CH0, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
[ADC_TEMP_SENSOR_CHARGER] = {
"TEMP_CHARGER", NPCX_ADC_CH1, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+ /* Vbus sensing (1/10 voltage divider). */
+ [ADC_VBUS_C0] = {
+ "VBUS_C0", NPCX_ADC_CH9, ADC_MAX_VOLT*10, ADC_READ_MAX+1, 0},
+ [ADC_VBUS_C1] = {
+ "VBUS_C1", NPCX_ADC_CH4, ADC_MAX_VOLT*10, ADC_READ_MAX+1, 0},
};
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
@@ -92,20 +92,6 @@ const struct temp_sensor_t temp_sensors[] = {
};
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
-static void customize_based_on_board_id(void)
-{
- uint32_t board_id = 0;
-
- /* Errors will count as board_id 0 */
- cbi_get_board_version(&board_id);
-
- if (board_id == 0) {
- if (anx7447_flash_erase(0 /* C0: ANX7447 */))
- ccprints("Failed to erase OCM flash!");
- }
-}
-DECLARE_HOOK(HOOK_INIT, customize_based_on_board_id, HOOK_PRIO_INIT_I2C + 1);
-
/* Motion sensors */
/* Mutexes */
static struct mutex g_lid_mutex;
@@ -125,31 +111,31 @@ static struct lsm6dsm_data lsm6dsm_data;
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
- .name = "Lid Accel",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_LIS2DE,
- .type = MOTIONSENSE_TYPE_ACCEL,
- .location = MOTIONSENSE_LOC_LID,
- .drv = &lis2dh_drv,
- .mutex = &g_lid_mutex,
- .drv_data = &g_lis2dh_data,
- .port = I2C_PORT_SENSOR,
- .addr = LIS2DH_ADDR1,
- .rot_standard_ref = &standard_rot_ref,
- /* We only use 2g because its resolution is only 8-bits */
- .default_range = 2, /* g */
- .min_frequency = LIS2DH_ODR_MIN_VAL,
- .max_frequency = LIS2DH_ODR_MAX_VAL,
- .config = {
- /* EC use accel for angle detection */
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- /* Sensor on for lid angle detection */
- [SENSOR_CONFIG_EC_S3] = {
- .odr = 10000 | ROUND_UP_FLAG,
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_LIS2DE,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &lis2dh_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_lis2dh_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = LIS2DH_ADDR1__7bf,
+ .rot_standard_ref = &standard_rot_ref,
+ /* We only use 2g because its resolution is only 8-bits */
+ .default_range = 2, /* g */
+ .min_frequency = LIS2DH_ODR_MIN_VAL,
+ .max_frequency = LIS2DH_ODR_MAX_VAL,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
},
- },
},
[BASE_ACCEL] = {
@@ -165,7 +151,7 @@ struct motion_sensor_t motion_sensors[] = {
.int_signal = GPIO_BASE_SIXAXIS_INT_L,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
.port = I2C_PORT_SENSOR,
- .addr = LSM6DSM_ADDR0,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR0__7bf,
.rot_standard_ref = &standard_rot_ref,
.default_range = 4, /* g */
.min_frequency = LSM6DSM_ODR_MIN_VAL,
@@ -182,7 +168,6 @@ struct motion_sensor_t motion_sensors[] = {
.ec_rate = 100 * MSEC,
},
},
- },
},
[BASE_GYRO] = {
@@ -198,7 +183,7 @@ struct motion_sensor_t motion_sensors[] = {
.int_signal = GPIO_BASE_SIXAXIS_INT_L,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
.port = I2C_PORT_SENSOR,
- .addr = LSM6DSM_ADDR0,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR0__7bf,
.default_range = 1000 | ROUND_UP_FLAG, /* dps */
.rot_standard_ref = &standard_rot_ref,
.min_frequency = LSM6DSM_ODR_MIN_VAL,
@@ -210,15 +195,23 @@ unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
static int board_is_convertible(void)
{
- return sku_id == 2 || sku_id == 3 || sku_id == 255;
+ return sku_id == 2 || sku_id == 3 || sku_id == 4 || sku_id == 5 || \
+ sku_id == 255;
}
-static void board_set_motion_sensor_count(void)
+static void board_update_sensor_config_from_sku(void)
{
- if (board_is_convertible())
+ if (board_is_convertible()) {
motion_sensor_count = ARRAY_SIZE(motion_sensors);
- else
+ /* Enable Base Accel interrupt */
+ gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
+ } else {
motion_sensor_count = 0;
+ hall_sensor_disable();
+ /* Base accel is not stuffed, don't allow line to float */
+ gpio_set_flags(GPIO_BASE_SIXAXIS_INT_L,
+ GPIO_INPUT | GPIO_PULL_DOWN);
+ }
}
static void cbi_init(void)
@@ -229,18 +222,10 @@ static void cbi_init(void)
sku_id = val;
ccprints("SKU: 0x%04x", sku_id);
- board_set_motion_sensor_count();
+ board_update_sensor_config_from_sku();
}
DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_INIT_I2C + 1);
-/* Initialize board. */
-static void board_init(void)
-{
- /* Enable Base Accel interrupt */
- gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
-}
-DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
-
#ifndef TEST_BUILD
/* This callback disables keyboard when convertibles are fully open */
void lid_angle_peripheral_enable(int enable)
@@ -262,3 +247,56 @@ int board_is_lid_angle_tablet_mode(void)
{
return board_is_convertible();
}
+
+/* Battery functions */
+#define SB_OPTIONALMFG_FUNCTION2 0x3e
+/* Optional mfg function2 */
+#define SMART_QUICK_CHARGE (1<<12)
+/* Quick charge support */
+#define MODE_QUICK_CHARGE_SUPPORT (1<<4)
+
+static void sb_quick_charge_mode(int enable)
+{
+ int val, rv;
+
+ rv = sb_read(SB_BATTERY_MODE, &val);
+ if (rv || !(val & MODE_QUICK_CHARGE_SUPPORT))
+ return;
+
+ rv = sb_read(SB_OPTIONALMFG_FUNCTION2, &val);
+ if (rv)
+ return;
+
+ if (enable)
+ val |= SMART_QUICK_CHARGE;
+ else
+ val &= ~SMART_QUICK_CHARGE;
+
+ sb_write(SB_OPTIONALMFG_FUNCTION2, val);
+}
+
+/* Called on AP S3/S0ix -> S0 transition */
+static void board_chipset_resume(void)
+{
+ /* Normal charge current */
+ sb_quick_charge_mode(0);
+}
+DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT);
+
+/* Called on AP S0 -> S3/S0ix transition */
+static void board_chipset_suspend(void)
+{
+ /* Quick charge current */
+ sb_quick_charge_mode(1);
+}
+DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT);
+
+void board_overcurrent_event(int port, int is_overcurrented)
+{
+ /* Sanity check the port. */
+ if ((port < 0) || (port >= CONFIG_USB_PD_PORT_COUNT))
+ return;
+
+ /* Note that the level is inverted because the pin is active low. */
+ gpio_set_level(GPIO_USB_C_OC, !is_overcurrented);
+}
diff --git a/board/plankton/board.c b/board/plankton/board.c
index 5cd9e54486..c6c65ce789 100644
--- a/board/plankton/board.c
+++ b/board/plankton/board.c
@@ -467,7 +467,7 @@ const struct i2c_port_t i2c_ports[] = {
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* 8-bit address */
-#define SN75DP130_I2C_ADDR 0x5c
+#define SN75DP130_I2C_ADDR__7bf 0x2e
/*
* Pin number for active-high reset from PCA9534 to CMOS pull-down to
* SN75DP130's RSTN (active-low)
@@ -476,7 +476,8 @@ const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
static int sn75dp130_i2c_write(uint8_t index, uint8_t value)
{
- return i2c_write8(I2C_PORT_MASTER, SN75DP130_I2C_ADDR, index, value);
+ return i2c_write8__7bf(I2C_PORT_MASTER, SN75DP130_I2C_ADDR__7bf,
+ index, value);
}
/**
@@ -489,15 +490,17 @@ static int sn75dp130_reset(void)
{
int rv;
- rv = pca9534_config_pin(I2C_PORT_MASTER, 0x40, REDRIVER_RST_PIN,
- PCA9534_OUTPUT);
+ rv = pca9534_config_pin__7bf(I2C_PORT_MASTER, 0x20,
+ REDRIVER_RST_PIN, PCA9534_OUTPUT);
/* Assert (its active high) */
- rv |= pca9534_set_level(I2C_PORT_MASTER, 0x40, REDRIVER_RST_PIN, 1);
+ rv |= pca9534_set_level__7bf(I2C_PORT_MASTER, 0x20,
+ REDRIVER_RST_PIN, 1);
/* datasheet recommends > 100usec */
usleep(200);
/* De-assert */
- rv |= pca9534_set_level(I2C_PORT_MASTER, 0x40, REDRIVER_RST_PIN, 0);
+ rv |= pca9534_set_level__7bf(I2C_PORT_MASTER, 0x20,
+ REDRIVER_RST_PIN, 0);
/* datasheet recommends > 400msec */
usleep(450 * MSEC);
return rv;
@@ -593,10 +596,12 @@ int board_in_hub_mode(void)
int ret;
int level;
- ret = pca9534_config_pin(I2C_PORT_MASTER, 0x40, 6, PCA9534_INPUT);
+ ret = pca9534_config_pin__7bf(I2C_PORT_MASTER, 0x20,
+ 6, PCA9534_INPUT);
if (ret)
return -1;
- ret = pca9534_get_level(I2C_PORT_MASTER, 0x40, 6, &level);
+ ret = pca9534_get_level__7bf(I2C_PORT_MASTER, 0x20,
+ 6, &level);
if (ret)
return -1;
return level;
@@ -606,14 +611,17 @@ static int board_usb_hub_reset(void)
{
int ret;
- ret = pca9534_config_pin(I2C_PORT_MASTER, 0x40, 7, PCA9534_OUTPUT);
+ ret = pca9534_config_pin__7bf(I2C_PORT_MASTER, 0x20,
+ 7, PCA9534_OUTPUT);
if (ret)
return ret;
- ret = pca9534_set_level(I2C_PORT_MASTER, 0x40, 7, 0);
+ ret = pca9534_set_level__7bf(I2C_PORT_MASTER, 0x20,
+ 7, 0);
if (ret)
return ret;
usleep(100 * MSEC);
- return pca9534_set_level(I2C_PORT_MASTER, 0x40, 7, 1);
+ return pca9534_set_level__7bf(I2C_PORT_MASTER, 0x20,
+ 7, 1);
}
void board_maybe_reset_usb_hub(void)
diff --git a/board/poppy/board.c b/board/poppy/board.c
index 189452bf97..90e56b6fa8 100644
--- a/board/poppy/board.c
+++ b/board/poppy/board.c
@@ -142,44 +142,8 @@ void anx74xx_cable_det_interrupt(enum gpio_signal signal)
}
#endif
-static int command_attach_base(int argc, char **argv)
-{
- tablet_set_mode(0);
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(attachbase, command_attach_base,
- NULL, "Simulate attach base");
-
-static int command_detach_base(int argc, char **argv)
-{
- tablet_set_mode(1);
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(detachbase, command_detach_base,
- NULL, "Simulate detach base");
-
#include "gpio_list.h"
-/* power signal list. Must match order of enum power_signal. */
-const struct power_signal_info power_signal_list[] = {
-#ifdef CONFIG_POWER_S0IX
- {GPIO_PCH_SLP_S0_L,
- POWER_SIGNAL_ACTIVE_HIGH | POWER_SIGNAL_DISABLE_AT_BOOT,
- "SLP_S0_DEASSERTED"},
-#endif
-#ifdef CONFIG_HOSTCMD_ESPI_VW_SLP_SIGNALS
- {VW_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
- {VW_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
-#else
- {GPIO_PCH_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
- {GPIO_PCH_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
-#endif
- {GPIO_PCH_SLP_SUS_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_SUS_DEASSERTED"},
- {GPIO_RSMRST_L_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "RSMRST_L_PGOOD"},
- {GPIO_PMIC_DPWROK, POWER_SIGNAL_ACTIVE_HIGH, "PMIC_DPWROK"},
-};
-BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
-
/* Hibernate wake configuration */
const enum gpio_signal hibernate_wake_pins[] = {
GPIO_AC_PRESENT,
@@ -229,7 +193,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 = ANX74XX_I2C_ADDR1,
+ .addr__7bf = ANX74XX_I2C_ADDR1__7bf,
},
.drv = &anx74xx_tcpm_drv,
},
@@ -237,7 +201,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,
},
@@ -327,7 +291,7 @@ void board_tcpc_init(void)
*
* NOTE: PS8751 A3 will wake on any I2C access.
*/
- i2c_read8(NPCX_I2C_PORT0_1, 0x10, 0xA0, &reg);
+ i2c_read8__7bf(NPCX_I2C_PORT0_1, 0x08, 0xA0, &reg);
/* Enable TCPC interrupts */
gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
@@ -394,29 +358,29 @@ 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;
- if (!(vrfault & (1 << 4)))
+ if (!(vrfault & BIT(4)))
return;
/* 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, (1 << 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
@@ -435,7 +399,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:
@@ -444,7 +408,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:
@@ -453,7 +417,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:
@@ -462,7 +426,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)
@@ -474,7 +438,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:
@@ -483,7 +447,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:
@@ -492,7 +456,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:
@@ -501,7 +465,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)
@@ -520,15 +484,15 @@ 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);
/* Disable power button shutdown timer. */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x14, 0x00);
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x14, 0x00);
}
DECLARE_DEFERRED(board_pmic_init);
@@ -541,7 +505,7 @@ static void board_init(void)
* floating SPI buffer input (MISO), which causes power leakage (see
* b/64797021).
*/
- NPCX_PUPD_EN1 |= (1 << NPCX_DEVPU1_F_SPI_PUD_EN);
+ NPCX_PUPD_EN1 |= BIT(NPCX_DEVPU1_F_SPI_PUD_EN);
/* Provide AC status to the PCH */
gpio_set_level(GPIO_PCH_ACOK, extpower_is_present());
@@ -688,23 +652,24 @@ void board_set_charge_limit(int port, int supplier, int charge_ma,
void board_hibernate(void)
{
- CPRINTS("Triggering PMIC shutdown.");
- uart_flush_output();
-
- /* Trigger PMIC shutdown. */
- if (i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 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
- * communicate with the PMIC next time.
- */
- CPRINTS("PMIC i2c failed.");
- system_reset(SYSTEM_RESET_LEAVE_AP_OFF);
- }
-
- /* Await shutdown. */
- while (1)
- ;
+ CPRINTS("Triggering PMIC shutdown.");
+ uart_flush_output();
+
+ /* Trigger PMIC shutdown. */
+ 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
+ * communicate with the PMIC next time.
+ */
+ CPRINTS("PMIC i2c failed.");
+ system_reset(SYSTEM_RESET_LEAVE_AP_OFF);
+ }
+
+ /* Await shutdown. */
+ while (1)
+ ;
}
int board_get_version(void)
@@ -786,7 +751,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = &lid_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -810,7 +775,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.default_range = 1000, /* dps */
.rot_standard_ref = &lid_standard_ref,
.min_frequency = BMI160_GYRO_MIN_FREQ,
@@ -827,8 +792,8 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
- .default_range = 1 << 11, /* 16LSB / uT, fixed */
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
+ .default_range = BIT(11), /* 16LSB / uT, fixed */
.rot_standard_ref = &mag_standard_ref,
.min_frequency = BMM150_MAG_MIN_FREQ,
.max_frequency = BMM150_MAG_MAX_FREQ(SPECIAL),
@@ -842,7 +807,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &opt3001_drv,
.drv_data = &g_opt3001_data,
.port = I2C_PORT_ALS,
- .addr = OPT3001_I2C_ADDR,
+ .i2c_spi_addr__7bf = OPT3001_I2C_ADDR__7bf,
.rot_standard_ref = NULL,
.default_range = 0x10000, /* scale = 1; uscale = 0 */
.min_frequency = OPT3001_LIGHT_MIN_FREQ,
diff --git a/board/poppy/board.h b/board/poppy/board.h
index 78beb1b5f1..3a90d35483 100644
--- a/board/poppy/board.h
+++ b/board/poppy/board.h
@@ -111,7 +111,7 @@
#define CONFIG_ALS
#define CONFIG_ALS_OPT3001
#define ALS_COUNT 1
-#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1
+#define OPT3001_I2C_ADDR__7bf OPT3001_I2C_ADDR1__7bf
#define CONFIG_TEMP_SENSOR
#define CONFIG_TEMP_SENSOR_BD99992GW
#define CONFIG_THERMISTOR_NCP15WB
@@ -124,7 +124,7 @@
#define CONFIG_ACCEL_INTERRUPTS
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL)
-#define CONFIG_ACCELGYRO_SEC_ADDR BMM150_ADDR0 /* 8-bit address */
+#define CONFIG_ACCELGYRO_SEC_ADDR__7BF BMM150_ADDR0__7bf
#define CONFIG_MAG_CALIBRATE
/* Lower maximal ODR to 100Hz */
#define CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ 100000
@@ -188,8 +188,8 @@
#define I2C_PORT_THERMAL I2C_PORT_PMIC
/* I2C addresses */
-#define I2C_ADDR_BD99992 0x60
-#define I2C_ADDR_MP2949 0x40
+#define I2C_ADDR_BD99992__7bf 0x30
+#define I2C_ADDR_MP2949__7bf 0x20
#ifndef __ASSEMBLER__
diff --git a/board/rainier/board.c b/board/rainier/board.c
index 7022b4076a..8173414bf7 100644
--- a/board/rainier/board.c
+++ b/board/rainier/board.c
@@ -46,10 +46,7 @@
static void tcpc_alert_event(enum gpio_signal signal)
{
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
+ schedule_deferred_pd_interrupt(0 /* port */);
}
static void overtemp_interrupt(enum gpio_signal signal)
@@ -134,7 +131,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = FUSB302_I2C_SLAVE_ADDR,
+ .addr__7bf = FUSB302_I2C_SLAVE_ADDR__7bf,
},
.drv = &fusb302_tcpm_drv,
},
@@ -380,7 +377,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = CONFIG_SPI_ACCEL_PORT,
- .addr = BMI160_SET_SPI_ADDRESS(CONFIG_SPI_ACCEL_PORT),
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(CONFIG_SPI_ACCEL_PORT),
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -403,7 +400,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = CONFIG_SPI_ACCEL_PORT,
- .addr = BMI160_SET_SPI_ADDRESS(CONFIG_SPI_ACCEL_PORT),
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(CONFIG_SPI_ACCEL_PORT),
.default_range = 1000, /* dps */
.rot_standard_ref = &base_standard_ref,
.min_frequency = BMI160_GYRO_MIN_FREQ,
@@ -425,8 +422,8 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &bmp280_drv,
.drv_data = &bmp280_drv_data,
.port = CONFIG_SPI_ACCEL_PORT,
- .addr = BMI160_SET_SPI_ADDRESS(CONFIG_SPI_ACCEL_PORT),
- .default_range = 1 << 18, /* 1bit = 4 Pa, 16bit ~= 2600 hPa */
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(CONFIG_SPI_ACCEL_PORT),
+ .default_range = BIT(18), /* 1bit = 4 Pa, 16bit ~= 2600 hPa */
.min_frequency = BMP280_BARO_MIN_FREQ,
.max_frequency = BMP280_BARO_MAX_FREQ,
},
diff --git a/board/rammus/board.c b/board/rammus/board.c
index 485cf3cc48..82af7a2667 100644
--- a/board/rammus/board.c
+++ b/board/rammus/board.c
@@ -62,17 +62,20 @@
static void tcpc_alert_event(enum gpio_signal signal)
{
- if ((signal == GPIO_USB_C0_PD_INT_ODL) &&
- !gpio_get_level(GPIO_USB_PD_RST_C0_L))
- return;
- else if ((signal == GPIO_USB_C1_PD_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C1_PD_RST_ODL))
+ int port = -1;
+
+ switch (signal) {
+ case GPIO_USB_C0_PD_INT_ODL:
+ port = 0;
+ break;
+ case GPIO_USB_C1_PD_INT_ODL:
+ port = 1;
+ break;
+ default:
return;
+ }
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
+ schedule_deferred_pd_interrupt(port);
}
/* Set PD discharge whenever VBUS detection is high (i.e. below threshold). */
@@ -111,21 +114,6 @@ void usb1_evt(enum gpio_signal signal)
#include "gpio_list.h"
-/* power signal list. Must match order of enum power_signal. */
-const struct power_signal_info power_signal_list[] = {
-#ifdef CONFIG_POWER_S0IX
- {GPIO_PCH_SLP_S0_L,
- POWER_SIGNAL_ACTIVE_HIGH | POWER_SIGNAL_DISABLE_AT_BOOT,
- "SLP_S0_DEASSERTED"},
-#endif
- {VW_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
- {VW_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
- {GPIO_PCH_SLP_SUS_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_SUS_DEASSERTED"},
- {GPIO_RSMRST_L_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "RSMRST_L_PGOOD"},
- {GPIO_PMIC_DPWROK, POWER_SIGNAL_ACTIVE_HIGH, "PMIC_DPWROK"},
-};
-BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
-
/* Hibernate wake configuration */
const enum gpio_signal hibernate_wake_pins[] = {
GPIO_AC_PRESENT,
@@ -163,7 +151,7 @@ struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -171,7 +159,8 @@ struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = AN7447_TCPC3_I2C_ADDR, /* Verified on v1.1 */
+ /* Verified on v1.1 */
+ .addr__7bf = AN7447_TCPC3_I2C_ADDR__7bf,
},
.drv = &anx7447_tcpm_drv,
},
@@ -208,10 +197,10 @@ const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = {
void board_reset_pd_mcu(void)
{
/* Assert reset */
- gpio_set_level(GPIO_USB_PD_RST_C0_L, 0);
+ gpio_set_level(GPIO_USB_PD_RST_C0, 1);
gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 0);
msleep(1);
- gpio_set_level(GPIO_USB_PD_RST_C0_L, 1);
+ gpio_set_level(GPIO_USB_PD_RST_C0, 0);
gpio_set_level(GPIO_USB_C1_PD_RST_ODL, 1);
/* After TEST_R release, anx7447/3447 needs 2ms to finish eFuse
* loading.
@@ -270,7 +259,7 @@ uint16_t tcpc_get_alert_status(void)
uint16_t status = 0;
if (!gpio_get_level(GPIO_USB_C0_PD_INT_ODL)) {
- if (gpio_get_level(GPIO_USB_PD_RST_C0_L))
+ if (!gpio_get_level(GPIO_USB_PD_RST_C0))
status |= PD_STATUS_TCPC_ALERT_0;
}
@@ -309,29 +298,29 @@ 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;
- if (!(vrfault & (1 << 4)))
+ if (!(vrfault & BIT(4)))
return;
/* 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, (1 << 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
@@ -350,7 +339,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:
@@ -359,16 +348,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);
-
- /*
- * V100ACNT:
- * Bits 7:6 (00) - Disable low power mode on SLP_S0# assertion
- * Bits 5:4 (01) - Nominal voltage 1.0V
- * 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, 0x34, 0x2a);
/*
* V085ACNT:
@@ -377,7 +357,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)
@@ -389,7 +369,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:
@@ -398,16 +378,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);
-
- /*
- * V100ACNT:
- * Bits 7:6 (01) - Enable low power mode on SLP_S0# assertion
- * Bits 5:4 (01) - Nominal voltage 1.0V
- * 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, 0x34, 0x6a);
/*
* V085ACNT:
@@ -416,7 +387,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)
@@ -434,13 +405,20 @@ static void board_pmic_init(void)
if (system_jumped_to_this_image())
return;
- /* DISCHGCNT3 - enable 100 ohm discharge on V1.00A */
- i2c_write8(I2C_PORT_PMIC, I2C_ADDR_BD99992, 0x3e, 0x04);
+ /*
+ * DISCHGCNT2 - enable 100 ohm discharge on
+ * V5A_DS3/V33A_DSW/V33A_PCH/V1.8A
+ */
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x3d, 0x55);
+ /* DISCHGCNT3 - enable 100 ohm discharge on V1.8U_25U/V1.00A */
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x3e, 0x44);
+ /* DISCHGCNT4 - enable 100 ohm discharge on v1.8S */
+ i2c_write8__7bf(I2C_PORT_PMIC, I2C_ADDR_BD99992__7bf, 0x3f, 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);
@@ -453,7 +431,7 @@ static void board_init(void)
* floating SPI buffer input (MISO), which causes power leakage (see
* b/64797021).
*/
- NPCX_PUPD_EN1 |= (1 << NPCX_DEVPU1_F_SPI_PUD_EN);
+ NPCX_PUPD_EN1 |= BIT(NPCX_DEVPU1_F_SPI_PUD_EN);
/* Provide AC status to the PCH */
gpio_set_level(GPIO_PCH_ACPRESENT, extpower_is_present());
@@ -477,6 +455,19 @@ static void board_init(void)
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+static void usb_charge_mode_init(void)
+{
+ /*
+ * By default, turn the charging off when system suspends.
+ * If system power on with connecting a USB device,
+ * the OS must send an event to EC to clear the
+ * inhibit_charging_in_suspend.
+ */
+ usb_charge_set_mode(0, CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE,
+ USB_DISALLOW_SUSPEND_CHARGE);
+}
+DECLARE_HOOK(HOOK_INIT, usb_charge_mode_init, HOOK_PRIO_DEFAULT + 1);
+
/**
* Buffer the AC present GPIO to the PCH.
*/
@@ -553,7 +544,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
@@ -589,8 +580,8 @@ static struct accelgyro_saved_data_t g_bma255_data;
/* Matrix to rotate accelrator into standard reference frame */
const mat33_fp_t base_standard_ref = {
- { FLOAT_TO_FP(-1), 0, 0 },
- { 0, FLOAT_TO_FP(1), 0 },
+ { FLOAT_TO_FP(1), 0, 0 },
+ { 0, FLOAT_TO_FP(-1), 0 },
{ 0, 0, FLOAT_TO_FP(-1) }
};
@@ -611,7 +602,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,
@@ -639,7 +630,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,
@@ -667,7 +658,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,
@@ -699,6 +690,7 @@ DECLARE_HOOK(HOOK_CHIPSET_RESET, board_chipset_reset, HOOK_PRIO_DEFAULT);
static void board_chipset_resume(void)
{
gpio_set_level(GPIO_ENABLE_BACKLIGHT, 1);
+ gpio_set_level(GPIO_KB_BL_EN, 1);
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT);
@@ -706,5 +698,20 @@ DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT);
static void board_chipset_suspend(void)
{
gpio_set_level(GPIO_ENABLE_BACKLIGHT, 0);
+ gpio_set_level(GPIO_KB_BL_EN, 0);
}
DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT);
+
+/* Called on AP S5 -> S3 transition */
+static void board_chipset_startup(void)
+{
+ gpio_set_level(GPIO_EN_PP3300_TRACKPAD, 1);
+}
+DECLARE_HOOK(HOOK_CHIPSET_STARTUP, board_chipset_startup, HOOK_PRIO_DEFAULT);
+
+/* Called on AP S3 -> S5 transition */
+static void board_chipset_shutdown(void)
+{
+ gpio_set_level(GPIO_EN_PP3300_TRACKPAD, 0);
+}
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, board_chipset_shutdown, HOOK_PRIO_DEFAULT);
diff --git a/board/rammus/board.h b/board/rammus/board.h
index 1088858a99..766e03d0af 100644
--- a/board/rammus/board.h
+++ b/board/rammus/board.h
@@ -189,9 +189,9 @@
#define I2C_PORT_THERMAL I2C_PORT_PMIC
/* I2C addresses */
-#define I2C_ADDR_BD99992 0x60
-#define I2C_ADDR_MP2949 0x40
-#define I2C_ADDR_EEPROM 0xa0
+#define I2C_ADDR_BD99992__7bf 0x30
+#define I2C_ADDR_MP2949__7bf 0x20
+#define I2C_ADDR_EEPROM__7bf 0x50
/* Rename GPIOs */
#define GPIO_PCH_SLP_S0_L GPIO_SLP_S0_L
diff --git a/board/reef/board.c b/board/reef/board.c
index 515d2da071..ea9e8e9e43 100644
--- a/board/reef/board.c
+++ b/board/reef/board.c
@@ -66,18 +66,20 @@
static void tcpc_alert_event(enum gpio_signal signal)
{
- if ((signal == GPIO_USB_C0_PD_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C0_PD_RST_L))
- return;
+ int port = -1;
- if ((signal == GPIO_USB_C1_PD_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C1_PD_RST_ODL))
+ switch (signal) {
+ case GPIO_USB_C0_PD_INT_ODL:
+ port = 0;
+ break;
+ case GPIO_USB_C1_PD_INT_ODL:
+ port = 1;
+ break;
+ default:
return;
+ }
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
+ schedule_deferred_pd_interrupt(port);
}
#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
@@ -123,25 +125,6 @@ void tablet_mode_interrupt(enum gpio_signal signal)
#include "gpio_list.h"
-/* power signal list. Must match order of enum power_signal. */
-const struct power_signal_info power_signal_list[] = {
-#ifdef CONFIG_POWER_S0IX
- {GPIO_PCH_SLP_S0_L,
- POWER_SIGNAL_ACTIVE_HIGH | POWER_SIGNAL_DISABLE_AT_BOOT,
- "SLP_S0_DEASSERTED"},
-#endif
- {GPIO_RSMRST_L_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "RSMRST_L"},
- {GPIO_PCH_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S3_DEASSERTED"},
- {GPIO_PCH_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH, "SLP_S4_DEASSERTED"},
- {GPIO_SUSPWRNACK, POWER_SIGNAL_ACTIVE_HIGH,
- "SUSPWRNACK_DEASSERTED"},
-
- {GPIO_ALL_SYS_PGOOD, POWER_SIGNAL_ACTIVE_HIGH, "ALL_SYS_PGOOD"},
- {GPIO_PP3300_PG, POWER_SIGNAL_ACTIVE_HIGH, "PP3300_PG"},
- {GPIO_PP5000_PG, POWER_SIGNAL_ACTIVE_HIGH, "PP5000_PG"},
-};
-BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
-
/* ADC channels */
const struct adc_t adc_channels[] = {
/* Vfs = Vref = 2.816V, 10-bit unsigned reading */
@@ -184,7 +167,7 @@ struct i2c_stress_test i2c_stress_tests[] = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_TCPC
{
.port = NPCX_I2C_PORT0_0,
- .addr = ANX74XX_I2C_ADDR1,
+ .addr__7bf = ANX74XX_I2C_ADDR1__7bf,
.i2c_test = &anx74xx_i2c_stress_test_dev,
},
#endif
@@ -193,7 +176,7 @@ struct i2c_stress_test i2c_stress_tests[] = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_TCPC
{
.port = NPCX_I2C_PORT0_1,
- .addr = PS8751_I2C_ADDR1,
+ .addr__7bf = PS8751_I2C_ADDR1__7bf,
.i2c_test = &ps8xxx_i2c_stress_test_dev,
},
#endif
@@ -202,7 +185,7 @@ struct i2c_stress_test i2c_stress_tests[] = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL
{
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .addr__7bf = BMI160_ADDR0__7bf,
.i2c_test = &bmi160_i2c_stress_test_dev,
},
#endif
@@ -211,19 +194,19 @@ struct i2c_stress_test i2c_stress_tests[] = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL
{
.port = I2C_PORT_BARO,
- .addr = BMP280_I2C_ADDRESS1,
+ .addr__7bf = BMP280_I2C_ADDRESS1__7bf,
.i2c_test = &bmp280_i2c_stress_test_dev,
},
{
.port = I2C_PORT_LID_ACCEL,
- .addr = KX022_ADDR1,
+ .addr__7bf = KX022_ADDR1__7bf,
.i2c_test = &kionix_i2c_stress_test_dev,
},
#endif
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ALS
{
.port = I2C_PORT_ALS,
- .addr = OPT3001_I2C_ADDR1,
+ .addr__7bf = OPT3001_I2C_ADDR1__7bf,
.i2c_test = &opt3001_i2c_stress_test_dev,
},
#endif
@@ -248,7 +231,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 = ANX74XX_I2C_ADDR1,
+ .addr__7bf = ANX74XX_I2C_ADDR1__7bf,
},
.drv = &anx74xx_tcpm_drv,
},
@@ -256,7 +239,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,
},
@@ -384,7 +367,7 @@ void board_tcpc_init(void)
*
* NOTE: PS8751 A3 will wake on any I2C access.
*/
- i2c_read8(NPCX_I2C_PORT0_1, 0x10, 0xA0, &reg);
+ i2c_read8__7bf(NPCX_I2C_PORT0_1, 0x08, 0xA0, &reg);
/* Enable TCPC0 interrupt */
gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
@@ -732,7 +715,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kx022_data,
.port = I2C_PORT_LID_ACCEL,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KX022_ACCEL_MIN_FREQ,
@@ -759,7 +742,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -788,7 +771,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .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,
@@ -804,8 +787,8 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
- .default_range = 1 << 11, /* 16LSB / uT, fixed */
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
+ .default_range = BIT(11), /* 16LSB / uT, fixed */
.rot_standard_ref = &mag_standard_ref,
.min_frequency = BMM150_MAG_MIN_FREQ,
.max_frequency = BMM150_MAG_MAX_FREQ(SPECIAL),
@@ -819,8 +802,8 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &bmp280_drv,
.drv_data = &bmp280_drv_data,
.port = I2C_PORT_BARO,
- .addr = BMP280_I2C_ADDRESS1,
- .default_range = 1 << 18, /* 1bit = 4 Pa, 16bit ~= 2600 hPa */
+ .i2c_spi_addr__7bf = BMP280_I2C_ADDRESS1__7bf,
+ .default_range = BIT(18), /* 1bit = 4 Pa, 16bit ~= 2600 hPa */
.min_frequency = BMP280_BARO_MIN_FREQ,
.max_frequency = BMP280_BARO_MAX_FREQ,
},
@@ -833,7 +816,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &opt3001_drv,
.drv_data = &g_opt3001_data,
.port = I2C_PORT_ALS,
- .addr = OPT3001_I2C_ADDR1,
+ .i2c_spi_addr__7bf = OPT3001_I2C_ADDR1__7bf,
.rot_standard_ref = NULL,
.default_range = 0x10000, /* scale = 1; uscale = 0 */
.min_frequency = OPT3001_LIGHT_MIN_FREQ,
diff --git a/board/reef/board.h b/board/reef/board.h
index ba31d0556c..143cdfea12 100644
--- a/board/reef/board.h
+++ b/board/reef/board.h
@@ -196,7 +196,7 @@
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
#define CONFIG_MAG_BMI160_BMM150
-#define CONFIG_ACCELGYRO_SEC_ADDR BMM150_ADDR0 /* 8-bit address */
+#define CONFIG_ACCELGYRO_SEC_ADDR__7BF BMM150_ADDR0__7bf
#define CONFIG_MAG_CALIBRATE
#define CONFIG_ACCEL_KX022
#define CONFIG_ALS_OPT3001
diff --git a/board/reef_it8320/board.c b/board/reef_it8320/board.c
index 47c63c0599..83e9b3fefa 100644
--- a/board/reef_it8320/board.c
+++ b/board/reef_it8320/board.c
@@ -181,12 +181,12 @@ static void it83xx_tcpc_update_hpd_status(int port, int hpd_lvl, int hpd_irq)
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
{
- .port_addr = 0xa8,
+ .port_addr = 0x54,
.driver = &pi3usb30532_usb_mux_driver,
.hpd_update = &it83xx_tcpc_update_hpd_status,
},
{
- .port_addr = 0x20,
+ .port_addr = 0x10,
.driver = &ps874x_usb_mux_driver,
.hpd_update = &it83xx_tcpc_update_hpd_status,
},
diff --git a/board/reef_mchp/board.c b/board/reef_mchp/board.c
index 4e3b1368c6..206d6dd1d0 100644
--- a/board/reef_mchp/board.c
+++ b/board/reef_mchp/board.c
@@ -100,18 +100,20 @@ void board_config_pre_init(void)
*/
static void tcpc_alert_event(enum gpio_signal signal)
{
- if ((signal == GPIO_USB_C0_PD_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C0_PD_RST_L))
- return;
+ int port = -1;
- if ((signal == GPIO_USB_C1_PD_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C1_PD_RST_ODL))
+ switch (signal) {
+ case GPIO_USB_C0_PD_INT_ODL:
+ port = 0;
+ break;
+ case GPIO_USB_C1_PD_INT_ODL:
+ port = 1;
+ break;
+ default:
return;
+ }
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
+ schedule_deferred_pd_interrupt(port);
}
#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
@@ -159,28 +161,6 @@ void tablet_mode_interrupt(enum gpio_signal signal)
#include "gpio_list.h"
-/* power signal list. Must match order of enum power_signal. */
-const struct power_signal_info power_signal_list[] = {
-#ifdef CONFIG_POWER_S0IX
- {GPIO_PCH_SLP_S0_L,
- POWER_SIGNAL_ACTIVE_HIGH | POWER_SIGNAL_DISABLE_AT_BOOT,
- "SLP_S0_DEASSERTED"},
-#endif
- {GPIO_RSMRST_L_PGOOD, POWER_SIGNAL_ACTIVE_HIGH,
- "RSMRST_L"},
- {GPIO_PCH_SLP_S3_L, POWER_SIGNAL_ACTIVE_HIGH,
- "SLP_S3_DEASSERTED"},
- {GPIO_PCH_SLP_S4_L, POWER_SIGNAL_ACTIVE_HIGH,
- "SLP_S4_DEASSERTED"},
- {GPIO_SUSPWRNACK, POWER_SIGNAL_ACTIVE_HIGH,
- "SUSPWRNACK_DEASSERTED"},
- {GPIO_ALL_SYS_PGOOD, POWER_SIGNAL_ACTIVE_HIGH,
- "ALL_SYS_PGOOD"},
- {GPIO_PP3300_PG, POWER_SIGNAL_ACTIVE_HIGH, "PP3300_PG"},
- {GPIO_PP5000_PG, POWER_SIGNAL_ACTIVE_HIGH, "PP5000_PG"},
-};
-BUILD_ASSERT(ARRAY_SIZE(power_signal_list) == POWER_SIGNAL_COUNT);
-
/* SPI devices */
const struct spi_device_t spi_devices[] = {
{ QMSPI0_PORT, 4, GPIO_QMSPI_CS0},
@@ -303,7 +283,7 @@ struct i2c_stress_test i2c_stress_tests[] = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_TCPC
{
.port = MCHP_I2C_PORT0,
- .addr = 0x50,
+ .addr__7bf = 0x28,
.i2c_test = &anx74xx_i2c_stress_test_dev,
},
#endif
@@ -311,33 +291,33 @@ struct i2c_stress_test i2c_stress_tests[] = {
#ifdef CONFIG_CMD_I2C_STRESS_TEST_TCPC
{
.port = MCHP_I2C_PORT2,
- .addr = 0x16,
+ .addr__7bf = 0x0B,
.i2c_test = &ps8xxx_i2c_stress_test_dev,
},
#endif
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL
{
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .addr__7bf = BMI160_ADDR0__7bf,
.i2c_test = &bmi160_i2c_stress_test_dev,
},
#endif
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL
{
.port = I2C_PORT_BARO,
- .addr = BMP280_I2C_ADDRESS1,
+ .addr__7bf = BMP280_I2C_ADDRESS1__7bf,
.i2c_test = &bmp280_i2c_stress_test_dev,
},
{
.port = I2C_PORT_LID_ACCEL,
- .addr = KX022_ADDR1,
+ .addr__7bf = KX022_ADDR1__7bf,
.i2c_test = &kionix_i2c_stress_test_dev,
},
#endif
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ALS
{
.port = I2C_PORT_ALS,
- .addr = OPT3001_I2C_ADDR1,
+ .addr__7bf = OPT3001_I2C_ADDR1__7bf,
.i2c_test = &opt3001_i2c_stress_test_dev,
},
#endif
@@ -362,7 +342,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = MCHP_I2C_PORT0,
- .addr = 0x50,
+ .addr__7bf = 0x28,
},
.drv = &anx74xx_tcpm_drv,
},
@@ -370,7 +350,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = MCHP_I2C_PORT2,
- .addr = 0x16,
+ .addr__7bf = 0x0B,
},
.drv = &ps8xxx_tcpm_drv,
},
@@ -533,7 +513,7 @@ void board_tcpc_init(void)
* address 0x10. Is this another attempt at waking PS8751
* from DRP low power idle mode?
*/
- i2c_read8(MCHP_I2C_PORT2, 0x10, 0xA0, &reg);
+ i2c_read8__7bf(MCHP_I2C_PORT2, 0x08, 0xA0, &reg);
/* Enable TCPC0 interrupt */
gpio_enable_interrupt(GPIO_USB_C0_PD_INT_ODL);
@@ -786,27 +766,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma,
CONFIG_CHARGER_INPUT_CURRENT), charge_mv);
}
-/*
- * MCHP next two functions from production firmware-reef-9042.B
- * Have changes to USB PD common and TCPCI driver code deprecated
- * these functions?
- */
-/**
- * Return whether ramping is allowed for given supplier
- */
-int board_is_ramp_allowed(int supplier)
-{
- /* Don't allow ramping in RO when write protected */
- if (system_get_image_copy() != SYSTEM_IMAGE_RW
- && system_is_locked())
- return 0;
- else
- return (supplier == CHARGE_SUPPLIER_BC12_DCP ||
- supplier == CHARGE_SUPPLIER_BC12_SDP ||
- supplier == CHARGE_SUPPLIER_BC12_CDP ||
- supplier == CHARGE_SUPPLIER_OTHER);
-}
-
/**
* Return if board is consuming full amount of input current
*/
@@ -1002,7 +961,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kx022_data,
.port = I2C_PORT_LID_ACCEL,
- .addr = KX022_ADDR1,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
.rot_standard_ref = NULL, /* Identity matrix. */
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KX022_ACCEL_MIN_FREQ,
@@ -1029,7 +988,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -1058,7 +1017,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .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,
@@ -1074,8 +1033,8 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = I2C_PORT_GYRO,
- .addr = BMI160_ADDR0,
- .default_range = 1 << 11, /* 16LSB / uT, fixed */
+ .i2c_spi_addr__7bf = BMI160_ADDR0__7bf,
+ .default_range = BIT(11), /* 16LSB / uT, fixed */
.rot_standard_ref = &mag_standard_ref,
.min_frequency = BMM150_MAG_MIN_FREQ,
.max_frequency = BMM150_MAG_MAX_FREQ(SPECIAL),
@@ -1089,8 +1048,8 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &bmp280_drv,
.drv_data = &bmp280_drv_data,
.port = I2C_PORT_BARO,
- .addr = BMP280_I2C_ADDRESS1,
- .default_range = 1 << 18, /* 1bit = 4 Pa, 16bit ~= 2600 hPa */
+ .i2c_spi_addr__7bf = BMP280_I2C_ADDRESS1__7bf,
+ .default_range = BIT(18), /* 1bit = 4 Pa, 16bit ~= 2600 hPa */
.min_frequency = BMP280_BARO_MIN_FREQ,
.max_frequency = BMP280_BARO_MAX_FREQ,
},
@@ -1103,7 +1062,7 @@ struct motion_sensor_t motion_sensors[] = {
.drv = &opt3001_drv,
.drv_data = &g_opt3001_data,
.port = I2C_PORT_ALS,
- .addr = OPT3001_I2C_ADDR1,
+ .i2c_spi_addr__7bf = OPT3001_I2C_ADDR1__7bf,
.rot_standard_ref = NULL,
.default_range = 0x10000, /* scale = 1; uscale = 0 */
.min_frequency = OPT3001_LIGHT_MIN_FREQ,
diff --git a/board/reef_mchp/board.h b/board/reef_mchp/board.h
index de3a36a291..78269f05b6 100644
--- a/board/reef_mchp/board.h
+++ b/board/reef_mchp/board.h
@@ -203,7 +203,7 @@
#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
#define CONFIG_MAG_BMI160_BMM150
-#define CONFIG_ACCELGYRO_SEC_ADDR BMM150_ADDR0 /* 8-bit address */
+#define CONFIG_ACCELGYRO_SEC_ADDR__7BF BMM150_ADDR0__7bf
#define CONFIG_MAG_CALIBRATE
#define CONFIG_ACCEL_KX022
#define CONFIG_ALS_OPT3001
diff --git a/board/samus/battery.c b/board/samus/battery.c
index f3c78e9d96..6990db853b 100644
--- a/board/samus/battery.c
+++ b/board/samus/battery.c
@@ -290,10 +290,10 @@ int board_cut_off_battery(void)
buf[2] = PARAM_CUT_OFF_HIGH;
i2c_lock(I2C_PORT_BATTERY, 1);
- rv = i2c_xfer_unlocked(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
- I2C_XFER_SINGLE);
- rv |= i2c_xfer_unlocked(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
- I2C_XFER_SINGLE);
+ rv = i2c_xfer_unlocked__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ buf, 3, NULL, 0, I2C_XFER_SINGLE);
+ rv |= i2c_xfer_unlocked__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ buf, 3, NULL, 0, I2C_XFER_SINGLE);
i2c_lock(I2C_PORT_BATTERY, 0);
return rv;
diff --git a/board/samus/board.c b/board/samus/board.c
index b8f66ca101..e8a25205a6 100644
--- a/board/samus/board.c
+++ b/board/samus/board.c
@@ -132,29 +132,35 @@ const struct i2c_port_t i2c_ports[] = {
};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
-#define TEMP_U40_REG_ADDR ((0x40 << 1) | I2C_FLAG_BIG_ENDIAN)
-#define TEMP_U41_REG_ADDR ((0x44 << 1) | I2C_FLAG_BIG_ENDIAN)
-#define TEMP_U42_REG_ADDR ((0x41 << 1) | I2C_FLAG_BIG_ENDIAN)
-#define TEMP_U43_REG_ADDR ((0x45 << 1) | I2C_FLAG_BIG_ENDIAN)
-#define TEMP_U115_REG_ADDR ((0x42 << 1) | I2C_FLAG_BIG_ENDIAN)
-#define TEMP_U116_REG_ADDR ((0x43 << 1) | I2C_FLAG_BIG_ENDIAN)
-
-#define TEMP_U40_ADDR TMP006_ADDR(I2C_PORT_THERMAL, TEMP_U40_REG_ADDR)
-#define TEMP_U41_ADDR TMP006_ADDR(I2C_PORT_THERMAL, TEMP_U41_REG_ADDR)
-#define TEMP_U42_ADDR TMP006_ADDR(I2C_PORT_THERMAL, TEMP_U42_REG_ADDR)
-#define TEMP_U43_ADDR TMP006_ADDR(I2C_PORT_THERMAL, TEMP_U43_REG_ADDR)
-#define TEMP_U115_ADDR TMP006_ADDR(I2C_PORT_THERMAL, TEMP_U115_REG_ADDR)
-#define TEMP_U116_ADDR TMP006_ADDR(I2C_PORT_THERMAL, TEMP_U116_REG_ADDR)
-
-const struct tmp006_t tmp006_sensors[TMP006_COUNT] = {
- {"Charger", TEMP_U40_ADDR},
- {"CPU", TEMP_U41_ADDR},
- {"Left C", TEMP_U42_ADDR},
- {"Right C", TEMP_U43_ADDR},
- {"Right D", TEMP_U115_ADDR},
- {"Left D", TEMP_U116_ADDR},
+#define TEMP_U40_REG_ADDR__7bf (0x40 | I2C_FLAG_BIG_ENDIAN)
+#define TEMP_U41_REG_ADDR__7bf (0x44 | I2C_FLAG_BIG_ENDIAN)
+#define TEMP_U42_REG_ADDR__7bf (0x41 | I2C_FLAG_BIG_ENDIAN)
+#define TEMP_U43_REG_ADDR__7bf (0x45 | I2C_FLAG_BIG_ENDIAN)
+#define TEMP_U115_REG_ADDR__7bf (0x42 | I2C_FLAG_BIG_ENDIAN)
+#define TEMP_U116_REG_ADDR__7bf (0x43 | I2C_FLAG_BIG_ENDIAN)
+
+#define TEMP_U40_ADDR__7bf TMP006_ADDR__7bf(I2C_PORT_THERMAL,\
+ TEMP_U40_REG_ADDR__7bf)
+#define TEMP_U41_ADDR__7bf TMP006_ADDR__7bf(I2C_PORT_THERMAL,\
+ TEMP_U41_REG_ADDR__7bf)
+#define TEMP_U42_ADDR__7bf TMP006_ADDR__7bf(I2C_PORT_THERMAL,\
+ TEMP_U42_REG_ADDR__7bf)
+#define TEMP_U43_ADDR__7bf TMP006_ADDR__7bf(I2C_PORT_THERMAL,\
+ TEMP_U43_REG_ADDR__7bf)
+#define TEMP_U115_ADDR__7bf TMP006_ADDR__7bf(I2C_PORT_THERMAL,\
+ TEMP_U115_REG_ADDR__7bf)
+#define TEMP_U116_ADDR__7bf TMP006_ADDR__7bf(I2C_PORT_THERMAL,\
+ TEMP_U116_REG_ADDR__7bf)
+
+const struct tmp006_t tmp006_sensors__7bf[TMP006_COUNT] = {
+ {"Charger", TEMP_U40_ADDR__7bf},
+ {"CPU", TEMP_U41_ADDR__7bf},
+ {"Left C", TEMP_U42_ADDR__7bf},
+ {"Right C", TEMP_U43_ADDR__7bf},
+ {"Right D", TEMP_U115_ADDR__7bf},
+ {"Left D", TEMP_U116_ADDR__7bf},
};
-BUILD_ASSERT(ARRAY_SIZE(tmp006_sensors) == TMP006_COUNT);
+BUILD_ASSERT(ARRAY_SIZE(tmp006_sensors__7bf) == TMP006_COUNT);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
const struct temp_sensor_t temp_sensors[] = {
@@ -326,7 +332,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_saved_data[0],
.port = I2C_PORT_ACCEL,
- .addr = LSM6DS0_ADDR1,
+ .i2c_spi_addr__7bf = LSM6DS0_ADDR1__7bf,
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = LSM6DS0_ACCEL_MIN_FREQ,
@@ -358,7 +364,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_lid_mutex,
.drv_data = &g_kxcj9_data,
.port = I2C_PORT_ACCEL,
- .addr = KXCJ9_ADDR0,
+ .i2c_spi_addr__7bf = KXCJ9_ADDR0__7bf,
.rot_standard_ref = &lid_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KXCJ9_ACCEL_MIN_FREQ,
@@ -381,7 +387,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_saved_data[1],
.port = I2C_PORT_ACCEL,
- .addr = LSM6DS0_ADDR1,
+ .i2c_spi_addr__7bf = LSM6DS0_ADDR1__7bf,
.rot_standard_ref = NULL,
.default_range = 2000, /* g, enough for laptop. */
.min_frequency = LSM6DS0_GYRO_MIN_FREQ,
diff --git a/board/samus/extpower.c b/board/samus/extpower.c
index c2fabbd35e..a803171e7a 100644
--- a/board/samus/extpower.c
+++ b/board/samus/extpower.c
@@ -159,7 +159,7 @@ static void allow_max_request(void)
int prochot_status;
if (charge_circuit_state == CHARGE_CIRCUIT_WEDGED) {
/* Read PROCHOT status register to clear it */
- i2c_read8(I2C_PORT_CHARGER, BQ24773_ADDR,
+ i2c_read8__7bf(I2C_PORT_CHARGER, BQ24773_ADDR__7bf,
BQ24773_PROCHOT_STATUS, &prochot_status);
charge_circuit_state = CHARGE_CIRCUIT_OK;
}
@@ -301,7 +301,7 @@ static void check_charge_wedged(void)
if (charge_circuit_state == CHARGE_CIRCUIT_OK) {
/* Check PROCHOT warning */
- rv = i2c_read8(I2C_PORT_CHARGER, BQ24773_ADDR,
+ rv = i2c_read8__7bf(I2C_PORT_CHARGER, BQ24773_ADDR__7bf,
BQ24773_PROCHOT_STATUS, &prochot_status);
if (rv)
prochot_status = 0;
diff --git a/board/samus/panel.c b/board/samus/panel.c
index 970197b9c8..bead90cdcd 100644
--- a/board/samus/panel.c
+++ b/board/samus/panel.c
@@ -15,7 +15,7 @@
#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args)
-#define I2C_ADDR_BACKLIGHT ((0x2C << 1) | I2C_FLAG_BIG_ENDIAN)
+#define I2C_ADDR_BACKLIGHT__7bf (0x2C | I2C_FLAG_BIG_ENDIAN)
#define I2C_RETRIES 3
#define I2C_RETRY_DELAY (5*MSEC)
@@ -61,7 +61,8 @@ static int lp8555_read_with_retry(int reg, int *data)
int i, rv;
for (i = 0; i < I2C_RETRIES; i++) {
- rv = i2c_read8(I2C_PORT_BACKLIGHT, I2C_ADDR_BACKLIGHT,
+ rv = i2c_read8__7bf(I2C_PORT_BACKLIGHT,
+ I2C_ADDR_BACKLIGHT__7bf,
reg, data);
if (rv == EC_SUCCESS)
return EC_SUCCESS;
@@ -78,8 +79,9 @@ static int lp8555_write_with_retry(int reg, int data)
int i, rv;
for (i = 0; i < I2C_RETRIES; i++) {
- rv = i2c_write8(I2C_PORT_BACKLIGHT, I2C_ADDR_BACKLIGHT,
- reg, data);
+ rv = i2c_write8__7bf(I2C_PORT_BACKLIGHT,
+ I2C_ADDR_BACKLIGHT__7bf,
+ reg, data);
if (rv == EC_SUCCESS)
return EC_SUCCESS;
usleep(I2C_RETRY_DELAY);
diff --git a/board/samus_pd/board.h b/board/samus_pd/board.h
index 2efeb35d56..d3f4a0b3f5 100644
--- a/board/samus_pd/board.h
+++ b/board/samus_pd/board.h
@@ -89,7 +89,7 @@
/* slave address for host commands */
#ifdef HAS_TASK_HOSTCMD
-#define CONFIG_HOSTCMD_I2C_SLAVE_ADDR CONFIG_USB_PD_I2C_SLAVE_ADDR
+#define CONFIG_HOSTCMD_I2C_SLAVE_ADDR__7BF CONFIG_USB_PD_I2C_SLAVE_ADDR__7BF
#endif
#ifndef __ASSEMBLER__
diff --git a/board/scarlet/board.c b/board/scarlet/board.c
index bf308266bf..1dbb815dff 100644
--- a/board/scarlet/board.c
+++ b/board/scarlet/board.c
@@ -130,7 +130,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC0,
- .addr = FUSB302_I2C_SLAVE_ADDR,
+ .addr__7bf = FUSB302_I2C_SLAVE_ADDR__7bf,
},
.drv = &fusb302_tcpm_drv,
},
@@ -400,7 +400,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = CONFIG_SPI_ACCEL_PORT,
- .addr = BMI160_SET_SPI_ADDRESS(CONFIG_SPI_ACCEL_PORT),
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(CONFIG_SPI_ACCEL_PORT),
.rot_standard_ref = &base_standard_ref,
.default_range = 4, /* g */
.min_frequency = BMI160_ACCEL_MIN_FREQ,
@@ -423,7 +423,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_base_mutex,
.drv_data = &g_bmi160_data,
.port = CONFIG_SPI_ACCEL_PORT,
- .addr = BMI160_SET_SPI_ADDRESS(CONFIG_SPI_ACCEL_PORT),
+ .i2c_spi_addr__7bf = SLAVE_MK_SPI_ADDR__7bf(CONFIG_SPI_ACCEL_PORT),
.default_range = 1000, /* dps */
.rot_standard_ref = &base_standard_ref,
.min_frequency = BMI160_GYRO_MIN_FREQ,
diff --git a/board/scarlet/board.h b/board/scarlet/board.h
index 842c6d546c..89071f2423 100644
--- a/board/scarlet/board.h
+++ b/board/scarlet/board.h
@@ -176,7 +176,7 @@
#define I2C_PORT_TCPC0 1
/* Route sbs host requests to virtual battery driver */
-#define VIRTUAL_BATTERY_ADDR 0x16
+#define VIRTUAL_BATTERY_ADDR__7bf 0x0B
/* Enable Accel over SPI */
#define CONFIG_SPI_ACCEL_PORT 0 /* The first SPI master port (SPI2) */
diff --git a/board/servo_micro/board.c b/board/servo_micro/board.c
index a06978b84d..cbc5f18f95 100644
--- a/board/servo_micro/board.c
+++ b/board/servo_micro/board.c
@@ -248,8 +248,8 @@ DECLARE_CONSOLE_COMMAND(baud, command_uart_baud,
* enable_ite_dfu stops working, or does not work on a new ITE EC chip revision.
*/
-#define ITE_DFU_I2C_CMD_ADDR 0xB4 /* 7 bit form is 0x5A */
-#define ITE_DFU_I2C_DATA_ADDR 0x6A /* 7 bit form is 0x35 */
+#define ITE_DFU_I2C_CMD_ADDR__7bf 0x5A
+#define ITE_DFU_I2C_DATA_ADDR__7bf 0x35
#define SMCLK_WAVEFORM_PERIOD_HZ (100 * KHz)
#define SMDAT_WAVEFORM_PERIOD_HZ (200 * KHz)
@@ -287,14 +287,17 @@ static int ite_i2c_read_register(uint8_t register_offset, uint8_t *output)
*/
int ret;
/* Tell the ITE EC which register we want to read. */
- ret = i2c_xfer_unlocked(I2C_PORT_MASTER, ITE_DFU_I2C_CMD_ADDR,
- &register_offset, sizeof(register_offset),
- NULL, 0, I2C_XFER_SINGLE);
+ ret = i2c_xfer_unlocked__7bf(I2C_PORT_MASTER,
+ ITE_DFU_I2C_CMD_ADDR__7bf,
+ &register_offset, sizeof(register_offset),
+ NULL, 0, I2C_XFER_SINGLE);
if (ret != EC_SUCCESS)
return ret;
/* Read in the 1 byte register value. */
- ret = i2c_xfer_unlocked(I2C_PORT_MASTER, ITE_DFU_I2C_DATA_ADDR, NULL, 0,
- output, sizeof(*output), I2C_XFER_SINGLE);
+ ret = i2c_xfer_unlocked__7bf(I2C_PORT_MASTER,
+ ITE_DFU_I2C_DATA_ADDR__7bf,
+ NULL, 0,
+ output, sizeof(*output), I2C_XFER_SINGLE);
return ret;
}
diff --git a/board/servo_v4/board.c b/board/servo_v4/board.c
index 982ed9ccfb..b95ae2e3e9 100644
--- a/board/servo_v4/board.c
+++ b/board/servo_v4/board.c
@@ -197,7 +197,7 @@ int usb_i2c_board_is_enabled(void) { return 1; }
/*
* Support tca6416 I2C ioexpander.
*/
-#define GPIOX_I2C_ADDR 0x40
+#define GPIOX_I2C_ADDR__7bf 0x20
#define GPIOX_IN_PORT_A 0x0
#define GPIOX_IN_PORT_B 0x1
#define GPIOX_OUT_PORT_A 0x2
@@ -212,13 +212,13 @@ static void write_ioexpander(int bank, int gpio, int val)
int tmp;
/* Read output port register */
- i2c_read8(1, GPIOX_I2C_ADDR, GPIOX_OUT_PORT_A + bank, &tmp);
+ i2c_read8__7bf(1, GPIOX_I2C_ADDR__7bf, GPIOX_OUT_PORT_A + bank, &tmp);
if (val)
tmp |= (1 << gpio);
else
tmp &= ~(1 << gpio);
/* Write back modified output port register */
- i2c_write8(1, GPIOX_I2C_ADDR, GPIOX_OUT_PORT_A + bank, tmp);
+ i2c_write8__7bf(1, GPIOX_I2C_ADDR__7bf, GPIOX_OUT_PORT_A + bank, tmp);
}
/* Read a single GPIO input on the tca6416 I2C ioexpander. */
@@ -228,7 +228,7 @@ static int read_ioexpander_bit(int bank, int bit)
int mask = 1 << bit;
/* Read input port register */
- i2c_read8(1, GPIOX_I2C_ADDR, GPIOX_IN_PORT_A + bank, &tmp);
+ i2c_read8__7bf(1, GPIOX_I2C_ADDR__7bf, GPIOX_IN_PORT_A + bank, &tmp);
return (tmp & mask) >> bit;
}
@@ -257,15 +257,15 @@ static void init_usb3_port(void)
static void init_ioexpander(void)
{
/* Write all GPIO to output 0 */
- i2c_write8(1, GPIOX_I2C_ADDR, GPIOX_OUT_PORT_A, 0x0);
- i2c_write8(1, GPIOX_I2C_ADDR, GPIOX_OUT_PORT_B, 0x0);
+ i2c_write8__7bf(1, GPIOX_I2C_ADDR__7bf, GPIOX_OUT_PORT_A, 0x0);
+ i2c_write8__7bf(1, GPIOX_I2C_ADDR__7bf, GPIOX_OUT_PORT_B, 0x0);
/*
* Write GPIO direction: strap resistors to input,
* all others to output.
*/
- i2c_write8(1, GPIOX_I2C_ADDR, GPIOX_DIR_PORT_A, 0x0);
- i2c_write8(1, GPIOX_I2C_ADDR, GPIOX_DIR_PORT_B, 0x18);
+ i2c_write8__7bf(1, GPIOX_I2C_ADDR__7bf, GPIOX_DIR_PORT_A, 0x0);
+ i2c_write8__7bf(1, GPIOX_I2C_ADDR__7bf, GPIOX_DIR_PORT_B, 0x18);
}
/* Define voltage thresholds for SBU USB detection */
@@ -429,7 +429,7 @@ static void board_init(void)
* Write USB3 Mode to PS8742 USB/DP Mux.
* 0x0:disable 0x20:enable.
*/
- i2c_write8(1, 0x20, 0x0, 0x0);
+ i2c_write8__7bf(1, 0x10, 0x0, 0x0);
/* Enable uservo USB by default. */
init_ioexpander();
diff --git a/board/strago/board.c b/board/strago/board.c
index f1852bb9ab..6e336ac3ca 100644
--- a/board/strago/board.c
+++ b/board/strago/board.c
@@ -110,7 +110,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
.bus_type = EC_BUS_TYPE_I2C,
.i2c_info = {
.port = I2C_PORT_TCPC,
- .addr = CONFIG_TCPC_I2C_BASE_ADDR,
+ .addr__7bf = CONFIG_TCPC_I2C_BASE_ADDR__7BF,
},
.drv = &tcpci_tcpm_drv,
},
@@ -141,7 +141,7 @@ BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) ==
struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
{
- .port_addr = 0xaa,
+ .port_addr = 0x55,
.driver = &pi3usb30532_usb_mux_driver,
},
};
@@ -213,7 +213,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_kxcj9_mutex[0],
.drv_data = &g_kxcj9_data[0],
.port = I2C_PORT_ACCEL,
- .addr = KXCJ9_ADDR1,
+ .i2c_spi_addr__7bf = KXCJ9_ADDR1__7bf,
.rot_standard_ref = &base_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KXCJ9_ACCEL_MIN_FREQ,
@@ -236,7 +236,7 @@ struct motion_sensor_t motion_sensors[] = {
.mutex = &g_kxcj9_mutex[1],
.drv_data = &g_kxcj9_data[1],
.port = I2C_PORT_ACCEL,
- .addr = KXCJ9_ADDR0,
+ .i2c_spi_addr__7bf = KXCJ9_ADDR0__7bf,
.rot_standard_ref = &lid_standard_ref,
.default_range = 2, /* g, enough for laptop. */
.min_frequency = KXCJ9_ACCEL_MIN_FREQ,
diff --git a/board/sweetberry/board.c b/board/sweetberry/board.c
index 2d94f06f76..1085a048de 100644
--- a/board/sweetberry/board.c
+++ b/board/sweetberry/board.c
@@ -121,6 +121,6 @@ static void board_init(void)
uint8_t tmp;
/* i2c 0 has a tendancy to get wedged. TODO(nsanders): why? */
- i2c_xfer(0, 0, NULL, 0, &tmp, 1);
+ i2c_xfer__7bf(0, 0, NULL, 0, &tmp, 1);
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/board/yorp/board.c b/board/yorp/board.c
index f00a95dd65..409914c898 100644
--- a/board/yorp/board.c
+++ b/board/yorp/board.c
@@ -44,18 +44,6 @@
#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args)
-static void tcpc_alert_event(enum gpio_signal signal)
-{
- if ((signal == GPIO_USB_C1_MUX_INT_ODL) &&
- !gpio_get_level(GPIO_USB_C1_PD_RST_ODL))
- return;
-
-#ifdef HAS_TASK_PDCMD
- /* Exchange status with TCPCs */
- host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
-#endif
-}
-
static void ppc_interrupt(enum gpio_signal signal)
{
switch (signal) {
@@ -122,28 +110,28 @@ static struct lsm6dsm_data lsm6dsm_data;
/* Drivers */
struct motion_sensor_t motion_sensors[] = {
[LID_ACCEL] = {
- .name = "Lid Accel",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_KX022,
- .type = MOTIONSENSE_TYPE_ACCEL,
- .location = MOTIONSENSE_LOC_LID,
- .drv = &kionix_accel_drv,
- .mutex = &g_lid_mutex,
- .drv_data = &g_kx022_data,
- .port = I2C_PORT_SENSOR,
- .addr = KX022_ADDR1,
- .rot_standard_ref = NULL, /* Identity matrix. */
- .default_range = 4, /* g */
- .config = {
- /* EC use accel for angle detection */
- [SENSOR_CONFIG_EC_S0] = {
- .odr = 10000 | ROUND_UP_FLAG,
- },
- /* Sensor on for lid angle detection */
- [SENSOR_CONFIG_EC_S3] = {
- .odr = 10000 | ROUND_UP_FLAG,
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_KX022,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &kionix_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_kx022_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr__7bf = KX022_ADDR1__7bf,
+ .rot_standard_ref = NULL, /* Identity matrix. */
+ .default_range = 4, /* g */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
},
- },
},
[BASE_ACCEL] = {
@@ -159,7 +147,7 @@ struct motion_sensor_t motion_sensors[] = {
.int_signal = GPIO_BASE_SIXAXIS_INT_L,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
.port = I2C_PORT_SENSOR,
- .addr = LSM6DSM_ADDR0,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR0__7bf,
.rot_standard_ref = &base_standard_ref,
.default_range = 4, /* g */
.min_frequency = LSM6DSM_ODR_MIN_VAL,
@@ -191,7 +179,7 @@ struct motion_sensor_t motion_sensors[] = {
.int_signal = GPIO_BASE_SIXAXIS_INT_L,
.flags = MOTIONSENSE_FLAG_INT_SIGNAL,
.port = I2C_PORT_SENSOR,
- .addr = LSM6DSM_ADDR0,
+ .i2c_spi_addr__7bf = LSM6DSM_ADDR0__7bf,
.default_range = 1000 | ROUND_UP_FLAG, /* dps */
.rot_standard_ref = &base_standard_ref,
.min_frequency = LSM6DSM_ODR_MIN_VAL,
@@ -257,3 +245,13 @@ static void post_old_board_warning(void)
}
DECLARE_HOOK(HOOK_INIT, post_old_board_warning, HOOK_PRIO_INIT_I2C + 1);
#endif
+
+void board_overcurrent_event(int port, int is_overcurrented)
+{
+ /* Sanity check the port. */
+ if ((port < 0) || (port >= CONFIG_USB_PD_PORT_COUNT))
+ return;
+
+ /* Note that the level is inverted because the pin is active low. */
+ gpio_set_level(GPIO_USB_C_OC, !is_overcurrented);
+}
diff --git a/chip/g/i2cm.c b/chip/g/i2cm.c
index b77bd91935..a7b8f9ad7e 100644
--- a/chip/g/i2cm.c
+++ b/chip/g/i2cm.c
@@ -173,21 +173,6 @@ static void i2cm_config_xfer_mode(int port, enum i2c_freq freq)
GWRITE_I(I2C, port, CTRL_MODE, i2c_mode_instruction);
}
-static void i2cm_set_fwbytes(int port, uint32_t *inst, const uint8_t *data,
- int size)
-{
- int i;
- uint32_t fwbytes = 0;
-
- /* Indicate that first write bytes field will be used */
- *inst |= size << GFIELD_LSB(I2C, INST, FWBYTESCOUNT);
-
- /* Now write data to FWBYTES register */
- for (i = 0; i < size; i++)
- fwbytes |= data[i] << (i * 8);
- GWRITE_I(I2C, port, FW, fwbytes);
-}
-
static void i2cm_write_rwbytes(int port, const uint8_t *out, int size)
{
volatile uint32_t *rw_ptr;
@@ -262,86 +247,105 @@ static int i2cm_poll_for_complete(int port)
return EC_ERROR_TIMEOUT;
}
-static uint32_t i2cm_build_sequence(int port, int slave_addr,
- const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
+static uint32_t i2cm_create_inst__7bf(int slave_addr__7bf, int is_write,
+ size_t size, uint32_t flags)
{
- int bytes_consumed;
uint32_t inst = 0;
- if (flags & I2C_XFER_START)
+ if (flags & I2C_XFER_START) {
+ /*
+ * Start sequence will have to be issued, slave address needs
+ * to be included.
+ */
inst |= INST_START;
-
- /*
- * Setup slave device address. Calls to chip_i2c_xfer assume an 8 bit
- * slave address. Need to shift right by 1 bit.
- */
- inst |= INST_DEVADDRVAL(slave_addr >> 1);
-
- if (out_size) {
- /* Send slave addr byte if this is start of I2C transaction */
- if (flags & I2C_XFER_START)
- inst |= INST_FWDEVADDR;
- bytes_consumed = MIN(I2CM_FW_BYTES_MAX, out_size);
- /* Setup first write bytes */
- i2cm_set_fwbytes(port, &inst, out, bytes_consumed);
- out_size -= bytes_consumed;
- /* If write data remains, then put the rest in RW fifo */
- if (out_size) {
- out += bytes_consumed;
- inst |= INST_RWBYTES(out_size);
- i2cm_write_rwbytes(port, out, out_size);
- }
+ inst |= INST_DEVADDRVAL(I2C_GET_ADDR__7b(slave_addr__7bf));
+ inst |= INST_RWDEVADDR;
}
- if (in_size) {
- /*
- * If I2C_XFER_START is marked, then send slave address and
- * indicate it's a read transaction.
- */
- if (flags & I2C_XFER_START) {
- inst |= INST_RWDEVADDR;
- inst |= INST_RWDEVADDR_RWB;
- inst |= INST_RPT_START;
- }
- /* Setup number of bytes to read */
- inst |= INST_RWBYTES(in_size);
+ if (!is_write)
+ inst |= INST_RWDEVADDR_RWB;
- /* NACK the last byte read */
- if (flags & I2C_XFER_STOP)
- inst |= INST_NA;
- }
+ inst |= INST_RWBYTES(size);
- if (flags & I2C_XFER_STOP)
+ if (flags & I2C_XFER_STOP) {
inst |= INST_STOP;
+ if (!is_write)
+ inst |= INST_NA;
+ }
return inst;
}
-static int i2cm_execute_sequence(int port, int slave_addr, const uint8_t *out,
- int out_size, uint8_t *in, int in_size,
+static int i2cm_execute_sequence__7bf(int port, int slave_addr__7bf,
+ const uint8_t *out, int out_size,
+ uint8_t *in, int in_size,
int flags)
{
int rv;
uint32_t inst;
+ uint32_t status;
+ size_t size;
+ int is_write;
+ size_t done_so_far;
+ uint32_t seq_flags;
+
+ size = in_size ? in_size : out_size;
+ done_so_far = 0;
+ is_write = !!out_size;
+
+ while (done_so_far < size) {
+ size_t batch_size;
+
+ seq_flags = flags;
+
+ batch_size = MIN(size - done_so_far, I2CM_RW_BYTES_MAX);
- /* Build sequence instruction */
- inst = i2cm_build_sequence(port, slave_addr, out, out_size, in,
- in_size, flags);
- /* Start transaction */
- GWRITE_I(I2C, port, INST, inst);
-
- /* Wait for transaction to be complete */
- rv = i2cm_poll_for_complete(port);
- /* Handle timeout case */
- if (rv)
- return rv;
-
- /* Check status value for errors */
- if (GREAD_I(I2C, port, STATUS) & I2CM_ERROR_MASK) {
- /* If failed, then clear INST register */
- GWRITE_I(I2C, port, INST, 0);
- return EC_ERROR_UNKNOWN;
+ if (done_so_far)
+ /* No need to generate start. */
+ seq_flags &= ~I2C_XFER_START;
+
+ if ((batch_size + done_so_far) != size)
+ /* No need to generate stop. */
+ seq_flags &= ~I2C_XFER_STOP;
+
+ /* Build sequence instruction */
+ inst = i2cm_create_inst__7bf(slave_addr__7bf, is_write,
+ batch_size, seq_flags);
+
+ /* If this is a write - copy data into the FIFO. */
+ if (is_write)
+ i2cm_write_rwbytes(port, out + done_so_far, batch_size);
+
+ /* Start transaction */
+ GWRITE_I(I2C, port, INST, inst);
+
+ /* Wait for transaction to be complete */
+ rv = i2cm_poll_for_complete(port);
+ /* Handle timeout case */
+ if (rv)
+ return rv;
+
+ /* Check status value for errors */
+ status = GREAD_I(I2C, port, STATUS);
+ if (status & I2CM_ERROR_MASK) {
+ if (status & GFIELD_MASK(I2C, STATUS, FINALSTOP)) {
+ /*
+ * A stop was requested but not generated,
+ * let's make sure the bus is brought back to
+ * the idle state.
+ */
+ GWRITE_I(I2C, port, INST, INST_STOP);
+ i2cm_poll_for_complete(port);
+ }
+ /* Clear INST register after processing failure(s). */
+ GWRITE_I(I2C, port, INST, 0);
+ return EC_ERROR_UNKNOWN;
+ }
+
+ if (!is_write)
+ i2cm_read_rwbytes(port, in + done_so_far, batch_size);
+
+ done_so_far += batch_size;
}
return EC_SUCCESS;
@@ -349,67 +353,40 @@ static int i2cm_execute_sequence(int port, int slave_addr, const uint8_t *out,
/* Perform an i2c transaction. */
-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)
{
int rv;
- int sequence_flags;
- int num_out, num_in;
if (!in_size && !out_size)
/* Nothing to do */
return EC_SUCCESS;
- /*
- * Cr50 can do sequences of up to 64 write or read bytes. In addition it
- * can accommodate up to 4 write bytes and up to 64 read bytes in a
- * sequence set up. However, if the number of write bytes is > 4, then
- * the write and read must be done in separate sequences.
- */
-
- while (out_size > I2CM_FW_BYTES_MAX) {
- /* number of bytes that can handed in 1 sequence */
- num_out = MIN(I2CM_RW_BYTES_MAX + I2CM_FW_BYTES_MAX, out_size);
- sequence_flags = flags;
- /* If more than 1 sequence remaining, mask stop bit flag */
- if ((out_size - num_out) || in_size)
- sequence_flags &= ~I2C_XFER_STOP;
- /* Execute transaction */
- rv = i2cm_execute_sequence(port, slave_addr, out, num_out, in,
- 0, sequence_flags);
- if (rv)
- return rv;
- /* Update counts and flags */
- out += num_out;
- out_size -= num_out;
- flags &= ~sequence_flags;
+ if (in_size && out_size &&
+ ((flags & I2C_XFER_SINGLE) != I2C_XFER_SINGLE)) {
+ /*
+ * Not clear what to do: this is not a complete transaction,
+ * but it has both receive and transmit parts.
+ */
+ CPRINTS("%s: error: in %d, out %d, flags 0x%x",
+ __func__, in_size, out_size, flags);
+ return EC_ERROR_INVAL;
}
- /* At this point out_size <= 4 */
- while (out_size || in_size) {
- num_in = MIN(I2CM_RW_BYTES_MAX, in_size);
- num_out = out_size;
- sequence_flags = flags;
- /* If more than 1 sequence remaining, mask stop bit flag */
- if (in_size - num_in)
- sequence_flags &= ~I2C_XFER_STOP;
-
- rv = i2cm_execute_sequence(port, slave_addr, out, num_out, in,
- num_in, sequence_flags);
- if (rv)
+ if (out_size) {
+ /* Process write before read. */
+ rv = i2cm_execute_sequence__7bf(port, slave_addr__7bf, out,
+ out_size, NULL, 0, flags);
+ if (rv != EC_SUCCESS)
return rv;
-
- /* If bytes were read, copy to destination buffer */
- if (num_in) {
- i2cm_read_rwbytes(port, in, num_in);
- in += num_in;
- in_size -= num_in;
- }
- out_size = 0;
- flags &= ~sequence_flags;
}
- return EC_SUCCESS;
+ if (in_size)
+ rv = i2cm_execute_sequence__7bf(port, slave_addr__7bf,
+ NULL, 0, in, in_size, flags);
+
+ return rv;
}
int i2c_raw_get_scl(int port)
diff --git a/chip/host/i2c.c b/chip/host/i2c.c
index ad0da261dc..12170d5415 100644
--- a/chip/host/i2c.c
+++ b/chip/host/i2c.c
@@ -14,7 +14,7 @@
struct i2c_dev {
int port;
- int slave_addr;
+ uint16_t slave_addr__7bf;
int valid;
};
@@ -28,7 +28,7 @@ static void detach_init(void)
}
DECLARE_HOOK(HOOK_INIT, detach_init, HOOK_PRIO_FIRST);
-int test_detach_i2c(int port, int slave_addr)
+int test_detach_i2c__7bf(const int port, const uint16_t slave_addr__7bf)
{
int i;
@@ -40,20 +40,20 @@ int test_detach_i2c(int port, int slave_addr)
return EC_ERROR_OVERFLOW;
detached_devs[i].port = port;
- detached_devs[i].slave_addr = slave_addr;
+ detached_devs[i].slave_addr__7bf = slave_addr__7bf;
detached_devs[i].valid = 1;
return EC_SUCCESS;
}
-int test_attach_i2c(int port, int slave_addr)
+int test_attach_i2c__7bf(const int port, const uint16_t slave_addr__7bf)
{
int i;
for (i = 0; i < MAX_DETACHED_DEV_COUNT; ++i)
if (detached_devs[i].valid &&
detached_devs[i].port == port &&
- detached_devs[i].slave_addr == slave_addr)
+ detached_devs[i].slave_addr__7bf == slave_addr__7bf)
break;
if (i == MAX_DETACHED_DEV_COUNT)
@@ -63,28 +63,31 @@ int test_attach_i2c(int port, int slave_addr)
return EC_SUCCESS;
}
-static int test_check_detached(int port, int slave_addr)
+static int test_check_detached__7bf(const int port,
+ const uint16_t slave_addr__7bf)
{
int i;
for (i = 0; i < MAX_DETACHED_DEV_COUNT; ++i)
if (detached_devs[i].valid &&
detached_devs[i].port == port &&
- detached_devs[i].slave_addr == slave_addr)
+ detached_devs[i].slave_addr__7bf == slave_addr__7bf)
return 1;
return 0;
}
-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)
{
const struct test_i2c_xfer *p;
int rv;
- if (test_check_detached(port, slave_addr))
+ if (test_check_detached__7bf(port, slave_addr__7bf))
return EC_ERROR_UNKNOWN;
for (p = __test_i2c_xfer; p < __test_i2c_xfer_end; ++p) {
- rv = p->routine(port, slave_addr, out, out_size,
+ rv = p->routine__7bf(port, slave_addr__7bf,
+ out, out_size,
in, in_size, flags);
if (rv != EC_ERROR_INVAL)
return rv;
diff --git a/chip/ish/i2c.c b/chip/ish/i2c.c
index 9525849085..fa3aca627a 100644
--- a/chip/ish/i2c.c
+++ b/chip/ish/i2c.c
@@ -7,6 +7,7 @@
#include "common.h"
#include "console.h"
+#include "config_chip.h"
#include "gpio.h"
#include "hooks.h"
#include "i2c.h"
@@ -21,9 +22,6 @@
#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args)
-#define I2C_FLAG_REPEATED_START_DISABLED 0
-#define EVENT_FLAG_I2C_TIMEOUT TASK_EVENT_CUSTOM(1 << 1)
-
/*25MHz, 50MHz, 100MHz, 120MHz, 40MHz, 20MHz, 37MHz*/
static uint16_t default_hcnt_scl_100[] = {
4000, 4420, 4920, 4400, 4000, 4000, 4300
@@ -34,26 +32,24 @@ static uint16_t default_lcnt_scl_100[] = {
};
static uint16_t default_hcnt_scl_400[] = {
- 600, 820, 1120, 1066, 600, 600, 450
+ 600, 820, 1120, 800, 600, 600, 450
};
static uint16_t default_lcnt_scl_400[] = {
- 1320, 1380, 1300, 1300, 1300, 1200, 1250
+ 1320, 1380, 1300, 1550, 1300, 1200, 1250
};
static uint16_t default_hcnt_scl_1000[] = {
- 260, 260, 260, 260, 260, 260, 260
+ 260, 260, 260, 305, 260, 260, 260
};
static uint16_t default_lcnt_scl_1000[] = {
- 500, 500, 500, 500, 500, 500, 500
+ 500, 500, 500, 525, 500, 500, 500
};
static uint16_t default_hcnt_scl_hs[] = { 160, 300, 160, 166, 175, 150, 162 };
static uint16_t default_lcnt_scl_hs[] = { 320, 340, 320, 325, 325, 300, 297 };
-static uint8_t speed_val_arr[] = {
- STD_SPEED_VAL, FAST_SPEED_VAL, FAST_PLUS_SPEED_VAL, HIGH_SPEED_VAL};
static uint8_t bus_freq[ISH_I2C_PORT_COUNT] = {
I2C_FREQ_120, I2C_FREQ_120, I2C_FREQ_120
@@ -63,19 +59,19 @@ static struct i2c_context i2c_ctxs[ISH_I2C_PORT_COUNT] = {
{
.bus = 0,
.base = (uint32_t *) ISH_I2C0_BASE,
- .speed = I2C_SPEED_FAST,
+ .speed = I2C_SPEED_400KHZ,
.int_pin = ISH_I2C0_IRQ,
},
{
.bus = 1,
.base = (uint32_t *) ISH_I2C1_BASE,
- .speed = I2C_SPEED_FAST,
+ .speed = I2C_SPEED_400KHZ,
.int_pin = ISH_I2C1_IRQ,
},
{
.bus = 2,
.base = (uint32_t *) ISH_I2C2_BASE,
- .speed = I2C_SPEED_FAST,
+ .speed = I2C_SPEED_400KHZ,
.int_pin = ISH_I2C2_IRQ,
},
};
@@ -83,24 +79,24 @@ static struct i2c_context i2c_ctxs[ISH_I2C_PORT_COUNT] = {
static struct i2c_bus_info board_config[ISH_I2C_PORT_COUNT] = {
{
.bus_id = 0,
- .std_speed.sda_hold = DEFAULT_SDA_HOLD,
- .fast_speed.sda_hold = DEFAULT_SDA_HOLD,
- .fast_plus_speed.sda_hold = DEFAULT_SDA_HOLD,
- .high_speed.sda_hold = DEFAULT_SDA_HOLD,
+ .std_speed.sda_hold = DEFAULT_SDA_HOLD_STD,
+ .fast_speed.sda_hold = DEFAULT_SDA_HOLD_FAST,
+ .fast_plus_speed.sda_hold = DEFAULT_SDA_HOLD_FAST_PLUS,
+ .high_speed.sda_hold = DEFAULT_SDA_HOLD_HIGH,
},
{
.bus_id = 1,
- .std_speed.sda_hold = DEFAULT_SDA_HOLD,
- .fast_speed.sda_hold = DEFAULT_SDA_HOLD,
- .fast_plus_speed.sda_hold = DEFAULT_SDA_HOLD,
- .high_speed.sda_hold = DEFAULT_SDA_HOLD,
+ .std_speed.sda_hold = DEFAULT_SDA_HOLD_STD,
+ .fast_speed.sda_hold = DEFAULT_SDA_HOLD_FAST,
+ .fast_plus_speed.sda_hold = DEFAULT_SDA_HOLD_FAST_PLUS,
+ .high_speed.sda_hold = DEFAULT_SDA_HOLD_HIGH,
},
{
.bus_id = 2,
- .std_speed.sda_hold = DEFAULT_SDA_HOLD,
- .fast_speed.sda_hold = DEFAULT_SDA_HOLD,
- .fast_plus_speed.sda_hold = DEFAULT_SDA_HOLD,
- .high_speed.sda_hold = DEFAULT_SDA_HOLD,
+ .std_speed.sda_hold = DEFAULT_SDA_HOLD_STD,
+ .fast_speed.sda_hold = DEFAULT_SDA_HOLD_FAST,
+ .fast_plus_speed.sda_hold = DEFAULT_SDA_HOLD_FAST_PLUS,
+ .high_speed.sda_hold = DEFAULT_SDA_HOLD_HIGH,
},
};
@@ -154,80 +150,76 @@ static void i2c_intr_switch(uint32_t *base, int mode)
}
}
-static void i2c_init_transaction(struct i2c_context *ctx,
- uint8_t slave_addr, uint8_t flags)
+static void i2c_init_transaction__7b(struct i2c_context *ctx,
+ uint16_t slave_addr__7b, uint8_t flags)
{
uint32_t con_value;
uint32_t *base = ctx->base;
struct i2c_bus_info *bus_info = &board_config[ctx->bus];
uint32_t clk_in_val = clk_in[bus_freq[ctx->bus]];
- /* Convert 8-bit slave addrees to 7-bit for driver expectation*/
- slave_addr >>= 1;
-
/* disable interrupts */
i2c_intr_switch(base, DISABLE_INT);
i2c_mmio_write(base, IC_ENABLE, IC_ENABLE_DISABLE);
- i2c_mmio_write(base, IC_TAR, (slave_addr << IC_TAR_OFFSET) |
- TAR_SPECIAL_VAL | IC_10BITADDR_MASTER_VAL);
+ i2c_mmio_write(base, IC_TAR, (slave_addr__7b << IC_TAR_OFFSET) |
+ TAR_SPECIAL_VAL | IC_10BITADDR_MASTER_VAL);
/* set Clock SCL Count */
switch (ctx->speed) {
- case I2C_SPEED_STD:
+ case I2C_SPEED_100KHZ:
i2c_mmio_write(base, IC_SS_SCL_HCNT,
- NS_2_COUNTERS(bus_info->std_speed.hcnt,
+ NS_2_COUNTERS(bus_info->std_speed.hcnt,
clk_in_val));
i2c_mmio_write(base, IC_SS_SCL_LCNT,
- NS_2_COUNTERS(bus_info->std_speed.lcnt,
+ NS_2_COUNTERS(bus_info->std_speed.lcnt,
clk_in_val));
i2c_mmio_write(base, IC_SDA_HOLD,
- NS_2_COUNTERS(bus_info->std_speed.sda_hold,
+ NS_2_COUNTERS(bus_info->std_speed.sda_hold,
clk_in_val));
break;
- case I2C_SPEED_FAST:
+ case I2C_SPEED_400KHZ:
i2c_mmio_write(base, IC_FS_SCL_HCNT,
- NS_2_COUNTERS(bus_info->fast_speed.hcnt,
+ NS_2_COUNTERS(bus_info->fast_speed.hcnt,
clk_in_val));
i2c_mmio_write(base, IC_FS_SCL_LCNT,
- NS_2_COUNTERS(bus_info->fast_speed.lcnt,
+ NS_2_COUNTERS(bus_info->fast_speed.lcnt,
clk_in_val));
i2c_mmio_write(base, IC_SDA_HOLD,
- NS_2_COUNTERS(bus_info->fast_speed.sda_hold,
+ NS_2_COUNTERS(bus_info->fast_speed.sda_hold,
clk_in_val));
break;
-
- case I2C_SPEED_FAST_PLUS:
+ case I2C_SPEED_1MHZ:
i2c_mmio_write(base, IC_FS_SCL_HCNT,
- NS_2_COUNTERS(bus_info->fast_plus_speed.hcnt,
+ NS_2_COUNTERS(bus_info->fast_plus_speed.hcnt,
clk_in_val));
i2c_mmio_write(base, IC_FS_SCL_LCNT,
- NS_2_COUNTERS(bus_info->fast_plus_speed.lcnt,
+ NS_2_COUNTERS(bus_info->fast_plus_speed.lcnt,
clk_in_val));
i2c_mmio_write(base, IC_SDA_HOLD,
- NS_2_COUNTERS(bus_info->fast_plus_speed.sda_hold,
+ NS_2_COUNTERS(bus_info->fast_plus_speed.sda_hold,
clk_in_val));
break;
- case I2C_SPEED_HIGH:
+ case I2C_SPEED_3M4HZ:
i2c_mmio_write(base, IC_HS_SCL_HCNT,
- NS_2_COUNTERS(bus_info->high_speed.hcnt,
+ NS_2_COUNTERS(bus_info->high_speed.hcnt,
clk_in_val));
i2c_mmio_write(base, IC_HS_SCL_LCNT,
- NS_2_COUNTERS(bus_info->high_speed.lcnt,
+ NS_2_COUNTERS(bus_info->high_speed.lcnt,
clk_in_val));
i2c_mmio_write(base, IC_SDA_HOLD,
- NS_2_COUNTERS(bus_info->high_speed.sda_hold,
+ NS_2_COUNTERS(bus_info->high_speed.sda_hold,
clk_in_val));
i2c_mmio_write(base, IC_FS_SCL_HCNT,
- NS_2_COUNTERS(bus_info->fast_speed.hcnt,
+ NS_2_COUNTERS(bus_info->fast_speed.hcnt,
clk_in_val));
i2c_mmio_write(base, IC_FS_SCL_LCNT,
- NS_2_COUNTERS(bus_info->fast_speed.lcnt,
+ NS_2_COUNTERS(bus_info->fast_speed.lcnt,
clk_in_val));
break;
@@ -238,10 +230,10 @@ static void i2c_init_transaction(struct i2c_context *ctx,
/* in SPT HW we need to sync between I2C clock and data signals */
con_value = i2c_mmio_read(base, IC_CON);
- if (flags & I2C_FLAG_REPEATED_START_DISABLED)
- con_value &= ~IC_RESTART_EN_VAL;
- else
+ if (flags != 0)
con_value |= IC_RESTART_EN_VAL;
+ else
+ con_value &= ~IC_RESTART_EN_VAL;
i2c_mmio_write(base, IC_CON, con_value);
i2c_mmio_write(base, IC_FS_SPKLEN, spkln[bus_freq[ctx->bus]]);
@@ -261,81 +253,148 @@ static void i2c_write_buffer(uint32_t *base, uint8_t len,
++(*cur_index);
out = (buffer[i] << DATA_CMD_DAT_OFFSET) | DATA_CMD_WRITE_VAL;
- if (*cur_index == total_len)
+ /* if Write ONLY and Last byte */
+ if (*cur_index == total_len) {
out |= DATA_CMD_STOP_VAL;
+ }
i2c_mmio_write(base, IC_DATA_CMD, out);
}
}
-static void i2c_write_read_commands(uint32_t *base, uint8_t len)
+static void i2c_write_read_commands(uint32_t *base, uint8_t len, int more_data,
+ unsigned restart_flag)
{
+ /* this routine just set RX FIFO's control bit(s),
+ * READ command or RESTART */
int i;
+ uint32_t data_cmd;
+
+ for (i = 0; i < len; i++) {
+ data_cmd = DATA_CMD_READ_VAL;
+
+ if ((i == 0) && restart_flag)
+ /* if restart for first byte */
+ data_cmd |= DATA_CMD_RESTART_VAL;
- for (i = 0; i < len - 1; i++)
- i2c_mmio_write(base, IC_DATA_CMD, DATA_CMD_READ_VAL);
+ /* if last byte & less than FIFO size
+ * or only one byte to read */
+ if (i == (len - 1) && !more_data)
+ data_cmd |= DATA_CMD_STOP_VAL;
- i2c_mmio_write(base, IC_DATA_CMD,
- DATA_CMD_READ_VAL | DATA_CMD_STOP_VAL);
+ i2c_mmio_write(base, IC_DATA_CMD, data_cmd);
+ }
}
-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)
{
- int i, is_read = 0;
+ int i;
ssize_t total_len;
uint64_t expire_ts;
struct i2c_context *ctx;
ssize_t curr_index = 0;
+ uint16_t addr__7b = I2C_GET_ADDR__7b(slave_addr__7bf);
+ int begin_indx;
+ uint8_t repeat_start = 0;
if (out_size == 0 && in_size == 0)
return EC_SUCCESS;
- if (in_size > 0)
- is_read = 1;
+ if (port < 0 || port >= ISH_I2C_PORT_COUNT)
+ return EC_ERROR_INVAL;
+
+ /* Check for reserved I2C addresses, pg. 74 in DW_apb_i2c.pdf
+ * Address cannot be any of the reserved address locations:
+ * 0x00 to 0x07 or 0x78 to 0x7f.
+ */
+ if (addr__7b <= 0x07 || (addr__7b >= 0x78 && addr__7b <= 0x7F))
+ return EC_ERROR_INVAL;
+
+ /* assume that if both out_size and in_size are not zero,
+ * then, it is 'repeated Start' condition. */
+ if (in_size != 0 && out_size != 0)
+ repeat_start = 1;
ctx = &i2c_ctxs[port];
ctx->error_flag = 0;
+ ctx->wait_task_id = task_get_current();
- total_len = is_read ? (1 + in_size) : out_size;
-
- i2c_init_transaction(ctx, slave_addr, flags);
+ total_len = in_size + out_size;
- /* Write device id */
- i2c_write_buffer(ctx->base, 1, out, &curr_index, total_len);
+ i2c_init_transaction__7b(ctx, addr__7b, repeat_start);
/* Write W data */
- i2c_write_buffer(ctx->base, (is_read ? 0 : out_size - 1),
- (is_read ? NULL : out + 1),
- &curr_index, total_len);
+ if (out_size)
+ i2c_write_buffer(ctx->base, out_size, out,
+ &curr_index, total_len);
+
+ /* Wait here until Tx is completed so that FIFO becomes empty.
+ * This is optimized for smaller Tx data size.
+ * If need to write big data ( > ISH_I2C_FIFO_SIZE ),
+ * it is better to use Tx FIFO threshold interrupt(as in Rx) for
+ * better CPU usuage.
+ * */
+ expire_ts = __hw_clock_source_read() + I2C_TX_FLUSH_TIMEOUT_USEC;
+ if (in_size > (ISH_I2C_FIFO_SIZE - out_size)) {
+
+ while ((i2c_mmio_read(ctx->base, IC_STATUS) &
+ BIT(IC_STATUS_TFE)) == 0) {
+
+ if (__hw_clock_source_read() >= expire_ts) {
+ ctx->error_flag = 1;
+ break;
+ }
+ CPU_RELAX();
+ }
+ }
- if (is_read) {
- /* Write R commands */
- i2c_write_read_commands(ctx->base, in_size);
+ begin_indx = 0;
+ while (in_size) {
+ int rd_size; /* read size for on i2c transaction */
- /* Set rx_theshold */
- i2c_mmio_write(ctx->base, IC_RX_TL, in_size - 1);
- }
+ /*
+ * check if in_size > ISH_I2C_FIFO_SIZE, then try to read
+ * FIFO_SIZE each time.
+ */
+ if (in_size > ISH_I2C_FIFO_SIZE) {
+ rd_size = ISH_I2C_FIFO_SIZE;
+ in_size -= ISH_I2C_FIFO_SIZE;
+ } else {
+ rd_size = in_size;
+ in_size = 0;
+ }
+ /* Set rx_threshold */
+ i2c_mmio_write(ctx->base, IC_RX_TL, rd_size - 1);
- /* Enable interrupts */
- i2c_intr_switch(ctx->base,
- is_read ? ENABLE_READ_INT : ENABLE_WRITE_INT);
+ i2c_intr_switch(ctx->base, ENABLE_READ_INT);
- /* Wait for interrupt */
- ctx->wait_task_id = task_get_current();
- task_wait_event_mask(EVENT_FLAG_I2C_TIMEOUT, -1);
-
- if ((ctx->interrupts & M_TX_ABRT) == 0) {
- if (is_read) {
- /* read data */
- for (i = 0; i < in_size; i++)
- in[i] = i2c_read_byte(ctx->base,
- IC_DATA_CMD, 0);
+ /*
+ * RESTART only once for entire i2c transaction.
+ * assume that if both out_size and in_size are not zero,
+ * then, it is 'repeated Start' condition.
+ * set R commands bit, start to read
+ */
+ i2c_write_read_commands(ctx->base, rd_size, in_size,
+ (begin_indx == 0) && (repeat_start != 0));
+
+
+ /* need timeout in case no ACK from slave */
+ task_wait_event_mask(TASK_EVENT_I2C_IDLE, 2*MSEC);
+
+ if (ctx->interrupts & M_TX_ABRT) {
+ ctx->error_flag = 1;
+ break; /* when bus abort, no more reading !*/
}
- } else {
- ctx->error_flag = 1;
- }
+ /* read data */
+ for (i = begin_indx; i < begin_indx + rd_size; i++)
+ in[i] = i2c_read_byte(ctx->base,
+ IC_DATA_CMD, 0);
+
+ begin_indx += rd_size;
+ } /* while (in_size) */
ctx->reason = 0;
ctx->interrupts = 0;
@@ -343,8 +402,9 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
/* do not disable device before master is idle */
expire_ts = __hw_clock_source_read() + I2C_TSC_TIMEOUT;
- while (i2c_mmio_read(ctx->base, IC_STATUS) &
- (1 << IC_STATUS_MASTER_ACTIVITY)) {
+ while ((i2c_mmio_read(ctx->base, IC_STATUS) &
+ (BIT(IC_STATUS_MASTER_ACTIVITY) | BIT(IC_STATUS_TFE))) !=
+ BIT(IC_STATUS_TFE)) {
if (__hw_clock_source_read() >= expire_ts) {
ctx->error_flag = 1;
@@ -352,20 +412,35 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
}
}
+ i2c_intr_switch(ctx->base, DISABLE_INT);
i2c_mmio_write(ctx->base, IC_ENABLE, IC_ENABLE_DISABLE);
+ if (ctx->error_flag)
+ return EC_ERROR_INVAL;
+
return EC_SUCCESS;
}
static void i2c_interrupt_handler(struct i2c_context *ctx)
{
+ uint32_t raw_intr;
+
+ if (IS_ENABLED(INTR_DEBUG))
+ raw_intr = 0x0000FFFF & i2c_mmio_read(ctx->base,
+ IC_RAW_INTR_STAT);
+
/* check interrupts */
ctx->interrupts = i2c_mmio_read(ctx->base, IC_INTR_STAT);
ctx->reason = (uint16_t) i2c_mmio_read(ctx->base, IC_TX_ABRT_SOURCE);
+ if (IS_ENABLED(INTR_DEBUG))
+ CPRINTS("INTR_STAT = 0x%04x, TX_ABORT_SRC = 0x%04x, "
+ "RAW_INTR_STAT = 0x%04x",
+ ctx->interrupts, ctx->reason, raw_intr);
+
/* disable interrupts */
i2c_intr_switch(ctx->base, DISABLE_INT);
- task_set_event(ctx->wait_task_id, EVENT_FLAG_I2C_TIMEOUT, 0);
+ task_set_event(ctx->wait_task_id, TASK_EVENT_I2C_IDLE, 0);
}
static void i2c_isr_bus0(void)
@@ -390,36 +465,43 @@ static void i2c_config_speed(struct i2c_context *ctx, int kbps)
{
if (kbps > 1000)
- ctx->speed = I2C_SPEED_HIGH;
+ ctx->speed = I2C_SPEED_3M4HZ;
else if (kbps > 400)
- ctx->speed = I2C_SPEED_FAST_PLUS;
+ ctx->speed = I2C_SPEED_1MHZ;
else if (kbps > 100)
- ctx->speed = I2C_SPEED_FAST;
+ ctx->speed = I2C_SPEED_400KHZ;
else
- ctx->speed = I2C_SPEED_STD;
+ ctx->speed = I2C_SPEED_100KHZ;
}
static void i2c_init_hardware(struct i2c_context *ctx)
{
+ static const uint8_t speed_val_arr[] = {
+ [I2C_SPEED_100KHZ] = STD_SPEED_VAL,
+ [I2C_SPEED_400KHZ] = FAST_SPEED_VAL,
+ [I2C_SPEED_1MHZ] = FAST_SPEED_VAL,
+ [I2C_SPEED_3M4HZ] = HIGH_SPEED_VAL,
+ };
+
uint32_t *base = ctx->base;
/* disable interrupts */
i2c_intr_switch(base, DISABLE_INT);
i2c_mmio_write(base, IC_ENABLE, IC_ENABLE_DISABLE);
i2c_mmio_write(base, IC_CON, (MASTER_MODE_VAL
- | speed_val_arr[ctx->speed]
- | IC_RESTART_EN_VAL
- | IC_SLAVE_DISABLE_VAL));
+ | speed_val_arr[ctx->speed]
+ | IC_RESTART_EN_VAL
+ | IC_SLAVE_DISABLE_VAL));
i2c_mmio_write(base, IC_FS_SPKLEN, spkln[bus_freq[ctx->bus]]);
i2c_mmio_write(base, IC_HS_SPKLEN, spkln[bus_freq[ctx->bus]]);
/* get RX_FIFO and TX_FIFO depth */
ctx->max_rx_depth = i2c_read_byte(base, IC_COMP_PARAM_1,
- RX_BUFFER_DEPTH_OFFSET) + 1;
+ RX_BUFFER_DEPTH_OFFSET) + 1;
ctx->max_tx_depth = i2c_read_byte(base, IC_COMP_PARAM_1,
- TX_BUFFER_DEPTH_OFFSET) + 1;
+ TX_BUFFER_DEPTH_OFFSET) + 1;
}
static void i2c_initial_board_config(struct i2c_context *ctx)
diff --git a/chip/it83xx/i2c.c b/chip/it83xx/i2c.c
index a88599b380..95124068a1 100644
--- a/chip/it83xx/i2c.c
+++ b/chip/it83xx/i2c.c
@@ -200,7 +200,7 @@ struct i2c_port_data {
int widx; /* Index into output data */
int ridx; /* Index into input data */
int err; /* Error code, if any */
- uint8_t addr; /* address of device */
+ uint8_t addr__8b; /* address of device */
uint32_t timeout_us; /* Transaction timeout, or 0 to use default */
uint8_t freq; /* Frequency setting */
@@ -280,7 +280,7 @@ static void i2c_w2r_change_direction(int p)
}
static void i2c_pio_trans_data(int p, enum enhanced_i2c_transfer_direct direct,
- uint8_t data, int first_byte)
+ uint8_t data, int first_byte)
{
struct i2c_port_data *pd = pdata + p;
int p_ch;
@@ -325,7 +325,7 @@ static int i2c_tran_write(int p)
* bit0, Direction of the host transfer.
* bit[1:7}, Address of the targeted slave.
*/
- IT83XX_SMB_TRASLA(p) = pd->addr;
+ IT83XX_SMB_TRASLA(p) = pd->addr__8b;
/* Send first byte */
IT83XX_SMB_HOBDB(p) = *(pd->out++);
pd->widx++;
@@ -385,7 +385,7 @@ static int i2c_tran_read(int p)
* bit0, Direction of the host transfer.
* bit[1:7}, Address of the targeted slave.
*/
- IT83XX_SMB_TRASLA(p) = pd->addr | 0x01;
+ IT83XX_SMB_TRASLA(p) = pd->addr__8b | 0x01;
/* clear start flag */
pd->flags &= ~I2C_XFER_START;
/*
@@ -474,7 +474,7 @@ static int enhanced_i2c_tran_write(int p)
pd->flags &= ~I2C_XFER_START;
enhanced_i2c_start(p);
/* Send ID */
- i2c_pio_trans_data(p, TX_DIRECT, pd->addr, 1);
+ i2c_pio_trans_data(p, TX_DIRECT, pd->addr__8b, 1);
} else {
/* Host has completed the transmission of a byte */
if (pd->widx < pd->out_size) {
@@ -494,7 +494,8 @@ static int enhanced_i2c_tran_write(int p)
/* Write to read protocol */
pd->i2ccs = I2C_CH_REPEAT_START;
/* Repeat Start */
- i2c_pio_trans_data(p, RX_DIRECT, pd->addr, 1);
+ i2c_pio_trans_data(p, RX_DIRECT,
+ pd->addr__8b, 1);
} else {
if (pd->flags & I2C_XFER_STOP) {
IT83XX_I2C_CTR(p_ch) = E_FINISH;
@@ -526,7 +527,7 @@ static int enhanced_i2c_tran_read(int p)
/* Direct read */
pd->i2ccs = I2C_CH_WAIT_READ;
/* Send ID */
- i2c_pio_trans_data(p, RX_DIRECT, pd->addr, 1);
+ i2c_pio_trans_data(p, RX_DIRECT, pd->addr__8b, 1);
} else {
if (pd->i2ccs) {
if (pd->i2ccs == I2C_CH_REPEAT_START) {
@@ -543,7 +544,8 @@ static int enhanced_i2c_tran_read(int p)
/* Write to read */
pd->i2ccs = I2C_CH_WAIT_READ;
/* Send ID */
- i2c_pio_trans_data(p, RX_DIRECT, pd->addr, 1);
+ i2c_pio_trans_data(p, RX_DIRECT,
+ pd->addr__8b, 1);
task_enable_irq(i2c_ctrl_regs[p].irq);
}
} else {
@@ -645,8 +647,9 @@ int i2c_is_busy(int port)
return (IT83XX_I2C_STR(p_ch) & E_HOSTA_BB);
}
-int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
- uint8_t *in, int in_size, int flags)
+int chip_i2c_xfer__7bf(int port, uint16_t slave_addr__7bf,
+ const uint8_t *out, int out_size,
+ uint8_t *in, int in_size, int flags)
{
struct i2c_port_data *pd = pdata + port;
uint32_t events = 0;
@@ -668,7 +671,7 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
pd->widx = 0;
pd->ridx = 0;
pd->err = 0;
- pd->addr = slave_addr;
+ pd->addr__8b = I2C_GET_ADDR__7b(slave_addr__7bf) << 1;
/* Make sure we're in a good state to start */
if ((flags & I2C_XFER_START) && (i2c_is_busy(port)
diff --git a/chip/lm4/i2c.c b/chip/lm4/i2c.c
index 6f3efb700e..30a89eca8f 100644
--- a/chip/lm4/i2c.c
+++ b/chip/lm4/i2c.c
@@ -165,7 +165,8 @@ int i2c_do_work(int port)
return 0;
}
-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)
{
struct i2c_port_data *pd = pdata + port;
@@ -191,11 +192,11 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
uint32_t tpr = LM4_I2C_MTPR(port);
CPRINTS("I2C%d Addr:%02X bad status 0x%02x, SCL=%d, SDA=%d",
- port,
- slave_addr,
- reg_mcs,
- i2c_get_line_levels(port) & I2C_LINE_SCL_HIGH,
- i2c_get_line_levels(port) & I2C_LINE_SDA_HIGH);
+ port,
+ I2C_GET_ADDR__7b(slave_addr__7bf),
+ reg_mcs,
+ i2c_get_line_levels(port) & I2C_LINE_SCL_HIGH,
+ i2c_get_line_levels(port) & I2C_LINE_SDA_HIGH);
/* Attempt to unwedge the port. */
i2c_unwedge(port);
@@ -218,7 +219,7 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
}
/* Set slave address for transmit */
- LM4_I2C_MSA(port) = slave_addr & 0xff;
+ LM4_I2C_MSA(port) = (I2C_GET_ADDR__7b(slave_addr__7bf) << 1) & 0xff;
/* Enable interrupts */
pd->task_waiting = task_get_current();
diff --git a/chip/mchp/i2c.c b/chip/mchp/i2c.c
index bfe4890d4f..1a36ceae0c 100644
--- a/chip/mchp/i2c.c
+++ b/chip/mchp/i2c.c
@@ -132,7 +132,7 @@ static struct {
uint32_t i2c_complete; /* ISR write */
uint32_t flags;
uint8_t port;
- uint8_t slv_addr;
+ uint8_t slv_addr__8b;
uint8_t ctrl;
uint8_t hwsts;
uint8_t hwsts2;
@@ -545,7 +545,7 @@ static int i2c_mtx(int ctrl)
cdata[ctrl].flags |= (1ul << 1);
if (cdata[ctrl].xflags & I2C_XFER_START) {
cdata[ctrl].flags |= (1ul << 2);
- MCHP_I2C_DATA(ctrl) = cdata[ctrl].slv_addr;
+ MCHP_I2C_DATA(ctrl) = cdata[ctrl].slv_addr__8b;
/* Clock out the slave address, sending START bit */
MCHP_I2C_CTRL(ctrl) = CTRL_PIN | CTRL_ESO | CTRL_ENI |
CTRL_ACK | CTRL_STA;
@@ -629,7 +629,7 @@ static int i2c_mrx_start(int ctrl)
/* Repeated-START then address */
MCHP_I2C_CTRL(ctrl) = u8;
}
- MCHP_I2C_DATA(ctrl) = cdata[ctrl].slv_addr | 0x01;
+ MCHP_I2C_DATA(ctrl) = cdata[ctrl].slv_addr__8b | 0x01;
if (cdata[ctrl].transaction_state == I2C_TRANSACTION_STOPPED) {
cdata[ctrl].flags |= (1ul << 6);
/* address then START */
@@ -716,8 +716,9 @@ static int i2c_mrx_data(int ctrl)
/*
* Called from common/i2c_master
*/
-int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out,
- int out_size, uint8_t *in, int in_size, int flags)
+int chip_i2c_xfer__7bf(int port, uint16_t slave_addr__7bf,
+ const uint8_t *out, int out_size,
+ uint8_t *in, int in_size, int flags)
{
int ctrl;
int ret_done;
@@ -739,8 +740,8 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out,
cdata[ctrl].hwsts2 = 0;
cdata[ctrl].hwsts3 = 0;
cdata[ctrl].hwsts4 = 0;
- cdata[ctrl].port = (uint8_t)(port & 0xff);
- cdata[ctrl].slv_addr = (uint8_t)(slave_addr & 0xff);
+ cdata[ctrl].port = port & 0xff;
+ cdata[ctrl].slv_addr__8b = I2C_GET_ADDR__7b(slave_addr__7bf) << 1;
cdata[ctrl].out_size = out_size;
cdata[ctrl].outp = out;
cdata[ctrl].in_size = in_size;
diff --git a/chip/mec1322/i2c.c b/chip/mec1322/i2c.c
index ce3e618c24..c1aa3fee97 100644
--- a/chip/mec1322/i2c.c
+++ b/chip/mec1322/i2c.c
@@ -236,7 +236,9 @@ static inline void push_in_buf(uint8_t **in, uint8_t val, int skip)
}
}
-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)
{
int i;
@@ -284,7 +286,9 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
if (out_size) {
if (send_start) {
- MEC1322_I2C_DATA(controller) = (uint8_t)slave_addr;
+ MEC1322_I2C_DATA(controller) =
+ (uint8_t)(I2C_GET_ADDR__7b(slave_addr__7bf)
+ << 1);
/* Clock out the slave address, sending START bit */
MEC1322_I2C_CTRL(controller) = CTRL_PIN | CTRL_ESO |
@@ -327,8 +331,10 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_size,
CTRL_ACK |
CTRL_ENI;
- MEC1322_I2C_DATA(controller) = (uint8_t)slave_addr
- | 0x01;
+ MEC1322_I2C_DATA(controller) =
+ (uint8_t)(I2C_GET_ADDR__7b(slave_addr__7bf)
+ << 1)
+ | 0x01;
/* New transaction case, clock out slave address. */
if (cdata[controller].transaction_state ==
diff --git a/chip/npcx/i2c.c b/chip/npcx/i2c.c
index 725a2e7015..6f09673de5 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;
diff --git a/chip/nrf51/i2c.c b/chip/nrf51/i2c.c
index 62a4102350..79e9e4698c 100644
--- a/chip/nrf51/i2c.c
+++ b/chip/nrf51/i2c.c
@@ -141,13 +141,13 @@ static void handle_i2c_error(int port, int rv)
i2c_recover(port);
}
-static int i2c_master_write(int port, int slave_addr, const uint8_t *data,
- int size, int stop)
+static int i2c_master_write__7bf(const int port, const uint16_t slave_addr__7bf,
+ const uint8_t *data, int size, int stop)
{
int bytes_sent;
int timeout = I2C_TIMEOUT;
- NRF51_TWI_ADDRESS(port) = slave_addr >> 1;
+ NRF51_TWI_ADDRESS__7b(port) = I2C_GET_ADDR__7b(slave_addr__7bf);
/* Clear the sent bit */
NRF51_TWI_TXDSENT(port) = 0;
@@ -187,12 +187,13 @@ static int i2c_master_write(int port, int slave_addr, const uint8_t *data,
return EC_SUCCESS;
}
-static int i2c_master_read(int port, int slave_addr, uint8_t *data, int size)
+static int i2c_master_read__7bf(const int port, const uint16_t slave__addr__7bf,
+ uint8_t *data, int size)
{
int curr_byte;
int timeout = I2C_TIMEOUT;
- NRF51_TWI_ADDRESS(port) = slave_addr >> 1;
+ NRF51_TWI_ADDRESS__7b(port) = I2C_GET_ADDR__7b(slave_addr__7bf);
if (size == 1) /* Last byte: stop after this one. */
NRF51_PPI_TEP(i2c_ppi_chan[port]) =
@@ -252,7 +253,8 @@ static int i2c_master_read(int port, int slave_addr, uint8_t *data, int size)
return EC_SUCCESS;
}
-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 rv = EC_SUCCESS;
@@ -261,10 +263,12 @@ int chip_i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
ASSERT(in || !in_bytes);
if (out_bytes)
- rv = i2c_master_write(port, slave_addr, out, out_bytes,
- in_bytes ? 0 : 1);
+ rv = i2c_master_write__7bf(port, slave_addr__7bf,
+ out, out_bytes,
+ in_bytes ? 0 : 1);
if (rv == EC_SUCCESS && in_bytes)
- rv = i2c_master_read(port, slave_addr, in, in_bytes);
+ rv = i2c_master_read__7bf(port, slave_addr__7bf,
+ in, in_bytes);
handle_i2c_error(port, rv);
diff --git a/chip/stm32/i2c-stm32f0.c b/chip/stm32/i2c-stm32f0.c
index ad4df85bdd..657789af50 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 d9c331237c..ea9cb49d79 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 136a9413ac..5801e7eb86 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 bffa6cea39..ff97f6ae02 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;
};
diff --git a/common/cbi.c b/common/cbi.c
index f37d6950b1..1bc069939e 100644
--- a/common/cbi.c
+++ b/common/cbi.c
@@ -72,8 +72,8 @@ static struct cbi_header * const head = (struct cbi_header *)cbi;
static int read_eeprom(uint8_t offset, uint8_t *in, int in_size)
{
- return i2c_read_block(I2C_PORT_EEPROM, I2C_ADDR_EEPROM, offset,
- in, in_size);
+ return i2c_read_block__7bf(I2C_PORT_EEPROM, I2C_ADDR_EEPROM__7bf,
+ offset, in, in_size);
}
/*
@@ -220,8 +220,8 @@ static int write_board_info(void)
while (rest > 0) {
int size = MIN(EEPROM_PAGE_WRITE_SIZE, rest);
int rv;
- rv = i2c_write_block(I2C_PORT_EEPROM, I2C_ADDR_EEPROM,
- p - cbi, p, size);
+ rv = i2c_write_block__7bf(I2C_PORT_EEPROM, I2C_ADDR_EEPROM__7bf,
+ p - cbi, p, size);
if (rv) {
CPRINTS("Failed to write for %d", rv);
return rv;
diff --git a/common/host_command_master.c b/common/host_command_master.c
index 9ba8ba64ab..a8ca77a4c2 100644
--- a/common/host_command_master.c
+++ b/common/host_command_master.c
@@ -80,9 +80,10 @@ static int pd_host_command_internal(int command, int version,
*/
i2c_lock(I2C_PORT_PD_MCU, 1);
i2c_set_timeout(I2C_PORT_PD_MCU, PD_HOST_COMMAND_TIMEOUT_US);
- ret = i2c_xfer_unlocked(I2C_PORT_PD_MCU, CONFIG_USB_PD_I2C_SLAVE_ADDR,
- &req_buf[0], outsize + sizeof(rq) + 1, &resp_buf[0],
- 2, I2C_XFER_START);
+ ret = i2c_xfer_unlocked__7bf(I2C_PORT_PD_MCU,
+ CONFIG_USB_PD_I2C_SLAVE_ADDR__7BF,
+ &req_buf[0], outsize + sizeof(rq) + 1,
+ &resp_buf[0], 2, I2C_XFER_START);
i2c_set_timeout(I2C_PORT_PD_MCU, 0);
if (ret) {
i2c_lock(I2C_PORT_PD_MCU, 0);
@@ -94,8 +95,9 @@ static int pd_host_command_internal(int command, int version,
if (resp_len > (insize + sizeof(rs))) {
/* Do a dummy read to generate stop condition */
- i2c_xfer_unlocked(I2C_PORT_PD_MCU, CONFIG_USB_PD_I2C_SLAVE_ADDR,
- 0, 0, &resp_buf[2], 1, I2C_XFER_STOP);
+ i2c_xfer_unlocked__7bf(I2C_PORT_PD_MCU,
+ CONFIG_USB_PD_I2C_SLAVE_ADDR__7BF,
+ 0, 0, &resp_buf[2], 1, I2C_XFER_STOP);
i2c_lock(I2C_PORT_PD_MCU, 0);
CPRINTF("[%T response size is too large %d > %d]\n",
resp_len, insize + sizeof(rs));
@@ -103,9 +105,10 @@ static int pd_host_command_internal(int command, int version,
}
/* Receive remaining data */
- ret = i2c_xfer_unlocked(I2C_PORT_PD_MCU, CONFIG_USB_PD_I2C_SLAVE_ADDR,
- 0, 0,
- &resp_buf[2], resp_len, I2C_XFER_STOP);
+ ret = i2c_xfer_unlocked__7bf(I2C_PORT_PD_MCU,
+ CONFIG_USB_PD_I2C_SLAVE_ADDR__7BF,
+ 0, 0,
+ &resp_buf[2], resp_len, I2C_XFER_STOP);
i2c_lock(I2C_PORT_PD_MCU, 0);
if (ret) {
CPRINTF("[%T i2c transaction 2 failed: %d]\n", ret);
diff --git a/common/i2c_master.c b/common/i2c_master.c
index 1cd60f930b..0aff1326d5 100644
--- a/common/i2c_master.c
+++ b/common/i2c_master.c
@@ -57,7 +57,7 @@ static int i2c_port_is_locked(int port)
}
-const struct i2c_port_t *get_i2c_port(int port)
+const struct i2c_port_t *get_i2c_port(const int port)
{
int i;
@@ -70,26 +70,29 @@ const struct i2c_port_t *get_i2c_port(int port)
return NULL;
}
-static int chip_i2c_xfer_with_notify(int port, int slave_addr,
+static int chip_i2c_xfer_with_notify__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)
{
int ret;
if (IS_ENABLED(CONFIG_I2C_DEBUG))
- i2c_trace_notify(port, slave_addr, 0, out, out_size);
+ i2c_trace_notify__7bf(port, slave_addr__7bf,
+ 0, out, out_size);
if (IS_ENABLED(CONFIG_I2C_XFER_BOARD_CALLBACK))
- i2c_start_xfer_notify(port, slave_addr);
+ i2c_start_xfer_notify__7bf(port, slave_addr__7bf);
- ret = chip_i2c_xfer(port, slave_addr, out, out_size, in, in_size,
- flags);
+ ret = chip_i2c_xfer__7bf(port, slave_addr__7bf,
+ out, out_size, in, in_size, flags);
if (IS_ENABLED(CONFIG_I2C_XFER_BOARD_CALLBACK))
- i2c_end_xfer_notify(port, slave_addr);
+ i2c_end_xfer_notify__7bf(port, slave_addr__7bf);
if (IS_ENABLED(CONFIG_I2C_DEBUG))
- i2c_trace_notify(port, slave_addr, 1, in, in_size);
+ i2c_trace_notify__7bf(port, slave_addr__7bf,
+ 1, in, in_size);
return ret;
}
@@ -99,8 +102,10 @@ static int chip_i2c_xfer_with_notify(int port, int slave_addr,
* Internal function that splits reading into multiple chip_i2c_xfer() calls
* if in_size exceeds CONFIG_I2C_CHIP_MAX_READ_SIZE.
*/
-static int i2c_xfer_no_retry(int port, int slave_addr, const uint8_t *out,
- int out_size, uint8_t *in, int in_size, int flags)
+static int i2c_xfer_no_retry__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)
{
int ret;
int out_flags = flags & I2C_XFER_START;
@@ -108,13 +113,15 @@ static int i2c_xfer_no_retry(int port, int slave_addr, const uint8_t *out,
in_size -= in_chunk_size;
out_flags |= !in_size ? (flags & I2C_XFER_STOP) : 0;
- ret = chip_i2c_xfer_with_notify(port, slave_addr, out, out_size, in,
+ ret = chip_i2c_xfer_with_notify__7bf(port, slave_addr__7bf,
+ out, out_size, in,
in_chunk_size, out_flags);
in += in_chunk_size;
while (in_size && ret == EC_SUCCESS) {
in_chunk_size = MIN(in_size, CONFIG_I2C_CHIP_MAX_READ_SIZE);
in_size -= in_chunk_size;
- ret = chip_i2c_xfer_with_notify(port, slave_addr, NULL, 0, in,
+ ret = chip_i2c_xfer_with_notify__7bf(port, slave_addr__7bf,
+ NULL, 0, in,
in_chunk_size, !in_size ? (flags & I2C_XFER_STOP) : 0);
in += in_chunk_size;
}
@@ -122,7 +129,8 @@ static int i2c_xfer_no_retry(int port, int slave_addr, const uint8_t *out,
}
#endif /* CONFIG_I2C_XFER_LARGE_READ */
-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)
{
@@ -136,11 +144,13 @@ int i2c_xfer_unlocked(int port, int slave_addr,
for (i = 0; i <= CONFIG_I2C_NACK_RETRY_COUNT; i++) {
#ifdef CONFIG_I2C_XFER_LARGE_READ
- ret = i2c_xfer_no_retry(port, slave_addr, out, out_size, in,
- in_size, flags);
+ ret = i2c_xfer_no_retry__7bf(port, slave_addr__7bf,
+ out, out_size, in,
+ in_size, flags);
#else
- ret = chip_i2c_xfer_with_notify(port, slave_addr, out, out_size,
- in, in_size, flags);
+ ret = chip_i2c_xfer_with_notify__7bf(port, slave_addr__7bf,
+ out, out_size,
+ in, in_size, flags);
#endif /* CONFIG_I2C_XFER_LARGE_READ */
if (ret != EC_ERROR_BUSY)
break;
@@ -148,14 +158,17 @@ int i2c_xfer_unlocked(int port, int slave_addr,
return ret;
}
-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)
{
int rv;
i2c_lock(port, 1);
- rv = i2c_xfer_unlocked(port, slave_addr, out, out_size, in, in_size,
- I2C_XFER_SINGLE);
+ rv = i2c_xfer_unlocked__7bf(port, slave_addr__7bf,
+ out, out_size, in, in_size,
+ I2C_XFER_SINGLE);
i2c_lock(port, 0);
return rv;
@@ -204,19 +217,22 @@ void i2c_prepare_sysjump(void)
mutex_lock(port_mutex + i);
}
-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)
{
int rv;
uint8_t reg, buf[sizeof(uint32_t)];
reg = offset & 0xff;
/* I2C read 32-bit word: transmit 8-bit offset, and read 32bits */
- rv = i2c_xfer(port, slave_addr, &reg, 1, buf, sizeof(uint32_t));
+ rv = i2c_xfer__7bf(port, slave_addr__7bf,
+ &reg, 1, buf, sizeof(uint32_t));
if (rv)
return rv;
- if (slave_addr & I2C_FLAG_BIG_ENDIAN)
+ if (I2C_IS_BIG_ENDIAN(slave_addr__7bf))
*data = ((int)buf[0] << 24) | ((int)buf[1] << 16) |
((int)buf[0] << 8) | buf[1];
else
@@ -226,13 +242,15 @@ int i2c_read32(int port, int slave_addr, int offset, int *data)
return EC_SUCCESS;
}
-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)
{
uint8_t buf[1 + sizeof(uint32_t)];
buf[0] = offset & 0xff;
- if (slave_addr & I2C_FLAG_BIG_ENDIAN) {
+ if (I2C_IS_BIG_ENDIAN(slave_addr__7bf)) {
buf[1] = (data >> 24) & 0xff;
buf[2] = (data >> 16) & 0xff;
buf[3] = (data >> 8) & 0xff;
@@ -244,23 +262,26 @@ int i2c_write32(int port, int slave_addr, int offset, int data)
buf[4] = (data >> 24) & 0xff;
}
- return i2c_xfer(port, slave_addr, buf, sizeof(uint32_t) + 1,
- NULL, 0);
+ return i2c_xfer__7bf(port, slave_addr__7bf,
+ buf, sizeof(uint32_t) + 1, NULL, 0);
}
-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)
{
int rv;
uint8_t reg, buf[sizeof(uint16_t)];
reg = offset & 0xff;
/* I2C read 16-bit word: transmit 8-bit offset, and read 16bits */
- rv = i2c_xfer(port, slave_addr, &reg, 1, buf, sizeof(uint16_t));
+ rv = i2c_xfer__7bf(port, slave_addr__7bf,
+ &reg, 1, buf, sizeof(uint16_t));
if (rv)
return rv;
- if (slave_addr & I2C_FLAG_BIG_ENDIAN)
+ if (I2C_IS_BIG_ENDIAN(slave_addr__7bf))
*data = ((int)buf[0] << 8) | buf[1];
else
*data = ((int)buf[1] << 8) | buf[0];
@@ -268,13 +289,15 @@ int i2c_read16(int port, int slave_addr, int offset, int *data)
return EC_SUCCESS;
}
-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)
{
uint8_t buf[1 + sizeof(uint16_t)];
buf[0] = offset & 0xff;
- if (slave_addr & I2C_FLAG_BIG_ENDIAN) {
+ if (I2C_IS_BIG_ENDIAN(slave_addr__7bf)) {
buf[1] = (data >> 8) & 0xff;
buf[2] = data & 0xff;
} else {
@@ -282,10 +305,13 @@ int i2c_write16(int port, int slave_addr, int offset, int data)
buf[2] = (data >> 8) & 0xff;
}
- return i2c_xfer(port, slave_addr, buf, 1 + sizeof(uint16_t), NULL, 0);
+ return i2c_xfer__7bf(port, slave_addr__7bf,
+ buf, 1 + sizeof(uint16_t), NULL, 0);
}
-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)
{
int rv;
uint8_t reg = offset;
@@ -293,25 +319,28 @@ int i2c_read8(int port, int slave_addr, int offset, int *data)
reg = offset;
- rv = i2c_xfer(port, slave_addr, &reg, 1, &buf, 1);
+ rv = i2c_xfer__7bf(port, slave_addr__7bf, &reg, 1, &buf, 1);
if (!rv)
*data = buf;
return rv;
}
-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)
{
uint8_t buf[2];
buf[0] = offset;
buf[1] = data;
- return i2c_xfer(port, slave_addr, buf, 2, 0, 0);
+ return i2c_xfer__7bf(port, slave_addr__7bf, buf, 2, 0, 0);
}
-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)
{
int rv;
uint8_t buf[sizeof(uint16_t)], addr[sizeof(uint16_t)];
@@ -323,7 +352,7 @@ int i2c_read_offset16(int port, int slave_addr, uint16_t offset, int *data,
addr[1] = offset & 0xff;
/* I2C read 16-bit word: transmit 16-bit offset, and read buffer */
- rv = i2c_xfer(port, slave_addr, addr, 2, buf, len);
+ rv = i2c_xfer__7bf(port, slave_addr__7bf, addr, 2, buf, len);
if (rv)
return rv;
@@ -331,7 +360,7 @@ int i2c_read_offset16(int port, int slave_addr, uint16_t offset, int *data,
if (len == 1) {
*data = buf[0];
} else {
- if (slave_addr & I2C_FLAG_BIG_ENDIAN)
+ if (I2C_IS_BIG_ENDIAN(slave_addr__7bf))
*data = ((int)buf[0] << 8) | buf[1];
else
*data = ((int)buf[1] << 8) | buf[0];
@@ -340,8 +369,9 @@ int i2c_read_offset16(int port, int slave_addr, uint16_t offset, int *data,
return EC_SUCCESS;
}
-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)
{
uint8_t buf[2 + sizeof(uint16_t)];
@@ -354,7 +384,7 @@ int i2c_write_offset16(int port, int slave_addr, uint16_t offset, int data,
if (len == 1) {
buf[2] = data & 0xff;
} else {
- if (slave_addr & I2C_FLAG_BIG_ENDIAN) {
+ if (I2C_IS_BIG_ENDIAN(slave_addr__7bf)) {
buf[2] = (data >> 8) & 0xff;
buf[3] = data & 0xff;
} else {
@@ -363,22 +393,24 @@ int i2c_write_offset16(int port, int slave_addr, uint16_t offset, int data,
}
}
- return i2c_xfer(port, slave_addr, buf, 2 + len, NULL, 0);
+ return i2c_xfer__7bf(port, slave_addr__7bf, buf, 2 + len, NULL, 0);
}
-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)
{
uint8_t addr[sizeof(uint16_t)];
addr[0] = (offset >> 8) & 0xff;
addr[1] = offset & 0xff;
- return i2c_xfer(port, slave_addr, addr, 2, data, len);
+ return i2c_xfer__7bf(port, slave_addr__7bf, addr, 2, data, len);
}
-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)
{
int rv;
uint8_t addr[sizeof(uint16_t)];
@@ -391,18 +423,19 @@ int i2c_write_offset16_block(int port, int slave_addr, uint16_t offset,
* appending the destination address with the data array.
*/
i2c_lock(port, 1);
- rv = i2c_xfer_unlocked(port, slave_addr, addr, 2, NULL, 0,
+ rv = i2c_xfer_unlocked__7bf(port, slave_addr__7bf, addr, 2, NULL, 0,
I2C_XFER_START);
if (!rv)
- rv = i2c_xfer_unlocked(port, slave_addr, data, len, NULL, 0,
- I2C_XFER_STOP);
+ rv = i2c_xfer_unlocked__7bf(port, slave_addr__7bf,
+ data, len, NULL, 0, I2C_XFER_STOP);
i2c_lock(port, 0);
return rv;
}
-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)
{
int rv;
uint8_t reg, block_length;
@@ -414,16 +447,16 @@ int i2c_read_string(int port, int slave_addr, int offset, uint8_t *data,
* Send device reg space offset, and read back block length. Keep this
* session open without a stop.
*/
- rv = i2c_xfer_unlocked(port, slave_addr, &reg, 1, &block_length, 1,
- I2C_XFER_START);
+ rv = i2c_xfer_unlocked__7bf(port, slave_addr__7bf,
+ &reg, 1, &block_length, 1, I2C_XFER_START);
if (rv)
goto exit;
if (len && block_length > (len - 1))
block_length = len - 1;
- rv = i2c_xfer_unlocked(port, slave_addr, 0, 0, data, block_length,
- I2C_XFER_STOP);
+ rv = i2c_xfer_unlocked__7bf(port, slave_addr__7bf,
+ 0, 0, data, block_length, I2C_XFER_STOP);
data[block_length] = 0;
exit:
@@ -431,18 +464,20 @@ exit:
return rv;
}
-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)
{
int rv;
uint8_t reg_address = offset;
- rv = i2c_xfer(port, slave_addr, &reg_address, 1, data, len);
+ rv = i2c_xfer__7bf(port, slave_addr__7bf, &reg_address, 1, data, len);
return rv;
}
-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)
{
int rv;
uint8_t reg_address = offset;
@@ -452,11 +487,11 @@ int i2c_write_block(int port, int slave_addr, int offset, const uint8_t *data,
* appending the destination address with the data array.
*/
i2c_lock(port, 1);
- rv = i2c_xfer_unlocked(port, slave_addr, &reg_address, 1, NULL, 0,
- I2C_XFER_START);
+ rv = i2c_xfer_unlocked__7bf(port, slave_addr__7bf,
+ &reg_address, 1, NULL, 0, I2C_XFER_START);
if (!rv) {
- rv = i2c_xfer_unlocked(port, slave_addr, data, len, NULL, 0,
- I2C_XFER_STOP);
+ rv = i2c_xfer_unlocked__7bf(port, slave_addr__7bf,
+ data, len, NULL, 0, I2C_XFER_STOP);
}
i2c_lock(port, 0);
@@ -712,7 +747,7 @@ static int check_i2c_params(const struct host_cmd_handler_args *args)
/* Loop and process messages */;
for (msgnum = 0, msg = params->msg; msgnum < params->num_msgs;
msgnum++, msg++) {
- unsigned int addr_flags = msg->addr_flags;
+ unsigned int addr_flags = msg->addr_flags__7bf;
PTHRUPRINTS("port=%d, %s, addr=0x%x(7-bit), len=%d",
params->port,
@@ -769,10 +804,10 @@ static int i2c_command_passthru(struct host_cmd_handler_args *args)
if (ret)
return ret;
- if (port_protected[params->port] && i2c_port->passthru_allowed) {
+ if (port_protected[params->port] && i2c_port->passthru_allowed__7bf) {
for (i = 0; i < params->num_msgs; i++) {
- if (!i2c_port->passthru_allowed(i2c_port,
- params->msg[i].addr_flags & EC_I2C_ADDR_MASK))
+ if (!i2c_port->passthru_allowed__7bf(i2c_port,
+ params->msg[i].addr_flags__7bf))
return EC_RES_ACCESS_DENIED;
}
}
@@ -785,13 +820,15 @@ static int i2c_command_passthru(struct host_cmd_handler_args *args)
for (resp->num_msgs = 0, msg = params->msg;
resp->num_msgs < params->num_msgs;
resp->num_msgs++, msg++) {
- /* EC uses 8-bit slave address */
- unsigned int addr = (msg->addr_flags & EC_I2C_ADDR_MASK) << 1;
int xferflags = I2C_XFER_START;
int read_len = 0, write_len = 0;
int rv = 1;
- if (msg->addr_flags & EC_I2C_FLAG_READ)
+ /* Have to remove the EC flags from the address flags */
+ uint16_t addr__7bf = msg->addr_flags__7bf & EC_I2C_ADDR_MASK;
+
+
+ if (msg->addr_flags__7bf & EC_I2C_FLAG_READ)
read_len = msg->len;
else
write_len = msg->len;
@@ -800,9 +837,9 @@ static int i2c_command_passthru(struct host_cmd_handler_args *args)
if (resp->num_msgs == params->num_msgs - 1)
xferflags |= I2C_XFER_STOP;
-#if defined(VIRTUAL_BATTERY_ADDR) && defined(I2C_PORT_VIRTUAL_BATTERY)
+#if defined(VIRTUAL_BATTERY_ADDR__7bf) && defined(I2C_PORT_VIRTUAL_BATTERY)
if (params->port == I2C_PORT_VIRTUAL_BATTERY &&
- VIRTUAL_BATTERY_ADDR == addr) {
+ VIRTUAL_BATTERY_ADDR__7bf == addr__7bf) {
if (virtual_battery_handler(resp, in_len, &rv,
xferflags, read_len,
write_len, out))
@@ -811,7 +848,8 @@ static int i2c_command_passthru(struct host_cmd_handler_args *args)
#endif
/* Transfer next message */
PTHRUPRINTS("xfer port=%x addr=0x%x rlen=%d flags=0x%x",
- params->port, addr, read_len, xferflags);
+ params->port, addr__7bf,
+ read_len, xferflags);
if (write_len) {
PTHRUPRINTF(" out:");
for (i = 0; i < write_len; i++)
@@ -829,7 +867,8 @@ static int i2c_command_passthru(struct host_cmd_handler_args *args)
#endif
if (!port_is_locked)
i2c_lock(params->port, (port_is_locked = 1));
- rv = i2c_xfer_unlocked(params->port, addr,
+ rv = i2c_xfer_unlocked__7bf(params->port,
+ addr__7bf,
out, write_len,
&resp->data[in_len], read_len,
xferflags);
@@ -885,7 +924,7 @@ static void i2c_passthru_protect_tcpc_ports(void)
for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) {
/* TCPC tunnel not configured. No need to protect anything */
- if (!tcpc_config[i].i2c_info.addr)
+ if (!I2C_GET_ADDR__7b(tcpc_config[i].i2c_info.addr__7bf))
continue;
i2c_passthru_protect_port(tcpc_config[i].i2c_info.port);
}
@@ -976,30 +1015,31 @@ DECLARE_CONSOLE_COMMAND(i2cprotect, command_i2cprotect,
#ifdef CONFIG_CMD_I2C_SCAN
static void scan_bus(int port, const char *desc)
{
- int a;
+ int level;
uint8_t tmp;
+ uint16_t addr__7bf;
ccprintf("Scanning %d %s", port, desc);
i2c_lock(port, 1);
/* Don't scan a busy port, since reads will just fail / time out */
- a = i2c_get_line_levels(port);
- if (a != I2C_LINE_IDLE) {
+ level = i2c_get_line_levels(port);
+ if (level != I2C_LINE_IDLE) {
ccprintf(": port busy (SDA=%d, SCL=%d)",
- (a & I2C_LINE_SDA_HIGH) ? 1 : 0,
- (a & I2C_LINE_SCL_HIGH) ? 1 : 0);
+ (level & I2C_LINE_SDA_HIGH) ? 1 : 0,
+ (level & I2C_LINE_SCL_HIGH) ? 1 : 0);
goto scan_bus_exit;
}
- for (a = 0; a < 0x100; a += 2) {
+ for (addr__7bf = 0; addr__7bf <= 0xEF; ++addr__7bf) {
watchdog_reload(); /* Otherwise a full scan trips watchdog */
ccputs(".");
/* Do a single read */
- if (!i2c_xfer_unlocked(port, a, NULL, 0, &tmp, 1,
- I2C_XFER_SINGLE))
- ccprintf("\n 0x%02x", a);
+ if (!i2c_xfer_unlocked__7bf(port, addr__7bf,
+ NULL, 0, &tmp, 1, I2C_XFER_SINGLE))
+ ccprintf("\n 0x%02x", addr__7bf);
}
scan_bus_exit:
@@ -1034,7 +1074,8 @@ DECLARE_CONSOLE_COMMAND(i2cscan, command_scan,
#ifdef CONFIG_CMD_I2C_XFER
static int command_i2cxfer(int argc, char **argv)
{
- int port, slave_addr;
+ int port;
+ uint16_t addr__7bf;
uint16_t offset = 0;
uint8_t offset_size = 0;
int v = 0;
@@ -1049,7 +1090,7 @@ static int command_i2cxfer(int argc, char **argv)
if (*e)
return EC_ERROR_PARAM2;
- slave_addr = strtoi(argv[3], &e, 0);
+ addr__7bf = strtoi(argv[3], &e, 0);
if (*e)
return EC_ERROR_PARAM3;
@@ -1068,18 +1109,22 @@ static int command_i2cxfer(int argc, char **argv)
if (strcasecmp(argv[1], "r") == 0) {
/* 8-bit read */
if (offset_size == 2)
- rv = i2c_read_offset16(port, slave_addr, offset, &v, 1);
+ rv = i2c_read_offset16__7bf(port, addr__7bf,
+ offset, &v, 1);
else
- rv = i2c_read8(port, slave_addr, offset, &v);
+ rv = i2c_read8__7bf(port, addr__7bf,
+ offset, &v);
if (!rv)
ccprintf("0x%02x [%d]\n", v, v);
} else if (strcasecmp(argv[1], "r16") == 0) {
/* 16-bit read */
if (offset_size == 2)
- rv = i2c_read_offset16(port, slave_addr, offset, &v, 2);
+ rv = i2c_read_offset16__7bf(port, addr__7bf,
+ offset, &v, 2);
else
- rv = i2c_read16(port, slave_addr, offset, &v);
+ rv = i2c_read16__7bf(port, addr__7bf,
+ offset, &v);
if (!rv)
ccprintf("0x%04x [%d]\n", v, v);
@@ -1088,7 +1133,8 @@ static int command_i2cxfer(int argc, char **argv)
if (argc < 6 || v < 0 || v > sizeof(data))
return EC_ERROR_PARAM5;
- rv = i2c_xfer(port, slave_addr, (uint8_t *)&offset, 1, data, v);
+ rv = i2c_xfer__7bf(port, addr__7bf,
+ (uint8_t *)&offset, 1, data, v);
if (!rv)
ccprintf("Data: %.*h\n", v, data);
@@ -1098,18 +1144,22 @@ static int command_i2cxfer(int argc, char **argv)
if (argc < 6)
return EC_ERROR_PARAM5;
if (offset_size == 2)
- rv = i2c_write_offset16(port, slave_addr, offset, v, 1);
+ rv = i2c_write_offset16__7bf(port, addr__7bf,
+ offset, v, 1);
else
- rv = i2c_write8(port, slave_addr, offset, v);
+ rv = i2c_write8__7bf(port, addr__7bf,
+ offset, v);
} else if (strcasecmp(argv[1], "w16") == 0) {
/* 16-bit write */
if (argc < 6)
return EC_ERROR_PARAM5;
if (offset_size == 2)
- rv = i2c_write_offset16(port, slave_addr, offset, v, 2);
+ rv = i2c_write_offset16__7bf(port, addr__7bf,
+ offset, v, 2);
else
- rv = i2c_write16(port, slave_addr, offset, v);
+ rv = i2c_write16__7bf(port, addr__7bf,
+ offset, v);
} else {
return EC_ERROR_PARAM1;
@@ -1149,7 +1199,6 @@ static int command_i2ctest(int argc, char **argv)
int i, j, rv;
uint32_t rand;
int data, data_verify;
- int port, addr;
int count = 10000;
int udelay = 100;
int test_dev = i2c_test_dev_used;
@@ -1177,6 +1226,9 @@ static int command_i2ctest(int argc, char **argv)
}
for (i = 0; i < count; i++) {
+ int port;
+ uint16_t addr__7bf;
+
if (!(i % 1000))
ccprintf("running test %d\n", i);
@@ -1186,7 +1238,7 @@ static int command_i2ctest(int argc, char **argv)
}
port = i2c_stress_tests[test_dev].port;
- addr = i2c_stress_tests[test_dev].addr;
+ addr__7bf = i2c_stress_tests[test_dev].addr__7bf;
i2c_s_test = i2c_stress_tests[test_dev].i2c_test;
reg_s_info = &i2c_s_test->reg_info;
test_s_results = &i2c_s_test->test_results;
@@ -1194,8 +1246,8 @@ static int command_i2ctest(int argc, char **argv)
rand = get_time().val;
if (rand & 0x1) {
/* read */
- rv = i2c_s_test->i2c_read ?
- i2c_s_test->i2c_read(port, addr,
+ rv = i2c_s_test->i2c_read__7bf ?
+ i2c_s_test->i2c_read__7bf(port, addr__7bf,
reg_s_info->read_reg, &data) :
i2c_s_test->i2c_read_dev(
reg_s_info->read_reg, &data);
@@ -1211,8 +1263,8 @@ static int command_i2ctest(int argc, char **argv)
*/
/* Read the write register */
- rv = i2c_s_test->i2c_read ?
- i2c_s_test->i2c_read(port, addr,
+ rv = i2c_s_test->i2c_read__7bf ?
+ i2c_s_test->i2c_read__7bf(port, addr__7bf,
reg_s_info->read_reg, &data) :
i2c_s_test->i2c_read_dev(
reg_s_info->read_reg, &data);
@@ -1226,8 +1278,9 @@ static int command_i2ctest(int argc, char **argv)
j = I2C_STRESS_TEST_DATA_VERIFY_RETRY_COUNT;
do {
/* Write same value back */
- rv = i2c_s_test->i2c_write ?
- i2c_s_test->i2c_write(port, addr,
+ rv = i2c_s_test->i2c_write__7bf ?
+ i2c_s_test->i2c_write__7bf(port,
+ addr__7bf,
reg_s_info->write_reg, data) :
i2c_s_test->i2c_write_dev(
reg_s_info->write_reg, data);
@@ -1240,8 +1293,9 @@ static int command_i2ctest(int argc, char **argv)
test_s_results->write_success++;
/* Read back to verify the data */
- rv = i2c_s_test->i2c_read ?
- i2c_s_test->i2c_read(port, addr,
+ rv = i2c_s_test->i2c_read__7bf ?
+ i2c_s_test->i2c_read__7bf(port,
+ addr__7bf,
reg_s_info->read_reg, &data_verify) :
i2c_s_test->i2c_read_dev(
reg_s_info->read_reg, &data_verify);
diff --git a/common/i2c_trace.c b/common/i2c_trace.c
index 52603c7244..ff237ed582 100644
--- a/common/i2c_trace.c
+++ b/common/i2c_trace.c
@@ -23,16 +23,17 @@ struct i2c_trace_range {
static struct i2c_trace_range trace_entries[8];
-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)
{
size_t i;
+ uint16_t addr__7b = I2C_GET_ADDR__7b(slave_addr__7bf);
for (i = 0; i < ARRAY_SIZE(trace_entries); i++)
if (trace_entries[i].enabled
&& trace_entries[i].port == port
- && trace_entries[i].slave_addr_lo <= slave_addr
- && trace_entries[i].slave_addr_hi >= slave_addr)
+ && trace_entries[i].slave_addr_lo <= addr__7b
+ && trace_entries[i].slave_addr_hi >= addr__7b)
goto trace_enabled;
return;
@@ -40,7 +41,7 @@ trace_enabled:
CPRINTF("i2c: %s %d:0x%X ",
direction ? "read" : "write",
port,
- slave_addr);
+ addr__7b);
for (i = 0; i < size; i++)
CPRINTF("%02X ", data[i]);
CPRINTF("\n");
diff --git a/common/lb_common.c b/common/lb_common.c
index f800a6a65a..8dbcd73092 100644
--- a/common/lb_common.c
+++ b/common/lb_common.c
@@ -111,7 +111,7 @@
/* Since there's absolutely nothing we can do about it if an I2C access
* isn't working, we're completely ignoring any failures. */
-static const uint8_t i2c_addr[] = { 0x54, 0x56 };
+static const uint16_t i2c_addr__7bf[] = { 0x2A, 0x2B };
static inline void controller_write(int ctrl_num, uint8_t reg, uint8_t val)
{
@@ -119,9 +119,10 @@ static inline void controller_write(int ctrl_num, uint8_t reg, uint8_t val)
buf[0] = reg;
buf[1] = val;
- ctrl_num = ctrl_num % ARRAY_SIZE(i2c_addr);
- i2c_xfer_unlocked(I2C_PORT_LIGHTBAR, i2c_addr[ctrl_num], buf, 2, 0, 0,
- I2C_XFER_SINGLE);
+ ctrl_num = ctrl_num % ARRAY_SIZE(i2c_addr__7bf);
+ i2c_xfer_unlocked__7bf(I2C_PORT_LIGHTBAR, i2c_addr__7bf[ctrl_num],
+ buf, 2, 0, 0,
+ I2C_XFER_SINGLE);
}
static inline uint8_t controller_read(int ctrl_num, uint8_t reg)
@@ -129,8 +130,8 @@ static inline uint8_t controller_read(int ctrl_num, uint8_t reg)
uint8_t buf[1];
int rv;
- ctrl_num = ctrl_num % ARRAY_SIZE(i2c_addr);
- rv = i2c_xfer_unlocked(I2C_PORT_LIGHTBAR, i2c_addr[ctrl_num],
+ ctrl_num = ctrl_num % ARRAY_SIZE(i2c_addr__7bf);
+ rv = i2c_xfer_unlocked__7bf(I2C_PORT_LIGHTBAR, i2c_addr__7bf[ctrl_num],
&reg, 1, buf, 1, I2C_XFER_SINGLE);
return rv ? 0 : buf[0];
}
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 414b35b95a..7d9993b1e0 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -2051,7 +2051,8 @@ 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", motion_sensors[i].addr);
+ ccprintf("addr: %d\n", I2C_GET_ADDR__7b(motion_sensors[i]
+ .i2c_spi_addr__7bf));
ccprintf("range: %d\n", motion_sensors[i].default_range);
ccprintf("min_freq: %d\n", motion_sensors[i].min_frequency);
ccprintf("max_freq: %d\n", motion_sensors[i].max_frequency);
diff --git a/common/peripheral.c b/common/peripheral.c
index 4f16cd981d..4ad9ed3b9f 100644
--- a/common/peripheral.c
+++ b/common/peripheral.c
@@ -22,8 +22,7 @@ static int hc_locate_chip(struct host_cmd_handler_args *args)
return EC_RES_OVERFLOW;
resp->bus_type = EC_BUS_TYPE_I2C;
resp->i2c_info.port = I2C_PORT_EEPROM;
- /* Convert from 8-bit address to 7-bit address */
- resp->i2c_info.addr = I2C_ADDR_EEPROM >> 1;
+ resp->i2c_info.addr__7bf = I2C_ADDR_EEPROM__7bf;
#else
/* Lookup type is supported, but not present on system. */
return EC_RES_UNAVAILABLE;
@@ -37,8 +36,8 @@ static int hc_locate_chip(struct host_cmd_handler_args *args)
if (resp->bus_type == EC_BUS_TYPE_I2C) {
resp->i2c_info.port =
tcpc_config[params->index].i2c_info.port;
- resp->i2c_info.addr =
- tcpc_config[params->index].i2c_info.addr >> 1;
+ resp->i2c_info.addr__7bf =
+ tcpc_config[params->index].i2c_info.addr__7bf;
}
#else
return EC_RES_UNAVAILABLE;
diff --git a/common/usb_i2c.c b/common/usb_i2c.c
index 241e86b5ce..bf162b0e2b 100644
--- a/common/usb_i2c.c
+++ b/common/usb_i2c.c
@@ -107,9 +107,7 @@ static void usb_i2c_execute(struct usb_i2c_config const *config)
/* Payload is ready to execute. */
uint32_t count = usb_i2c_read_packet(config);
int portindex = (config->buffer[0] >> 0) & 0xf;
- /* Convert 7-bit slave address to chromium EC 8-bit address. */
- uint8_t slave_addr = (config->buffer[0] >> 7) & 0xfe;
-
+ uint16_t addr__7bf = (config->buffer[0] >> 8) & 0x7f;
int write_count = ((config->buffer[0] << 4) & 0xf00) |
((config->buffer[1] >> 0) & 0xff);
int read_count = (config->buffer[1] >> 8) & 0xff;
@@ -136,7 +134,7 @@ static void usb_i2c_execute(struct usb_i2c_config const *config)
config->buffer[0] = USB_I2C_READ_COUNT_INVALID;
} else if (portindex >= i2c_ports_used) {
config->buffer[0] = USB_I2C_PORT_INVALID;
- } else if (slave_addr == USB_I2C_CMD_ADDR) {
+ } else if (addr__7bf == USB_I2C_CMD_ADDR__7bf) {
/*
* This is a non-i2c command, invoke the handler if it has
* been registered, if not - report the appropriate error.
@@ -157,8 +155,7 @@ static void usb_i2c_execute(struct usb_i2c_config const *config)
* knows about. It should behave closer to
* EC_CMD_I2C_PASSTHRU, which can protect ports and ranges.
*/
- ret = i2c_xfer(i2c_ports[portindex].port,
- slave_addr,
+ ret = i2c_xfer__7bf(i2c_ports[portindex].port, addr__7bf,
(uint8_t *)(config->buffer + 2) + offset,
write_count,
(uint8_t *)(config->buffer + 2),
diff --git a/cts/i2c/dut.c b/cts/i2c/dut.c
index e4a87f440e..033aca7ffc 100644
--- a/cts/i2c/dut.c
+++ b/cts/i2c/dut.c
@@ -13,25 +13,28 @@
#include "uart.h"
#include "watchdog.h"
-#define TH_ADDR 0x3c
+#define TH_ADDR__7bf 0x1e
enum cts_rc write8_test(void)
{
- if (i2c_write8(i2c_ports[0].port, TH_ADDR, WRITE8_OFF, WRITE8_DATA))
+ if (i2c_write8__7bf(i2c_ports[0].port, TH_ADDR__7bf,
+ WRITE8_OFF, WRITE8_DATA))
return CTS_RC_FAILURE;
return CTS_RC_SUCCESS;
}
enum cts_rc write16_test(void)
{
- if (i2c_write16(i2c_ports[0].port, TH_ADDR, WRITE16_OFF, WRITE16_DATA))
+ if (i2c_write16__7bf(i2c_ports[0].port, TH_ADDR__7bf,
+ WRITE16_OFF, WRITE16_DATA))
return CTS_RC_FAILURE;
return CTS_RC_SUCCESS;
}
enum cts_rc write32_test(void)
{
- if (i2c_write32(i2c_ports[0].port, TH_ADDR, WRITE32_OFF, WRITE32_DATA))
+ if (i2c_write32__7bf(i2c_ports[0].port, TH_ADDR__7bf,
+ WRITE32_OFF, WRITE32_DATA))
return CTS_RC_FAILURE;
return CTS_RC_SUCCESS;
}
@@ -40,7 +43,8 @@ enum cts_rc read8_test(void)
{
int data;
- if (i2c_read8(i2c_ports[0].port, TH_ADDR, READ8_OFF, &data))
+ if (i2c_read8__7bf(i2c_ports[0].port, TH_ADDR__7bf,
+ READ8_OFF, &data))
return CTS_RC_FAILURE;
if (data != READ8_DATA) {
CPRINTL("Expecting 0x%x but read 0x%x", READ8_DATA, data);
@@ -54,7 +58,8 @@ enum cts_rc read16_test(void)
{
int data;
- if (i2c_read16(i2c_ports[0].port, TH_ADDR, READ16_OFF, &data))
+ if (i2c_read16__7bf(i2c_ports[0].port, TH_ADDR__7bf,
+ READ16_OFF, &data))
return CTS_RC_FAILURE;
if (data != READ16_DATA) {
CPRINTL("Expecting 0x%x but read 0x%x", READ16_DATA, data);
@@ -68,7 +73,8 @@ enum cts_rc read32_test(void)
{
int data;
- if (i2c_read32(i2c_ports[0].port, TH_ADDR, READ32_OFF, &data))
+ if (i2c_read32__7bf(i2c_ports[0].port, TH_ADDR__7bf,
+ READ32_OFF, &data))
return CTS_RC_FAILURE;
if (data != READ32_DATA) {
CPRINTL("Read 0x%x expecting 0x%x", data, READ32_DATA);
diff --git a/driver/accel_bma2x2.c b/driver/accel_bma2x2.c
index c1e9eb4d63..5253783623 100644
--- a/driver/accel_bma2x2.c
+++ b/driver/accel_bma2x2.c
@@ -28,19 +28,19 @@
/**
* Read register from accelerometer.
*/
-static inline int raw_read8(const int port, const int addr, const int reg,
- int *data_ptr)
+static inline int raw_read8__7bf(const int port, const uint16_t i2c_addr__7bf,
+ const int reg, int *data_ptr)
{
- return i2c_read8(port, addr, reg, data_ptr);
+ return i2c_read8__7bf(port, i2c_addr__7bf, reg, data_ptr);
}
/**
* Write register from accelerometer.
*/
-static inline int raw_write8(const int port, const int addr, const int reg,
- int data)
+static inline int raw_write8__7bf(const int port, const uint16_t i2c_addr__7bf,
+ const int reg, int data)
{
- return i2c_write8(port, addr, reg, data);
+ return i2c_write8__7bf(port, i2c_addr__7bf, reg, data);
}
static int set_range(const struct motion_sensor_t *s, int range, int rnd)
@@ -55,14 +55,15 @@ static int set_range(const struct motion_sensor_t *s, int range, int rnd)
mutex_lock(s->mutex);
/* Determine the new value of control reg and attempt to write it. */
- ret = raw_read8(s->port, s->addr, BMA2x2_RANGE_SELECT_ADDR,
- &range_reg_val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMA2x2_RANGE_SELECT_ADDR, &range_reg_val);
if (ret != EC_SUCCESS) {
mutex_unlock(s->mutex);
return ret;
}
reg_val = (range_reg_val & ~BMA2x2_RANGE_SELECT_MSK) | range_val;
- ret = raw_write8(s->port, s->addr, BMA2x2_RANGE_SELECT_ADDR, reg_val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMA2x2_RANGE_SELECT_ADDR, reg_val);
/* If successfully written, then save the range. */
if (ret == EC_SUCCESS)
@@ -97,14 +98,16 @@ static int set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
mutex_lock(s->mutex);
/* Determine the new value of control reg and attempt to write it. */
- ret = raw_read8(s->port, s->addr, BMA2x2_BW_SELECT_ADDR, &odr_reg_val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMA2x2_BW_SELECT_ADDR, &odr_reg_val);
if (ret != EC_SUCCESS) {
mutex_unlock(s->mutex);
return ret;
}
reg_val = (odr_reg_val & ~BMA2x2_BW_MSK) | odr_val;
/* Set output data rate. */
- ret = raw_write8(s->port, s->addr, BMA2x2_BW_SELECT_ADDR, reg_val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMA2x2_BW_SELECT_ADDR, reg_val);
/* If successfully written, then save the new data rate. */
if (ret == EC_SUCCESS)
@@ -129,7 +132,7 @@ static int set_offset(const struct motion_sensor_t *s, const int16_t *offset,
/* temperature is ignored */
/* Offset from host is in 1/1024g, 1/128g internally. */
for (i = X; i <= Z; i++) {
- ret = raw_write8(s->port, s->addr,
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
BMA2x2_OFFSET_X_AXIS_ADDR + i, offset[i] / 8);
if (ret)
return ret;
@@ -143,8 +146,8 @@ static int get_offset(const struct motion_sensor_t *s, int16_t *offset,
int i, val, ret;
for (i = X; i <= Z; i++) {
- ret = raw_read8(s->port, s->addr, BMA2x2_OFFSET_X_AXIS_ADDR + i,
- &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMA2x2_OFFSET_X_AXIS_ADDR + i, &val);
if (ret)
return ret;
offset[i] = (int8_t)val * 8;
@@ -160,7 +163,8 @@ static int read(const struct motion_sensor_t *s, intv3_t v)
/* Read 6 bytes starting at X_AXIS_LSB. */
mutex_lock(s->mutex);
- ret = i2c_read_block(s->port, s->addr, BMA2x2_X_AXIS_LSB_ADDR, acc, 6);
+ ret = i2c_read_block__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMA2x2_X_AXIS_LSB_ADDR, acc, 6);
mutex_unlock(s->mutex);
if (ret != EC_SUCCESS)
@@ -189,7 +193,8 @@ static int perform_calib(const struct motion_sensor_t *s)
int ret, val, status, rate, range, i;
timestamp_t deadline;
- ret = raw_read8(s->port, s->addr, BMA2x2_OFFSET_CTRL_ADDR, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMA2x2_OFFSET_CTRL_ADDR, &val);
if (ret)
return ret;
if (!(val & BMA2x2_OFFSET_CAL_READY))
@@ -213,11 +218,13 @@ static int perform_calib(const struct motion_sensor_t *s)
val = ((BMA2x2_OFC_TARGET_0G << BMA2x2_OFC_TARGET_AXIS(X)) |
(BMA2x2_OFC_TARGET_0G << BMA2x2_OFC_TARGET_AXIS(Y)) |
(val << BMA2x2_OFC_TARGET_AXIS(Z)));
- raw_write8(s->port, s->addr, BMA2x2_OFC_SETTING_ADDR, val);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMA2x2_OFC_SETTING_ADDR, val);
for (i = X; i <= Z; i++) {
val = (i + 1) << BMA2x2_OFFSET_TRIGGER_OFF;
- raw_write8(s->port, s->addr, BMA2x2_OFFSET_CTRL_ADDR, val);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMA2x2_OFFSET_CTRL_ADDR, val);
/*
* The sensor needs 16 samples. At 100Hz/10ms, it needs 160ms to
* complete. Set 400ms to have some margin.
@@ -229,7 +236,7 @@ static int perform_calib(const struct motion_sensor_t *s)
goto end_perform_calib;
}
msleep(50);
- ret = raw_read8(s->port, s->addr,
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
BMA2x2_OFFSET_CTRL_ADDR, &status);
if (ret != EC_SUCCESS)
goto end_perform_calib;
@@ -246,7 +253,8 @@ static int init(const struct motion_sensor_t *s)
{
int ret = 0, tries = 0, val, reg, reset_field;
- ret = raw_read8(s->port, s->addr, BMA2x2_CHIP_ID_ADDR, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMA2x2_CHIP_ID_ADDR, &val);
if (ret)
return EC_ERROR_UNKNOWN;
@@ -259,13 +267,13 @@ static int init(const struct motion_sensor_t *s)
mutex_lock(s->mutex);
- ret = raw_read8(s->port, s->addr, reg, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, reg, &val);
if (ret != EC_SUCCESS) {
mutex_unlock(s->mutex);
return ret;
}
val |= reset_field;
- ret = raw_write8(s->port, s->addr, reg, val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, reg, val);
if (ret != EC_SUCCESS) {
mutex_unlock(s->mutex);
return ret;
@@ -273,7 +281,7 @@ static int init(const struct motion_sensor_t *s)
/* The SRST will be cleared when reset is complete. */
do {
- ret = raw_read8(s->port, s->addr, reg, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, reg, &val);
/* Reset complete. */
if ((ret == EC_SUCCESS) && !(val & reset_field))
diff --git a/driver/accel_bma2x2.h b/driver/accel_bma2x2.h
index 09a4ea2452..ecd3deac23 100644
--- a/driver/accel_bma2x2.h
+++ b/driver/accel_bma2x2.h
@@ -22,16 +22,16 @@ extern const struct accelgyro_drv bma2x2_accel_drv;
* BMA250E
* BMA222E
*/
-#define BMA2x2_I2C_ADDR1 0x30
-#define BMA2x2_I2C_ADDR2 0x19
+#define BMA2x2_I2C_ADDR1__7bf 0x18
+#define BMA2x2_I2C_ADDR2__7bf 0x19
/* The following definition of I2C address is used for the following sensors
* BMC150
* BMC056
* BMC156
*/
-#define BMA2x2_I2C_ADDR3 0x10
-#define BMA2x2_I2C_ADDR4 0x11
+#define BMA2x2_I2C_ADDR3__7bf 0x10
+#define BMA2x2_I2C_ADDR4__7bf 0x11
/*** Chip-specific registers ***/
/* REGISTER ADDRESS DEFINITIONS */
diff --git a/driver/accel_kionix.c b/driver/accel_kionix.c
index d486d4bcd5..4e1f5bb4fc 100644
--- a/driver/accel_kionix.c
+++ b/driver/accel_kionix.c
@@ -133,24 +133,27 @@ static int find_param_index(const int eng_val, const int round_up,
/**
* Read register from accelerometer.
*/
-static int raw_read8(const int port, const int addr, const int reg,
- int *data_ptr)
+static int raw_read8__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const int reg, int *data_ptr)
{
int rv = EC_ERROR_INVAL;
- if (KIONIX_IS_SPI(addr)) {
+ if (SLAVE_IS_SPI(i2c_spi_addr__7bf)) {
#ifdef CONFIG_SPI_ACCEL_PORT
uint8_t val;
uint8_t cmd = 0x80 | reg;
- rv = spi_transaction(&spi_devices[KIONIX_SPI_ADDRESS(addr)],
- &cmd, 1, &val, 1);
+ rv = spi_transaction(
+ &spi_devices[SLAVE_GET_SPI_ADDR__7b(i2c_spi_addr__7bf)],
+ &cmd, 1, &val, 1);
if (rv == EC_SUCCESS)
*data_ptr = val;
#endif
} else {
- rv = i2c_read8(port, addr, reg, data_ptr);
+ rv = i2c_read8__7bf(port, i2c_spi_addr__7bf,
+ reg, data_ptr);
}
return rv;
}
@@ -158,36 +161,43 @@ static int raw_read8(const int port, const int addr, const int reg,
/**
* Write register from accelerometer.
*/
-static int raw_write8(const int port, const int addr, const int reg, int data)
+static int raw_write8__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const int reg, int data)
{
int rv = EC_ERROR_INVAL;
- if (KIONIX_IS_SPI(addr)) {
+ if (SLAVE_IS_SPI(i2c_spi_addr__7bf)) {
#ifdef CONFIG_SPI_ACCEL_PORT
uint8_t cmd[2] = { reg, data };
- rv = spi_transaction(&spi_devices[KIONIX_SPI_ADDRESS(addr)],
- cmd, 2, NULL, 0);
+ rv = spi_transaction(
+ &spi_devices[SLAVE_GET_SPI_ADDR__7b(i2c_spi_addr__7bf)],
+ cmd, 2, NULL, 0);
#endif
} else {
- rv = i2c_write8(port, addr, reg, data);
+ rv = i2c_write8__7bf(port, i2c_spi_addr__7bf,
+ reg, data);
}
return rv;
}
-static int raw_read_multi(const int port, int addr, uint8_t reg,
- uint8_t *rxdata, int rxlen)
+static int raw_read_multi__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ uint8_t reg, uint8_t *rxdata, int rxlen)
{
int rv = EC_ERROR_INVAL;
- if (KIONIX_IS_SPI(addr)) {
+ if (SLAVE_IS_SPI(i2c_spi_addr__7bf)) {
#ifdef CONFIG_SPI_ACCEL_PORT
reg |= 0x80;
- rv = spi_transaction(&spi_devices[KIONIX_SPI_ADDRESS(addr)],
- &reg, 1, rxdata, rxlen);
+ rv = spi_transaction(
+ &spi_devices[SLAVE_GET_SPI_ADDR__7b(i2c_spi_addr__7bf)],
+ &reg, 1, rxdata, rxlen);
#endif
} else {
- rv = i2c_read_block(port, addr, reg, rxdata, rxlen);
+ rv = i2c_read_block__7bf(port, i2c_spi_addr__7bf,
+ reg, rxdata, rxlen);
}
return rv;
}
@@ -215,13 +225,15 @@ static int disable_sensor(const struct motion_sensor_t *s, int *reg_val)
* so that we can restore it later.
*/
for (i = 0; i < SENSOR_ENABLE_ATTEMPTS; i++) {
- ret = raw_read8(s->port, s->addr, reg, reg_val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ reg, reg_val);
if (ret != EC_SUCCESS)
continue;
*reg_val &= ~pc1_field;
- ret = raw_write8(s->port, s->addr, reg, *reg_val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ reg, *reg_val);
if (ret == EC_SUCCESS)
return EC_SUCCESS;
}
@@ -246,7 +258,8 @@ static int enable_sensor(const struct motion_sensor_t *s, int reg_val)
pc1_field = KIONIX_PC1_FIELD(V(s));
for (i = 0; i < SENSOR_ENABLE_ATTEMPTS; i++) {
- ret = raw_read8(s->port, s->addr, reg, &reg_val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ reg, &reg_val);
if (ret != EC_SUCCESS)
continue;
@@ -257,8 +270,8 @@ static int enable_sensor(const struct motion_sensor_t *s, int reg_val)
#endif
/* Enable accelerometer based on reg_val value. */
- ret = raw_write8(s->port, s->addr, reg,
- reg_val | pc1_field);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ reg, reg_val | pc1_field);
/* On first success, we are done. */
if (ret == EC_SUCCESS)
@@ -292,7 +305,8 @@ static int set_value(const struct motion_sensor_t *s, int reg, int val,
/* Determine new value of control reg and attempt to write it. */
reg_val_new = (reg_val & ~field) | val;
- ret = raw_write8(s->port, s->addr, reg, reg_val_new);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ reg, reg_val_new);
/* If successfully written, then save the range. */
if (ret == EC_SUCCESS)
@@ -433,7 +447,7 @@ static int check_orientation_locked(const struct motion_sensor_t *s)
int orientation, raw_orientation;
int ret;
- ret = raw_read8(s->port, s->addr,
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
KX022_TSCP, &raw_orientation);
if (ret != EC_SUCCESS)
return ret;
@@ -459,7 +473,7 @@ static int read(const struct motion_sensor_t *s, intv3_t v)
/* Read 6 bytes starting at XOUT_L. */
reg = KIONIX_XOUT_L(V(s));
mutex_lock(s->mutex);
- ret = raw_read_multi(s->port, s->addr, reg, acc, 6);
+ ret = raw_read_multi__7bf(s->port, s->i2c_spi_addr__7bf, reg, acc, 6);
#ifdef CONFIG_KX022_ORIENTATION_SENSOR
if ((s->location == MOTIONSENSE_LOC_LID) && (V(s) == 0) &&
(ret == EC_SUCCESS))
@@ -518,7 +532,8 @@ static int init(const struct motion_sensor_t *s)
do {
msleep(1);
/* Read WHO_AM_I to be sure the device has booted */
- ret = raw_read8(s->port, s->addr, reg, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ reg, &val);
if (ret == EC_SUCCESS)
break;
@@ -531,16 +546,22 @@ static int init(const struct motion_sensor_t *s)
} else {
/* Write 0x00 to the internal register for KX022 */
reg = KX022_INTERNAL;
- ret = raw_write8(s->port, s->addr, reg, 0x0);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ reg, 0x0);
if (ret != EC_SUCCESS) {
/*
* For I2C communication, if ACK was not received
* from the first address, resend the command using
* the second address.
*/
- if (!KIONIX_IS_SPI(s->addr)) {
- ret = raw_write8(s->port, s->addr & ~4, reg,
- 0x0);
+ if (!SLAVE_IS_SPI(s->i2c_spi_addr__7bf)) {
+ const uint16_t i2c_alt_addr__7bf =
+ I2C_GET_ADDR__7b(
+ s->i2c_spi_addr__7bf)
+ & ~2;
+ ret = raw_write8__7bf(s->port,
+ i2c_alt_addr__7bf,
+ reg, 0x0);
}
}
}
@@ -557,21 +578,21 @@ static int init(const struct motion_sensor_t *s)
ret = disable_sensor(s, &val);
if (ret != EC_SUCCESS)
goto reset_failed;
- ret = raw_read8(s->port, s->addr, reg, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, reg, &val);
if (ret != EC_SUCCESS)
goto reset_failed;
val |= reset_field;
} else {
/* Write 0 to CTRL2 for KX022 */
- ret = raw_write8(s->port, s->addr, reg, 0x0);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, reg, 0x0);
if (ret != EC_SUCCESS)
goto reset_failed;
val = reset_field;
}
- ret = raw_write8(s->port, s->addr, reg, val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, reg, val);
if (ret != EC_SUCCESS)
goto reset_failed;
@@ -581,7 +602,8 @@ static int init(const struct motion_sensor_t *s)
do {
msleep(1);
- ret = raw_read8(s->port, s->addr, reg, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ reg, &val);
/* Reset complete. */
if ((ret == EC_SUCCESS) && !(val & reset_field))
break;
@@ -596,7 +618,7 @@ static int init(const struct motion_sensor_t *s)
msleep(2);
reg = KX022_COTR;
- ret = raw_read8(s->port, s->addr, reg, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, reg, &val);
if (val != KX022_COTR_VAL_DEFAULT) {
CPRINTF("[%s: the software reset failed]\n", s->name);
ret = EC_ERROR_HW_INTERNAL;
@@ -605,7 +627,7 @@ static int init(const struct motion_sensor_t *s)
}
reg = KIONIX_WHO_AM_I(V(s));
- ret = raw_read8(s->port, s->addr, reg, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, reg, &val);
if (ret != EC_SUCCESS || val != KIONIX_WHO_AM_I_VAL(V(s))) {
ret = EC_ERROR_HW_INTERNAL;
goto reset_failed;
@@ -648,7 +670,7 @@ struct i2c_stress_test_dev kionix_i2c_stress_test_dev = {
.read_val = KIONIX_WHO_AM_I_VAL(V(s)),
.write_reg = KIONIX_ODR_REG(V(s)),
},
- .i2c_read = &raw_read8,
- .i2c_write = &raw_write8,
+ .i2c_read__7bf = &raw_read8__7bf,
+ .i2c_write__7bf = &raw_write8__7bf,
};
#endif /* CONFIG_CMD_I2C_STRESS_TEST_ACCEL */
diff --git a/driver/accel_kionix.h b/driver/accel_kionix.h
index b6dfa08b48..2491c5d39d 100644
--- a/driver/accel_kionix.h
+++ b/driver/accel_kionix.h
@@ -47,9 +47,6 @@ extern const struct accelgyro_drv kionix_accel_drv;
* | SPI device ID | 1 |
* +-------------------------------+---+
*/
-#define KIONIX_IS_SPI(_addr) ((_addr) & 1)
-#define KIONIX_SPI_ADDRESS(_addr) ((_addr) >> 1)
-
#define KIONIX_CTRL1_REG(v) (KX022_CNTL1 + \
(v) * (KXCJ9_CTRL1 - KX022_CNTL1))
#define KIONIX_CTRL2_REG(v) (KX022_CNTL2 + \
diff --git a/driver/accel_kx022.h b/driver/accel_kx022.h
index b37de8b6f9..03c29bbd23 100644
--- a/driver/accel_kx022.h
+++ b/driver/accel_kx022.h
@@ -12,8 +12,8 @@
* 7-bit address is 001111Xb. Where 'X' is determined
* by the voltage on the ADDR pin.
*/
-#define KX022_ADDR0 0x3c
-#define KX022_ADDR1 0x3e
+#define KX022_ADDR0__7bf (0x1e)
+#define KX022_ADDR1__7bf (0x1f)
#define KX022_WHO_AM_I_VAL 0x14
/* Chip-specific registers */
diff --git a/driver/accel_kxcj9.h b/driver/accel_kxcj9.h
index 1c54f07ad5..bf48f227c7 100644
--- a/driver/accel_kxcj9.h
+++ b/driver/accel_kxcj9.h
@@ -14,8 +14,8 @@
* 7-bit address is 000111Xb. Where 'X' is determined
* by the voltage on the ADDR pin.
*/
-#define KXCJ9_ADDR0 0x1c
-#define KXCJ9_ADDR1 0x1e
+#define KXCJ9_ADDR0__7bf 0x0E
+#define KXCJ9_ADDR1__7bf 0x0D
#define KXCJ9_WHO_AM_I_VAL 0x0A
/* Chip-specific registers */
diff --git a/driver/accel_lis2dh.c b/driver/accel_lis2dh.c
index 771128c4f8..983e0f8ad0 100644
--- a/driver/accel_lis2dh.c
+++ b/driver/accel_lis2dh.c
@@ -121,7 +121,8 @@ static int is_data_ready(const struct motion_sensor_t *s, int *ready)
{
int ret, tmp;
- ret = st_raw_read8(s->port, s->addr, LIS2DH_STATUS_REG, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2DH_STATUS_REG, &tmp);
if (ret != EC_SUCCESS) {
CPRINTF("[%T %s type:0x%X RS Error]", s->name, s->type);
return ret;
@@ -153,8 +154,8 @@ static int read(const struct motion_sensor_t *s, intv3_t v)
}
/* Read output data bytes starting at LIS2DH_OUT_X_L_ADDR */
- ret = st_raw_read_n(s->port, s->addr, LIS2DH_OUT_X_L_ADDR, raw,
- OUT_XYZ_SIZE);
+ ret = st_raw_read_n__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2DH_OUT_X_L_ADDR, raw, OUT_XYZ_SIZE);
if (ret != EC_SUCCESS) {
CPRINTF("[%T %s type:0x%X RD XYZ Error]",
s->name, s->type);
@@ -180,7 +181,8 @@ static int init(const struct motion_sensor_t *s)
* complete boot procedure.
*/
do {
- ret = st_raw_read8(s->port, s->addr, LIS2DH_WHO_AM_I_REG, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2DH_WHO_AM_I_REG, &tmp);
if (ret != EC_SUCCESS) {
udelay(10);
count--;
@@ -201,34 +203,34 @@ static int init(const struct motion_sensor_t *s)
* register must be restored to it's default.
*/
/* Enable all accel axes data and clear old settings */
- ret = st_raw_write8(s->port, s->addr, LIS2DH_CTRL1_ADDR,
- LIS2DH_ENABLE_ALL_AXES);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2DH_CTRL1_ADDR, LIS2DH_ENABLE_ALL_AXES);
if (ret != EC_SUCCESS)
goto err_unlock;
- ret = st_raw_write8(s->port, s->addr, LIS2DH_CTRL2_ADDR,
- LIS2DH_CTRL2_RESET_VAL);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2DH_CTRL2_ADDR, LIS2DH_CTRL2_RESET_VAL);
if (ret != EC_SUCCESS)
goto err_unlock;
- ret = st_raw_write8(s->port, s->addr, LIS2DH_CTRL3_ADDR,
- LIS2DH_CTRL3_RESET_VAL);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2DH_CTRL3_ADDR, LIS2DH_CTRL3_RESET_VAL);
if (ret != EC_SUCCESS)
goto err_unlock;
/* Enable BDU */
- ret = st_raw_write8(s->port, s->addr, LIS2DH_CTRL4_ADDR,
- LIS2DH_BDU_MASK);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2DH_CTRL4_ADDR, LIS2DH_BDU_MASK);
if (ret != EC_SUCCESS)
goto err_unlock;
- ret = st_raw_write8(s->port, s->addr, LIS2DH_CTRL5_ADDR,
- LIS2DH_CTRL5_RESET_VAL);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2DH_CTRL5_ADDR, LIS2DH_CTRL5_RESET_VAL);
if (ret != EC_SUCCESS)
goto err_unlock;
- ret = st_raw_write8(s->port, s->addr, LIS2DH_CTRL6_ADDR,
- LIS2DH_CTRL6_RESET_VAL);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2DH_CTRL6_ADDR, LIS2DH_CTRL6_RESET_VAL);
if (ret != EC_SUCCESS)
goto err_unlock;
diff --git a/driver/accel_lis2dh.h b/driver/accel_lis2dh.h
index 691cca6865..ac5193d388 100644
--- a/driver/accel_lis2dh.h
+++ b/driver/accel_lis2dh.h
@@ -16,8 +16,8 @@
* 8-bit address is 0011 00XW b. Where 'X' is determined
* by the voltage on the ADDR pin, and 'W' is read write bit
*/
-#define LIS2DH_ADDR0 0x30
-#define LIS2DH_ADDR1 0x32
+#define LIS2DH_ADDR0__7bf 0x18
+#define LIS2DH_ADDR1__7bf 0x19
/*
* LNG2DM:
@@ -25,8 +25,8 @@
* 8-bit address is 0101 00XW b. Where 'X' is determined
* by the voltage on the ADDR pin, and 'W' is read write bit
*/
-#define LNG2DM_ADDR0 0x50
-#define LNG2DM_ADDR1 0x52
+#define LNG2DM_ADDR0__7bf 0x28
+#define LNG2DM_ADDR1__7bf 0x29
/* Who Am I */
#define LIS2DH_WHO_AM_I_REG 0x0f
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
index c7755ea4b3..4811f7bb83 100644
--- a/driver/accelgyro_bmi160.c
+++ b/driver/accelgyro_bmi160.c
@@ -144,21 +144,23 @@ static inline int spi_raw_read(const int addr, const uint8_t reg,
/**
* Read 8bit register from accelerometer.
*/
-static int raw_read8(const int port, const int addr, const int reg,
- int *data_ptr)
+static int raw_read8__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const int reg, int *data_ptr)
{
int rv = -EC_ERROR_PARAM1;
- if (BMI160_IS_SPI(addr)) {
+ if (SLAVE_IS_SPI(i2c_spi_addr__7bf)) {
#ifdef CONFIG_SPI_ACCEL_PORT
uint8_t val;
- rv = spi_raw_read(BMI160_SPI_ADDRESS(addr), reg, &val, 1);
+ rv = spi_raw_read(SLAVE_GET_SPI_ADDR__7b(i2c_spi_addr__7bf),
+ reg, &val, 1);
if (rv == EC_SUCCESS)
*data_ptr = val;
#endif
} else {
#ifdef I2C_PORT_ACCEL
- rv = i2c_read8(port, BMI160_I2C_ADDRESS(addr),
+ rv = i2c_read8__7bf(port, i2c_spi_addr__7bf,
reg, data_ptr);
#endif
}
@@ -168,20 +170,22 @@ static int raw_read8(const int port, const int addr, const int reg,
/**
* Write 8bit register from accelerometer.
*/
-static int raw_write8(const int port, const int addr, const int reg,
- int data)
+static int raw_write8__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const int reg, int data)
{
int rv = -EC_ERROR_PARAM1;
- if (BMI160_IS_SPI(addr)) {
+ if (SLAVE_IS_SPI(i2c_spi_addr__7bf)) {
#ifdef CONFIG_SPI_ACCEL_PORT
uint8_t cmd[2] = { reg, data };
- rv = spi_transaction(&spi_devices[BMI160_SPI_ADDRESS(addr)],
- cmd, 2, NULL, 0);
+ rv = spi_transaction(
+ &spi_devices[SLAVE_GET_SPI_ADDR__7b(i2c_spi_addr__7bf)],
+ cmd, 2, NULL, 0);
#endif
} else {
#ifdef I2C_PORT_ACCEL
- rv = i2c_write8(port, BMI160_I2C_ADDRESS(addr),
+ rv = i2c_write8__7bf(port, i2c_spi_addr__7bf,
reg, data);
#endif
}
@@ -199,18 +203,19 @@ static int raw_write8(const int port, const int addr, const int reg,
/**
* Read 32bit register from accelerometer.
*/
-static int raw_read32(const int port, const int addr, const uint8_t reg,
- int *data_ptr)
+static int raw_read32__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const uint8_t reg, int *data_ptr)
{
int rv = -EC_ERROR_PARAM1;
- if (BMI160_IS_SPI(addr)) {
+ if (SLAVE_IS_SPI(i2c_spi_addr__7bf)) {
#ifdef CONFIG_SPI_ACCEL_PORT
- rv = spi_raw_read(BMI160_SPI_ADDRESS(addr), reg,
- (uint8_t *)data_ptr, 4);
+ rv = spi_raw_read(SLAVE_GET_SPI_ADDR__7b(i2c_spi_addr__7bf),
+ reg, (uint8_t *)data_ptr, 4);
#endif
} else {
#ifdef I2C_PORT_ACCEL
- rv = i2c_read32(port, BMI160_I2C_ADDRESS(addr),
+ rv = i2c_read32__7bf(port, i2c_spi_addr__7bf,
reg, data_ptr);
#endif
}
@@ -221,19 +226,21 @@ static int raw_read32(const int port, const int addr, const uint8_t reg,
/**
* Read n bytes from accelerometer.
*/
-static int raw_read_n(const int port, const int addr, const uint8_t reg,
- uint8_t *data_ptr, const int len)
+static int raw_read_n__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const uint8_t reg, uint8_t *data_ptr, const int len)
{
int rv = -EC_ERROR_PARAM1;
- if (BMI160_IS_SPI(addr)) {
+ if (SLAVE_IS_SPI(i2c_spi_addr__7bf)) {
#ifdef CONFIG_SPI_ACCEL_PORT
- rv = spi_raw_read(BMI160_SPI_ADDRESS(addr), reg, data_ptr, len);
+ rv = spi_raw_read(SLAVE_GET_SPI_ADDR__7b(i2c_spi_addr__7bf),
+ reg, data_ptr, len);
#endif
} else {
#ifdef I2C_PORT_ACCEL
- rv = i2c_read_block(port, BMI160_I2C_ADDRESS(addr), reg,
- data_ptr, len);
+ rv = i2c_read_block__7bf(port, i2c_spi_addr__7bf,
+ reg, data_ptr, len);
#endif
}
return rv;
@@ -246,11 +253,13 @@ static int raw_read_n(const int port, const int addr, const uint8_t reg,
* 1: manual access, we can issue i2c to the compass
* 0: data access: BMI160 gather data periodically from the compass.
*/
-static int bmi160_sec_access_ctrl(const int port, const int addr,
+static int bmi160_sec_access_ctrl__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
const int enable)
{
int mag_if_ctrl;
- raw_read8(port, addr, BMI160_MAG_IF_1, &mag_if_ctrl);
+ raw_read8__7bf(port, i2c_spi_addr__7bf,
+ BMI160_MAG_IF_1, &mag_if_ctrl);
if (enable) {
mag_if_ctrl |= BMI160_MAG_MANUAL_EN;
mag_if_ctrl &= ~BMI160_MAG_READ_BURST_MASK;
@@ -260,30 +269,37 @@ static int bmi160_sec_access_ctrl(const int port, const int addr,
mag_if_ctrl &= ~BMI160_MAG_READ_BURST_MASK;
mag_if_ctrl |= BMI160_MAG_READ_BURST_8;
}
- return raw_write8(port, addr, BMI160_MAG_IF_1, mag_if_ctrl);
+ return raw_write8__7bf(port, i2c_spi_addr__7bf,
+ BMI160_MAG_IF_1, mag_if_ctrl);
}
/**
* Read register from compass.
* Assuming we are in manual access mode, read compass i2c register.
*/
-int bmi160_sec_raw_read8(const int port, const int addr, const uint8_t reg,
- int *data_ptr)
+int bmi160_sec_raw_read8__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const uint8_t reg, int *data_ptr)
{
/* Only read 1 bytes */
- raw_write8(port, addr, BMI160_MAG_I2C_READ_ADDR, reg);
- return raw_read8(port, addr, BMI160_MAG_I2C_READ_DATA, data_ptr);
+ raw_write8__7bf(port, i2c_spi_addr__7bf,
+ BMI160_MAG_I2C_READ_ADDR, reg);
+ return raw_read8__7bf(port, i2c_spi_addr__7bf,
+ BMI160_MAG_I2C_READ_DATA, data_ptr);
}
/**
* Write register from compass.
* Assuming we are in manual access mode, write to compass i2c register.
*/
-int bmi160_sec_raw_write8(const int port, const int addr, const uint8_t reg,
- int data)
+int bmi160_sec_raw_write8__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const uint8_t reg, int data)
{
- raw_write8(port, addr, BMI160_MAG_I2C_WRITE_DATA, data);
- return raw_write8(port, addr, BMI160_MAG_I2C_WRITE_ADDR, reg);
+ raw_write8__7bf(port, i2c_spi_addr__7bf,
+ BMI160_MAG_I2C_WRITE_DATA, data);
+ return raw_write8__7bf(port, i2c_spi_addr__7bf,
+ BMI160_MAG_I2C_WRITE_ADDR, reg);
}
#endif
@@ -295,17 +311,21 @@ static int enable_fifo(const struct motion_sensor_t *s, int enable)
if (enable) {
/* FIFO start collecting events */
- ret = raw_read8(s->port, s->addr, BMI160_FIFO_CONFIG_1, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_FIFO_CONFIG_1, &val);
val |= BMI160_FIFO_SENSOR_EN(s->type);
- ret = raw_write8(s->port, s->addr, BMI160_FIFO_CONFIG_1, val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_FIFO_CONFIG_1, val);
if (ret == EC_SUCCESS)
data->flags |= 1 << (s->type + BMI160_FIFO_FLAG_OFFSET);
} else {
/* FIFO stop collecting events */
- ret = raw_read8(s->port, s->addr, BMI160_FIFO_CONFIG_1, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_FIFO_CONFIG_1, &val);
val &= ~BMI160_FIFO_SENSOR_EN(s->type);
- ret = raw_write8(s->port, s->addr, BMI160_FIFO_CONFIG_1, val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_FIFO_CONFIG_1, val);
if (ret == EC_SUCCESS)
data->flags &=
~(1 << (s->type + BMI160_FIFO_FLAG_OFFSET));
@@ -332,7 +352,8 @@ static int set_range(const struct motion_sensor_t *s,
ranges = get_range_table(s->type, &range_tbl_size);
reg_val = get_reg_val(range, rnd, ranges, range_tbl_size);
- ret = raw_write8(s->port, s->addr, ctrl_reg, reg_val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ ctrl_reg, reg_val);
/* Now that we have set the range, update the driver's value. */
if (ret == EC_SUCCESS)
data->range = get_engineering_val(reg_val, ranges,
@@ -369,7 +390,8 @@ static int set_data_rate(const struct motion_sensor_t *s,
enable_fifo(s, 0);
#endif
/* go to suspend mode */
- ret = raw_write8(s->port, s->addr, BMI160_CMD_REG,
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG,
BMI160_CMD_MODE_SUSPEND(s->type));
msleep(3);
data->odr = 0;
@@ -380,7 +402,8 @@ static int set_data_rate(const struct motion_sensor_t *s,
return ret;
} else if (data->odr == 0) {
/* back from suspend mode. */
- ret = raw_write8(s->port, s->addr, BMI160_CMD_REG,
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG,
BMI160_CMD_MODE_NORMAL(s->type));
msleep(wakeup_time[s->type]);
}
@@ -421,12 +444,12 @@ static int set_data_rate(const struct motion_sensor_t *s,
*/
mutex_lock(s->mutex);
- ret = raw_read8(s->port, s->addr, ctrl_reg, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, ctrl_reg, &val);
if (ret != EC_SUCCESS)
goto accel_cleanup;
val = (val & ~BMI160_ODR_MASK) | reg_val;
- ret = raw_write8(s->port, s->addr, ctrl_reg, val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, ctrl_reg, val);
if (ret != EC_SUCCESS)
goto accel_cleanup;
@@ -483,8 +506,8 @@ static int get_offset(const struct motion_sensor_t *s,
* range selected for the accelerometer.
*/
for (i = X; i <= Z; i++) {
- raw_read8(s->port, s->addr, BMI160_OFFSET_ACC70 + i,
- &val);
+ raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_OFFSET_ACC70 + i, &val);
if (val > 0x7f)
val = -256 + val;
v[i] = val * BMI160_OFFSET_ACC_MULTI_MG /
@@ -493,7 +516,8 @@ static int get_offset(const struct motion_sensor_t *s,
break;
case MOTIONSENSE_TYPE_GYRO:
/* Read the MSB first */
- raw_read8(s->port, s->addr, BMI160_OFFSET_EN_GYR98, &val98);
+ raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_OFFSET_EN_GYR98, &val98);
/*
* The offset of the gyroscope off_gyr_[xyz] is a 10 bit
* two-complement number in units of 0.061 °/s.
@@ -501,8 +525,8 @@ static int get_offset(const struct motion_sensor_t *s,
* -31.25 °/s to +31.25 °/s
*/
for (i = X; i <= Z; i++) {
- raw_read8(s->port, s->addr, BMI160_OFFSET_GYR70 + i,
- &val);
+ raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_OFFSET_GYR70 + i, &val);
val |= ((val98 >> (2 * i)) & 0x3) << 8;
if (val > 0x1ff)
val = -1024 + val;
@@ -537,7 +561,8 @@ static int set_offset(const struct motion_sensor_t *s,
rotate_inv(v, *s->rot_standard_ref, v);
- ret = raw_read8(s->port, s->addr, BMI160_OFFSET_EN_GYR98, &val98);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_OFFSET_EN_GYR98, &val98);
if (ret != 0)
return ret;
@@ -552,10 +577,11 @@ static int set_offset(const struct motion_sensor_t *s,
val = -128;
if (val < 0)
val = 256 + val;
- raw_write8(s->port, s->addr, BMI160_OFFSET_ACC70 + i,
- val);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_OFFSET_ACC70 + i, val);
}
- ret = raw_write8(s->port, s->addr, BMI160_OFFSET_EN_GYR98,
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_OFFSET_EN_GYR98,
val98 | BMI160_OFFSET_ACC_EN);
break;
case MOTIONSENSE_TYPE_GYRO:
@@ -568,12 +594,13 @@ static int set_offset(const struct motion_sensor_t *s,
val = -512;
if (val < 0)
val = 1024 + val;
- raw_write8(s->port, s->addr, BMI160_OFFSET_GYR70 + i,
- val & 0xFF);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_OFFSET_GYR70 + i, val & 0xFF);
val98 &= ~(0x3 << (2 * i));
val98 |= (val >> 8) << (2 * i);
}
- ret = raw_write8(s->port, s->addr, BMI160_OFFSET_EN_GYR98,
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_OFFSET_EN_GYR98,
val98 | BMI160_OFFSET_GYRO_EN);
break;
#ifdef CONFIG_MAG_BMI160_BMM150
@@ -644,9 +671,10 @@ static int perform_calib(const struct motion_sensor_t *s)
ret = EC_RES_INVALID_PARAM;
goto end_perform_calib;
}
- ret = raw_write8(s->port, s->addr, BMI160_FOC_CONF, val);
- ret = raw_write8(s->port, s->addr, BMI160_CMD_REG,
- BMI160_CMD_START_FOC);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_FOC_CONF, val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_START_FOC);
deadline.val = get_time().val + 400 * MSEC;
do {
if (timestamp_expired(deadline, NULL)) {
@@ -654,15 +682,17 @@ static int perform_calib(const struct motion_sensor_t *s)
goto end_perform_calib;
}
msleep(50);
- ret = raw_read8(s->port, s->addr, BMI160_STATUS, &status);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_STATUS, &status);
if (ret != EC_SUCCESS)
goto end_perform_calib;
} while ((status & BMI160_FOC_RDY) == 0);
/* Calibration is successful, and loaded, use the result */
- ret = raw_read8(s->port, s->addr, BMI160_OFFSET_EN_GYR98, &val);
- ret = raw_write8(s->port, s->addr, BMI160_OFFSET_EN_GYR98,
- val | en_flag);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_OFFSET_EN_GYR98, &val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_OFFSET_EN_GYR98, val | en_flag);
end_perform_calib:
set_data_rate(s, rate, 0);
return ret;
@@ -715,7 +745,8 @@ int manage_activity(const struct motion_sensor_t *s,
return ret;
if (enable) {
/* We should use parameters from caller */
- raw_write8(s->port, s->addr, BMI160_INT_MOTION_3,
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_MOTION_3,
BMI160_MOTION_PROOF_TIME(
CONFIG_GESTURE_SIGMO_PROOF_MS) <<
BMI160_MOTION_PROOF_OFF |
@@ -723,7 +754,8 @@ int manage_activity(const struct motion_sensor_t *s,
CONFIG_GESTURE_SIGMO_SKIP_MS) <<
BMI160_MOTION_SKIP_OFF |
BMI160_MOTION_SIG_MOT_SEL);
- raw_write8(s->port, s->addr, BMI160_INT_MOTION_1,
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_MOTION_1,
BMI160_MOTION_TH(s,
CONFIG_GESTURE_SIGMO_THRES_MG));
tmp |= BMI160_INT_ANYMO_X_EN |
@@ -734,7 +766,8 @@ int manage_activity(const struct motion_sensor_t *s,
BMI160_INT_ANYMO_Y_EN |
BMI160_INT_ANYMO_Z_EN);
}
- ret = raw_write8(s->port, s->addr, BMI160_INT_EN_0, tmp);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_EN_0, tmp);
if (ret)
ret = EC_RES_UNAVAILABLE;
break;
@@ -744,14 +777,16 @@ int manage_activity(const struct motion_sensor_t *s,
case MOTIONSENSE_ACTIVITY_DOUBLE_TAP: {
int tmp;
/* Set double tap interrupt */
- ret = raw_read8(s->port, s->addr, BMI160_INT_EN_0, &tmp);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_EN_0, &tmp);
if (ret)
return ret;
if (enable)
tmp |= BMI160_INT_D_TAP_EN;
else
tmp &= ~BMI160_INT_D_TAP_EN;
- ret = raw_write8(s->port, s->addr, BMI160_INT_EN_0, tmp);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_EN_0, tmp);
if (ret)
ret = EC_RES_UNAVAILABLE;
break;
@@ -888,13 +923,14 @@ static int load_fifo(struct motion_sensor_t *s, uint32_t last_ts)
* Flush potential left over:
* When sensor is resumed, we won't read old data.
*/
- raw_write8(s->port, s->addr, BMI160_CMD_REG,
- BMI160_CMD_FIFO_FLUSH);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_FIFO_FLUSH);
return EC_SUCCESS;
}
- raw_read_n(s->port, s->addr, BMI160_FIFO_LENGTH_0,
- (uint8_t *)&length, sizeof(length));
+ raw_read_n__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_FIFO_LENGTH_0,
+ (uint8_t *)&length, sizeof(length));
length &= BMI160_FIFO_LENGTH_MASK;
/*
@@ -914,8 +950,8 @@ static int load_fifo(struct motion_sensor_t *s, uint32_t last_ts)
length = MIN(length, sizeof(bmi160_buffer));
- raw_read_n(s->port, s->addr, BMI160_FIFO_DATA, bmi160_buffer,
- length);
+ raw_read_n__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_FIFO_DATA, bmi160_buffer, length);
beginning = *(uint32_t *)bmi160_buffer;
ep = bmi160_buffer + length;
/*
@@ -959,7 +995,7 @@ static int load_fifo(struct motion_sensor_t *s, uint32_t last_ts)
default:
CPRINTS("Unknown header: 0x%02x @ %d",
hdr, bp - bmi160_buffer);
- raw_write8(s->port, s->addr,
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
BMI160_CMD_REG,
BMI160_CMD_FIFO_FLUSH);
return EC_ERROR_NOT_HANDLED;
@@ -1023,36 +1059,45 @@ static int config_interrupt(const struct motion_sensor_t *s)
return EC_SUCCESS;
mutex_lock(s->mutex);
- raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_FIFO_FLUSH);
- raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_INT_RESET);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_FIFO_FLUSH);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_INT_RESET);
#ifdef CONFIG_GESTURE_SENSOR_BATTERY_TAP
- raw_write8(s->port, s->addr, BMI160_INT_TAP_0,
- BMI160_TAP_DUR(s, CONFIG_GESTURE_TAP_MAX_INTERSTICE_T));
- ret = raw_write8(s->port, s->addr, BMI160_INT_TAP_1,
- BMI160_TAP_TH(s, CONFIG_GESTURE_TAP_THRES_MG));
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_TAP_0,
+ BMI160_TAP_DUR(s, CONFIG_GESTURE_TAP_MAX_INTERSTICE_T));
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_TAP_1,
+ BMI160_TAP_TH(s, CONFIG_GESTURE_TAP_THRES_MG));
#endif
#ifdef CONFIG_BMI160_ORIENTATION_SENSOR
/* only use orientation sensor on the lid sensor */
if (s->location == MOTIONSENSE_LOC_LID) {
- ret = raw_write8(s->port, s->addr, BMI160_INT_ORIENT_0,
- BMI160_INT_ORIENT_0_INIT_VAL);
- ret = raw_write8(s->port, s->addr, BMI160_INT_ORIENT_1,
- BMI160_INT_ORIENT_1_INIT_VAL);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_ORIENT_0,
+ BMI160_INT_ORIENT_0_INIT_VAL);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_ORIENT_1,
+ BMI160_INT_ORIENT_1_INIT_VAL);
}
#endif
#ifdef CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT
- ret = raw_write8(s->port, s->addr, BMI160_INT_LATCH, BMI160_LATCH_5MS);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_LATCH, BMI160_LATCH_5MS);
#else
/* Also, configure int2 as an external input. */
- ret = raw_write8(s->port, s->addr, BMI160_INT_LATCH,
- BMI160_INT2_INPUT_EN | BMI160_LATCH_5MS);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_LATCH,
+ BMI160_INT2_INPUT_EN | BMI160_LATCH_5MS);
#endif
/* configure int1 as an interrupt */
- ret = raw_write8(s->port, s->addr, BMI160_INT_OUT_CTRL,
- BMI160_INT_CTRL(1, OUTPUT_EN));
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_OUT_CTRL,
+ BMI160_INT_CTRL(1, OUTPUT_EN));
/* Map activity interrupt to int 1 */
tmp = 0;
@@ -1067,29 +1112,36 @@ static int config_interrupt(const struct motion_sensor_t *s)
if (s->location == MOTIONSENSE_LOC_LID)
tmp |= BMI160_INT_ORIENT;
#endif
- ret = raw_write8(s->port, s->addr, BMI160_INT_MAP_REG(1), tmp);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_MAP_REG(1), tmp);
#ifdef CONFIG_ACCEL_FIFO
/* map fifo water mark to int 1 */
- ret = raw_write8(s->port, s->addr, BMI160_INT_FIFO_MAP,
- BMI160_INT_MAP(1, FWM) |
- BMI160_INT_MAP(1, FFULL));
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_FIFO_MAP,
+ BMI160_INT_MAP(1, FWM) |
+ BMI160_INT_MAP(1, FFULL));
/* configure fifo watermark to int whenever there's any data in there */
- ret = raw_write8(s->port, s->addr, BMI160_FIFO_CONFIG_0, 1);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_FIFO_CONFIG_0, 1);
#ifdef CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT
- ret = raw_write8(s->port, s->addr, BMI160_FIFO_CONFIG_1,
- BMI160_FIFO_HEADER_EN);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_FIFO_CONFIG_1,
+ BMI160_FIFO_HEADER_EN);
#else
- ret = raw_write8(s->port, s->addr, BMI160_FIFO_CONFIG_1,
- BMI160_FIFO_TAG_INT2_EN |
- BMI160_FIFO_HEADER_EN);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_FIFO_CONFIG_1,
+ BMI160_FIFO_TAG_INT2_EN |
+ BMI160_FIFO_HEADER_EN);
#endif
/* Set fifo*/
- ret = raw_read8(s->port, s->addr, BMI160_INT_EN_1, &tmp);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_EN_1, &tmp);
tmp |= BMI160_INT_FWM_EN | BMI160_INT_FFUL_EN;
- ret = raw_write8(s->port, s->addr, BMI160_INT_EN_1, tmp);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_EN_1, tmp);
#endif
mutex_unlock(s->mutex);
return ret;
@@ -1148,8 +1200,8 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
return EC_ERROR_NOT_HANDLED;
do {
- rv = raw_read32(s->port, s->addr, BMI160_INT_STATUS_0,
- &interrupt);
+ rv = raw_read32__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_INT_STATUS_0, &interrupt);
/*
* Bail out of this loop there was an error reading the register
*/
@@ -1185,7 +1237,8 @@ static int read(const struct motion_sensor_t *s, intv3_t v)
uint8_t data[6];
int ret, status = 0;
- ret = raw_read8(s->port, s->addr, BMI160_STATUS, &status);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_STATUS, &status);
if (ret != EC_SUCCESS)
return ret;
@@ -1201,7 +1254,8 @@ static int read(const struct motion_sensor_t *s, intv3_t v)
}
/* Read 6 bytes starting at xyz_reg */
- ret = raw_read_n(s->port, s->addr, get_xyz_reg(s->type), data, 6);
+ ret = raw_read_n__7bf(s->port, s->i2c_spi_addr__7bf,
+ get_xyz_reg(s->type), data, 6);
if (ret != EC_SUCCESS) {
CPRINTS("%s: type:0x%X RD XYZ Error %d", s->name, s->type, ret);
@@ -1216,21 +1270,23 @@ static int init(const struct motion_sensor_t *s)
int ret = 0, tmp, i;
struct accelgyro_saved_data_t *saved_data = BMI160_GET_SAVED_DATA(s);
- ret = raw_read8(s->port, s->addr, BMI160_CHIP_ID, &tmp);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CHIP_ID, &tmp);
if (ret)
return EC_ERROR_UNKNOWN;
if (tmp != BMI160_CHIP_ID_MAJOR && tmp != BMI168_CHIP_ID_MAJOR) {
/* The device may be lock on paging mode. Try to unlock it. */
- raw_write8(s->port, s->addr, BMI160_CMD_REG,
- BMI160_CMD_EXT_MODE_EN_B0);
- raw_write8(s->port, s->addr, BMI160_CMD_REG,
- BMI160_CMD_EXT_MODE_EN_B1);
- raw_write8(s->port, s->addr, BMI160_CMD_REG,
- BMI160_CMD_EXT_MODE_EN_B2);
- raw_write8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR,
- BMI160_CMD_PAGING_EN);
- raw_write8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR, 0);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B0);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B1);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B2);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_EXT_MODE_ADDR, BMI160_CMD_PAGING_EN);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_EXT_MODE_ADDR, 0);
return EC_ERROR_ACCESS_DENIED;
}
@@ -1239,8 +1295,8 @@ static int init(const struct motion_sensor_t *s)
struct bmi160_drv_data_t *data = BMI160_GET_DATA(s);
/* Reset the chip to be in a good state */
- raw_write8(s->port, s->addr, BMI160_CMD_REG,
- BMI160_CMD_SOFT_RESET);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_SOFT_RESET);
msleep(1);
data->flags &= ~(BMI160_FLAG_SEC_I2C_ENABLED |
(BMI160_FIFO_ALL_MASK <<
@@ -1258,7 +1314,8 @@ static int init(const struct motion_sensor_t *s)
#endif
#endif
/* To avoid gyro wakeup */
- raw_write8(s->port, s->addr, BMI160_PMU_TRIGGER, 0);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_PMU_TRIGGER, 0);
}
#ifdef CONFIG_BMI160_SEC_I2C
@@ -1269,8 +1326,8 @@ static int init(const struct motion_sensor_t *s)
* To be able to configure the real magnetometer, we must set
* the BMI160 magnetometer part (a pass through) in normal mode.
*/
- raw_write8(s->port, s->addr, BMI160_CMD_REG,
- BMI160_CMD_MODE_NORMAL(s->type));
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_MODE_NORMAL(s->type));
msleep(wakeup_time[s->type]);
if ((data->flags & BMI160_FLAG_SEC_I2C_ENABLED) == 0) {
@@ -1283,48 +1340,57 @@ static int init(const struct motion_sensor_t *s)
*
* Magic command sequences
*/
- raw_write8(s->port, s->addr, BMI160_CMD_REG,
- BMI160_CMD_EXT_MODE_EN_B0);
- raw_write8(s->port, s->addr, BMI160_CMD_REG,
- BMI160_CMD_EXT_MODE_EN_B1);
- raw_write8(s->port, s->addr, BMI160_CMD_REG,
- BMI160_CMD_EXT_MODE_EN_B2);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B0);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B1);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_REG, BMI160_CMD_EXT_MODE_EN_B2);
/*
* Change the register page to target mode, to change
* the internal pull ups of the secondary interface.
*/
- raw_read8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR,
- &ext_page_reg);
- raw_write8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR,
- ext_page_reg | BMI160_CMD_TARGET_PAGE);
- raw_read8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR,
- &ext_page_reg);
- raw_write8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR,
- ext_page_reg | BMI160_CMD_PAGING_EN);
- raw_read8(s->port, s->addr, BMI160_COM_C_TRIM_ADDR,
- &pullup_reg);
- raw_write8(s->port, s->addr, BMI160_COM_C_TRIM_ADDR,
- pullup_reg | BMI160_COM_C_TRIM);
- raw_read8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR,
- &ext_page_reg);
- raw_write8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR,
- ext_page_reg & ~BMI160_CMD_TARGET_PAGE);
- raw_read8(s->port, s->addr, BMI160_CMD_EXT_MODE_ADDR,
- &ext_page_reg);
+ raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_EXT_MODE_ADDR, &ext_page_reg);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_EXT_MODE_ADDR,
+ ext_page_reg | BMI160_CMD_TARGET_PAGE);
+ raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_EXT_MODE_ADDR, &ext_page_reg);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_EXT_MODE_ADDR,
+ ext_page_reg | BMI160_CMD_PAGING_EN);
+ raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_COM_C_TRIM_ADDR, &pullup_reg);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_COM_C_TRIM_ADDR,
+ pullup_reg | BMI160_COM_C_TRIM);
+ raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_EXT_MODE_ADDR, &ext_page_reg);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_EXT_MODE_ADDR,
+ ext_page_reg & ~BMI160_CMD_TARGET_PAGE);
+ raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_CMD_EXT_MODE_ADDR, &ext_page_reg);
/* Set the i2c address of the compass */
- ret = raw_write8(s->port, s->addr, BMI160_MAG_IF_0,
- CONFIG_ACCELGYRO_SEC_ADDR);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_MAG_IF_0,
+ I2C_GET_ADDR__7b(
+ CONFIG_ACCELGYRO_SEC_ADDR__7BF)
+ << 1);
/* Enable the secondary interface as I2C */
- ret = raw_write8(s->port, s->addr, BMI160_IF_CONF,
- BMI160_IF_MODE_AUTO_I2C << BMI160_IF_MODE_OFF);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_IF_CONF,
+ BMI160_IF_MODE_AUTO_I2C <<
+ BMI160_IF_MODE_OFF);
data->flags |= BMI160_FLAG_SEC_I2C_ENABLED;
}
- bmi160_sec_access_ctrl(s->port, s->addr, 1);
+ bmi160_sec_access_ctrl__7bf(s->port, s->i2c_spi_addr__7bf, 1);
ret = bmm150_init(s);
if (ret)
@@ -1332,13 +1398,13 @@ static int init(const struct motion_sensor_t *s)
return ret;
/* Leave the address for reading the data */
- raw_write8(s->port, s->addr, BMI160_MAG_I2C_READ_ADDR,
- BMM150_BASE_DATA);
+ raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_MAG_I2C_READ_ADDR, BMM150_BASE_DATA);
/*
* Put back the secondary interface in normal mode.
* BMI160 will poll based on the configure ODR.
*/
- bmi160_sec_access_ctrl(s->port, s->addr, 0);
+ bmi160_sec_access_ctrl__7bf(s->port, s->i2c_spi_addr__7bf, 0);
/*
* Clean interrupt event that may have occurred while the
@@ -1396,8 +1462,8 @@ struct i2c_stress_test_dev bmi160_i2c_stress_test_dev = {
.read_val = BMI160_CHIP_ID_MAJOR,
.write_reg = BMI160_PMU_TRIGGER,
},
- .i2c_read = &raw_read8,
- .i2c_write = &raw_write8,
+ .i2c_read__7bf = &raw_read8__7bf,
+ .i2c_write__7bf = &raw_write8__7bf,
};
#endif /* CONFIG_CMD_I2C_STRESS_TEST_ACCEL */
@@ -1407,7 +1473,8 @@ int bmi160_get_sensor_temp(int idx, int *temp_ptr)
int16_t temp;
int ret;
- ret = raw_read_n(s->port, s->addr, BMI160_TEMPERATURE_0,
+ ret = raw_read_n__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMI160_TEMPERATURE_0,
(uint8_t *)&temp, sizeof(temp));
if (ret || temp == BMI160_INVALID_TEMP)
diff --git a/driver/accelgyro_bmi160.h b/driver/accelgyro_bmi160.h
index dd3fec59c0..29a339d822 100644
--- a/driver/accelgyro_bmi160.h
+++ b/driver/accelgyro_bmi160.h
@@ -22,14 +22,10 @@
* | SPI device ID | 1 |
* +-------------------------------+---+
*/
-#define BMI160_SET_SPI_ADDRESS(_addr) (((_addr) << 1) | 1)
-#define BMI160_IS_SPI(_addr) ((_addr) & 1)
-#define BMI160_SPI_ADDRESS(_addr) ((_addr) >> 1)
-#define BMI160_I2C_ADDRESS(_addr) (_addr)
/* I2C addresses */
-#define BMI160_ADDR0 0xd0
-#define BMI160_ADDR1 0xd2
+#define BMI160_ADDR0__7bf 0x68
+#define BMI160_ADDR1__7bf 0x69
#define BMI160_CHIP_ID 0x00
#define BMI160_CHIP_ID_MAJOR 0xd1
@@ -490,10 +486,10 @@ void bmi160_interrupt(enum gpio_signal signal);
#ifdef CONFIG_BMI160_SEC_I2C
/* Functions to access the secondary device through the accel/gyro. */
-int bmi160_sec_raw_read8(const int port, const int addr, const uint8_t reg,
- int *data_ptr);
-int bmi160_sec_raw_write8(const int port, const int addr, const uint8_t reg,
- int data);
+int bmi160_sec_raw_read8__7bf(const int port, const uint16_t addr__7bf,
+ const uint8_t reg, int *data_ptr);
+int bmi160_sec_raw_write8__7bf(const int port, const uint16_t addr__7bf,
+ const uint8_t reg, int data);
#endif
#ifdef CONFIG_CMD_I2C_STRESS_TEST_ACCEL
diff --git a/driver/accelgyro_lsm6ds0.c b/driver/accelgyro_lsm6ds0.c
index b48e84dc0d..03701fa0c3 100644
--- a/driver/accelgyro_lsm6ds0.c
+++ b/driver/accelgyro_lsm6ds0.c
@@ -150,19 +150,19 @@ static int get_engineering_val(const int reg_val,
/**
* Read register from accelerometer.
*/
-static inline int raw_read8(const int port, const int addr, const int reg,
- int *data_ptr)
+static inline int raw_read8__7bf(const int port, const uint16_t i2c_addr__7bf,
+ const int reg, int *data_ptr)
{
- return i2c_read8(port, addr, reg, data_ptr);
+ return i2c_read8__7bf(port, i2c_addr__7bf, reg, data_ptr);
}
/**
* Write register from accelerometer.
*/
-static inline int raw_write8(const int port, const int addr, const int reg,
- int data)
+static inline int raw_write8__7bf(const int port, const uint16_t i2c_addr__7bf,
+ const int reg, int data)
{
- return i2c_write8(port, addr, reg, data);
+ return i2c_write8__7bf(port, i2c_addr__7bf, reg, data);
}
static int set_range(const struct motion_sensor_t *s,
@@ -185,12 +185,14 @@ static int set_range(const struct motion_sensor_t *s,
*/
mutex_lock(s->mutex);
- ret = raw_read8(s->port, s->addr, ctrl_reg, &ctrl_val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ ctrl_reg, &ctrl_val);
if (ret != EC_SUCCESS)
goto accel_cleanup;
ctrl_val = (ctrl_val & ~LSM6DS0_RANGE_MASK) | reg_val;
- ret = raw_write8(s->port, s->addr, ctrl_reg, ctrl_val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ ctrl_reg, ctrl_val);
/* Now that we have set the range, update the driver's value. */
if (ret == EC_SUCCESS)
@@ -233,12 +235,12 @@ static int set_data_rate(const struct motion_sensor_t *s,
*/
mutex_lock(s->mutex);
- ret = raw_read8(s->port, s->addr, ctrl_reg, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, ctrl_reg, &val);
if (ret != EC_SUCCESS)
goto accel_cleanup;
val = (val & ~LSM6DS0_ODR_MASK) | reg_val;
- ret = raw_write8(s->port, s->addr, ctrl_reg, val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, ctrl_reg, val);
/* Now that we have set the odr, update the driver's value. */
if (ret == EC_SUCCESS)
@@ -253,14 +255,16 @@ static int set_data_rate(const struct motion_sensor_t *s,
* Table 48 Gyroscope high-pass filter cutoff frequency
*/
if (MOTIONSENSE_TYPE_GYRO == s->type) {
- ret = raw_read8(s->port, s->addr, LSM6DS0_CTRL_REG3_G, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DS0_CTRL_REG3_G, &val);
if (ret != EC_SUCCESS)
goto accel_cleanup;
val &= ~(0x3 << 4); /* clear bit [5:4] */
val = (rate > 119000) ?
(val | (1<<7)) /* set high-power mode */ :
(val & ~(1<<7)); /* set low-power mode */
- ret = raw_write8(s->port, s->addr, LSM6DS0_CTRL_REG3_G, val);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DS0_CTRL_REG3_G, val);
}
accel_cleanup:
@@ -303,7 +307,8 @@ static int is_data_ready(const struct motion_sensor_t *s, int *ready)
{
int ret, tmp;
- ret = raw_read8(s->port, s->addr, LSM6DS0_STATUS_REG, &tmp);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DS0_STATUS_REG, &tmp);
if (ret != EC_SUCCESS) {
CPRINTF("[%T %s type:0x%X RS Error]", s->name, s->type);
@@ -343,7 +348,8 @@ static int read(const struct motion_sensor_t *s, intv3_t v)
xyz_reg = get_xyz_reg(s->type);
/* Read 6 bytes starting at xyz_reg */
- ret = i2c_read_block(s->port, s->addr, xyz_reg, raw, 6);
+ ret = i2c_read_block__7bf(s->port, s->i2c_spi_addr__7bf,
+ xyz_reg, raw, 6);
if (ret != EC_SUCCESS) {
CPRINTF("[%T %s type:0x%X RD XYZ Error]",
@@ -368,7 +374,8 @@ static int init(const struct motion_sensor_t *s)
{
int ret = 0, tmp;
- ret = raw_read8(s->port, s->addr, LSM6DS0_WHO_AM_I_REG, &tmp);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DS0_WHO_AM_I_REG, &tmp);
if (ret)
return EC_ERROR_UNKNOWN;
@@ -390,21 +397,23 @@ static int init(const struct motion_sensor_t *s)
if (MOTIONSENSE_TYPE_ACCEL == s->type) {
mutex_lock(s->mutex);
- ret = raw_read8(s->port, s->addr, LSM6DS0_CTRL_REG8, &tmp);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DS0_CTRL_REG8, &tmp);
if (ret) {
mutex_unlock(s->mutex);
return EC_ERROR_UNKNOWN;
}
tmp |= (1 | LSM6DS0_BDU_ENABLE);
- ret = raw_write8(s->port, s->addr, LSM6DS0_CTRL_REG8, tmp);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DS0_CTRL_REG8, tmp);
mutex_unlock(s->mutex);
if (ret)
return ret;
/* Power Down Gyro */
- ret = raw_write8(s->port, s->addr,
- LSM6DS0_CTRL_REG1_G, 0x0);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DS0_CTRL_REG1_G, 0x0);
if (ret)
return ret;
}
diff --git a/driver/accelgyro_lsm6ds0.h b/driver/accelgyro_lsm6ds0.h
index cd1fefb199..8904d23ef3 100644
--- a/driver/accelgyro_lsm6ds0.h
+++ b/driver/accelgyro_lsm6ds0.h
@@ -15,8 +15,8 @@
* 7-bit address is 110101Xb. Where 'X' is determined
* by the voltage on the ADDR pin.
*/
-#define LSM6DS0_ADDR0 0xd4
-#define LSM6DS0_ADDR1 0xd6
+#define LSM6DS0_ADDR0__7bf 0x6a
+#define LSM6DS0_ADDR1__7bf 0x6b
/* who am I */
#define LSM6DS0_WHO_AM_I 0x68
diff --git a/driver/accelgyro_lsm6dsm.c b/driver/accelgyro_lsm6dsm.c
index e5166eccc9..5476d227b3 100644
--- a/driver/accelgyro_lsm6dsm.c
+++ b/driver/accelgyro_lsm6dsm.c
@@ -106,23 +106,24 @@ static int config_interrupt(const struct motion_sensor_t *accel)
int ret = EC_SUCCESS;
int int1_ctrl_val;
- ret = st_raw_read8(accel->port, accel->addr, LSM6DSM_INT1_CTRL,
- &int1_ctrl_val);
+ ret = st_raw_read8__7bf(accel->port, accel->i2c_spi_addr__7bf,
+ LSM6DSM_INT1_CTRL, &int1_ctrl_val);
if (ret != EC_SUCCESS)
return ret;
#ifdef CONFIG_ACCEL_FIFO
/* As soon as one sample is ready, trigger an interrupt. */
- ret = st_raw_write8(accel->port, accel->addr, LSM6DSM_FIFO_CTRL1_ADDR,
- OUT_XYZ_SIZE / sizeof(uint16_t));
+ ret = st_raw_write8__7bf(accel->port, accel->i2c_spi_addr__7bf,
+ LSM6DSM_FIFO_CTRL1_ADDR,
+ OUT_XYZ_SIZE / sizeof(uint16_t));
if (ret != EC_SUCCESS)
return ret;
int1_ctrl_val |= LSM6DSM_INT_FIFO_TH | LSM6DSM_INT_FIFO_OVR |
LSM6DSM_INT_FIFO_FULL;
#endif /* CONFIG_ACCEL_FIFO */
- return st_raw_write8(
- accel->port, accel->addr, LSM6DSM_INT1_CTRL, int1_ctrl_val);
+ return st_raw_write8__7bf(accel->port, accel->i2c_spi_addr__7bf,
+ LSM6DSM_INT1_CTRL, int1_ctrl_val);
}
@@ -134,7 +135,7 @@ static int config_interrupt(const struct motion_sensor_t *accel)
*/
static int fifo_disable(const struct motion_sensor_t *accel)
{
- return st_raw_write8(accel->port, accel->addr,
+ return st_raw_write8__7bf(accel->port, accel->i2c_spi_addr__7bf,
LSM6DSM_FIFO_CTRL5_ADDR, 0x00);
}
@@ -194,8 +195,8 @@ static int fifo_enable(const struct motion_sensor_t *accel)
/* FIFO ODR must be set before the decimation factors */
odr_reg_val = LSM6DSM_ODR_TO_REG(max_odr) <<
LSM6DSM_FIFO_CTRL5_ODR_OFF;
- err = st_raw_write8(accel->port, accel->addr, LSM6DSM_FIFO_CTRL5_ADDR,
- odr_reg_val);
+ err = st_raw_write8__7bf(accel->port, accel->i2c_spi_addr__7bf,
+ LSM6DSM_FIFO_CTRL5_ADDR, odr_reg_val);
/* Scan all sensors configuration to calculate FIFO decimator. */
private->config.total_samples_in_pattern = 0;
@@ -212,12 +213,14 @@ static int fifo_enable(const struct motion_sensor_t *accel)
private->config.samples_in_pattern[i] = 0;
}
}
- st_raw_write8(accel->port, accel->addr, LSM6DSM_FIFO_CTRL3_ADDR,
+ st_raw_write8__7bf(accel->port, accel->i2c_spi_addr__7bf,
+ LSM6DSM_FIFO_CTRL3_ADDR,
(decimators[FIFO_DEV_GYRO] << LSM6DSM_FIFO_DEC_G_OFF) |
(decimators[FIFO_DEV_ACCEL] << LSM6DSM_FIFO_DEC_XL_OFF));
#ifdef CONFIG_LSM6DSM_SEC_I2C
- st_raw_write8(accel->port, accel->addr, LSM6DSM_FIFO_CTRL4_ADDR,
- decimators[FIFO_DEV_MAG]);
+ st_raw_write8__7bf(accel->port, accel->i2c_spi_addr__7bf,
+ LSM6DSM_FIFO_CTRL4_ADDR,
+ decimators[FIFO_DEV_MAG]);
/*
* FIFO ODR is limited by odr of gyro or accel.
@@ -252,7 +255,8 @@ static int fifo_enable(const struct motion_sensor_t *accel)
* After ODR and decimation values are set, continuous mode can be
* enabled
*/
- err = st_raw_write8(accel->port, accel->addr, LSM6DSM_FIFO_CTRL5_ADDR,
+ err = st_raw_write8__7bf(accel->port, accel->i2c_spi_addr__7bf,
+ LSM6DSM_FIFO_CTRL5_ADDR,
odr_reg_val | LSM6DSM_FIFO_MODE_CONTINUOUS_VAL);
if (err != EC_SUCCESS)
return err;
@@ -392,7 +396,7 @@ static int load_fifo(struct motion_sensor_t *s, const struct fstatus *fsts,
length = left;
/* Read data and copy in buffer. */
- err = st_raw_read_n_noinc(s->port, s->addr,
+ err = st_raw_read_n_noinc__7bf(s->port, s->i2c_spi_addr__7bf,
LSM6DSM_FIFO_DATA_ADDR,
fifo, length);
*last_fifo_read_ts = __hw_clock_source_read();
@@ -423,9 +427,9 @@ static int is_fifo_empty(struct motion_sensor_t *s, struct fstatus *fsts)
if (s->flags & MOTIONSENSE_FLAG_INT_SIGNAL)
return gpio_get_level(s->int_signal);
CPRINTS("Interrupt signal not set for %s", s->name);
- res = st_raw_read_n_noinc(s->port, s->addr,
- LSM6DSM_FIFO_STS1_ADDR,
- (int8_t *)fsts, sizeof(*fsts));
+ res = st_raw_read_n_noinc__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_FIFO_STS1_ADDR,
+ (int8_t *)fsts, sizeof(*fsts));
/* If we failed to read the FIFO size assume empty. */
if (res != EC_SUCCESS)
return 1;
@@ -471,9 +475,9 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
last_interrupt_timestamp;
/* Read how many data pattern on FIFO to read and pattern. */
- ret = st_raw_read_n_noinc(s->port, s->addr,
- LSM6DSM_FIFO_STS1_ADDR,
- (uint8_t *)&fsts, sizeof(fsts));
+ ret = st_raw_read_n_noinc__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_FIFO_STS1_ADDR,
+ (uint8_t *)&fsts, sizeof(fsts));
if (ret != EC_SUCCESS)
return ret;
last_fifo_read_ts = __hw_clock_source_read();
@@ -653,7 +657,8 @@ static int is_data_ready(const struct motion_sensor_t *s, int *ready)
{
int ret, tmp;
- ret = st_raw_read8(s->port, s->addr, LSM6DSM_STATUS_REG, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_STATUS_REG, &tmp);
if (ret != EC_SUCCESS) {
CPRINTF("[%T %s type:0x%X RS Error]", s->name, s->type);
return ret;
@@ -696,8 +701,8 @@ static int read(const struct motion_sensor_t *s, intv3_t v)
xyz_reg = get_xyz_reg(s->type);
/* Read data bytes starting at xyz_reg. */
- ret = st_raw_read_n_noinc(s->port, s->addr, xyz_reg, raw,
- OUT_XYZ_SIZE);
+ ret = st_raw_read_n_noinc__7bf(s->port, s->i2c_spi_addr__7bf,
+ xyz_reg, raw, OUT_XYZ_SIZE);
if (ret != EC_SUCCESS)
return ret;
@@ -712,7 +717,8 @@ static int init(const struct motion_sensor_t *s)
struct stprivate_data *data = s->drv_data;
uint8_t ctrl_reg, reg_val = 0;
- ret = st_raw_read8(s->port, s->addr, LSM6DSM_WHO_AM_I_REG, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_WHO_AM_I_REG, &tmp);
if (ret != EC_SUCCESS)
return EC_ERROR_UNKNOWN;
@@ -737,18 +743,20 @@ static int init(const struct motion_sensor_t *s)
ctrl_reg = LSM6DSM_ODR_REG(MOTIONSENSE_TYPE_ACCEL);
/* Power OFF gyro. */
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_CTRL2_ADDR, 0);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_CTRL2_ADDR, 0);
if (ret != EC_SUCCESS)
goto err_unlock;
/* Power ON Accel. */
- ret = st_raw_write8(s->port, s->addr, ctrl_reg, reg_val);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ ctrl_reg, reg_val);
if (ret != EC_SUCCESS)
goto err_unlock;
/* Software reset. */
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_CTRL3_ADDR,
- LSM6DSM_SW_RESET);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_CTRL3_ADDR, LSM6DSM_SW_RESET);
if (ret != EC_SUCCESS)
goto err_unlock;
@@ -761,12 +769,13 @@ static int init(const struct motion_sensor_t *s)
*/
/* Power ON Accel. */
- ret = st_raw_write8(s->port, s->addr, ctrl_reg, reg_val);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ ctrl_reg, reg_val);
if (ret != EC_SUCCESS)
goto err_unlock;
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_CTRL3_ADDR,
- LSM6DSM_BOOT);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_CTRL3_ADDR, LSM6DSM_BOOT);
if (ret != EC_SUCCESS)
goto err_unlock;
@@ -777,7 +786,8 @@ static int init(const struct motion_sensor_t *s)
msleep(15);
/* Power OFF Accel. */
- ret = st_raw_write8(s->port, s->addr, ctrl_reg, 0);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ ctrl_reg, 0);
if (ret != EC_SUCCESS)
goto err_unlock;
#endif
@@ -786,9 +796,11 @@ static int init(const struct motion_sensor_t *s)
* Output data not updated until have been read.
* Prefer interrupt to be active low.
*/
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_CTRL3_ADDR,
- LSM6DSM_BDU | LSM6DSM_H_L_ACTIVE |
- LSM6DSM_IF_INC);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_CTRL3_ADDR,
+ LSM6DSM_BDU
+ | LSM6DSM_H_L_ACTIVE
+ | LSM6DSM_IF_INC);
if (ret != EC_SUCCESS)
goto err_unlock;
diff --git a/driver/accelgyro_lsm6dsm.h b/driver/accelgyro_lsm6dsm.h
index 3d4e2645f1..a23298f11b 100644
--- a/driver/accelgyro_lsm6dsm.h
+++ b/driver/accelgyro_lsm6dsm.h
@@ -13,14 +13,12 @@
#include "mag_bmm150.h"
#include "mag_lis2mdl.h"
-#define LSM6DSM_I2C_ADDR(__x) (__x << 1)
-
/*
* 7-bit address is 110101xb. Where 'x' is determined
* by the voltage on the ADDR pin
*/
-#define LSM6DSM_ADDR0 LSM6DSM_I2C_ADDR(0x6a)
-#define LSM6DSM_ADDR1 LSM6DSM_I2C_ADDR(0x6b)
+#define LSM6DSM_ADDR0__7bf 0x6a
+#define LSM6DSM_ADDR1__7bf 0x6b
/* COMMON DEFINE FOR ACCEL-GYRO SENSORS */
#define LSM6DSM_EN_BIT 0x01
diff --git a/driver/accelgyro_lsm6dso.c b/driver/accelgyro_lsm6dso.c
index d50e24aa17..6c79f91881 100644
--- a/driver/accelgyro_lsm6dso.c
+++ b/driver/accelgyro_lsm6dso.c
@@ -55,8 +55,8 @@ static int config_interrupt(const struct motion_sensor_t *s)
#ifdef CONFIG_ACCEL_FIFO
int int1_ctrl_val;
- ret = st_raw_read8(s->port, s->addr, LSM6DSO_INT1_CTRL,
- &int1_ctrl_val);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSO_INT1_CTRL, &int1_ctrl_val);
if (ret != EC_SUCCESS)
return ret;
@@ -67,15 +67,16 @@ static int config_interrupt(const struct motion_sensor_t *s)
* number or samples still present in FIFO exceeds the configured
* threshold.
*/
- ret = st_raw_write8(s->port, s->addr, LSM6DSO_FIFO_CTRL1_ADDR, 1);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSO_FIFO_CTRL1_ADDR, 1);
if (ret != EC_SUCCESS)
return ret;
int1_ctrl_val |= LSM6DSO_INT_FIFO_TH | LSM6DSO_INT_FIFO_OVR |
LSM6DSO_INT_FIFO_FULL;
- ret = st_raw_write8(s->port, s->addr, LSM6DSO_INT1_CTRL,
- int1_ctrl_val);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSO_INT1_CTRL, int1_ctrl_val);
#endif /* CONFIG_ACCEL_FIFO */
return ret;
@@ -88,7 +89,8 @@ static int config_interrupt(const struct motion_sensor_t *s)
*/
static int fifo_disable(const struct motion_sensor_t *s)
{
- return st_raw_write8(s->port, s->addr, LSM6DSO_FIFO_CTRL4_ADDR,
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSO_FIFO_CTRL4_ADDR,
LSM6DSO_FIFO_MODE_BYPASS_VAL);
}
@@ -100,7 +102,8 @@ static int fifo_disable(const struct motion_sensor_t *s)
*/
static int fifo_enable(const struct motion_sensor_t *s)
{
- return st_raw_write8(s->port, s->addr, LSM6DSO_FIFO_CTRL4_ADDR,
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSO_FIFO_CTRL4_ADDR,
LSM6DSO_FIFO_MODE_CONTINUOUS_VAL);
}
@@ -168,7 +171,7 @@ static inline int load_fifo(struct motion_sensor_t *s,
fifo_len = fifo_depth * LSM6DSO_FIFO_SAMPLE_SIZE;
while (read_len < fifo_len) {
word_len = GENERIC_MIN(fifo_len - read_len, sizeof(fifo));
- err = st_raw_read_n_noinc(s->port, s->addr,
+ err = st_raw_read_n_noinc__7bf(s->port, s->i2c_spi_addr__7bf,
LSM6DSO_FIFO_DATA_ADDR_TAG,
fifo, word_len);
if (err != EC_SUCCESS)
@@ -244,7 +247,7 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
#ifdef CONFIG_ACCEL_FIFO
/* Read how many data patterns on FIFO to read. */
- ret = st_raw_read_n_noinc(s->port, s->addr,
+ ret = st_raw_read_n_noinc__7bf(s->port, s->i2c_spi_addr__7bf,
LSM6DSO_FIFO_STS1_ADDR,
(uint8_t *)&fsts, sizeof(fsts));
if (ret != EC_SUCCESS)
@@ -366,7 +369,8 @@ static int is_data_ready(const struct motion_sensor_t *s, int *ready)
{
int ret, tmp;
- ret = st_raw_read8(s->port, s->addr, LSM6DSO_STATUS_REG, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSO_STATUS_REG, &tmp);
if (ret != EC_SUCCESS) {
CPRINTS("%s type:0x%X RS Error", s->name, s->type);
@@ -411,8 +415,8 @@ static int read(const struct motion_sensor_t *s, intv3_t v)
xyz_reg = get_xyz_reg(s->type);
/* Read data bytes starting at xyz_reg. */
- ret = st_raw_read_n_noinc(s->port, s->addr, xyz_reg, raw,
- OUT_XYZ_SIZE);
+ ret = st_raw_read_n_noinc__7bf(s->port, s->i2c_spi_addr__7bf,
+ xyz_reg, raw, OUT_XYZ_SIZE);
if (ret != EC_SUCCESS)
return ret;
@@ -427,7 +431,8 @@ static int init(const struct motion_sensor_t *s)
int ret = 0, tmp;
struct stprivate_data *data = LSM6DSO_GET_DATA(s);
- ret = st_raw_read8(s->port, s->addr, LSM6DSO_WHO_AM_I_REG, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSO_WHO_AM_I_REG, &tmp);
if (ret != EC_SUCCESS)
return EC_ERROR_UNKNOWN;
@@ -445,8 +450,8 @@ static int init(const struct motion_sensor_t *s)
mutex_lock(s->mutex);
/* Software reset. */
- ret = st_raw_write8(s->port, s->addr, LSM6DSO_CTRL3_ADDR,
- LSM6DSO_SW_RESET);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSO_CTRL3_ADDR, LSM6DSO_SW_RESET);
if (ret != EC_SUCCESS)
goto err_unlock;
@@ -454,7 +459,8 @@ static int init(const struct motion_sensor_t *s)
* Output data not updated until have been read.
* Prefer interrupt to be active low.
*/
- ret = st_raw_write8(s->port, s->addr, LSM6DSO_CTRL3_ADDR,
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSO_CTRL3_ADDR,
LSM6DSO_BDU | LSM6DSO_IF_INC);
if (ret != EC_SUCCESS)
goto err_unlock;
diff --git a/driver/accelgyro_lsm6dso.h b/driver/accelgyro_lsm6dso.h
index 7748c7fe94..4d59fd1a07 100644
--- a/driver/accelgyro_lsm6dso.h
+++ b/driver/accelgyro_lsm6dso.h
@@ -10,14 +10,12 @@
#include "stm_mems_common.h"
-#define LSM6DSO_I2C_ADDR(__x) (__x << 1)
-
/*
* 7-bit address is 110101xb. Where 'x' is determined
* by the voltage on the ADDR pin
*/
-#define LSM6DSO_ADDR0 LSM6DSO_I2C_ADDR(0x6a)
-#define LSM6DSO_ADDR1 LSM6DSO_I2C_ADDR(0x6b)
+#define LSM6DSO_ADDR0__7bf 0x6a
+#define LSM6DSO_ADDR1__7bf 0x6b
/* Access to embedded sensor hub register bank */
#define LSM6DSO_FUNC_CFG_ACC_ADDR 0x01
diff --git a/driver/als_al3010.h b/driver/als_al3010.h
index eb06762883..f4de75ed0e 100644
--- a/driver/als_al3010.h
+++ b/driver/als_al3010.h
@@ -9,9 +9,9 @@
#define __CROS_EC_ALS_AL3010_H
/* I2C interface */
-#define AL3010_I2C_ADDR1 (0x1C << 1)
-#define AL3010_I2C_ADDR2 (0x1D << 1)
-#define AL3010_I2C_ADDR3 (0x1E << 1)
+#define AL3010_I2C_ADDR1__7bf (0x1C)
+#define AL3010_I2C_ADDR2__7bf (0x1D)
+#define AL3010_I2C_ADDR3__7bf (0x1E)
/* AL3010 registers */
#define AL3010_REG_SYSTEM 0x00
diff --git a/driver/als_bh1730.c b/driver/als_bh1730.c
index 0f96680471..4b0b50e0a1 100644
--- a/driver/als_bh1730.c
+++ b/driver/als_bh1730.c
@@ -62,7 +62,8 @@ static int bh1730_read_lux(const struct motion_sensor_t *s, intv3_t v)
int data0_1;
/* read data0 and data1 from sensor */
- ret = i2c_read32(s->port, s->addr, BH1730_DATA0LOW, &data0_1);
+ ret = i2c_read32__7bf(s->port, s->i2c_spi_addr__7bf,
+ BH1730_DATA0LOW, &data0_1);
if (ret != EC_SUCCESS) {
CPRINTF("bh1730_read_lux - fail %d\n", ret);
return ret;
@@ -136,9 +137,10 @@ static int bh1730_init(const struct motion_sensor_t *s)
int ret;
/* power and measurement bit high */
- ret = i2c_write8(s->port, s->addr,
+ ret = i2c_write8__7bf(s->port, s->i2c_spi_addr__7bf,
BH1730_CONTROL,
- BH1730_CONTROL_POWER_ENABLE|BH1730_CONTROL_ADC_EN_ENABLE);
+ BH1730_CONTROL_POWER_ENABLE
+ | BH1730_CONTROL_ADC_EN_ENABLE);
if (ret != EC_SUCCESS) {
CPRINTF("bh1730_init_sensor - enable fail %d\n", ret);
@@ -146,13 +148,15 @@ static int bh1730_init(const struct motion_sensor_t *s)
}
/* set timing */
- ret = i2c_write8(s->port, s->addr, BH1730_TIMING, BH1730_CONF_ITIME);
+ ret = i2c_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BH1730_TIMING, BH1730_CONF_ITIME);
if (ret != EC_SUCCESS) {
CPRINTF("bh1730_init_sensor - time fail %d\n", ret);
return ret;
}
/* set ADC gain */
- ret = i2c_write8(s->port, s->addr, BH1730_GAIN, BH1730_CONF_GAIN);
+ ret = i2c_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BH1730_GAIN, BH1730_CONF_GAIN);
if (ret != EC_SUCCESS) {
CPRINTF("bh1730_init_sensor - gain fail %d\n", ret);
diff --git a/driver/als_bh1730.h b/driver/als_bh1730.h
index 3cd8757822..f729d3edaa 100644
--- a/driver/als_bh1730.h
+++ b/driver/als_bh1730.h
@@ -9,7 +9,7 @@
#define __CROS_EC_ALS_BH1730_H
/* I2C interface */
-#define BH1730_I2C_ADDR (0x29 << 1)
+#define BH1730_I2C_ADDR__7bf 0x29
/* BH1730 registers */
#define BH1730_CONTROL 0x80
diff --git a/driver/als_isl29035.c b/driver/als_isl29035.c
index 357cc99089..d0cfc1be25 100644
--- a/driver/als_isl29035.c
+++ b/driver/als_isl29035.c
@@ -9,7 +9,7 @@
#include "i2c.h"
/* I2C interface */
-#define ILS29035_I2C_ADDR 0x88
+#define ILS29035_I2C_ADDR__7bf 0x44
#define ILS29035_REG_COMMAND_I 0
#define ILS29035_REG_COMMAND_II 1
#define ILS29035_REG_DATA_LSB 2
@@ -27,8 +27,8 @@ int isl29035_init(void)
* zero, but it makes the hook/update code cleaner (we don't want to
* wait 90ms to read on demand while processing hook callbacks).
*/
- return i2c_write8(I2C_PORT_ALS, ILS29035_I2C_ADDR,
- ILS29035_REG_COMMAND_I, 0xa0);
+ return i2c_write8__7bf(I2C_PORT_ALS, ILS29035_I2C_ADDR__7bf,
+ ILS29035_REG_COMMAND_I, 0xa0);
}
int isl29035_read_lux(int *lux, int af)
@@ -43,13 +43,13 @@ int isl29035_read_lux(int *lux, int af)
*/
/* Read lsb */
- rv = i2c_read8(I2C_PORT_ALS, ILS29035_I2C_ADDR,
+ rv = i2c_read8__7bf(I2C_PORT_ALS, ILS29035_I2C_ADDR__7bf,
ILS29035_REG_DATA_LSB, &lsb);
if (rv)
return rv;
/* Read msb */
- rv = i2c_read8(I2C_PORT_ALS, ILS29035_I2C_ADDR,
+ rv = i2c_read8__7bf(I2C_PORT_ALS, ILS29035_I2C_ADDR__7bf,
ILS29035_REG_DATA_MSB, &msb);
if (rv)
return rv;
diff --git a/driver/als_opt3001.c b/driver/als_opt3001.c
index fd5dded45d..42a06bfdcc 100644
--- a/driver/als_opt3001.c
+++ b/driver/als_opt3001.c
@@ -17,7 +17,8 @@ static int opt3001_i2c_read(const int reg, int *data_ptr)
{
int ret;
- ret = i2c_read16(I2C_PORT_ALS, OPT3001_I2C_ADDR, reg, data_ptr);
+ ret = i2c_read16__7bf(I2C_PORT_ALS, OPT3001_I2C_ADDR__7bf,
+ reg, data_ptr);
if (!ret)
*data_ptr = ((*data_ptr << 8) & 0xFF00) |
((*data_ptr >> 8) & 0x00FF);
@@ -31,7 +32,8 @@ static int opt3001_i2c_read(const int reg, int *data_ptr)
static int opt3001_i2c_write(const int reg, int data)
{
data = ((data << 8) & 0xFF00) | ((data >> 8) & 0x00FF);
- return i2c_write16(I2C_PORT_ALS, OPT3001_I2C_ADDR, reg, data);
+ return i2c_write16__7bf(I2C_PORT_ALS, OPT3001_I2C_ADDR__7bf,
+ reg, data);
}
/**
@@ -108,12 +110,14 @@ struct i2c_stress_test_dev opt3001_i2c_stress_test_dev = {
/**
* Read register from OPT3001 light sensor.
*/
-static int opt3001_i2c_read(const int port, const int addr, const int reg,
- int *data_ptr)
+static int opt3001_i2c_read__7bf(const int port,
+ const uint16_t i2c_addr__7bf,
+ const int reg, int *data_ptr)
{
int ret;
- ret = i2c_read16(port, addr, reg, data_ptr);
+ ret = i2c_read16__7bf(port, i2c_addr__7bf,
+ reg, data_ptr);
if (!ret)
*data_ptr = ((*data_ptr << 8) & 0xFF00) |
((*data_ptr >> 8) & 0x00FF);
@@ -124,11 +128,13 @@ static int opt3001_i2c_read(const int port, const int addr, const int reg,
/**
* Write register to OPT3001 light sensor.
*/
-static int opt3001_i2c_write(const int port, const int addr, const int reg,
- int data)
+static int opt3001_i2c_write__7bf(const int port,
+ const uint16_t i2c_addr__7bf,
+ const int reg, int data)
{
data = ((data << 8) & 0xFF00) | ((data >> 8) & 0x00FF);
- return i2c_write16(port, addr, reg, data);
+ return i2c_write16__7bf(port, i2c_addr__7bf,
+ reg, data);
}
/**
@@ -140,7 +146,8 @@ int opt3001_read_lux(const struct motion_sensor_t *s, intv3_t v)
int ret;
int data;
- ret = opt3001_i2c_read(s->port, s->addr, OPT3001_REG_RESULT, &data);
+ ret = opt3001_i2c_read__7bf(s->port, s->i2c_spi_addr__7bf,
+ OPT3001_REG_RESULT, &data);
if (ret)
return ret;
@@ -211,13 +218,15 @@ static int opt3001_set_data_rate(const struct motion_sensor_t *s,
if (rate > 1000)
rate = 1000;
}
- rv = opt3001_i2c_read(s->port, s->addr, OPT3001_REG_CONFIGURE, &reg);
+ rv = opt3001_i2c_read__7bf(s->port, s->i2c_spi_addr__7bf,
+ OPT3001_REG_CONFIGURE, &reg);
if (rv)
return rv;
- rv = opt3001_i2c_write(s->port, s->addr, OPT3001_REG_CONFIGURE,
+ rv = opt3001_i2c_write__7bf(s->port, s->i2c_spi_addr__7bf,
+ OPT3001_REG_CONFIGURE,
(reg & OPT3001_MODE_MASK) |
- (mode << OPT3001_MODE_OFFSET));
+ (mode << OPT3001_MODE_OFFSET));
if (rv)
return rv;
@@ -262,13 +271,15 @@ static int opt3001_init(const struct motion_sensor_t *s)
int data;
int ret;
- ret = opt3001_i2c_read(s->port, s->addr, OPT3001_REG_MAN_ID, &data);
+ ret = opt3001_i2c_read__7bf(s->port, s->i2c_spi_addr__7bf,
+ OPT3001_REG_MAN_ID, &data);
if (ret)
return ret;
if (data != OPT3001_MANUFACTURER_ID)
return EC_ERROR_ACCESS_DENIED;
- ret = opt3001_i2c_read(s->port, s->addr, OPT3001_REG_DEV_ID, &data);
+ ret = opt3001_i2c_read__7bf(s->port, s->i2c_spi_addr__7bf,
+ OPT3001_REG_DEV_ID, &data);
if (ret)
return ret;
if (data != OPT3001_DEVICE_ID)
@@ -279,7 +290,8 @@ static int opt3001_init(const struct motion_sensor_t *s)
* [11] : 1b Conversion time 800ms
* [4] : 1b Latched window-style comparison operation
*/
- opt3001_i2c_write(s->port, s->addr, OPT3001_REG_CONFIGURE, 0xC810);
+ opt3001_i2c_write__7bf(s->port, s->i2c_spi_addr__7bf,
+ OPT3001_REG_CONFIGURE, 0xC810);
opt3001_set_range(s, s->default_range, 0);
@@ -304,8 +316,8 @@ struct i2c_stress_test_dev opt3001_i2c_stress_test_dev = {
.read_val = OPT3001_DEVICE_ID,
.write_reg = OPT3001_REG_INT_LIMIT_LSB,
},
- .i2c_read = &opt3001_i2c_read,
- .i2c_write = &opt3001_i2c_write,
+ .i2c_read__7bf = &opt3001_i2c_read__7bf,
+ .i2c_write__7bf = &opt3001_i2c_write__7bf,
};
#endif /* CONFIG_CMD_I2C_STRESS_TEST_ALS */
#endif /* HAS_TASK_ALS */
diff --git a/driver/als_opt3001.h b/driver/als_opt3001.h
index d2d2737e20..34d129b5a5 100644
--- a/driver/als_opt3001.h
+++ b/driver/als_opt3001.h
@@ -9,10 +9,10 @@
#define __CROS_EC_ALS_OPT3001_H
/* I2C interface */
-#define OPT3001_I2C_ADDR1 (0x44 << 1)
-#define OPT3001_I2C_ADDR2 (0x45 << 1)
-#define OPT3001_I2C_ADDR3 (0x46 << 1)
-#define OPT3001_I2C_ADDR4 (0x47 << 1)
+#define OPT3001_I2C_ADDR1__7bf 0x44
+#define OPT3001_I2C_ADDR2__7bf 0x45
+#define OPT3001_I2C_ADDR3__7bf 0x46
+#define OPT3001_I2C_ADDR4__7bf 0x47
/* OPT3001 registers */
#define OPT3001_REG_RESULT 0x00
diff --git a/driver/als_si114x.c b/driver/als_si114x.c
index b51cf8cfc6..f0b3165e67 100644
--- a/driver/als_si114x.c
+++ b/driver/als_si114x.c
@@ -27,28 +27,28 @@ static int init(const struct motion_sensor_t *s);
/**
* Read 8bit register from device.
*/
-static inline int raw_read8(const int port, const int addr, const int reg,
- int *data_ptr)
+static inline int raw_read8__7bf(const int port, const uint16_t i2c_addr__7bf,
+ const int reg, int *data_ptr)
{
- return i2c_read8(port, addr, reg, data_ptr);
+ return i2c_read8__7bf(port, i2c_addr__7bf, reg, data_ptr);
}
/**
* Write 8bit register from device.
*/
-static inline int raw_write8(const int port, const int addr, const int reg,
- int data)
+static inline int raw_write8__7bf(const int port, const uint16_t i2c_addr__7bf,
+ const int reg, int data)
{
- return i2c_write8(port, addr, reg, data);
+ return i2c_write8__7bf(port, i2c_addr__7bf, reg, data);
}
/**
* Read 16bit register from device.
*/
-static inline int raw_read16(const int port, const int addr, const int reg,
- int *data_ptr)
+static inline int raw_read16__7bf(const int port, const uint16_t i2c_addr__7bf,
+ const int reg, int *data_ptr)
{
- return i2c_read16(port, addr, reg, data_ptr);
+ return i2c_read16__7bf(port, i2c_addr__7bf, reg, data_ptr);
}
/* helper function to operate on parameter values: op can be query/set/or/and */
@@ -62,17 +62,19 @@ static int si114x_param_op(const struct motion_sensor_t *s,
mutex_lock(s->mutex);
if (op != SI114X_CMD_PARAM_QUERY) {
- ret = raw_write8(s->port, s->addr, SI114X_REG_PARAM_WR, *value);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_PARAM_WR, *value);
if (ret != EC_SUCCESS)
goto error;
}
- ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND,
- op | (param & 0x1F));
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_COMMAND, op | (param & 0x1F));
if (ret != EC_SUCCESS)
goto error;
- ret = raw_read8(s->port, s->addr, SI114X_REG_PARAM_RD, value);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_PARAM_RD, value);
if (ret != EC_SUCCESS)
goto error;
@@ -96,7 +98,7 @@ static int si114x_read_results(struct motion_sensor_t *s, int nb)
/* Read ALX result */
for (i = 0; i < nb; i++) {
- ret = raw_read16(s->port, s->addr,
+ ret = raw_read16__7bf(s->port, s->i2c_spi_addr__7bf,
type_data->base_data_reg + i * 2,
&val);
if (ret)
@@ -196,7 +198,8 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
if (!(*event & CONFIG_ALS_SI114X_INT_EVENT))
return EC_ERROR_NOT_HANDLED;
- ret = raw_read8(s->port, s->addr, SI114X_REG_IRQ_STATUS, &val);
+ ret = raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_IRQ_STATUS, &val);
if (ret)
return ret;
@@ -204,7 +207,8 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
return EC_ERROR_INVAL;
/* clearing IRQ */
- ret = raw_write8(s->port, s->addr, SI114X_REG_IRQ_STATUS,
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_IRQ_STATUS,
val & type_data->irq_flags);
if (ret != EC_SUCCESS)
CPRINTS("clearing irq failed");
@@ -216,8 +220,9 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
ret = si114x_read_results(s, 1);
/* Fire pending requests */
if (data->state == SI114X_ALS_IN_PROGRESS_PS_PENDING) {
- ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND,
- SI114X_CMD_PS_FORCE);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_COMMAND,
+ SI114X_CMD_PS_FORCE);
data->state = SI114X_PS_IN_PROGRESS;
} else {
data->state = SI114X_IDLE;
@@ -228,8 +233,9 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event)
/* Read PS results */
ret = si114x_read_results(s, SI114X_NUM_LEDS);
if (data->state == SI114X_PS_IN_PROGRESS_ALS_PENDING) {
- ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND,
- SI114X_CMD_ALS_FORCE);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_COMMAND,
+ SI114X_CMD_ALS_FORCE);
data->state = SI114X_ALS_IN_PROGRESS;
} else {
data->state = SI114X_IDLE;
@@ -282,7 +288,8 @@ static int read(const struct motion_sensor_t *s, intv3_t v)
CPRINTS("Invalid sensor type");
return EC_ERROR_INVAL;
}
- ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND, cmd);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_COMMAND, cmd);
#ifdef CONFIG_ALS_SI114X_POLLING
hook_call_deferred(&si114x_read_deferred_data,
SI114x_POLLING_DELAY);
@@ -370,63 +377,68 @@ static int si114x_initialize(const struct motion_sensor_t *s)
int ret, val;
/* send reset command */
- ret = raw_write8(s->port, s->addr, SI114X_REG_COMMAND,
- SI114X_CMD_RESET);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_COMMAND, SI114X_CMD_RESET);
if (ret != EC_SUCCESS)
return ret;
msleep(20);
/* hardware key, magic value */
- ret = raw_write8(s->port, s->addr, SI114X_REG_HW_KEY, 0x17);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_HW_KEY, 0x17);
if (ret != EC_SUCCESS)
return ret;
msleep(20);
/* interrupt configuration, interrupt output enable */
- ret = raw_write8(s->port, s->addr, SI114X_REG_INT_CFG,
- SI114X_INT_CFG_OE);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_INT_CFG, SI114X_INT_CFG_OE);
if (ret != EC_SUCCESS)
return ret;
/* enable interrupt for certain activities */
- ret = raw_write8(s->port, s->addr, SI114X_REG_IRQ_ENABLE,
- SI114X_PS3_IE | SI114X_PS2_IE | SI114X_PS1_IE |
- SI114X_ALS_INT0_IE);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_IRQ_ENABLE,
+ SI114X_PS3_IE | SI114X_PS2_IE | SI114X_PS1_IE |
+ SI114X_ALS_INT0_IE);
if (ret != EC_SUCCESS)
return ret;
/* Only forced mode */
- ret = raw_write8(s->port, s->addr, SI114X_REG_MEAS_RATE, 0);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_MEAS_RATE, 0);
if (ret != EC_SUCCESS)
return ret;
/* measure ALS every time device wakes up */
- ret = raw_write8(s->port, s->addr, SI114X_REG_ALS_RATE, 0);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_ALS_RATE, 0);
if (ret != EC_SUCCESS)
return ret;
/* measure proximity every time device wakes up */
- ret = raw_write8(s->port, s->addr, SI114X_REG_PS_RATE, 0);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_PS_RATE, 0);
if (ret != EC_SUCCESS)
return ret;
/* set LED currents to maximum */
switch (SI114X_NUM_LEDS) {
case 3:
- ret = raw_write8(s->port, s->addr,
- SI114X_REG_PS_LED3, 0x0f);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_PS_LED3, 0x0f);
if (ret != EC_SUCCESS)
return ret;
- ret = raw_write8(s->port, s->addr,
- SI114X_REG_PS_LED21, 0xff);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_PS_LED21, 0xff);
break;
case 2:
- ret = raw_write8(s->port, s->addr,
- SI114X_REG_PS_LED21, 0xff);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_PS_LED21, 0xff);
break;
case 1:
- ret = raw_write8(s->port, s->addr,
- SI114X_REG_PS_LED21, 0x0f);
+ ret = raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ SI114X_REG_PS_LED21, 0x0f);
break;
}
if (ret != EC_SUCCESS)
diff --git a/driver/als_si114x.h b/driver/als_si114x.h
index e3a19895ba..758bc09536 100644
--- a/driver/als_si114x.h
+++ b/driver/als_si114x.h
@@ -22,7 +22,7 @@
#ifndef __CROS_EC_ALS_SI114X_H
#define __CROS_EC_ALS_SI114X_H
-#define SI114X_ADDR (0x5a << 1)
+#define SI114X_ADDR__7bf 0x5a
#define SI114X_REG_PART_ID 0x00
#define SI114X_SI1141_ID 0x41
diff --git a/driver/als_tcs3400.c b/driver/als_tcs3400.c
new file mode 100644
index 0000000000..8544f51a4b
--- /dev/null
+++ b/driver/als_tcs3400.c
@@ -0,0 +1,494 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * AMS TCS3400 light sensor driver
+ */
+
+#include "accelgyro.h"
+#include "common.h"
+#include "console.h"
+#include "driver/als_tcs3400.h"
+#include "hooks.h"
+#include "hwtimer.h"
+#include "i2c.h"
+#include "math_util.h"
+#include "task.h"
+
+#define CPRINTS(fmt, args...) cprints(CC_ACCEL, "%s "fmt, __func__, ## args)
+
+#ifdef CONFIG_ACCEL_FIFO
+static volatile uint32_t last_interrupt_timestamp;
+#endif
+
+static inline int tcs3400_i2c_read8(const struct motion_sensor_t *s,
+ int reg, int *data)
+{
+ return i2c_read8__7bf(s->port, s->i2c_spi_addr__7bf, reg, data);
+}
+
+static inline int tcs3400_i2c_write8(const struct motion_sensor_t *s,
+ int reg, int data)
+{
+ return i2c_write8__7bf(s->port, s->i2c_spi_addr__7bf, reg, data);
+}
+
+static void tcs3400_read_deferred(void)
+{
+ task_set_event(TASK_ID_MOTIONSENSE, CONFIG_ALS_TCS3400_INT_EVENT, 0);
+}
+DECLARE_DEFERRED(tcs3400_read_deferred);
+
+/* convert ATIME register to integration time, in microseconds */
+static int tcs3400_get_integration_time(int atime)
+{
+ return 2780 * (256 - atime);
+}
+
+static int tcs3400_read(const struct motion_sensor_t *s, intv3_t v)
+{
+ int ret;
+
+ /* Enable power, ADC, and interrupt to start cycle */
+ ret = tcs3400_i2c_write8(s, TCS_I2C_ENABLE, TCS3400_MODE_COLLECTING);
+ if (ret)
+ return ret;
+
+ if (IS_ENABLED(CONFIG_ALS_TCS3400_EMULATED_IRQ_EVENT)) {
+ int atime;
+
+ ret = tcs3400_i2c_read8(s, TCS_I2C_ATIME, &atime);
+ if (ret)
+ return ret;
+
+ hook_call_deferred(&tcs3400_read_deferred_data,
+ tcs3400_get_integration_time(atime));
+ }
+
+ /*
+ * If write succeeded, we've started the read process, but can't
+ * complete it yet until data is ready, so pass back EC_RES_IN_PROGRESS
+ * to inform upper level that read data process is under way and data
+ * will be delivered when available.
+ */
+ return EC_RES_IN_PROGRESS;
+}
+
+static int tcs3400_rgb_read(const struct motion_sensor_t *s, intv3_t v)
+{
+ return EC_SUCCESS;
+}
+
+static int tcs3400_post_events(struct motion_sensor_t *s, uint32_t last_ts)
+{
+ /*
+ * Rule says RGB sensor is right after ALS sensor, and this
+ * routine will only get called from ALS sensor driver.
+ */
+ struct motion_sensor_t *rgb_s = s + 1;
+ struct als_drv_data_t *drv_data = TCS3400_DRV_DATA(s);
+ struct tcs3400_rgb_drv_data_t *rgb_drv_data =
+ TCS3400_RGB_DRV_DATA(rgb_s);
+ struct ec_response_motion_sensor_data vector;
+ uint8_t light_data[TCS_RGBC_DATA_SIZE];
+ int *v = s->raw_xyz;
+ int retries = 20; /* 400 ms max */
+ int rgb_data[3];
+ int data = 0;
+ int i, ret;
+
+ /* Make sure data is valid */
+ do {
+ ret = tcs3400_i2c_read8(s, TCS_I2C_STATUS, &data);
+ if (ret)
+ return ret;
+ if (!(data & TCS_I2C_STATUS_RGBC_VALID)) {
+ retries--;
+ if (retries == 0) {
+ CPRINTS("RGBC not valid (0x%x)", data);
+ return EC_ERROR_UNCHANGED;
+ }
+ msleep(20);
+ }
+ } while (!(data & TCS_I2C_STATUS_RGBC_VALID));
+
+ /* Read the light registers */
+ ret = i2c_read_block__7bf(s->port, s->i2c_spi_addr__7bf,
+ TCS_DATA_START_LOCATION,
+ light_data, sizeof(light_data));
+ if (ret)
+ return ret;
+
+ /* Transfer Clear data into sensor struct and into fifo */
+ data = (light_data[1] << 8) | light_data[0];
+ data += drv_data->als_cal.offset;
+ data = data * drv_data->als_cal.scale +
+ data * drv_data->als_cal.uscale / 10000;
+
+ /* Correct negative values to zero */
+ if (data < 0) {
+ CPRINTS("Negative clear val 0x%x set to 0", data);
+ data = 0;
+ }
+
+ if (data != drv_data->last_value) {
+ drv_data->last_value = data;
+ vector.flags = 0;
+#ifdef CONFIG_ACCEL_SPOOF_MODE
+ if (s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) {
+ for (i = 0; i < 3; i++)
+ vector.data[i] = v[i] = s->spoof_xyz[i];
+ goto skip_clear_vector_load;
+ }
+#endif /* defined(CONFIG_ACCEL_SPOOF_MODE) */
+
+ vector.data[X] = v[X] = data;
+ vector.data[Y] = v[Y] = 0;
+ vector.data[Z] = v[Z] = 0;
+
+#ifdef CONFIG_ACCEL_SPOOF_MODE
+skip_clear_vector_load:
+#endif
+
+#ifdef CONFIG_ACCEL_FIFO
+ vector.sensor_num = s - motion_sensors;
+ motion_sense_fifo_stage_data(&vector, s, 3, last_ts);
+#endif
+ }
+
+#ifdef CONFIG_ACCEL_SPOOF_MODE
+ if (s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) {
+ rgb_data[X] = s->spoof_xyz[X];
+ rgb_data[Y] = s->spoof_xyz[Y];
+ rgb_data[Z] = s->spoof_xyz[Z];
+ goto skip_rgb_load;
+ }
+#endif
+
+ for (i = 0; i < 3; i++) {
+ /* rgb data at indicies 2 thru 7 inclusive in light_data */
+ int index = 3 + (i * 2);
+
+ rgb_data[i] = ((light_data[index] << 8) | light_data[index-1]);
+ rgb_data[i] += rgb_drv_data->rgb_cal[i].offset;
+ rgb_data[i] *= rgb_drv_data->rgb_cal[i].scale >> 15;
+ rgb_data[i] = rgb_data[i] * rgb_drv_data->device_scale +
+ rgb_data[i] * rgb_drv_data->device_uscale / 10000;
+
+ /* Correct any negative values to zero */
+ if (rgb_data[i] < 0) {
+ CPRINTS("Negative rgb channel #%d val 0x%x set to 0",
+ i, rgb_data[i]);
+ rgb_data[i] = 0;
+ }
+ }
+
+#ifdef CONFIG_ACCEL_SPOOF_MODE
+skip_rgb_load:
+#endif
+ /* If anything changed, transfer RGB data */
+ if ((rgb_drv_data->last_value[X] != rgb_data[X]) ||
+ (rgb_drv_data->last_value[Y] != rgb_data[Y]) ||
+ (rgb_drv_data->last_value[Z] != rgb_data[Z])) {
+ for (i = 0; i < 3; i++)
+ rgb_drv_data->last_value[i] = rgb_data[i];
+ v = rgb_s->raw_xyz;
+ vector.flags = 0;
+#ifdef CONFIG_ACCEL_SPOOF_MODE
+ if (rgb_s->flags & MOTIONSENSE_FLAG_IN_SPOOF_MODE) {
+ for (i = 0; i < 3; i++)
+ vector.data[i] = v[i] = rgb_s->spoof_xyz[i];
+ goto skip_vector_load;
+ }
+#endif /* defined(CONFIG_ACCEL_SPOOF_MODE) */
+
+ vector.data[X] = v[X] = rgb_data[X];
+ vector.data[Y] = v[Y] = rgb_data[Y];
+ vector.data[Z] = v[Z] = rgb_data[Z];
+
+#ifdef CONFIG_ACCEL_SPOOF_MODE
+skip_vector_load:
+#endif
+ vector.sensor_num = rgb_s - motion_sensors;
+ motion_sense_fifo_stage_data(&vector, rgb_s, 3, last_ts);
+ }
+ motion_sense_fifo_commit_data();
+ return EC_SUCCESS;
+}
+
+void tcs3400_interrupt(enum gpio_signal signal)
+{
+#ifdef CONFIG_ACCEL_FIFO
+ last_interrupt_timestamp = __hw_clock_source_read();
+#endif
+ task_set_event(TASK_ID_MOTIONSENSE,
+ CONFIG_ALS_TCS3400_INT_EVENT, 0);
+}
+
+/*
+ * tcs3400_irq_handler - bottom half of the interrupt stack.
+ * Ran from the motion_sense task, finds the events that raised the interrupt,
+ * and posts those events via motion_sense_fifo_stage_data()..
+ */
+static int tcs3400_irq_handler(struct motion_sensor_t *s, uint32_t *event)
+{
+ int status = 0;
+ int ret = EC_SUCCESS;
+
+ if (!(*event & CONFIG_ALS_TCS3400_INT_EVENT))
+ return EC_ERROR_NOT_HANDLED;
+
+ ret = tcs3400_i2c_read8(s, TCS_I2C_STATUS, &status);
+ if (ret)
+ return ret;
+
+ /* Disable future interrupts */
+ ret = tcs3400_i2c_write8(s, TCS_I2C_ENABLE, TCS3400_MODE_IDLE);
+ if (ret)
+ return ret;
+
+ if ((status & TCS_I2C_STATUS_RGBC_VALID) ||
+ ((status & TCS_I2C_STATUS_ALS_IRQ) &&
+ (status & TCS_I2C_STATUS_ALS_VALID)) ||
+ IS_ENABLED(CONFIG_ALS_TCS3400_EMULATED_IRQ_EVENT)) {
+ ret = tcs3400_post_events(s, last_interrupt_timestamp);
+ if (ret)
+ return ret;
+ }
+
+ tcs3400_i2c_write8(s, TCS_I2C_AICLEAR, 0);
+
+ /* Disable ADC and turn off internal oscillator */
+ ret = tcs3400_i2c_write8(s, TCS_I2C_ENABLE, TCS3400_MODE_SUSPEND);
+ if (ret)
+ return ret;
+
+ return ret;
+}
+
+static int tcs3400_rgb_get_range(const struct motion_sensor_t *s)
+{
+ /* Currently, calibration info is same for all channels */
+ return (TCS3400_RGB_DRV_DATA(s)->device_scale << 16) |
+ TCS3400_RGB_DRV_DATA(s)->device_uscale;
+}
+
+static int tcs3400_rgb_set_range(const struct motion_sensor_t *s,
+ int range,
+ int rnd)
+{
+ TCS3400_RGB_DRV_DATA(s)->device_scale = range >> 16;
+ TCS3400_RGB_DRV_DATA(s)->device_uscale = range & 0xffff;
+ return EC_SUCCESS;
+}
+
+static int tcs3400_rgb_get_scale(const struct motion_sensor_t *s,
+ uint16_t *scale,
+ int16_t *temp)
+{
+ scale[X] = TCS3400_RGB_DRV_DATA(s)->rgb_cal[X].scale;
+ scale[Y] = TCS3400_RGB_DRV_DATA(s)->rgb_cal[Y].scale;
+ scale[Z] = TCS3400_RGB_DRV_DATA(s)->rgb_cal[Z].scale;
+ *temp = EC_MOTION_SENSE_INVALID_CALIB_TEMP;
+ return EC_SUCCESS;
+}
+
+static int tcs3400_rgb_set_scale(const struct motion_sensor_t *s,
+ const uint16_t *scale,
+ int16_t temp)
+{
+ TCS3400_RGB_DRV_DATA(s)->rgb_cal[X].scale = scale[X];
+ TCS3400_RGB_DRV_DATA(s)->rgb_cal[Y].scale = scale[Y];
+ TCS3400_RGB_DRV_DATA(s)->rgb_cal[Z].scale = scale[Z];
+ return EC_SUCCESS;
+}
+
+static int tcs3400_rgb_get_offset(const struct motion_sensor_t *s,
+ int16_t *offset,
+ int16_t *temp)
+{
+ offset[X] = TCS3400_RGB_DRV_DATA(s)->rgb_cal[X].offset;
+ offset[Y] = TCS3400_RGB_DRV_DATA(s)->rgb_cal[Y].offset;
+ offset[Z] = TCS3400_RGB_DRV_DATA(s)->rgb_cal[Z].offset;
+ *temp = EC_MOTION_SENSE_INVALID_CALIB_TEMP;
+ return EC_SUCCESS;
+}
+
+static int tcs3400_rgb_set_offset(const struct motion_sensor_t *s,
+ const int16_t *offset,
+ int16_t temp)
+{
+ TCS3400_RGB_DRV_DATA(s)->rgb_cal[X].offset = offset[X];
+ TCS3400_RGB_DRV_DATA(s)->rgb_cal[Y].offset = offset[Y];
+ TCS3400_RGB_DRV_DATA(s)->rgb_cal[Z].offset = offset[Z];
+ return EC_SUCCESS;
+}
+
+static int tcs3400_rgb_get_data_rate(const struct motion_sensor_t *s)
+{
+ return TCS3400_RGB_DRV_DATA(s)->rate;
+}
+
+static int tcs3400_rgb_set_data_rate(const struct motion_sensor_t *s,
+ int rate,
+ int rnd)
+{
+ TCS3400_RGB_DRV_DATA(s)->rate = rate;
+ return EC_SUCCESS;
+}
+
+static int tcs3400_get_range(const struct motion_sensor_t *s)
+{
+ return (TCS3400_DRV_DATA(s)->als_cal.scale << 16) |
+ (TCS3400_DRV_DATA(s)->als_cal.uscale);
+}
+
+static int tcs3400_set_range(const struct motion_sensor_t *s,
+ int range,
+ int rnd)
+{
+ TCS3400_DRV_DATA(s)->als_cal.scale = range >> 16;
+ TCS3400_DRV_DATA(s)->als_cal.uscale = range & 0xffff;
+ return EC_SUCCESS;
+}
+
+static int tcs3400_get_offset(const struct motion_sensor_t *s,
+ int16_t *offset,
+ int16_t *temp)
+{
+ offset[X] = TCS3400_DRV_DATA(s)->als_cal.offset;
+ offset[Y] = 0;
+ offset[Z] = 0;
+ *temp = EC_MOTION_SENSE_INVALID_CALIB_TEMP;
+ return EC_SUCCESS;
+}
+
+static int tcs3400_set_offset(const struct motion_sensor_t *s,
+ const int16_t *offset,
+ int16_t temp)
+{
+ TCS3400_DRV_DATA(s)->als_cal.offset = offset[X];
+ return EC_SUCCESS;
+}
+
+static int tcs3400_get_data_rate(const struct motion_sensor_t *s)
+{
+ return TCS3400_DRV_DATA(s)->rate;
+}
+
+static int tcs3400_set_data_rate(const struct motion_sensor_t *s,
+ int rate,
+ int rnd)
+{
+ enum tcs3400_mode mode;
+ int data;
+ int ret;
+
+ if (rate == 0) {
+ /* Suspend driver */
+ mode = TCS3400_MODE_SUSPEND;
+ } else {
+ /*
+ * We set the sensor for continuous mode,
+ * integrating over 800ms.
+ * Do not allow range higher than 1Hz.
+ */
+ if (rate > 1000)
+ rate = 1000;
+ mode = TCS3400_MODE_COLLECTING;
+ }
+ TCS3400_DRV_DATA(s)->rate = rate;
+
+ ret = tcs3400_i2c_read8(s, TCS_I2C_ENABLE, &data);
+ if (ret)
+ return ret;
+
+ data = (data & TCS_I2C_ENABLE_MASK) | mode;
+ ret = tcs3400_i2c_write8(s, TCS_I2C_ENABLE, data);
+
+ return ret;
+}
+
+/**
+ * Initialise TCS3400 light sensor.
+ */
+static int tcs3400_rgb_init(const struct motion_sensor_t *s)
+{
+ return sensor_init_done(s);
+}
+
+static int tcs3400_init(const struct motion_sensor_t *s)
+{
+ /*
+ * These are default power-on register values with two exceptions:
+ * Set ATIME = 0 (712 ms)
+ * Set AGAIN = 16 (0x10) (AGAIN is in CONTROL register)
+ */
+ const struct reg_data {
+ uint8_t reg;
+ uint8_t data;
+ } defaults[] = {
+ { TCS_I2C_ENABLE, 0 },
+ { TCS_I2C_ATIME, TCS_DEFAULT_ATIME },
+ { TCS_I2C_WTIME, 0xFF },
+ { TCS_I2C_AILTL, 0 },
+ { TCS_I2C_AILTH, 0 },
+ { TCS_I2C_AIHTL, 0 },
+ { TCS_I2C_AIHTH, 0 },
+ { TCS_I2C_PERS, 0 },
+ { TCS_I2C_CONFIG, 0x40 },
+ { TCS_I2C_CONTROL, (TCS_DEFAULT_AGAIN & TCS_I2C_CONTROL_MASK)},
+ { TCS_I2C_AUX, 0 },
+ { TCS_I2C_IR, 0 },
+ { TCS_I2C_CICLEAR, 0 },
+ { TCS_I2C_AICLEAR, 0 }
+ };
+ int data = 0;
+ int ret;
+
+ ret = tcs3400_i2c_read8(s, TCS_I2C_ID, &data);
+ if (ret) {
+ CPRINTS("failed reading ID reg 0x%x, ret=%d", TCS_I2C_ID, ret);
+ return ret;
+ }
+ if ((data != TCS340015_DEVICE_ID) && (data != TCS340037_DEVICE_ID)) {
+ CPRINTS("no ID match, data = 0x%x", data);
+ return EC_ERROR_ACCESS_DENIED;
+ }
+
+ /* reset chip to default power-on settings, changes ATIME and CONTROL */
+ for (int x = 0; x < ARRAY_SIZE(defaults); x++) {
+ ret = tcs3400_i2c_write8(s, defaults[x].reg, defaults[x].data);
+ if (ret)
+ return ret;
+ }
+
+ return sensor_init_done(s);
+}
+
+const struct accelgyro_drv tcs3400_drv = {
+ .init = tcs3400_init,
+ .read = tcs3400_read,
+ .set_range = tcs3400_set_range,
+ .get_range = tcs3400_get_range,
+ .set_offset = tcs3400_set_offset,
+ .get_offset = tcs3400_get_offset,
+ .set_data_rate = tcs3400_set_data_rate,
+ .get_data_rate = tcs3400_get_data_rate,
+#ifdef CONFIG_ACCEL_INTERRUPTS
+ .irq_handler = tcs3400_irq_handler,
+#endif
+};
+
+const struct accelgyro_drv tcs3400_rgb_drv = {
+ .init = tcs3400_rgb_init,
+ .read = tcs3400_rgb_read,
+ .set_range = tcs3400_rgb_set_range,
+ .get_range = tcs3400_rgb_get_range,
+ .set_offset = tcs3400_rgb_set_offset,
+ .get_offset = tcs3400_rgb_get_offset,
+ .set_scale = tcs3400_rgb_set_scale,
+ .get_scale = tcs3400_rgb_get_scale,
+ .set_data_rate = tcs3400_rgb_set_data_rate,
+ .get_data_rate = tcs3400_rgb_get_data_rate,
+};
diff --git a/driver/als_tcs3400.h b/driver/als_tcs3400.h
new file mode 100644
index 0000000000..bfe1f0e5ab
--- /dev/null
+++ b/driver/als_tcs3400.h
@@ -0,0 +1,121 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * AMS TCS3400 light sensor driver
+ */
+
+#ifndef __CROS_EC_ALS_TCS3400_H
+#define __CROS_EC_ALS_TCS3400_H
+
+/* I2C Interface */
+#define TCS3400_I2C_ADDR__7bf 0x39
+
+/* ID for TCS34001 and TCS34005 */
+#define TCS340015_DEVICE_ID 0x90
+
+/* ID for TCS34003 and TCS34007 */
+#define TCS340037_DEVICE_ID 0x93
+
+/* Register Map */
+#define TCS_I2C_ENABLE 0x80 /* R/W Enables states and interrupts */
+#define TCS_I2C_ATIME 0x81 /* R/W RGBC integration time */
+#define TCS_I2C_WTIME 0x83 /* R/W Wait time */
+#define TCS_I2C_AILTL 0x84 /* R/W Clear irq low threshold low byte */
+#define TCS_I2C_AILTH 0x85 /* R/W Clear irq low threshold high byte */
+#define TCS_I2C_AIHTL 0x86 /* R/W Clear irq high threshold low byte */
+#define TCS_I2C_AIHTH 0x87 /* R/W Clear irq high threshold high byte */
+#define TCS_I2C_PERS 0x8C /* R/W Interrupt persistence filter */
+#define TCS_I2C_CONFIG 0x8D /* R/W Configuration */
+#define TCS_I2C_CONTROL 0x8F /* R/W Gain control register */
+#define TCS_I2C_AUX 0x90 /* R/W Auxiliary control register */
+#define TCS_I2C_REVID 0x91 /* R Revision ID */
+#define TCS_I2C_ID 0x92 /* R Device ID */
+#define TCS_I2C_STATUS 0x93 /* R Device status */
+#define TCS_I2C_CDATAL 0x94 /* R Clear / IR channel low data register */
+#define TCS_I2C_CDATAH 0x95 /* R Clear / IR channel high data register */
+#define TCS_I2C_RDATAL 0x96 /* R Red ADC low data register */
+#define TCS_I2C_RDATAH 0x97 /* R Red ADC high data register */
+#define TCS_I2C_GDATAL 0x98 /* R Green ADC low data register */
+#define TCS_I2C_GDATAH 0x99 /* R Green ADC high data register */
+#define TCS_I2C_BDATAL 0x9A /* R Blue ADC low data register */
+#define TCS_I2C_BDATAH 0x9B /* R Blue ADC high data register */
+#define TCS_I2C_IR 0xC0 /* R/W Access IR Channel */
+#define TCS_I2C_IFORCE 0xE4 /* W Force Interrupt */
+#define TCS_I2C_CICLEAR 0xE6 /* W Clear channel interrupt clear */
+#define TCS_I2C_AICLEAR 0xE7 /* W Clear all interrupts */
+
+#define TCS_I2C_ENABLE_POWER_ON BIT(0)
+#define TCS_I2C_ENABLE_ADC_ENABLE BIT(1)
+#define TCS_I2C_ENABLE_WAIT_ENABLE BIT(3)
+#define TCS_I2C_ENABLE_INT_ENABLE BIT(4)
+#define TCS_I2C_ENABLE_SLEEP_AFTER_INT BIT(6)
+#define TCS_I2C_ENABLE_MASK (TCS_I2C_ENABLE_POWER_ON | \
+ TCS_I2C_ENABLE_ADC_ENABLE | \
+ TCS_I2C_ENABLE_WAIT_ENABLE | \
+ TCS_I2C_ENABLE_INT_ENABLE | \
+ TCS_I2C_ENABLE_SLEEP_AFTER_INT)
+
+enum tcs3400_mode {
+ TCS3400_MODE_SUSPEND = 0,
+ TCS3400_MODE_IDLE = (TCS_I2C_ENABLE_POWER_ON |
+ TCS_I2C_ENABLE_ADC_ENABLE),
+ TCS3400_MODE_COLLECTING = (TCS_I2C_ENABLE_POWER_ON |
+ TCS_I2C_ENABLE_ADC_ENABLE |
+ TCS_I2C_ENABLE_INT_ENABLE),
+};
+
+#define TCS_I2C_CONTROL_MASK 0x03
+#define TCS_I2C_STATUS_RGBC_VALID BIT(0)
+#define TCS_I2C_STATUS_ALS_IRQ BIT(4)
+#define TCS_I2C_STATUS_ALS_VALID BIT(7)
+
+#define TCS_I2C_AUX_ASL_INT_ENABLE BIT(5)
+
+/* Light data resides at 0x94 thru 0x98 */
+#define TCS_DATA_START_LOCATION TCS_I2C_CDATAL
+#define TCS_CLEAR_DATA_SIZE 2
+#define TCS_RGBC_DATA_SIZE 8
+
+/* Min and Max sampling frequency in mHz */
+#define TCS3400_LIGHT_MIN_FREQ 149
+#define TCS3400_LIGHT_MAX_FREQ 10000
+#if (CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ <= TCS3400_LIGHT_MAX_FREQ)
+#error "EC too slow for light sensor"
+#endif
+
+#define TCS3400_DRV_DATA(_s) ((struct als_drv_data_t *)(_s)->drv_data)
+#define TCS3400_RGB_DRV_DATA(_s) \
+ ((struct tcs3400_rgb_drv_data_t *)(_s)->drv_data)
+
+/* NOTE: The higher the ATIME value in reg, the shorter the accumulation time */
+#define TCS_MIN_ATIME 0x00 /* 712 ms */
+#define TCS_MAX_ATIME 0x70 /* 400 ms */
+#define TCS_DEFAULT_ATIME TCS_MIN_ATIME /* 712 ms */
+
+#define TCS_MIN_AGAIN 0x00 /* 1x gain */
+#define TCS_MAX_AGAIN 0x03 /* 64x gain */
+#define TCS_DEFAULT_AGAIN 0x02 /* 16x gain */
+
+/* tcs3400 rgb als driver data */
+struct tcs3400_rgb_drv_data_t {
+ /*
+ * device_scale and device_uscale are used to adjust raw rgb channel
+ * values prior to applying any channel-specific scaling required.
+ * raw_value += rgb_cal.offset;
+ * adjusted_value = raw_value * device_scale +
+ * raw_value * device_uscale / 10000;
+ */
+ uint16_t device_scale;
+ uint16_t device_uscale;
+
+ int rate; /* holds current sensor rate */
+ int last_value[3]; /* holds last RGB values */
+ struct rgb_calibration_t rgb_cal[3]; /* calibration data */
+};
+
+extern const struct accelgyro_drv tcs3400_drv;
+extern const struct accelgyro_drv tcs3400_rgb_drv;
+
+void tcs3400_interrupt(enum gpio_signal signal);
+#endif /* __CROS_EC_ALS_TCS3400_H */
diff --git a/driver/baro_bmp280.c b/driver/baro_bmp280.c
index b622535819..10d1c4b91a 100644
--- a/driver/baro_bmp280.c
+++ b/driver/baro_bmp280.c
@@ -98,7 +98,7 @@ static int bmp280_get_calib_param(const struct motion_sensor_t *s)
uint8_t a_data_u8[BMP280_CALIB_DATA_SIZE] = {0};
struct bmp280_drv_data_t *data = BMP280_GET_DATA(s);
- ret = i2c_read_block(s->port, s->addr,
+ ret = i2c_read_block__7bf(s->port, s->i2c_spi_addr__7bf,
BMP280_TEMPERATURE_CALIB_DIG_T1_LSB_REG,
a_data_u8, BMP280_CALIB_DATA_SIZE);
@@ -129,7 +129,7 @@ static int bmp280_read_uncomp_pressure(const struct motion_sensor_t *s,
int ret;
uint8_t a_data_u8[BMP280_PRESSURE_DATA_SIZE] = {0};
- ret = i2c_read_block(s->port, s->addr,
+ ret = i2c_read_block__7bf(s->port, s->i2c_spi_addr__7bf,
BMP280_PRESSURE_MSB_REG,
a_data_u8, BMP280_PRESSURE_DATA_SIZE);
@@ -218,13 +218,13 @@ static int bmp280_set_standby_durn(const struct motion_sensor_t *s,
{
int ret, val;
- ret = i2c_read8(s->port, s->addr,
+ ret = i2c_read8__7bf(s->port, s->i2c_spi_addr__7bf,
BMP280_CONFIG_REG, &val);
if (ret == EC_SUCCESS) {
val = (val & 0xE0) | ((durn << 5) & 0xE0);
/* write the standby duration*/
- ret = i2c_write8(s->port, s->addr,
+ ret = i2c_write8__7bf(s->port, s->i2c_spi_addr__7bf,
BMP280_CONFIG_REG, val);
}
@@ -239,7 +239,8 @@ static int bmp280_set_power_mode(const struct motion_sensor_t *s,
val = (BMP280_OVERSAMP_TEMP << 5) +
(BMP280_OVERSAMP_PRES << 2) + power_mode;
- return i2c_write8(s->port, s->addr, BMP280_CTRL_MEAS_REG, val);
+ return i2c_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMP280_CTRL_MEAS_REG, val);
}
static int bmp280_set_range(const struct motion_sensor_t *s,
@@ -277,7 +278,7 @@ static int bmp280_init(const struct motion_sensor_t *s)
return EC_ERROR_INVAL;
/* Read chip id */
- ret = i2c_read8(s->port, s->addr,
+ ret = i2c_read8__7bf(s->port, s->i2c_spi_addr__7bf,
BMP280_CHIP_ID_REG, &val);
if (ret)
return ret;
@@ -383,7 +384,7 @@ struct i2c_stress_test_dev bmp280_i2c_stress_test_dev = {
.read_val = BMP280_CHIP_ID,
.write_reg = BMP280_CONFIG_REG,
},
- .i2c_read = &i2c_read8,
- .i2c_write = &i2c_write8,
+ .i2c_read__7bf = &i2c_read8__7bf,
+ .i2c_write__7bf = &i2c_write8__7bf,
};
#endif /* CONFIG_CMD_I2C_STRESS_TEST_ACCEL */
diff --git a/driver/baro_bmp280.h b/driver/baro_bmp280.h
index be2611289c..484f7a8615 100644
--- a/driver/baro_bmp280.h
+++ b/driver/baro_bmp280.h
@@ -74,8 +74,9 @@
* Bit 1 of 7-bit address: 0 - If SDO is connected to GND
* Bit 1 of 7-bit address: 1 - If SDO is connected to Vddio
*/
-#define BMP280_I2C_ADDRESS1 ((0x76) << 1)
-#define BMP280_I2C_ADDRESS2 ((0x77) << 1)
+#define BMP280_I2C_ADDRESS1__7bf 0x76
+#define BMP280_I2C_ADDRESS2__7bf 0x77
+
/*
* CHIP ID
*/
diff --git a/driver/battery/bq27541.c b/driver/battery/bq27541.c
index b01aef3714..13c7689e8b 100644
--- a/driver/battery/bq27541.c
+++ b/driver/battery/bq27541.c
@@ -12,7 +12,7 @@
#include "i2c.h"
#include "util.h"
-#define BQ27541_ADDR 0xaa
+#define BQ27541_ADDR__7bf 0x55
#define BQ27541_TYPE_ID 0x0541
#define BQ27741_TYPE_ID 0x0741
#define BQ27742_TYPE_ID 0x0742
diff --git a/driver/battery/bq27621_g1.c b/driver/battery/bq27621_g1.c
index 304fe67241..c242d54461 100644
--- a/driver/battery/bq27621_g1.c
+++ b/driver/battery/bq27621_g1.c
@@ -13,7 +13,7 @@
#include "util.h"
#include "timer.h"
-#define BQ27621_ADDR 0xaa
+#define BQ27621_ADDR__7bf 0x55
#define BQ27621_TYPE_ID 0x0621
#define REG_CTRL 0x00
diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c
index d0e0124468..f11be99f96 100644
--- a/driver/battery/max17055.c
+++ b/driver/battery/max17055.c
@@ -65,12 +65,14 @@ static int fake_state_of_charge = -1;
static int max17055_read(int offset, int *data)
{
- return i2c_read16(I2C_PORT_BATTERY, MAX17055_ADDR, offset, data);
+ return i2c_read16__7bf(I2C_PORT_BATTERY, MAX17055_ADDR__7bf,
+ offset, data);
}
static int max17055_write(int offset, int data)
{
- return i2c_write16(I2C_PORT_BATTERY, MAX17055_ADDR, offset, data);
+ return i2c_write16__7bf(I2C_PORT_BATTERY, MAX17055_ADDR__7bf,
+ offset, data);
}
/* Return 1 if the device id is correct. */
diff --git a/driver/battery/max17055.h b/driver/battery/max17055.h
index 5a3764d9de..1e1c2e8c42 100644
--- a/driver/battery/max17055.h
+++ b/driver/battery/max17055.h
@@ -8,7 +8,7 @@
#ifndef __CROS_EC_MAX17055_H
#define __CROS_EC_MAX17055_H
-#define MAX17055_ADDR 0x6c
+#define MAX17055_ADDR__7bf 0x36
#define MAX17055_DEVICE_ID 0x4010
#define REG_STATUS 0x00
diff --git a/driver/battery/mm8013.c b/driver/battery/mm8013.c
index 012f3a25bd..87926553db 100644
--- a/driver/battery/mm8013.c
+++ b/driver/battery/mm8013.c
@@ -23,7 +23,7 @@ static int mm8013_read16(int offset, int *data)
int rv;
*data = 0;
- rv = i2c_read16(I2C_PORT_BATTERY, MM8013_ADDR, offset, data);
+ rv = i2c_read16__7bf(I2C_PORT_BATTERY, MM8013_ADDR__7bf, offset, data);
usleep(I2C_WAIT_TIME);
if (rv)
return rv;
@@ -34,7 +34,8 @@ static int mm8013_read_block(int offset, uint8_t *data, int len)
{
int rv;
- rv = i2c_read_block(I2C_PORT_BATTERY, MM8013_ADDR, offset, data, len);
+ rv = i2c_read_block__7bf(I2C_PORT_BATTERY, MM8013_ADDR__7bf,
+ offset, data, len);
usleep(I2C_WAIT_TIME);
if (rv)
return rv;
diff --git a/driver/battery/mm8013.h b/driver/battery/mm8013.h
new file mode 100644
index 0000000000..5acdcdff68
--- /dev/null
+++ b/driver/battery/mm8013.h
@@ -0,0 +1,40 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Battery driver for MM8013.
+ */
+
+#ifndef __CROS_EC_MM8013_H
+#define __CROS_EC_MM8013_H
+
+#define MM8013_ADDR__7bf 0x55
+
+#define REG_TEMPERATURE 0x06
+#define REG_VOLTAGE 0x08
+#define REG_FLAGS 0x0a
+#define REG_FULL_CHARGE_CAPACITY 0x0e
+#define REG_REMAINING_CAPACITY 0x10
+#define REG_AVERAGE_CURRENT 0x14
+#define REG_AVERAGE_TIME_TO_EMPTY 0x16
+#define REG_AVERAGE_TIME_TO_FULL 0x18
+#define REG_STATE_OF_CHARGE 0x2c
+#define REG_CYCLE_COUNT 0x2a
+#define REG_DESIGN_CAPACITY 0x3c
+#define REG_PRODUCT_INFORMATION 0x64
+
+/* Over Temperature in charge */
+#define MM8013_FLAG_OTC BIT(15)
+/* Over Temperature in discharge */
+#define MM8013_FLAG_OTD BIT(14)
+/* Over-charge */
+#define MM8013_FLAG_BATHI BIT(13)
+/* Full Charge */
+#define MM8013_FLAG_FC BIT(9)
+/* Charge allowed */
+#define MM8013_FLAG_CHG BIT(8)
+/* Discharge */
+#define MM8013_FLAG_DSG BIT(0)
+
+
+#endif /* __CROS_EC_MM8013_H */
diff --git a/driver/battery/smart.c b/driver/battery/smart.c
index 7a47a93f19..d231ce6148 100644
--- a/driver/battery/smart.c
+++ b/driver/battery/smart.c
@@ -30,7 +30,9 @@ test_mockable int sb_read(int cmd, int *param)
if (battery_is_cut_off())
return EC_RES_ACCESS_DENIED;
#endif
- return i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param);
+
+ return i2c_read16__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ cmd, param);
}
test_mockable int sb_write(int cmd, int param)
@@ -42,7 +44,9 @@ test_mockable int sb_write(int cmd, int param)
if (battery_is_cut_off())
return EC_RES_ACCESS_DENIED;
#endif
- return i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param);
+
+ return i2c_write16__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ cmd, param);
}
int sb_read_string(int offset, uint8_t *data, int len)
@@ -54,8 +58,9 @@ int sb_read_string(int offset, uint8_t *data, int len)
if (battery_is_cut_off())
return EC_RES_ACCESS_DENIED;
#endif
- return i2c_read_string(I2C_PORT_BATTERY, BATTERY_ADDR,
- offset, data, len);
+
+ return i2c_read_string__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ offset, data, len);
}
int sb_read_mfgacc(int cmd, int block, uint8_t *data, int len)
@@ -99,8 +104,8 @@ int sb_write_block(int reg, const uint8_t *val, int len)
#endif
/* TODO: implement smbus_write_block. */
- return i2c_write_block(I2C_PORT_BATTERY, BATTERY_ADDR, reg, val, len);
-
+ return i2c_write_block__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ reg, val, len);
}
int battery_get_mode(int *mode)
diff --git a/driver/bc12/pi3usb9201.c b/driver/bc12/pi3usb9201.c
new file mode 100644
index 0000000000..2fdb9719a5
--- /dev/null
+++ b/driver/bc12/pi3usb9201.c
@@ -0,0 +1,369 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* PI3USB9201 USB BC 1.2 Charger Detector driver. */
+
+#include "pi3usb9201.h"
+#include "charge_manager.h"
+#include "chipset.h"
+#include "common.h"
+#include "console.h"
+#include "gpio.h"
+#include "power.h"
+#include "task.h"
+#include "tcpm.h"
+#include "timer.h"
+#include "usb_charge.h"
+#include "usb_pd.h"
+#include "util.h"
+
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+
+enum pi3usb9201_client_sts {
+ CHG_OTHER = 0,
+ CHG_2_4A,
+ CHG_2_0A,
+ CHG_1_0A,
+ CHG_RESERVED,
+ CHG_CDP,
+ CHG_SDP,
+ CHG_DCP,
+};
+
+struct bc12_status {
+ enum charge_supplier supplier;
+ int current_limit;
+};
+
+/* Used to store last BC1.2 detection result */
+static enum charge_supplier bc12_supplier[CONFIG_USB_PD_PORT_COUNT];
+
+static const struct bc12_status bc12_chg_limits[] = {
+ [CHG_OTHER] = {CHARGE_SUPPLIER_OTHER, 500},
+ [CHG_2_4A] = {CHARGE_SUPPLIER_PROPRIETARY, 2400},
+ [CHG_2_0A] = {CHARGE_SUPPLIER_PROPRIETARY, 2000},
+ [CHG_1_0A] = {CHARGE_SUPPLIER_PROPRIETARY, 1000},
+ [CHG_RESERVED] = {CHARGE_SUPPLIER_NONE, 0},
+ [CHG_CDP] = {CHARGE_SUPPLIER_BC12_CDP, 1500},
+ [CHG_SDP] = {CHARGE_SUPPLIER_BC12_SDP, 500},
+#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW)
+ /*
+ * If ramping is supported, then for DCP set the current limit to be the
+ * max supported for the port by the board. This because for DCP the
+ * charger is allowed to set its own max up to 5A.
+ */
+ [CHG_DCP] = {CHARGE_SUPPLIER_BC12_DCP, PD_MAX_CURRENT_MA},
+#else
+ [CHG_DCP] = {CHARGE_SUPPLIER_BC12_DCP, 500},
+#endif
+};
+
+static inline int raw_read8(int port, int offset, int *value)
+{
+ return i2c_read8__7bf(pi3usb2901_bc12_chips[port].i2c_port,
+ pi3usb2901_bc12_chips[port].i2c_addr__7bf,
+ offset, value);
+}
+
+static inline int raw_write8(int port, int offset, int value)
+{
+ return i2c_write8__7bf(pi3usb2901_bc12_chips[port].i2c_port,
+ pi3usb2901_bc12_chips[port].i2c_addr__7bf,
+ offset, value);
+}
+
+static int pi3usb9201_raw(int port, int reg, int mask, int val)
+{
+ int rv;
+ int reg_val;
+
+ rv = raw_read8(port, reg, &reg_val);
+ if (rv)
+ return rv;
+
+ reg_val &= ~mask;
+ reg_val |= val;
+
+ return raw_write8(port, reg, reg_val);
+}
+
+static int pi3usb9201_interrupt_mask(int port, int enable)
+{
+ return pi3usb9201_raw(port, PI3USB9201_REG_CTRL_1,
+ PI3USB9201_REG_CTRL_1_INT_MASK,
+ enable);
+}
+
+static int pi3usb9201_bc12_detect_ctrl(int port, int enable)
+{
+ return pi3usb9201_raw(port, PI3USB9201_REG_CTRL_2,
+ PI3USB9201_REG_CTRL_2_START_DET,
+ enable ? PI3USB9201_REG_CTRL_2_START_DET : 0);
+}
+
+static int pi3usb9201_set_mode(int port, int desired_mode)
+{
+ return pi3usb9201_raw(port, PI3USB9201_REG_CTRL_1,
+ PI3USB9201_REG_CTRL_1_MODE_MASK,
+ desired_mode << PI3USB9201_REG_CTRL_1_MODE_SHIFT);
+}
+
+static int pi3usb9201_get_mode(int port, int *mode)
+{
+ int rv;
+
+ rv = raw_read8(port, PI3USB9201_REG_CTRL_1, mode);
+ if (rv)
+ return rv;
+
+ *mode &= PI3USB9201_REG_CTRL_1_MODE_MASK;
+ *mode >>= PI3USB9201_REG_CTRL_1_MODE_SHIFT;
+
+ return EC_SUCCESS;
+}
+
+static int pi3usb9201_get_status(int port, int *client, int *host)
+{
+ int rv;
+ int status;
+
+ rv = raw_read8(port, PI3USB9201_REG_CLIENT_STS, &status);
+ if (client)
+ *client = status;
+ rv |= raw_read8(port, PI3USB9201_REG_HOST_STS, &status);
+ if (host)
+ *host = status;
+
+ return rv;
+}
+
+static void bc12_update_supplier(enum charge_supplier supplier, int port,
+ struct charge_port_info *new_chg)
+{
+ /*
+ * If most recent supplier type is not CHARGE_SUPPLIER_NONE, then the
+ * charge manager table entry for that supplier type needs to be cleared
+ * out.
+ */
+ if (bc12_supplier[port] != CHARGE_SUPPLIER_NONE)
+ charge_manager_update_charge(bc12_supplier[port], port, NULL);
+ /* Now update the current supplier type */
+ bc12_supplier[port] = supplier;
+ /* If new supplier type != NONE, then notify charge manager */
+ if (supplier != CHARGE_SUPPLIER_NONE)
+ charge_manager_update_charge(supplier, port, new_chg);
+}
+
+static void bc12_update_charge_manager(int port, int client_status)
+{
+ struct charge_port_info new_chg;
+ enum charge_supplier supplier;
+ int bit_pos;
+
+ /* Set charge voltage to 5V */
+ new_chg.voltage = USB_CHARGER_VOLTAGE_MV;
+
+ /*
+ * Find set bit position. Note that this funciton is only called if a
+ * bit was set in client_status, so bit_pos won't be negative.
+ */
+ bit_pos = __builtin_ffs(client_status) - 1;
+
+ new_chg.current = bc12_chg_limits[bit_pos].current_limit;
+ supplier = bc12_chg_limits[bit_pos].supplier;
+
+ CPRINTS("pi3usb9201[p%d]: sts = 0x%x, lim = %d mA, supplier = %d",
+ port, client_status, new_chg.current, supplier);
+ /* bc1.2 is complete and start bit does not auto clear */
+ pi3usb9201_bc12_detect_ctrl(port, 0);
+ /* Inform charge manager of new supplier type and current limit */
+ bc12_update_supplier(supplier, port, &new_chg);
+}
+
+static int bc12_detect_start(int port)
+{
+ int rv;
+
+ /*
+ * Read both status registers to ensure that all interrupt indications
+ * are cleared prior to starting bc1.2 detection.
+ */
+ pi3usb9201_get_status(port, NULL, NULL);
+
+ /* Put pi3usb9201 into client mode */
+ rv = pi3usb9201_set_mode(port, PI3USB9201_CLIENT_MODE);
+ if (rv)
+ return rv;
+ /* Have pi3usb9201 start bc1.2 detection */
+ rv = pi3usb9201_bc12_detect_ctrl(port, 1);
+ if (rv)
+ return rv;
+ /* Unmask interrupt to wake task when detection completes */
+ return pi3usb9201_interrupt_mask(port, 0);
+}
+
+static void bc12_power_down(int port)
+{
+ /* Put pi3usb9201 into its power down mode */
+ pi3usb9201_set_mode(port, PI3USB9201_POWER_DOWN);
+ /* The start bc1.2 bit does not auto clear */
+ pi3usb9201_bc12_detect_ctrl(port, 0);
+ /* Mask interrupts unitl next bc1.2 detection event */
+ pi3usb9201_interrupt_mask(port, 1);
+ /*
+ * Let charge manager know there's no more charge available for the
+ * supplier type that was most recently detected.
+ */
+ bc12_update_supplier(CHARGE_SUPPLIER_NONE, port, NULL);
+#if defined(CONFIG_POWER_PP5000_CONTROL) && defined(HAS_TASK_CHIPSET)
+ /* Indicate PP5000_A rail is not required by USB_CHG task. */
+ power_5v_enable(task_get_current(), 0);
+#endif
+}
+
+static void bc12_power_up(int port)
+{
+#if defined(CONFIG_POWER_PP5000_CONTROL) && defined(HAS_TASK_CHIPSET)
+ /* Turn on the 5V rail to allow the chip to be powered. */
+ power_5v_enable(task_get_current(), 1);
+ /* Give the pi3usb9201 time so it's ready to receive i2c messages */
+ msleep(1);
+#endif
+ pi3usb9201_interrupt_mask(port, 1);
+}
+
+void usb_charger_task(void *u)
+{
+ int port = (task_get_current() == TASK_ID_USB_CHG_P0 ? 0 : 1);
+ uint32_t evt;
+ int i;
+
+ /*
+ * Set most recent bc1.2 detection supplier result to
+ * CHARGE_SUPPLIER_NONE for all ports.
+ */
+ for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++)
+ bc12_supplier[port] = CHARGE_SUPPLIER_NONE;
+
+ /*
+ * The is no specific initialization required for the pi3usb9201 other
+ * than enabling the interrupt mask.
+ */
+ pi3usb9201_interrupt_mask(port, 1);
+
+ while (1) {
+ /* Wait for interrupt */
+ evt = task_wait_event(-1);
+
+ /* Interrupt from the Pericom chip, determine charger type */
+ if (evt & USB_CHG_EVENT_BC12) {
+ int client;
+ int rv;
+
+ rv = pi3usb9201_get_status(port, &client, NULL);
+ if (!rv && client)
+ /*
+ * Any bit set in client status register
+ * indicates that BC1.2 detection has
+ * completed.
+ */
+ bc12_update_charge_manager(port, client);
+ }
+
+#ifndef CONFIG_USB_PD_VBUS_DETECT_TCPC
+ if (evt & USB_CHG_EVENT_VBUS)
+ CPRINTS("VBUS p%d %d", port,
+ pd_snk_is_vbus_provided(port));
+#endif
+
+ if (evt & USB_CHG_EVENT_DR_UFP) {
+ bc12_power_up(port);
+ if (bc12_detect_start(port)) {
+ struct charge_port_info new_chg;
+
+ /*
+ * VBUS is present, but starting bc1.2 detection
+ * failed for some reason. So limit charge
+ * current to default 500 mA for this case.
+ */
+
+ new_chg.voltage = USB_CHARGER_VOLTAGE_MV;
+ new_chg.current = USB_CHARGER_MIN_CURR_MA;
+ /* Save supplier type and notify chg manager */
+ bc12_update_supplier(CHARGE_SUPPLIER_OTHER,
+ port, &new_chg);
+ CPRINTS("pi3usb9201[p%d]: bc1.2 failed use "
+ "defaults", port);
+ }
+ }
+
+ /*
+ * TODO(b/124061702): For host mode, currently only setting it
+ * to host CDP mode. However, there are 3 host status bits to
+ * know things such as an adapter connected, but no USB device
+ * present, or bc1.2 activity detected.
+ */
+ if (evt & USB_CHG_EVENT_DR_DFP) {
+ int mode;
+ int rv;
+
+ /*
+ * Update the charge manager if bc1.2 client mode is
+ * currently active.
+ */
+ bc12_update_supplier(CHARGE_SUPPLIER_NONE, port, NULL);
+ /*
+ * If the port is in DFP mode, then need to set mode to
+ * CDP_HOST which will auto close D+/D- switches.
+ */
+ bc12_power_up(port);
+ rv = pi3usb9201_get_mode(port, &mode);
+ if (!rv && (mode != PI3USB9201_CDP_HOST_MODE))
+ pi3usb9201_set_mode(port,
+ PI3USB9201_CDP_HOST_MODE);
+ }
+
+ if (evt & USB_CHG_EVENT_CC_OPEN)
+ bc12_power_down(port);
+ }
+}
+
+void usb_charger_set_switches(int port, enum usb_switch setting)
+{
+ /*
+ * Switches are controlled automatically based on whether the port is
+ * acting as a source or as sink and the result of BC1.2 detection.
+ */
+}
+
+#if defined(CONFIG_CHARGE_RAMP_SW) || defined(CONFIG_CHARGE_RAMP_HW)
+int usb_charger_ramp_allowed(int supplier)
+{
+ /* Don't allow ramp if charge supplier is OTHER, SDP, or NONE */
+ return !(supplier == CHARGE_SUPPLIER_OTHER ||
+ supplier == CHARGE_SUPPLIER_BC12_SDP ||
+ supplier == CHARGE_SUPPLIER_NONE);
+}
+
+int usb_charger_ramp_max(int supplier, int sup_curr)
+{
+ /*
+ * Use the level from the bc12_chg_limits table above except for
+ * proprietary of CDP and in those cases the charge current from the
+ * charge manager is already set at the max determined by bc1.2
+ * detection.
+ */
+ switch (supplier) {
+ case CHARGE_SUPPLIER_BC12_DCP:
+ return PD_MAX_CURRENT_MA;
+ case CHARGE_SUPPLIER_BC12_CDP:
+ case CHARGE_SUPPLIER_PROPRIETARY:
+ return sup_curr;
+ case CHARGE_SUPPLIER_BC12_SDP:
+ default:
+ return 500;
+ }
+}
+#endif /* CONFIG_CHARGE_RAMP_SW || CONFIG_CHARGE_RAMP_HW */
diff --git a/driver/bc12/pi3usb9201.h b/driver/bc12/pi3usb9201.h
new file mode 100644
index 0000000000..ba379ffff3
--- /dev/null
+++ b/driver/bc12/pi3usb9201.h
@@ -0,0 +1,52 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* PI3USB9201 USB BC 1.2 Charger Detector driver definitions */
+
+/* I2C address */
+#define PI3USB9201_I2C_ADDR_0__7bf 0x5C
+#define PI3USB9201_I2C_ADDR_1__7bf 0x5D
+#define PI3USB9201_I2C_ADDR_2__7bf 0x5E
+#define PI3USB9201_I2C_ADDR_3__7bf 0x5F
+
+#define PI3USB9201_REG_CTRL_1 0x0
+#define PI3USB9201_REG_CTRL_2 0x1
+#define PI3USB9201_REG_CLIENT_STS 0x2
+#define PI3USB9201_REG_HOST_STS 0x3
+
+/* Control_1 regiter bit definitions */
+#define PI3USB9201_REG_CTRL_1_INT_MASK BIT(0)
+#define PI3USB9201_REG_CTRL_1_MODE_SHIFT 1
+#define PI3USB9201_REG_CTRL_1_MODE_MASK (0x7 << \
+ PI3USB9201_REG_CTRL_1_MODE_SHIFT)
+
+/* Control_2 regiter bit definitions */
+#define PI3USB9201_REG_CTRL_2_AUTO_SW BIT(1)
+#define PI3USB9201_REG_CTRL_2_START_DET BIT(3)
+
+/* Host status register bit definitions */
+#define PI3USB9201_REG_HOST_STS_BC12_DET BIT(0)
+#define PI3USB9201_REG_HOST_STS_DEV_PLUG BIT(1)
+#define PI3USB9201_REG_HOST_STS_DEV_UNPLUG BIT(2)
+
+struct pi3usb2901_config_t {
+ const int i2c_port;
+ const int i2c_addr__7bf;
+};
+
+enum pi3usb9201_mode {
+ PI3USB9201_POWER_DOWN,
+ PI3USB9201_SDP_HOST_MODE,
+ PI3USB9201_DCP_HOST_MODE,
+ PI3USB9201_CDP_HOST_MODE,
+ PI3USB9201_CLIENT_MODE,
+ PI3USB9201_RESERVED_1,
+ PI3USB9201_RESERVED_2,
+ PI3USB9201_USB_PATH_ON,
+};
+
+/* Configuration struct defined at board level */
+extern const struct pi3usb2901_config_t pi3usb2901_bc12_chips[];
+
diff --git a/driver/bc12/pi3usb9281.c b/driver/bc12/pi3usb9281.c
index f1bd3ce8d4..b1a82b36f4 100644
--- a/driver/bc12/pi3usb9281.c
+++ b/driver/bc12/pi3usb9281.c
@@ -23,8 +23,8 @@
#define CPUTS(outstr) cputs(CC_USBCHARGE, outstr)
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
-/* 8-bit I2C address */
-#define PI3USB9281_I2C_ADDR (0x25 << 1)
+/* I2C address */
+#define PI3USB9281_I2C_ADDR__7bf (0x25)
/* Delay values */
#define PI3USB9281_SW_RESET_DELAY 20
@@ -72,7 +72,8 @@ static uint8_t pi3usb9281_do_read(int port, uint8_t reg, int with_lock)
if (with_lock)
select_chip(port);
- res = i2c_read8(chip->i2c_port, PI3USB9281_I2C_ADDR, reg, &val);
+ res = i2c_read8__7bf(chip->i2c_port, PI3USB9281_I2C_ADDR__7bf,
+ reg, &val);
if (with_lock)
unselect_chip(port);
@@ -102,7 +103,8 @@ static int pi3usb9281_do_write(
if (with_lock)
select_chip(port);
- res = i2c_write8(chip->i2c_port, PI3USB9281_I2C_ADDR, reg, val);
+ res = i2c_write8__7bf(chip->i2c_port, PI3USB9281_I2C_ADDR__7bf,
+ reg, val);
if (with_lock)
unselect_chip(port);
diff --git a/driver/charger/bd9995x.c b/driver/charger/bd9995x.c
index 9ab69a7c38..5b6dc65d4a 100644
--- a/driver/charger/bd9995x.c
+++ b/driver/charger/bd9995x.c
@@ -131,7 +131,7 @@ static inline int ch_raw_read16(int cmd, int *param,
/* Map the Charge command code to appropriate region */
mutex_lock(&bd9995x_map_mutex);
if (charger_map_cmd != map_cmd) {
- rv = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
+ rv = i2c_write16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
BD9995X_CMD_MAP_SET, map_cmd);
if (rv) {
charger_map_cmd = BD9995X_INVALID_COMMAND;
@@ -141,7 +141,8 @@ static inline int ch_raw_read16(int cmd, int *param,
charger_map_cmd = map_cmd;
}
- rv = i2c_read16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, cmd, param);
+ rv = i2c_read16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ cmd, param);
bd9995x_read_cleanup:
mutex_unlock(&bd9995x_map_mutex);
@@ -157,7 +158,7 @@ static inline int ch_raw_write16(int cmd, int param,
/* Map the Charge command code to appropriate region */
mutex_lock(&bd9995x_map_mutex);
if (charger_map_cmd != map_cmd) {
- rv = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
+ rv = i2c_write16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
BD9995X_CMD_MAP_SET, map_cmd);
if (rv) {
charger_map_cmd = BD9995X_INVALID_COMMAND;
@@ -167,7 +168,8 @@ static inline int ch_raw_write16(int cmd, int param,
charger_map_cmd = map_cmd;
}
- rv = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, cmd, param);
+ rv = i2c_write16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ cmd, param);
bd9995x_write_cleanup:
mutex_unlock(&bd9995x_map_mutex);
diff --git a/driver/charger/bd9995x.h b/driver/charger/bd9995x.h
index f9fb092b24..1850d0824a 100644
--- a/driver/charger/bd9995x.h
+++ b/driver/charger/bd9995x.h
@@ -8,8 +8,8 @@
#ifndef __CROS_EC_BD9995X_H
#define __CROS_EC_BD9995X_H
-#define BD9995X_ADDR 0x12 /* 7bit address 0001_001 */
-#define I2C_ADDR_CHARGER BD9995X_ADDR
+#define BD9995X_ADDR__7bf 0x09
+#define I2C_ADDR_CHARGER__7bf BD9995X_ADDR__7bf
#define BD9995X_CHARGER_NAME "bd9995x"
#define BD99955_CHIP_ID 0x221
diff --git a/driver/charger/bq24192.h b/driver/charger/bq24192.h
index 6cf5fdecdb..3150e22f67 100644
--- a/driver/charger/bq24192.h
+++ b/driver/charger/bq24192.h
@@ -8,7 +8,7 @@
#ifndef __CROS_EC_BQ24192_H
#define __CROS_EC_BQ24192_H
-#define BQ24192_ADDR 0xd6
+#define BQ24192_ADDR__7bf 0x6b
/* Registers */
#define BQ24192_REG_INPUT_CTRL 0x0
diff --git a/driver/charger/bq24715.c b/driver/charger/bq24715.c
index 507c44e7da..f3a3a7931e 100644
--- a/driver/charger/bq24715.c
+++ b/driver/charger/bq24715.c
@@ -37,12 +37,14 @@ static const struct charger_info bq24725_charger_info = {
static inline int sbc_read(int cmd, int *param)
{
- return i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, cmd, param);
+ return i2c_read16__7bf(I2C_PORT_CHARGER, CHARGER_ADDR__7bf,
+ cmd, param);
}
static inline int sbc_write(int cmd, int param)
{
- return i2c_write16(I2C_PORT_CHARGER, CHARGER_ADDR, cmd, param);
+ return i2c_write16__7bf(I2C_PORT_CHARGER, CHARGER_ADDR__7bf,
+ cmd, param);
}
int charger_set_input_current(int input_current)
diff --git a/driver/charger/bq24773.h b/driver/charger/bq24773.h
index 216e3d4c77..d58adb6875 100644
--- a/driver/charger/bq24773.h
+++ b/driver/charger/bq24773.h
@@ -12,8 +12,8 @@
#include "i2c.h"
/* I2C address */
-#define BQ24770_ADDR (0x12)
-#define BQ24773_ADDR (0x6a << 1)
+#define BQ24770_ADDR__7bf 0x09
+#define BQ24773_ADDR__7bf 0x6a
/* Chip specific commands */
#define BQ24770_CHARGE_OPTION0 0x12
@@ -72,7 +72,7 @@
#ifdef CONFIG_CHARGER_BQ24770
#define CHARGER_NAME "bq24770"
- #define I2C_ADDR_CHARGER BQ24770_ADDR
+ #define I2C_ADDR_CHARGER__7bf BQ24770_ADDR__7bf
#define REG_CHARGE_OPTION0 BQ24770_CHARGE_OPTION0
#define REG_CHARGE_OPTION1 BQ24770_CHARGE_OPTION1
@@ -88,7 +88,7 @@
#elif defined(CONFIG_CHARGER_BQ24773)
#define CHARGER_NAME "bq24773"
- #define I2C_ADDR_CHARGER BQ24773_ADDR
+ #define I2C_ADDR_CHARGER__7bf BQ24773_ADDR__7bf
#define REG_CHARGE_OPTION0 BQ24773_CHARGE_OPTION0
#define REG_CHARGE_OPTION1 BQ24773_CHARGE_OPTION1
@@ -105,23 +105,27 @@
#ifdef CONFIG_CHARGER_BQ24773
static inline int raw_read8(int offset, int *value)
{
- return i2c_read8(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, offset, value);
+ return i2c_read8__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ offset, value);
}
static inline int raw_write8(int offset, int value)
{
- return i2c_write8(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, offset, value);
+ return i2c_write8__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ offset, value);
}
#endif
static inline int raw_read16(int offset, int *value)
{
- return i2c_read16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, offset, value);
+ return i2c_read16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ offset, value);
}
static inline int raw_write16(int offset, int value)
{
- return i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, offset, value);
+ return i2c_write16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ offset, value);
}
#endif /* __CROS_EC_BQ24773_H */
diff --git a/driver/charger/bq25703.h b/driver/charger/bq25703.h
index db2c246658..a01da5fae8 100644
--- a/driver/charger/bq25703.h
+++ b/driver/charger/bq25703.h
@@ -9,7 +9,7 @@
#define __CROS_EC_BQ25703_H
/* I2C Interface */
-#define BQ25703_I2C_ADDR1 0xD6
+#define BQ25703_I2C_ADDR1__7bf 0x6B
/*
* BC1.2 minimum voltage threshold for BQ25703.
diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c
index a3f5d878c4..27d1c3bf80 100644
--- a/driver/charger/bq25710.c
+++ b/driver/charger/bq25710.c
@@ -45,13 +45,14 @@ static const struct charger_info bq25710_charger_info = {
static inline int raw_read16(int offset, int *value)
{
- return i2c_read16(I2C_PORT_CHARGER, BQ25710_SMBUS_ADDR1, offset, value);
+ return i2c_read16__7bf(I2C_PORT_CHARGER, BQ25710_SMBUS_ADDR1__7bf,
+ offset, value);
}
static inline int raw_write16(int offset, int value)
{
- return i2c_write16(I2C_PORT_CHARGER, BQ25710_SMBUS_ADDR1, offset,
- value);
+ return i2c_write16__7bf(I2C_PORT_CHARGER, BQ25710_SMBUS_ADDR1__7bf,
+ offset, value);
}
#ifdef CONFIG_CHARGE_RAMP_HW
diff --git a/driver/charger/bq25710.h b/driver/charger/bq25710.h
index 317bfee074..37475fc567 100644
--- a/driver/charger/bq25710.h
+++ b/driver/charger/bq25710.h
@@ -9,7 +9,7 @@
#define __CROS_EC_BQ25710_H
/* SMBUS Interface */
-#define BQ25710_SMBUS_ADDR1 0x12
+#define BQ25710_SMBUS_ADDR1__7bf 0x09
#define BQ25703_BC12_MIN_VOLTAGE_MV 1408
diff --git a/driver/charger/bq2589x.h b/driver/charger/bq2589x.h
index ed49aeb661..45538133bf 100644
--- a/driver/charger/bq2589x.h
+++ b/driver/charger/bq2589x.h
@@ -99,13 +99,13 @@
/* Variant-specific configuration */
#if defined(CONFIG_CHARGER_BQ25890)
#define BQ2589X_DEVICE_ID BQ25890_DEVICE_ID
-#define BQ2589X_ADDR (0x6A << 1)
+#define BQ2589X_ADDR__7bf (0x6A)
#elif defined(CONFIG_CHARGER_BQ25895)
#define BQ2589X_DEVICE_ID BQ25895_DEVICE_ID
-#define BQ2589X_ADDR (0x6A << 1)
+#define BQ2589X_ADDR__7bf (0x6A)
#elif defined(CONFIG_CHARGER_BQ25892)
#define BQ2589X_DEVICE_ID BQ25892_DEVICE_ID
-#define BQ2589X_ADDR (0x6B << 1)
+#define BQ2589X_ADDR__7bf (0x6B)
#else
#error BQ2589X unknown variant
#endif
diff --git a/driver/charger/isl923x.c b/driver/charger/isl923x.c
index 89fd3ad1c2..556e385d90 100644
--- a/driver/charger/isl923x.c
+++ b/driver/charger/isl923x.c
@@ -56,17 +56,20 @@ static const struct charger_info isl9237_charger_info = {
static inline int raw_read8(int offset, int *value)
{
- return i2c_read8(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, offset, value);
+ return i2c_read8__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ offset, value);
}
static inline int raw_read16(int offset, int *value)
{
- return i2c_read16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, offset, value);
+ return i2c_read16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ offset, value);
}
static inline int raw_write16(int offset, int value)
{
- return i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, offset, value);
+ return i2c_write16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ offset, value);
}
static int isl9237_set_current(uint16_t current)
@@ -564,8 +567,8 @@ static int print_amon_bmon(enum amon_bmon amon, int direction,
int adc, curr, reg, ret;
#ifdef CONFIG_CHARGER_ISL9238
- ret = i2c_read16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
- ISL9238_REG_CONTROL3, &reg);
+ ret = i2c_read16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ ISL9238_REG_CONTROL3, &reg);
if (ret)
return ret;
@@ -574,15 +577,15 @@ static int print_amon_bmon(enum amon_bmon amon, int direction,
reg |= ISL9238_C3_AMON_BMON_DIRECTION;
else
reg &= ~ISL9238_C3_AMON_BMON_DIRECTION;
- ret = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
- ISL9238_REG_CONTROL3, reg);
+ ret = i2c_write16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ ISL9238_REG_CONTROL3, reg);
if (ret)
return ret;
#endif
mutex_lock(&control1_mutex);
- ret = i2c_read16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
+ ret = i2c_read16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
ISL923X_REG_CONTROL1, &reg);
if (!ret) {
/* Switch between AMON/BMON */
@@ -593,8 +596,8 @@ static int print_amon_bmon(enum amon_bmon amon, int direction,
/* Enable monitor */
reg &= ~ISL923X_C1_DISABLE_MON;
- ret = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
- ISL923X_REG_CONTROL1, reg);
+ ret = i2c_write16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ ISL923X_REG_CONTROL1, reg);
}
mutex_unlock(&control1_mutex);
@@ -678,8 +681,8 @@ static void dump_reg_range(int low, int high)
for (reg = low; reg <= high; reg++) {
CPRINTF("[%Xh] = ", reg);
- rv = i2c_read16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, reg,
- &regval);
+ rv = i2c_read16__7bf(I2C_PORT_CHARGER, I2C_ADDR_CHARGER__7bf,
+ reg, &regval);
if (!rv)
CPRINTF("0x%04x\n", regval);
else
diff --git a/driver/charger/isl923x.h b/driver/charger/isl923x.h
index 118f22b77d..5e32a76938 100644
--- a/driver/charger/isl923x.h
+++ b/driver/charger/isl923x.h
@@ -8,7 +8,7 @@
#ifndef __CROS_EC_ISL923X_H
#define __CROS_EC_ISL923X_H
-#define ISL923X_ADDR 0x12 /* 7bit address 0001001 */
+#define ISL923X_ADDR__7bf (0x09)
/* Registers */
#define ISL923X_REG_CHG_CURRENT 0x14
@@ -296,5 +296,5 @@ enum isl9237_fsm_state {
#define INPUT_I_MIN 4
#define INPUT_I_STEP 4
-#define I2C_ADDR_CHARGER ISL923X_ADDR
+#define I2C_ADDR_CHARGER__7bf ISL923X_ADDR__7bf
#endif /* __CROS_EC_ISL923X_H */
diff --git a/driver/charger/isl9241.h b/driver/charger/isl9241.h
new file mode 100644
index 0000000000..e145abc610
--- /dev/null
+++ b/driver/charger/isl9241.h
@@ -0,0 +1,115 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Renesas (Intersil) ISL-9241 battery charger driver header.
+ */
+
+#ifndef __CROS_EC_ISL9241_H
+#define __CROS_EC_ISL9241_H
+
+#define ISL9241_ADDR__7bf 0x09
+#define I2C_ADDR_CHARGER__7bf ISL9241_ADDR__7bf
+
+#define CHARGER_NAME "ISL9241"
+#define CHARGE_V_MAX 18304
+#define CHARGE_V_MIN 64
+#define CHARGE_V_STEP 8
+#define CHARGE_I_MAX 6140
+#define CHARGE_I_MIN 4
+#define CHARGE_I_STEP 4
+#define INPUT_I_MAX 6140
+#define INPUT_I_MIN 4
+#define INPUT_I_STEP 4
+
+/* Registers */
+
+/*
+ * ChargeCurrentLimit [12:2] 11-bit (0x0000h = disables fast charging,
+ * trickle charging is allowed)
+ */
+#define ISL9241_REG_CHG_CURRENT_LIMIT 0x14
+
+/* MaxSystemVoltage [14:3] 12-bit, (0x0000h = disables switching) */
+#define ISL9241_REG_MAX_SYSTEM_VOLTAGE 0x15
+
+#define ISL9241_REG_CONTROL7 0x38
+
+/* Configures various charger options */
+#define ISL9241_REG_CONTROL0 0x39
+/* 2: Input Voltage Regulation (0 = Enable (default), 1 = Disable) */
+#define ISL9241_CONTROL0_INPUT_VTG_REGULATION BIT(2)
+
+#define ISL9241_REG_INFORMATION1 0x3A
+#define ISL9241_REG_ADAPTER_CUR_LIMIT2 0x3B
+
+/* Configures various charger options */
+#define ISL9241_REG_CONTROL1 0x3C
+#define ISL9241_CONTROL1_LEARN_MODE BIT(12)
+
+/* Configures various charger options */
+#define ISL9241_REG_CONTROL2 0x3D
+/*
+ * 15:13 - Trickle Charging Current
+ * <000> 32mA (do not use)
+ * <001> 64mA
+ * <010> 96mA
+ * <011> 128mA (default)
+ * <100> 160mA
+ * <101> 192mA
+ * <110> 224mA
+ * <111> 256mA
+ */
+#define ISL9241_CONTROL2_TRICKLE_CHG_CURR(curr) ((((curr) >> 5) - 1) << 13)
+/* 12 - Two-Level Adapter Current Limit */
+#define ISL9241_CONTROL2_TWO_LEVEL_ADP_CURR BIT(12)
+/* 10:9 PROCHOT# debounce time in uS */
+#define ISL9241_CONTROL2_PROCHOT_DEBOUNCE_1000 (3 << 9)
+
+/* MinSystemVoltage [13:6] 8-bit (0x0000h = disables all battery charging) */
+#define ISL9241_REG_MIN_SYSTEM_VOLTAGE 0x3E
+
+#define ISL9241_REG_ADAPTER_CUR_LIMIT1 0x3F
+#define ISL9241_REG_ACOK_REFERENCE 0x40
+#define ISL9241_REG_CONTROL6 0x43
+#define ISL9241_REG_AC_PROCHOT 0x47
+#define ISL9241_REG_DC_PROCHOT 0x48
+#define ISL9241_REG_OTG_VOLTAGE 0x49
+#define ISL9241_REG_OTG_CURRENT 0x4A
+
+/* VIN Voltage (ADP Min Voltage) (default 4.096V) */
+#define ISL9241_REG_VIN_VOLTAGE 0x4B
+
+/* Configures various charger options */
+#define ISL9241_REG_CONTROL3 0x4C
+/* 14: ACLIM Reload (0 - reload, 1 - Do not reload */
+#define ISL9241_CONTROL3_ACLIM_RELOAD BIT(14)
+/* 2: Digital Reset (0 - Idle, 1 - Reset */
+#define ISL9241_CONTROL3_DIGITAL_RESET BIT(2)
+
+/* Indicates various charger status */
+#define ISL9241_REG_INFORMATION2 0x4D
+/* 12: BATGONE pin status (0 = Battery is present, 1 = No battery) */
+#define ISL9241_INFORMATION2_BATGONE_PIN BIT(12)
+/* 14: ACOK pin status (0 = No adapter, 1 = Adapter is present) */
+#define ISL9241_INFORMATION2_ACOK_PIN BIT(14)
+
+#define ISL9241_REG_CONTROL4 0x4E
+#define ISL9241_REG_CONTROL5 0x4F
+#define ISL9241_REG_NTC_ADC_RESULTS 0x80
+#define ISL9241_REG_VBAT_ADC_RESULTS 0x81
+#define ISL9241_REG_TJ_ADC_RESULTS 0x82
+
+/* ADC result for adapter current measurements, LSB = 22.2mA */
+#define ISL9241_REG_IADP_ADC_RESULTS 0x83
+
+#define ISL9241_REG_DC_ADC_RESULTS 0x84
+#define ISL9241_REG_CC_ADC_RESULTS 0x85
+#define ISL9241_REG_VSYS_ADC_RESULTS 0x86
+#define ISL9241_REG_VIN_ADC_RESULTS 0x87
+#define ISL9241_REG_INFORMATION3 0x90
+#define ISL9241_REG_INFORMATION4 0x91
+#define ISL9241_REG_MANUFACTURER_ID 0xFE
+#define ISL9241_REG_DEVICE_ID 0xFF
+
+#endif /* __CROS_EC_ISL9241_H */
diff --git a/driver/charger/rt946x.c b/driver/charger/rt946x.c
index 9bb1a6cfd7..a197023ab9 100644
--- a/driver/charger/rt946x.c
+++ b/driver/charger/rt946x.c
@@ -143,17 +143,18 @@ static const uint16_t rt946x_boost_current[] = {
static int rt946x_read8(int reg, int *val)
{
- return i2c_read8(I2C_PORT_CHARGER, RT946X_ADDR, reg, val);
+ return i2c_read8__7bf(I2C_PORT_CHARGER, RT946X_ADDR__7bf, reg, val);
}
static int rt946x_write8(int reg, int val)
{
- return i2c_write8(I2C_PORT_CHARGER, RT946X_ADDR, reg, val);
+ return i2c_write8__7bf(I2C_PORT_CHARGER, RT946X_ADDR__7bf, reg, val);
}
static int rt946x_block_write(int reg, const uint8_t *val, int len)
{
- return i2c_write_block(I2C_PORT_CHARGER, RT946X_ADDR, reg, val, len);
+ return i2c_write_block__7bf(I2C_PORT_CHARGER, RT946X_ADDR__7bf,
+ reg, val, len);
}
static int rt946x_update_bits(int reg, int mask, int val)
diff --git a/driver/charger/rt946x.h b/driver/charger/rt946x.h
index ff126bc079..36c44716ee 100644
--- a/driver/charger/rt946x.h
+++ b/driver/charger/rt946x.h
@@ -460,15 +460,15 @@
#if defined(CONFIG_CHARGER_RT9466)
#define RT946X_CHARGER_NAME "rt9466"
#define RT946X_VENDOR_ID 0x80
- #define RT946X_ADDR (0x53 << 1)
+ #define RT946X_ADDR__7bf 0x53
#elif defined(CONFIG_CHARGER_RT9467)
#define RT946X_CHARGER_NAME "rt9467"
#define RT946X_VENDOR_ID 0x90
- #define RT946X_ADDR (0x5B << 1)
+ #define RT946X_ADDR__7bf 0x5B
#elif defined(CONFIG_CHARGER_MT6370)
#define RT946X_CHARGER_NAME "mt6370"
#define RT946X_VENDOR_ID 0xE0
- #define RT946X_ADDR (0x34 << 1)
+ #define RT946X_ADDR__7bf 0x34
#else
#error "No suitable charger option defined"
#endif
diff --git a/driver/charger/sy21612.c b/driver/charger/sy21612.c
index 378c8891a3..0ec3a570e3 100644
--- a/driver/charger/sy21612.c
+++ b/driver/charger/sy21612.c
@@ -22,7 +22,7 @@ static int sy21612_clear_set_reg(int reg, int clear, int set)
{
int val, old_val, rv;
- rv = i2c_read8(I2C_PORT_SY21612, SY21612_ADDR, reg, &old_val);
+ rv = i2c_read8__7bf(I2C_PORT_SY21612, SY21612_ADDR__7bf, reg, &old_val);
if (rv)
return rv;
@@ -31,14 +31,15 @@ static int sy21612_clear_set_reg(int reg, int clear, int set)
val |= set;
if (val != old_val || clear || set)
- rv = i2c_write8(I2C_PORT_SY21612, SY21612_ADDR, reg, val);
+ rv = i2c_write8__7bf(I2C_PORT_SY21612, SY21612_ADDR__7bf,
+ reg, val);
return rv;
}
static int sy21612_read(int reg, int *val)
{
- return i2c_read8(I2C_PORT_SY21612, SY21612_ADDR, reg, val);
+ return i2c_read8__7bf(I2C_PORT_SY21612, SY21612_ADDR__7bf, reg, val);
}
int sy21612_enable_regulator(int enable)
diff --git a/driver/charger/sy21612.h b/driver/charger/sy21612.h
index 9d531a1ee2..90f8c3a474 100644
--- a/driver/charger/sy21612.h
+++ b/driver/charger/sy21612.h
@@ -10,8 +10,8 @@
#include "gpio.h"
-#ifndef SY21612_ADDR
-#define SY21612_ADDR 0xe2 /* 7bit address 1110_010 */
+#ifndef SY21612_ADDR__7bf
+#define SY21612_ADDR__7bf 0x71
#endif
enum sy21612_switching_freq {
diff --git a/driver/gyro_l3gd20h.h b/driver/gyro_l3gd20h.h
index 24ad81a693..f274d3d0dd 100644
--- a/driver/gyro_l3gd20h.h
+++ b/driver/gyro_l3gd20h.h
@@ -15,8 +15,8 @@
* 7-bit address is 110101Xb. Where 'X' is determined
* by the voltage on the ADDR pin.
*/
-#define L3GD20_ADDR0 0xd4
-#define L3GD20_ADDR1 0xd6
+#define L3GD20_ADDR0__7bf 0x6a
+#define L3GD20_ADDR1__7bf 0x6b
/* who am I */
#define L3GD20_WHO_AM_I 0xd7
diff --git a/driver/ina2xx.c b/driver/ina2xx.c
index d610285710..7a8bdbf0f3 100644
--- a/driver/ina2xx.c
+++ b/driver/ina2xx.c
@@ -16,16 +16,16 @@
/* Console output macros */
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
-/* 8-bit I2C base address */
-#define INA2XX_I2C_ADDR (0x40 << 1)
+/* I2C base address */
+#define INA2XX_I2C_ADDR__7bf 0x40
uint16_t ina2xx_read(uint8_t idx, uint8_t reg)
{
int res;
int val;
- uint8_t addr = INA2XX_I2C_ADDR | (idx << 1);
- res = i2c_read16(I2C_PORT_MASTER, addr, reg, &val);
+ res = i2c_read16__7bf(I2C_PORT_MASTER, INA2XX_I2C_ADDR__7bf | idx,
+ reg, &val);
if (res) {
CPRINTS("INA2XX I2C read failed");
return 0x0bad;
@@ -36,10 +36,10 @@ uint16_t ina2xx_read(uint8_t idx, uint8_t reg)
int ina2xx_write(uint8_t idx, uint8_t reg, uint16_t val)
{
int res;
- uint8_t addr = INA2XX_I2C_ADDR | (idx << 1);
uint16_t be_val = (val >> 8) | ((val & 0xff) << 8);
- res = i2c_write16(I2C_PORT_MASTER, addr, reg, be_val);
+ res = i2c_write16__7bf(I2C_PORT_MASTER, INA2XX_I2C_ADDR__7bf | idx,
+ reg, be_val);
if (res)
CPRINTS("INA2XX I2C write failed");
return res;
diff --git a/driver/ioexpander_pca9534.c b/driver/ioexpander_pca9534.c
index 1ac9a5164b..1d29c8032d 100644
--- a/driver/ioexpander_pca9534.c
+++ b/driver/ioexpander_pca9534.c
@@ -8,37 +8,45 @@
#include "i2c.h"
#include "ioexpander_pca9534.h"
-static int pca9534_pin_read(int port, int addr, int reg, int pin, int *val)
+static int pca9534_pin_read__7bf(const int port, const uint16_t addr__7bf,
+ int reg, int pin, int *val)
{
int ret;
- ret = i2c_read8(port, addr, reg, val);
- *val = (*val & (1 << pin)) ? 1 : 0;
+ ret = i2c_read8__7bf(port, addr__7bf, reg, val);
+ *val = (*val & BIT(pin)) ? 1 : 0;
return ret;
}
-static int pca9534_pin_write(int port, int addr, int reg, int pin, int val)
+static int pca9534_pin_write__7bf(const int port, const uint16_t addr__7bf,
+ int reg, int pin, int val)
{
int ret, v;
- ret = i2c_read8(port, addr, reg, &v);
+ ret = i2c_read8__7bf(port, addr__7bf, reg, &v);
if (ret != EC_SUCCESS)
return ret;
v &= ~(1 << pin);
if (val)
v |= 1 << pin;
- return i2c_write8(port, addr, reg, v);
+ return i2c_write8__7bf(port, addr__7bf, reg, v);
}
-int pca9534_get_level(int port, int addr, int pin, int *level)
+int pca9534_get_level__7bf(const int port, const uint16_t addr__7bf,
+ int pin, int *level)
{
- return pca9534_pin_read(port, addr, PCA9534_REG_INPUT, pin, level);
+ return pca9534_pin_read__7bf(port, addr__7bf,
+ PCA9534_REG_INPUT, pin, level);
}
-int pca9534_set_level(int port, int addr, int pin, int level)
+int pca9534_set_level__7bf(const int port, const uint16_t addr__7bf,
+ int pin, int level)
{
- return pca9534_pin_write(port, addr, PCA9534_REG_OUTPUT, pin, level);
+ return pca9534_pin_write__7bf(port, addr__7bf,
+ PCA9534_REG_OUTPUT, pin, level);
}
-int pca9534_config_pin(int port, int addr, int pin, int is_input)
+int pca9534_config_pin__7bf(const int port, const uint16_t addr__7bf,
+ int pin, int is_input)
{
- return pca9534_pin_write(port, addr, PCA9534_REG_CONFIG, pin, is_input);
+ return pca9534_pin_write__7bf(port, addr__7bf,
+ PCA9534_REG_CONFIG, pin, is_input);
}
diff --git a/driver/ioexpander_pca9534.h b/driver/ioexpander_pca9534.h
index d8cf896a49..e6848e21a2 100644
--- a/driver/ioexpander_pca9534.h
+++ b/driver/ioexpander_pca9534.h
@@ -26,7 +26,8 @@
*
* @return EC_SUCCESS, or EC_ERROR_* on error.
*/
-int pca9534_get_level(int port, int addr, int pin, int *level);
+int pca9534_get_level__7bf(const int port, const uint16_t addr__7bf,
+ int pin, int *level);
/*
* Set output level. This function has no effect if the pin is
@@ -39,7 +40,8 @@ int pca9534_get_level(int port, int addr, int pin, int *level);
*
* @return EC_SUCCESS, or EC_ERROR_* on error.
*/
-int pca9534_set_level(int port, int addr, int pin, int level);
+int pca9534_set_level__7bf(const int port, const uint16_t addr__7bf,
+ int pin, int level);
/*
* Config a pin as input or output.
@@ -51,6 +53,7 @@ int pca9534_set_level(int port, int addr, int pin, int level);
*
* @return EC_SUCCESS, or EC_ERROR_* on error.
*/
-int pca9534_config_pin(int port, int addr, int pin, int is_input);
+int pca9534_config_pin__7bf(const int port, const uint16_t addr__7bf,
+ int pin, int is_input);
#endif /* __CROS_EC_IOEXPANDER_PCA9534_H */
diff --git a/driver/ioexpander_pca9555.h b/driver/ioexpander_pca9555.h
index 3a932ceef0..0ecaf35a34 100644
--- a/driver/ioexpander_pca9555.h
+++ b/driver/ioexpander_pca9555.h
@@ -28,14 +28,18 @@
#define PCA9555_IO_6 (1 << 6)
#define PCA9555_IO_7 (1 << 7)
-static inline int pca9555_read(int port, int addr, int reg, int *data_ptr)
+static inline int pca9555_read__7bf(const int port,
+ const uint16_t i2c_addr__7bf,
+ int reg, int *data_ptr)
{
- return i2c_read8(port, addr, reg, data_ptr);
+ return i2c_read8__7bf(port, i2c_addr__7bf, reg, data_ptr);
}
-static inline int pca9555_write(int port, int addr, int reg, int data)
+static inline int pca9555_write__7bf(const int port,
+ const uint16_t i2c_addr__7bf,
+ int reg, int data)
{
- return i2c_write8(port, addr, reg, data);
+ return i2c_write8__7bf(port, i2c_addr__7bf, reg, data);
}
#endif /* __CROS_EC_IOEXPANDER_PCA9555_H */
diff --git a/driver/led/lm3509.c b/driver/led/lm3509.c
index 0f44681659..c940dd69e2 100644
--- a/driver/led/lm3509.c
+++ b/driver/led/lm3509.c
@@ -12,12 +12,14 @@
static inline int lm3509_write(uint8_t reg, uint8_t val)
{
- return i2c_write8(I2C_PORT_KBLIGHT, LM3509_I2C_ADDR, reg, val);
+ return i2c_write8__7bf(I2C_PORT_KBLIGHT, LM3509_I2C_ADDR__7bf,
+ reg, val);
}
static inline int lm3509_read(uint8_t reg, int *val)
{
- return i2c_read8(I2C_PORT_KBLIGHT, LM3509_I2C_ADDR, reg, val);
+ return i2c_read8__7bf(I2C_PORT_KBLIGHT, LM3509_I2C_ADDR__7bf,
+ reg, val);
}
/* Brightness level (0.0 to 100.0%) to brightness register conversion table */
diff --git a/driver/led/lm3509.h b/driver/led/lm3509.h
index 8318197a8e..fce0c993dc 100644
--- a/driver/led/lm3509.h
+++ b/driver/led/lm3509.h
@@ -8,8 +8,7 @@
#ifndef __CROS_EC_LM3509_H
#define __CROS_EC_LM3509_H
-/* 8-bit I2C address */
-#define LM3509_I2C_ADDR 0x6C
+#define LM3509_I2C_ADDR__7bf 0x36
/*
* General purpose register
diff --git a/driver/led/lm3630a.c b/driver/led/lm3630a.c
index 5515771ffa..10f850b09d 100644
--- a/driver/led/lm3630a.c
+++ b/driver/led/lm3630a.c
@@ -11,17 +11,19 @@
#include "timer.h"
-/* 8-bit I2C address */
-#define LM3630A_I2C_ADDR (0x36 << 1)
+/* I2C address */
+#define LM3630A_I2C_ADDR__7bf 0x36
static inline int lm3630a_write(uint8_t reg, uint8_t val)
{
- return i2c_write8(I2C_PORT_KBLIGHT, LM3630A_I2C_ADDR, reg, val);
+ return i2c_write8__7bf(I2C_PORT_KBLIGHT, LM3630A_I2C_ADDR__7bf,
+ reg, val);
}
static inline int lm3630a_read(uint8_t reg, int *val)
{
- return i2c_read8(I2C_PORT_KBLIGHT, LM3630A_I2C_ADDR, reg, val);
+ return i2c_read8__7bf(I2C_PORT_KBLIGHT, LM3630A_I2C_ADDR__7bf,
+ reg, val);
}
static void deferred_lm3630a_poweron(void)
diff --git a/driver/led/lp5562.c b/driver/led/lp5562.c
index 88efb72e7b..00cb5a9d43 100644
--- a/driver/led/lp5562.c
+++ b/driver/led/lp5562.c
@@ -11,8 +11,8 @@
#include "timer.h"
#include "util.h"
-/* 8-bit I2C address */
-#define LP5562_I2C_ADDR (0x30 << 1)
+/* I2C address */
+#define LP5562_I2C_ADDR__7bf (0x30)
inline int lp5562_write(uint8_t reg, uint8_t val)
{
diff --git a/driver/led/max695x.h b/driver/led/max695x.h
new file mode 100644
index 0000000000..4bead04194
--- /dev/null
+++ b/driver/led/max695x.h
@@ -0,0 +1,44 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * MAX6958/MAX6959 7-Segment LED Display Driver header
+ */
+
+#ifndef __CROS_EC_MAX656X_H
+#define __CROS_EC_MAX656X_H
+
+/* I2C interface */
+#define MAX695X_I2C_ADDR1__7bf (0x38)
+#define MAX695X_I2C_ADDR2__7bf (0x39)
+
+/* Decode mode register */
+#define MAX695X_REG_DECODE_MODE 0x01
+/* Hexadecimal decode for digits 3–0 */
+#define MAX695X_DECODE_MODE_HEX_DECODE 0x0f
+
+/* Intensity register */
+#define MAX695X_REG_INTENSITY 0x02
+/* Setting meduim intensity */
+#define MAX695X_INTENSITY_MEDIUM 0x20
+
+/* Scan limit register value */
+#define MAX695X_REG_SCAN_LIMIT 0x03
+
+/* Scanning digits 0-3 */
+#define MAX695X_SCAN_LIMIT_4 0x03
+
+/* Configuration register */
+#define MAX695X_REG_CONFIG 0x04
+/* Shutdown seven segment display */
+#define MAX695X_CONFIG_OPR_SHUTDOWN 0x00
+/* Start seven segment display */
+#define MAX695X_CONFIG_OPR_NORMAL 0x01
+
+/* Digit addresses */
+#define MAX695X_DIGIT0_ADDR 0x20
+#define MAX695X_DIGIT1_ADDR 0x21
+#define MAX695X_DIGIT2_ADDR 0x22
+#define MAX695X_DIGIT3_ADDR 0x23
+
+#endif /* __CROS_EC_MAX656X_H */
diff --git a/driver/led/oz554.c b/driver/led/oz554.c
new file mode 100644
index 0000000000..6369e064a3
--- /dev/null
+++ b/driver/led/oz554.c
@@ -0,0 +1,145 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * O2 Micro OZ554 LED driver.
+ */
+
+#include "console.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "oz554.h"
+#include "task.h"
+#include "timer.h"
+
+#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args)
+
+#define I2C_ADDR_OZ554__7bf 0x31
+
+struct oz554_value {
+ uint8_t offset;
+ uint8_t data;
+};
+
+/*
+ * OZ554ALN asserts the interrupt when it's ready for writing settings, which
+ * are cleared when it's turned off. We enable the interrupt on HOOK_INIT and
+ * keep it enabled in S0/S3/S5.
+ *
+ * It's assumed the device doesn't have a lid and OZ554ALN is powered only in
+ * S0. For clamshell devices, different interrupt & power control scheme may be
+ * needed.
+ */
+
+/* This ordering is suggested by vendor. */
+static struct oz554_value oz554_conf[] = {
+ /*
+ * Reigster 0x01: Operation frequency control
+ * Frequency selection: 300(KHz)
+ * Short circuit protection: 8(V)
+ */
+ {.offset = 1, .data = 0x43},
+ /*
+ * Reigster 0x02: LED current amplitude control
+ * ISET Resistor: 10.2(Kohm)
+ * Maximum LED current: 1636/10.2 = 160.4(mA)
+ * Setting LED current: 65(mA)
+ */
+ {.offset = 2, .data = 0x65},
+ /*
+ * Reigster 0x03: LED backlight Status
+ * Status function: Read only
+ */
+ {.offset = 3, .data = 0x00},
+ /*
+ * Reigster 0x04: LED current control with SMBus
+ * SMBus PWM function: None Use
+ */
+ {.offset = 4, .data = 0x00},
+ /*
+ * Reigster 0x05: OVP, OCP control
+ * Over Current Protection: 0.5(V)
+ * Panel LED Voltage(Max): 47.8(V)
+ * OVP setting: 54(V)
+ */
+ {.offset = 5, .data = 0x97},
+ /*
+ * Reigster 0x00: Dimming mode and string ON/OFF control
+ * String Selection: 4(Number)
+ * Interface Selection: 1
+ * Brightness mode: 3
+ */
+ {.offset = 0, .data = 0xF2},
+};
+static const int oz554_conf_size = ARRAY_SIZE(oz554_conf);
+
+static void set_oz554_reg(void)
+{
+ int i;
+
+ for (i = 0; i < oz554_conf_size; ++i) {
+ int rv = i2c_write8__7bf(I2C_PORT_BACKLIGHT,
+ I2C_ADDR_OZ554__7bf,
+ oz554_conf[i].offset, oz554_conf[i].data);
+ if (rv) {
+ CPRINTS("Write OZ554 register %d failed rv=%d" , i, rv);
+ return;
+ }
+ }
+ CPRINTS("Wrote OZ554 settings");
+}
+
+static void backlight_enable_deferred(void)
+{
+ if (gpio_get_level(GPIO_PANEL_BACKLIGHT_EN))
+ set_oz554_reg();
+}
+DECLARE_DEFERRED(backlight_enable_deferred);
+
+void backlight_enable_interrupt(enum gpio_signal signal)
+{
+ /*
+ * 1. Spec says backlight should be turned on after 500ms
+ * after eDP signals are ready.
+ *
+ * 2. There's no way to get exact eDP ready time, therefore,
+ * give one second delay.
+ *
+ * power up __/----------------
+ * eDP ______/------------
+ * backlight _____________/-----
+ * |- t1 -| : >=500 ms
+ * |- t2 -| : 1 second is enough
+ */
+ hook_call_deferred(&backlight_enable_deferred_data,
+ OZ554_POWER_BACKLIGHT_DELAY);
+}
+
+int oz554_set_config(int offset, int data)
+{
+ int i;
+ for (i = 0; i < oz554_conf_size; i++) {
+ if (oz554_conf[i].offset == offset)
+ break;
+ }
+ if (i >= oz554_conf_size)
+ /* Matching offset not found */
+ return EC_ERROR_INVAL;
+ oz554_conf[i].data = data;
+ return EC_SUCCESS;
+}
+
+static void init_oz554(void)
+{
+ oz554_board_init();
+
+ gpio_enable_interrupt(GPIO_PANEL_BACKLIGHT_EN);
+}
+DECLARE_HOOK(HOOK_INIT, init_oz554, HOOK_PRIO_DEFAULT);
+
+
+__overridable void oz554_board_init(void)
+{
+}
diff --git a/driver/mag_bmm150.c b/driver/mag_bmm150.c
index cb53641c00..e1f073bddb 100644
--- a/driver/mag_bmm150.c
+++ b/driver/mag_bmm150.c
@@ -19,8 +19,8 @@
#ifdef CONFIG_MAG_BMI160_BMM150
#include "driver/accelgyro_bmi160.h"
-#define raw_mag_read8 bmi160_sec_raw_read8
-#define raw_mag_write8 bmi160_sec_raw_write8
+#define raw_mag_read8__7bf bmi160_sec_raw_read8__7bf
+#define raw_mag_write8__7bf bmi160_sec_raw_write8__7bf
#else
#error "Not implemented"
#endif
@@ -73,9 +73,9 @@
#define BMI150_READ_16BIT_COM_REG(store_, addr_) do { \
int val; \
- raw_mag_read8(s->port, s->addr, (addr_), &val); \
+ raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, (addr_), &val); \
store_ = val; \
- raw_mag_read8(s->port, s->addr, (addr_) + 1, &val); \
+ raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf, (addr_) + 1, &val); \
store_ |= (val << 8); \
} while (0)
@@ -88,10 +88,12 @@ int bmm150_init(const struct motion_sensor_t *s)
struct mag_cal_t *moc = BMM150_CAL(s);
/* Set the compass from Suspend to Sleep */
- ret = raw_mag_write8(s->port, s->addr, BMM150_PWR_CTRL, BMM150_PWR_ON);
+ ret = raw_mag_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_PWR_CTRL, BMM150_PWR_ON);
msleep(4);
/* Now we can read the device id */
- ret = raw_mag_read8(s->port, s->addr, BMM150_CHIP_ID, &val);
+ ret = raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_CHIP_ID, &val);
if (ret)
return EC_ERROR_UNKNOWN;
@@ -99,21 +101,27 @@ int bmm150_init(const struct motion_sensor_t *s)
return EC_ERROR_ACCESS_DENIED;
/* Read the private registers for compensation */
- ret = raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_X1, &val);
+ ret = raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_REGA_DIG_X1, &val);
if (ret)
return EC_ERROR_UNKNOWN;
regs->dig1[X] = val;
- raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_Y1, &val);
+ raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_REGA_DIG_Y1, &val);
regs->dig1[Y] = val;
- raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_X2, &val);
+ raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_REGA_DIG_X2, &val);
regs->dig2[X] = val;
- raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_Y2, &val);
+ raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_REGA_DIG_Y2, &val);
regs->dig2[Y] = val;
- raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_XY1, &val);
+ raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_REGA_DIG_XY1, &val);
regs->dig_xy1 = val;
- raw_mag_read8(s->port, s->addr, BMM150_REGA_DIG_XY2, &val);
+ raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_REGA_DIG_XY2, &val);
regs->dig_xy2 = val;
BMI150_READ_16BIT_COM_REG(regs->dig_z1, BMM150_REGA_DIG_Z1_LSB);
@@ -124,15 +132,20 @@ int bmm150_init(const struct motion_sensor_t *s)
/* Set the repetition in "Regular Preset" */
- raw_mag_write8(s->port, s->addr, BMM150_REPXY, BMM150_REP(SPECIAL, XY));
- raw_mag_write8(s->port, s->addr, BMM150_REPZ, BMM150_REP(SPECIAL, Z));
- ret = raw_mag_read8(s->port, s->addr, BMM150_REPXY, &val);
- ret = raw_mag_read8(s->port, s->addr, BMM150_REPZ, &val);
+ raw_mag_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_REPXY, BMM150_REP(SPECIAL, XY));
+ raw_mag_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_REPZ, BMM150_REP(SPECIAL, Z));
+ ret = raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_REPXY, &val);
+ ret = raw_mag_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_REPZ, &val);
/*
* Set the compass forced mode, to sleep after each measure.
*/
- ret = raw_mag_write8(s->port, s->addr, BMM150_OP_CTRL,
- BMM150_OP_MODE_FORCED << BMM150_OP_MODE_OFFSET);
+ ret = raw_mag_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ BMM150_OP_CTRL,
+ BMM150_OP_MODE_FORCED << BMM150_OP_MODE_OFFSET);
init_mag_cal(moc);
moc->radius = 0.0f;
diff --git a/driver/mag_bmm150.h b/driver/mag_bmm150.h
index c15cbc065b..b03e81f3f8 100644
--- a/driver/mag_bmm150.h
+++ b/driver/mag_bmm150.h
@@ -11,10 +11,10 @@
#include "accelgyro.h"
#include "mag_cal.h"
-#define BMM150_ADDR0 0x20
-#define BMM150_ADDR1 0x22
-#define BMM150_ADDR2 0x24
-#define BMM150_ADDR3 0x26
+#define BMM150_ADDR0__7bf 0x10
+#define BMM150_ADDR1__7bf 0x11
+#define BMM150_ADDR2__7bf 0x12
+#define BMM150_ADDR3__7bf 0x13
#define BMM150_CHIP_ID 0x40
#define BMM150_CHIP_ID_MAJOR 0x32
diff --git a/driver/mag_lis2mdl.c b/driver/mag_lis2mdl.c
index 460d3cb81d..91b78c3d99 100644
--- a/driver/mag_lis2mdl.c
+++ b/driver/mag_lis2mdl.c
@@ -146,25 +146,25 @@ int lis2mdl_thru_lsm6dsm_init(const struct motion_sensor_t *s)
mutex_lock(s->mutex);
/* Magnetometer in cascade mode */
- ret = sensorhub_check_and_rst(
+ ret = sensorhub_check_and_rst__7bf(
LSM6DSM_MAIN_SENSOR(s),
- CONFIG_ACCELGYRO_SEC_ADDR,
+ CONFIG_ACCELGYRO_SEC_ADDR__7BF,
LIS2MDL_WHO_AM_I_REG, LIS2MDL_WHO_AM_I,
LIS2MDL_CFG_REG_A_ADDR, LIS2MDL_SW_RESET);
if (ret != EC_SUCCESS)
goto err_unlock;
- ret = sensorhub_config_ext_reg(
+ ret = sensorhub_config_ext_reg__7bf(
LSM6DSM_MAIN_SENSOR(s),
- CONFIG_ACCELGYRO_SEC_ADDR,
+ CONFIG_ACCELGYRO_SEC_ADDR__7BF,
LIS2MDL_CFG_REG_A_ADDR,
LIS2MDL_ODR_50HZ | LIS2MDL_CONT_MODE);
if (ret != EC_SUCCESS)
goto err_unlock;
- ret = sensorhub_config_slv0_read(
+ ret = sensorhub_config_slv0_read__7bf(
LSM6DSM_MAIN_SENSOR(s),
- CONFIG_ACCELGYRO_SEC_ADDR,
+ CONFIG_ACCELGYRO_SEC_ADDR__7BF,
LIS2MDL_OUT_REG, OUT_XYZ_SIZE);
if (ret != EC_SUCCESS)
goto err_unlock;
@@ -200,7 +200,8 @@ static int lis2mdl_is_data_ready(const struct motion_sensor_t *s, int *ready)
{
int ret, tmp;
- ret = st_raw_read8(s->port, s->addr, LIS2MDL_STATUS_REG, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2MDL_STATUS_REG, &tmp);
if (ret != EC_SUCCESS) {
*ready = 0;
return ret;
@@ -241,8 +242,8 @@ int lis2mdl_read(const struct motion_sensor_t *s, intv3_t v)
}
mutex_lock(s->mutex);
- ret = st_raw_read_n(s->port, s->addr, LIS2MDL_OUT_REG, raw,
- OUT_XYZ_SIZE);
+ ret = st_raw_read_n__7bf(s->port, s->i2c_spi_addr__7bf,
+ LIS2MDL_OUT_REG, raw, OUT_XYZ_SIZE);
mutex_unlock(s->mutex);
if (ret == EC_SUCCESS) {
lis2mdl_normalize(s, v, raw);
@@ -261,8 +262,8 @@ int lis2mdl_init(const struct motion_sensor_t *s)
/* Check who am I value */
do {
- ret = st_raw_read8(s->port, LIS2MDL_ADDR, LIS2MDL_WHO_AM_I_REG,
- &who_am_i);
+ ret = st_raw_read8__7bf(s->port, LIS2MDL_ADDR__7bf,
+ LIS2MDL_WHO_AM_I_REG, &who_am_i);
if (ret != EC_SUCCESS) {
/* Make sure we wait for the chip to start up. Sleep 1ms
* and try again.
@@ -281,7 +282,8 @@ int lis2mdl_init(const struct motion_sensor_t *s)
mutex_lock(s->mutex);
/* Reset the sensor */
- ret = st_raw_write8(s->port, LIS2MDL_ADDR, LIS2MDL_CFG_REG_A_ADDR,
+ ret = st_raw_write8__7bf(s->port, LIS2MDL_ADDR__7bf,
+ LIS2MDL_CFG_REG_A_ADDR,
LIS2MDL_FLAG_SW_RESET);
if (ret != EC_SUCCESS)
goto lis2mdl_init_error;
@@ -357,13 +359,13 @@ int lis2mdl_set_data_rate(const struct motion_sensor_t *s, int rate, int rnd)
mutex_lock(s->mutex);
if (rate <= 0) {
- ret = st_raw_write8(s->port, LIS2MDL_ADDR,
+ ret = st_raw_write8__7bf(s->port, LIS2MDL_ADDR__7bf,
LIS2MDL_CFG_REG_A_ADDR,
LIS2MDL_FLAG_SW_RESET);
} else {
/* Add continuous and temp compensation flags */
reg_val |= LIS2MDL_MODE_CONT | LIS2MDL_FLAG_TEMP_COMPENSATION;
- ret = st_raw_write8(s->port, LIS2MDL_ADDR,
+ ret = st_raw_write8__7bf(s->port, LIS2MDL_ADDR__7bf,
LIS2MDL_CFG_REG_A_ADDR, reg_val);
}
diff --git a/driver/mag_lis2mdl.h b/driver/mag_lis2mdl.h
index 0a415ceebd..aeb2c66b1c 100644
--- a/driver/mag_lis2mdl.h
+++ b/driver/mag_lis2mdl.h
@@ -16,7 +16,7 @@
* 8-bit address is 0011110Wb where the last bit represents whether the
* operation is a read or a write.
*/
-#define LIS2MDL_ADDR 0x3c
+#define LIS2MDL_ADDR__7bf 0x1e
#define LIS2MDL_STARTUP_MS 10
diff --git a/driver/pmic_tps650x30.h b/driver/pmic_tps650x30.h
index 5198686800..7a9dc751fc 100644
--- a/driver/pmic_tps650x30.h
+++ b/driver/pmic_tps650x30.h
@@ -9,9 +9,9 @@
#define __CROS_EC_PMIC_TPS650X30_H
/* I2C interface */
-#define TPS650X30_I2C_ADDR1 (0x30 << 1)
-#define TPS650X30_I2C_ADDR2 (0x32 << 1)
-#define TPS650X30_I2C_ADDR3 (0x34 << 1)
+#define TPS650X30_I2C_ADDR1__7bf 0x30
+#define TPS650X30_I2C_ADDR2__7bf 0x32
+#define TPS650X30_I2C_ADDR3__7bf 0x34
/* TPS650X30 registers */
#define TPS650X30_REG_VENDORID 0x00
diff --git a/driver/ppc/nx20p348x.c b/driver/ppc/nx20p348x.c
index a5ee9d5e31..e8d2f52563 100644
--- a/driver/ppc/nx20p348x.c
+++ b/driver/ppc/nx20p348x.c
@@ -31,16 +31,16 @@ static uint8_t flags[CONFIG_USB_PD_PORT_COUNT];
static int read_reg(uint8_t port, int reg, int *regval)
{
- return i2c_read8(ppc_chips[port].i2c_port,
- ppc_chips[port].i2c_addr,
+ return i2c_read8__7bf(ppc_chips[port].i2c_port,
+ ppc_chips[port].i2c_addr__7bf,
reg,
regval);
}
static int write_reg(uint8_t port, int reg, int regval)
{
- return i2c_write8(ppc_chips[port].i2c_port,
- ppc_chips[port].i2c_addr,
+ return i2c_write8__7bf(ppc_chips[port].i2c_port,
+ ppc_chips[port].i2c_addr__7bf,
reg,
regval);
}
diff --git a/driver/ppc/nx20p348x.h b/driver/ppc/nx20p348x.h
index 52224b6a8e..e34c5a2b56 100644
--- a/driver/ppc/nx20p348x.h
+++ b/driver/ppc/nx20p348x.h
@@ -8,10 +8,15 @@
#ifndef __CROS_EC_NX20P348X_H
#define __CROS_EC_NX20P348X_H
-#define NX20P3483_ADDR0 0xE0
-#define NX20P3483_ADDR1 0xE2
-#define NX20P3483_ADDR2 0xE4
-#define NX20P3483_ADDR3 0xE6
+#define NX20P3483_ADDR0__7bf (0x70)
+#define NX20P3483_ADDR1__7bf (0x71)
+#define NX20P3483_ADDR2__7bf (0x72)
+#define NX20P3483_ADDR3__7bf (0x73)
+
+#define NX20P3481_ADDR0__7bf (0x74)
+#define NX20P3481_ADDR1__7bf (0x75)
+#define NX20P3481_ADDR2__7bf (0x76)
+#define NX20P3481_ADDR3__7bf (0x77)
/*
* This PPC hard-codes the over voltage protect of Vbus at 6.8V in dead-battery
diff --git a/driver/ppc/sn5s330.c b/driver/ppc/sn5s330.c
index ef63402b6b..13834a8bf3 100644
--- a/driver/ppc/sn5s330.c
+++ b/driver/ppc/sn5s330.c
@@ -31,16 +31,16 @@ static int source_enabled[CONFIG_USB_PD_PORT_COUNT];
static int read_reg(uint8_t port, int reg, int *regval)
{
- return i2c_read8(ppc_chips[port].i2c_port,
- ppc_chips[port].i2c_addr,
+ return i2c_read8__7bf(ppc_chips[port].i2c_port,
+ ppc_chips[port].i2c_addr__7bf,
reg,
regval);
}
static int write_reg(uint8_t port, int reg, int regval)
{
- return i2c_write8(ppc_chips[port].i2c_port,
- ppc_chips[port].i2c_addr,
+ return i2c_write8__7bf(ppc_chips[port].i2c_port,
+ ppc_chips[port].i2c_addr__7bf,
reg,
regval);
}
@@ -78,12 +78,12 @@ static int sn5s330_dump(int port)
int i;
int data;
const int i2c_port = ppc_chips[port].i2c_port;
- const int i2c_addr = ppc_chips[port].i2c_addr;
+ const uint16_t i2c_addr__7bf = ppc_chips[port].i2c_addr__7bf;
/* Flush after every set otherwise console buffer may get full. */
for (i = SN5S330_FUNC_SET1; i <= SN5S330_FUNC_SET12; i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("FUNC_SET%d [%02Xh] = 0x%02x\n",
i - SN5S330_FUNC_SET1 + 1,
i,
@@ -93,7 +93,7 @@ static int sn5s330_dump(int port)
cflush();
for (i = SN5S330_INT_STATUS_REG1; i <= SN5S330_INT_STATUS_REG4; i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("INT_STATUS_REG%d [%02Xh] = 0x%02x\n",
i - SN5S330_INT_STATUS_REG1 + 1,
i,
@@ -104,7 +104,7 @@ static int sn5s330_dump(int port)
for (i = SN5S330_INT_TRIP_RISE_REG1; i <= SN5S330_INT_TRIP_RISE_REG3;
i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("INT_TRIP_RISE_REG%d [%02Xh] = 0x%02x\n",
i - SN5S330_INT_TRIP_RISE_REG1 + 1,
i,
@@ -115,7 +115,7 @@ static int sn5s330_dump(int port)
for (i = SN5S330_INT_TRIP_FALL_REG1; i <= SN5S330_INT_TRIP_FALL_REG3;
i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("INT_TRIP_FALL_REG%d [%02Xh] = 0x%02x\n",
i - SN5S330_INT_TRIP_FALL_REG1 + 1,
i,
@@ -126,7 +126,7 @@ static int sn5s330_dump(int port)
for (i = SN5S330_INT_MASK_RISE_REG1; i <= SN5S330_INT_MASK_RISE_REG3;
i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("INT_MASK_RISE_REG%d [%02Xh] = 0x%02x\n",
i - SN5S330_INT_MASK_RISE_REG1 + 1,
i,
@@ -137,7 +137,7 @@ static int sn5s330_dump(int port)
for (i = SN5S330_INT_MASK_FALL_REG1; i <= SN5S330_INT_MASK_FALL_REG3;
i++) {
- i2c_read8(i2c_port, i2c_addr, i, &data);
+ i2c_read8__7bf(i2c_port, i2c_addr__7bf, i, &data);
ccprintf("INT_MASK_FALL_REG%d [%02Xh] = 0x%02x\n",
i - SN5S330_INT_MASK_FALL_REG1 + 1,
i,
@@ -184,7 +184,7 @@ static int sn5s330_init(int port)
int retries;
int reg;
const int i2c_port = ppc_chips[port].i2c_port;
- const int i2c_addr = ppc_chips[port].i2c_addr;
+ const uint16_t i2c_addr__7bf = ppc_chips[port].i2c_addr__7bf;
#ifdef CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT
/* Set the sourcing current limit value. */
@@ -211,8 +211,8 @@ static int sn5s330_init(int port)
*/
retries = 0;
do {
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET1,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET1, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET1! Retrying..",
port);
@@ -225,21 +225,24 @@ static int sn5s330_init(int port)
/* Set Vbus OVP threshold to ~22.325V. */
regval = 0x37;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET5, regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET5, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET5!", port);
return status;
}
/* Set Vbus UVP threshold to ~2.75V. */
- status = i2c_read8(i2c_port, i2c_addr, SN5S330_FUNC_SET6, &regval);
+ status = i2c_read8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET6, &regval);
if (status) {
CPRINTS("ppc p%d: Failed to read FUNC_SET6!", port);
return status;
}
regval &= ~0x3F;
regval |= 1;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET6, regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET6, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write FUNC_SET6!", port);
return status;
@@ -247,7 +250,8 @@ static int sn5s330_init(int port)
/* Enable SBU Fets and set PP2 current limit to ~3A. */
regval = SN5S330_SBU_EN | 0x8;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET2, regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET2, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET2!", port);
return status;
@@ -266,7 +270,8 @@ static int sn5s330_init(int port)
* low voltage protection).
*/
regval = SN5S330_OVP_EN_CC | SN5S330_PP2_CONFIG | SN5S330_CONFIG_UVP;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET9, regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET9, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET9!", port);
return status;
@@ -274,8 +279,8 @@ static int sn5s330_init(int port)
/* Set analog current limit delay to 200 us for both PP1 & PP2. */
regval = (PPX_ILIM_DEGLITCH_0_US_200 << 3) | PPX_ILIM_DEGLITCH_0_US_200;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET11,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET11, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET11", port);
return status;
@@ -288,14 +293,16 @@ static int sn5s330_init(int port)
* reset default (20 us).
*/
regval = 0;
- status = i2c_read8(i2c_port, i2c_addr, SN5S330_FUNC_SET8, &regval);
+ status = i2c_read8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET8, &regval);
if (status) {
CPRINTS("ppc p%d: Failed to read FUNC_SET8!", port);
return status;
}
regval &= ~SN5S330_VCONN_DEGLITCH_MASK;
regval |= SN5S330_VCONN_DEGLITCH_640_US;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_FUNC_SET8, regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_FUNC_SET8, regval);
if (status) {
CPRINTS("ppc p%d: Failed to set FUNC_SET8!", port);
return status;
@@ -347,8 +354,8 @@ static int sn5s330_init(int port)
* is checked below.
*/
regval = SN5S330_DIG_RES | SN5S330_VSAFE0V_MASK;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_STATUS_REG4,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_STATUS_REG4, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_STATUS_REG4!", port);
return status;
@@ -365,30 +372,30 @@ static int sn5s330_init(int port)
*/
regval = ~SN5S330_ILIM_PP1_MASK;
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_RISE_REG1,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_RISE_REG1, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_RISE1!", port);
return status;
}
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_FALL_REG1,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_FALL_REG1, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_FALL1!", port);
return status;
}
/* Now mask all the other interrupts. */
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_RISE_REG2,
- 0xFF);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_RISE_REG2, 0xFF);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_RISE2!", port);
return status;
}
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_FALL_REG2,
- 0xFF);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_FALL_REG2, 0xFF);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_FALL2!", port);
return status;
@@ -401,15 +408,15 @@ static int sn5s330_init(int port)
regval = 0xFF;
#endif /* CONFIG_USB_PD_VBUS_DETECT_PPC && CONFIG_USB_CHARGER */
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_RISE_REG3,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_RISE_REG3, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_RISE3!", port);
return status;
}
- status = i2c_write8(i2c_port, i2c_addr, SN5S330_INT_MASK_FALL_REG3,
- regval);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_MASK_FALL_REG3, regval);
if (status) {
CPRINTS("ppc p%d: Failed to write INT_MASK_FALL3!", port);
return status;
@@ -419,7 +426,8 @@ static int sn5s330_init(int port)
for (reg = SN5S330_INT_TRIP_RISE_REG1;
reg <= SN5S330_INT_TRIP_FALL_REG3;
reg++) {
- status = i2c_write8(i2c_port, i2c_addr, reg, 0xFF);
+ status = i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ reg, 0xFF);
if (status) {
CPRINTS("ppc p%d: Failed to write reg 0x%2x!", port);
return status;
@@ -431,8 +439,8 @@ static int sn5s330_init(int port)
* For PP2, check to see if we booted in dead battery mode. If we
* booted in dead battery mode, the PP2 FET will already be enabled.
*/
- status = i2c_read8(i2c_port, i2c_addr, SN5S330_INT_STATUS_REG4,
- &regval);
+ status = i2c_read8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_STATUS_REG4, &regval);
if (status) {
CPRINTS("ppc p%d: Failed to read INT_STATUS_REG4!", port);
return status;
@@ -443,8 +451,8 @@ static int sn5s330_init(int port)
* Clear the bit by writing 1 and keep vSafe0V_MASK
* unchanged.
*/
- i2c_write8(i2c_port, i2c_addr, SN5S330_INT_STATUS_REG4,
- regval);
+ i2c_write8__7bf(i2c_port, i2c_addr__7bf,
+ SN5S330_INT_STATUS_REG4, regval);
/* Turn on PP2 FET. */
status = sn5s330_pp_fet_enable(port, SN5S330_PP2, 1);
diff --git a/driver/ppc/sn5s330.h b/driver/ppc/sn5s330.h
index c5b16ea73b..a153b9d25a 100644
--- a/driver/ppc/sn5s330.h
+++ b/driver/ppc/sn5s330.h
@@ -12,7 +12,7 @@
struct sn5s330_config {
uint8_t i2c_port;
- uint8_t i2c_addr;
+ uint8_t i2c_addr__7bf;
};
extern const struct sn5s330_config sn5s330_chips[];
@@ -25,10 +25,10 @@ enum sn5s330_pp_idx {
SN5S330_PP_COUNT,
};
-#define SN5S330_ADDR0 0x80
-#define SN5S330_ADDR1 0x82
-#define SN5S330_ADDR2 0x84
-#define SN5S330_ADDR3 0x86
+#define SN5S330_ADDR0__7bf (0x40)
+#define SN5S330_ADDR1__7bf (0x41)
+#define SN5S330_ADDR2__7bf (0x42)
+#define SN5S330_ADDR3__7bf (0x43)
#define SN5S330_FUNC_SET1 0x50
#define SN5S330_FUNC_SET2 0x51
diff --git a/driver/ppc/syv682x.c b/driver/ppc/syv682x.c
new file mode 100644
index 0000000000..a8f5c146bb
--- /dev/null
+++ b/driver/ppc/syv682x.c
@@ -0,0 +1,351 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Silergy SYV682x USB-C Power Path Controller */
+#include "common.h"
+#include "console.h"
+#include "driver/ppc/syv682x.h"
+#include "i2c.h"
+#include "usb_charge.h"
+#include "usb_pd_tcpm.h"
+#include "usbc_ppc.h"
+#include "util.h"
+
+#define SYV682X_FLAGS_SOURCE_ENABLED BIT(0)
+/* 0 -> CC1, 1 -> CC2 */
+#define SYV682X_FLAGS_CC_POLARITY BIT(1)
+#define SYV682X_FLAGS_VBUS_PRESENT BIT(2)
+static uint8_t flags[CONFIG_USB_PD_PORT_COUNT];
+
+#define SYV682X_VBUS_DET_THRESH_MV 4000
+
+static int read_reg(uint8_t port, int reg, int *regval)
+{
+ return i2c_read8__7bf(ppc_chips[port].i2c_port,
+ ppc_chips[port].i2c_addr__7bf,
+ reg,
+ regval);
+}
+
+static int write_reg(uint8_t port, int reg, int regval)
+{
+ return i2c_write8__7bf(ppc_chips[port].i2c_port,
+ ppc_chips[port].i2c_addr__7bf,
+ reg,
+ regval);
+}
+
+static int syv682x_is_sourcing_vbus(int port)
+{
+ return flags[port] & SYV682X_FLAGS_SOURCE_ENABLED;
+}
+
+static int syv682x_vbus_sink_enable(int port, int enable)
+{
+ int regval;
+ int rv;
+
+ /*
+ * For sink mode need to make sure high voltage power path is connected
+ * and sink mode is selected.
+ */
+ rv = read_reg(port, SYV682X_CONTROL_1_REG, &regval);
+ if (rv)
+ return rv;
+
+ if (enable) {
+ /* Select high voltage path */
+ regval |= SYV682X_CONTROL_1_CH_SEL;
+ /* Select Sink mode and turn on the channel */
+ regval &= ~(SYV682X_CONTROL_1_HV_DR |
+ SYV682X_CONTROL_1_PWR_ENB);
+ } else {
+ /*
+ * No need to change the voltage path or channel direction. But,
+ * turn both paths off.
+ */
+ regval |= SYV682X_CONTROL_1_PWR_ENB;
+ }
+
+ return write_reg(port, SYV682X_CONTROL_1_REG, regval);
+}
+
+#ifdef CONFIG_USB_PD_VBUS_DETECT_PPC
+static int syv682x_is_vbus_present(int port)
+{
+ int val;
+ int vbus = 0;
+
+ /*
+ * TODO (b/112661747): This PPC doesn't fully support VBUS detection.
+ * It can detect both VSafe5V and VSafe0V. This function is intended
+ * here until detecting VBUS differently per channel is supported.
+ */
+ if (read_reg(port, SYV682X_STATUS_REG, &val))
+ return vbus;
+
+ /*
+ * VBUS is considered present if VSafe5V is detected or neither VSafe5V
+ * or VSafe0V is detected, which implies VBUS > 5V.
+ */
+ if ((val & SYV682X_STATUS_VSAFE_5V) ||
+ !(val & (SYV682X_STATUS_VSAFE_5V | SYV682X_STATUS_VSAFE_0V)))
+ vbus = 1;
+#ifdef CONFIG_USB_CHARGER
+ if (!!(flags[port] & SYV682X_FLAGS_VBUS_PRESENT) != vbus)
+ usb_charger_vbus_change(port, vbus);
+
+ if (vbus)
+ flags[port] |= SYV682X_FLAGS_VBUS_PRESENT;
+ else
+ flags[port] &= ~SYV682X_FLAGS_VBUS_PRESENT;
+#endif
+
+ return vbus;
+}
+#endif
+
+static int syv682x_vbus_source_enable(int port, int enable)
+{
+ int regval;
+ int rv;
+
+ /*
+ * For source mode need to make sure 5V power path is connected
+ * and source mode is selected.
+ */
+ rv = read_reg(port, SYV682X_CONTROL_1_REG, &regval);
+ if (rv)
+ return rv;
+
+ if (enable) {
+ /* Select 5V path and turn on channel */
+ regval &= ~(SYV682X_CONTROL_1_CH_SEL |
+ SYV682X_CONTROL_1_PWR_ENB);
+ /* Disable HV Sink path */
+ regval |= SYV682X_CONTROL_1_HV_DR;
+ } else if (flags[port] & SYV682X_FLAGS_SOURCE_ENABLED) {
+ /*
+ * For the disable case, make sure that VBUS was being sourced
+ * prior to disabling the source path. Because the source/sink
+ * paths can't be independently disabled, and this function will
+ * get called as part of USB PD initialization, setting the
+ * PWR_ENB always can lead to broken dead battery behavior.
+ *
+ * No need to change the voltage path or channel direction. But,
+ * turn both paths off.
+ */
+ regval |= SYV682X_CONTROL_1_PWR_ENB;
+ }
+
+ rv = write_reg(port, SYV682X_CONTROL_1_REG, regval);
+ if (rv)
+ return rv;
+
+ if (enable)
+ flags[port] |= SYV682X_FLAGS_SOURCE_ENABLED;
+ else
+ flags[port] &= ~SYV682X_FLAGS_SOURCE_ENABLED;
+
+#if defined(CONFIG_USB_CHARGER) && defined(CONFIG_USB_PD_VBUS_DETECT_PPC)
+ /*
+ * Since the VBUS state could be changing here, need to wake the
+ * USB_CHG_N task so that BC 1.2 detection will be triggered.
+ */
+ usb_charger_vbus_change(port, enable);
+#endif
+
+ return EC_SUCCESS;
+}
+
+static int syv682x_set_vbus_source_current_limit(int port,
+ enum tcpc_rp_value rp)
+{
+ int rv;
+ int limit;
+ int regval;
+
+ rv = read_reg(port, SYV682X_CONTROL_1_REG, &regval);
+ if (rv)
+ return rv;
+
+ /* We need buffer room for all current values. */
+ switch (rp) {
+ case TYPEC_RP_3A0:
+ limit = SYV682X_ILIM_3_30;
+ break;
+
+ case TYPEC_RP_1A5:
+ limit = SYV682X_ILIM_1_75;
+ break;
+
+ case TYPEC_RP_USB:
+ default:
+ /* 1.25 A is lowest current limit setting for SVY682 */
+ limit = SYV682X_ILIM_1_25;
+ break;
+ };
+
+ regval &= ~SYV682X_ILIM_MASK;
+ regval |= (limit << SYV682X_ILIM_BIT_SHIFT);
+ return write_reg(port, SYV682X_CONTROL_1_REG, regval);
+}
+
+static int syv682x_discharge_vbus(int port, int enable)
+{
+ int regval;
+ int rv;
+
+ rv = read_reg(port, SYV682X_CONTROL_2_REG, &regval);
+ if (rv)
+ return rv;
+
+ if (enable)
+ regval |= SYV682X_CONTROL_2_FDSG;
+ else
+ regval &= ~SYV682X_CONTROL_2_FDSG;
+
+ return write_reg(port, SYV682X_CONTROL_2_REG, regval);
+}
+
+#ifdef CONFIG_USBC_PPC_POLARITY
+static int syv682x_set_polarity(int port, int polarity)
+{
+ /*
+ * The SYV682x does not explicitly set CC polarity. However, if VCONN is
+ * being used then the polarity is required to connect 5V to the correct
+ * CC line. So this function saves the CC polarity as a bit in the flags
+ * variable so VCONN is connected the correct CC line. The flag bit
+ * being set means polarity = CC2, the flag bit clear means
+ * polarity = CC1.
+ */
+ if (polarity)
+ flags[port] |= SYV682X_FLAGS_CC_POLARITY;
+ else
+ flags[port] &= ~SYV682X_FLAGS_CC_POLARITY;
+
+ return EC_SUCCESS;
+}
+#endif
+
+#ifdef CONFIG_USBC_PPC_VCONN
+static int syv682x_set_vconn(int port, int enable)
+{
+ int regval;
+ int rv;
+
+ rv = read_reg(port, SYV682X_CONTROL_4_REG, &regval);
+ if (rv)
+ return rv;
+
+ if (enable)
+ regval |= flags[port] & SYV682X_FLAGS_CC_POLARITY ?
+ SYV682X_CONTROL_4_VCONN1 : SYV682X_CONTROL_4_VCONN2;
+ else
+ regval &= ~(SYV682X_CONTROL_4_VCONN2 |
+ SYV682X_CONTROL_4_VCONN1);
+
+ return write_reg(port, SYV682X_CONTROL_4_REG, regval);
+}
+#endif
+
+#ifdef CONFIG_CMD_PPC_DUMP
+static int syv682x_dump(int port)
+{
+ int reg_addr;
+ int data;
+ int rv;
+ const int i2c_port = ppc_chips[port].i2c_port;
+ const int i2c_addr__7bf = ppc_chips[port].i2c_addr__7bf;
+
+ for (reg_addr = SYV682X_STATUS_REG; reg_addr <= SYV682X_CONTROL_4_REG;
+ reg_addr++) {
+ rv = i2c_read8__7bf(i2c_port, i2c_addr__7bf, reg_addr, &data);
+ if (rv)
+ ccprintf("ppc_syv682[p%d]: Failed to read reg 0x%02x\n",
+ port, reg_addr);
+ else
+ ccprintf("ppc_syv682[p%d]: reg 0x%02x = 0x%02x\n",
+ port, reg_addr, data);
+ }
+
+ cflush();
+
+ return EC_SUCCESS;
+}
+#endif /* defined(CONFIG_CMD_PPC_DUMP) */
+
+static int syv682x_init(int port)
+{
+ int rv;
+ int regval;
+
+ /* Set VBUS discharge to manual mode */
+ rv = read_reg(port, SYV682X_CONTROL_2_REG, &regval);
+ if (rv)
+ return rv;
+ regval &= ~SYV682X_CONTROL_2_SDSG;
+ rv = write_reg(port, SYV682X_CONTROL_2_REG, regval);
+ if (rv)
+ return rv;
+
+ /* Select max voltage for OVP */
+ rv = read_reg(port, SYV682X_CONTROL_3_REG, &regval);
+ if (rv)
+ return rv;
+ regval &= ~SYV682X_OVP_MASK;
+ regval |= (SYV682X_OVP_23_7 << SYV682X_OVP_BIT_SHIFT);
+ rv = write_reg(port, SYV682X_CONTROL_3_REG, regval);
+ if (rv)
+ return rv;
+
+ /* Check if this if dead battery case */
+ rv = read_reg(port, SYV682X_CONTROL_1_REG, &regval);
+ if (rv)
+ return rv;
+ if (regval & SYV682X_STATUS_VSAFE_0V) {
+ /* Not dead battery case, so disable channel */
+ regval |= SYV682X_CONTROL_1_PWR_ENB;
+ rv = write_reg(port, SYV682X_CONTROL_1_REG, regval);
+ if (rv)
+ return rv;
+ } else {
+ syv682x_vbus_sink_enable(port, 1);
+ }
+
+ rv = read_reg(port, SYV682X_CONTROL_4_REG, &regval);
+ if (rv)
+ return rv;
+ /* Remove Rd and connect CC1/CC2 lines to TCPC */
+ regval |= SYV682X_CONTROL_4_CC1_BPS | SYV682X_CONTROL_4_CC2_BPS;
+ /* Disable Fast Role Swap (FRS) */
+ regval |= SYV682X_CONTROL_4_CC_FRS;
+ rv = write_reg(port, SYV682X_CONTROL_4_REG, regval);
+ if (rv)
+ return rv;
+
+ return EC_SUCCESS;
+}
+
+const struct ppc_drv syv682x_drv = {
+ .init = &syv682x_init,
+ .is_sourcing_vbus = &syv682x_is_sourcing_vbus,
+ .vbus_sink_enable = &syv682x_vbus_sink_enable,
+ .vbus_source_enable = &syv682x_vbus_source_enable,
+#ifdef CONFIG_CMD_PPC_DUMP
+ .reg_dump = &syv682x_dump,
+#endif /* defined(CONFIG_CMD_PPC_DUMP) */
+#ifdef CONFIG_USB_PD_VBUS_DETECT_PPC
+ .is_vbus_present = &syv682x_is_vbus_present,
+#endif /* defined(CONFIG_USB_PD_VBUS_DETECT_PPC) */
+ .set_vbus_source_current_limit = &syv682x_set_vbus_source_current_limit,
+ .discharge_vbus = &syv682x_discharge_vbus,
+#ifdef CONFIG_USBC_PPC_POLARITY
+ .set_polarity = &syv682x_set_polarity,
+#endif
+#ifdef CONFIG_USBC_PPC_VCONN
+ .set_vconn = &syv682x_set_vconn,
+#endif
+};
diff --git a/driver/ppc/syv682x.h b/driver/ppc/syv682x.h
new file mode 100644
index 0000000000..f355fe1cf9
--- /dev/null
+++ b/driver/ppc/syv682x.h
@@ -0,0 +1,68 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Silergy SYV682x Type-C Power Path Controller */
+
+#ifndef __CROS_EC_SYV682X_H
+#define __CROS_EC_SYV682X_H
+
+/* I2C addresses */
+#define SYV682X_ADDR0__7bf 0x40
+#define SYV682X_ADDR1__7bf 0x41
+#define SYV682X_ADDR2__7bf 0x42
+#define SYV682x_ADDR3__7bf 0x43
+
+/* SYV682x register addresses */
+#define SYV682X_STATUS_REG 0x00
+#define SYV682X_CONTROL_1_REG 0x01
+#define SYV682X_CONTROL_2_REG 0x02
+#define SYV682X_CONTROL_3_REG 0x03
+#define SYV682X_CONTROL_4_REG 0x04
+
+/* Status Register */
+#define SYV682X_STATUS_VSAFE_5V BIT(1)
+#define SYV682X_STATUS_VSAFE_0V BIT(0)
+
+/* Control Register 1 */
+#define SYV682X_CONTROL_1_CH_SEL BIT(1)
+#define SYV682X_CONTROL_1_HV_DR BIT(2)
+#define SYV682X_CONTROL_1_PWR_ENB BIT(7)
+
+#define SYV682X_ILIM_MASK 0x18
+#define SYV682X_ILIM_BIT_SHIFT 3
+#define SYV682X_ILIM_1_25 0
+#define SYV682X_ILIM_1_75 1
+#define SYV682X_ILIM_2_25 2
+#define SYV682X_ILIM_3_30 3
+
+/* Control Register 2 */
+#define SYV682X_CONTROL_2_SDSG BIT(1)
+#define SYV682X_CONTROL_2_FDSG BIT(0)
+
+/* Control Register 3 */
+#define SYV682X_OVP_MASK 0x70
+#define SYV682X_OVP_BIT_SHIFT 4
+#define SYV682X_OVP_06_0 0
+#define SYV682X_OVP_08_0 1
+#define SYV682X_OVP_11_1 2
+#define SYV682X_OVP_12_1 3
+#define SYV682X_OVP_14_2 4
+#define SYV682X_OVP_17_9 5
+#define SYV682X_OVP_21_6 6
+#define SYV682X_OVP_23_7 7
+
+/* Control Register 4 */
+#define SYV682X_CONTROL_4_CC1_BPS BIT(7)
+#define SYV682X_CONTROL_4_CC2_BPS BIT(6)
+#define SYV682X_CONTROL_4_VCONN1 BIT(5)
+#define SYV682X_CONTROL_4_VCONN2 BIT(4)
+#define SYV682X_CONTROL_4_VBAT_OVP BIT(3)
+#define SYV682X_CONTROL_4_VCONN_OCP BIT(2)
+#define SYV682X_CONTROL_4_CC_FRS BIT(1)
+
+struct ppc_drv;
+extern const struct ppc_drv syv682x_drv;
+
+#endif /* defined(__CROS_EC_SYV682X_H) */
diff --git a/driver/regulator_ir357x.c b/driver/regulator_ir357x.c
index 4f65db13e6..6b8a24396f 100644
--- a/driver/regulator_ir357x.c
+++ b/driver/regulator_ir357x.c
@@ -16,8 +16,8 @@
#define CPUTS(outstr) cputs(CC_CHIPSET, outstr)
#define CPRINTF(format, args...) cprintf(CC_CHIPSET, format, ## args)
-/* 8-bit I2C address */
-#define IR357x_I2C_ADDR (0x8 << 1)
+/* I2C address */
+#define IR357x_I2C_ADDR__7bf (0x8)
struct ir_setting {
uint8_t reg;
diff --git a/driver/sensorhub_lsm6dsm.c b/driver/sensorhub_lsm6dsm.c
index f663f5a5ae..711294fb98 100644
--- a/driver/sensorhub_lsm6dsm.c
+++ b/driver/sensorhub_lsm6dsm.c
@@ -21,12 +21,12 @@ static int set_reg_bit_field(const struct motion_sensor_t *s,
int tmp;
int ret;
- ret = st_raw_read8(s->port, s->addr, reg, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, reg, &tmp);
if (ret != EC_SUCCESS)
return ret;
tmp |= bit_field;
- return st_raw_write8(s->port, s->addr, reg, tmp);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, reg, tmp);
}
static int clear_reg_bit_field(const struct motion_sensor_t *s,
@@ -35,12 +35,12 @@ static int clear_reg_bit_field(const struct motion_sensor_t *s,
int tmp;
int ret;
- ret = st_raw_read8(s->port, s->addr, reg, &tmp);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf, reg, &tmp);
if (ret != EC_SUCCESS)
return ret;
tmp &= ~(bit_field);
- return st_raw_write8(s->port, s->addr, reg, tmp);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf, reg, tmp);
}
static inline int enable_sensorhub_func(const struct motion_sensor_t *s)
@@ -89,7 +89,8 @@ static inline int disable_aux_i2c_master(const struct motion_sensor_t *s)
static inline int restore_master_cfg(const struct motion_sensor_t *s,
int cache)
{
- return st_raw_write8(s->port, s->addr, LSM6DSM_MASTER_CFG_ADDR, cache);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_MASTER_CFG_ADDR, cache);
}
static int enable_i2c_pass_through(const struct motion_sensor_t *s,
@@ -97,7 +98,8 @@ static int enable_i2c_pass_through(const struct motion_sensor_t *s,
{
int ret;
- ret = st_raw_read8(s->port, s->addr, LSM6DSM_MASTER_CFG_ADDR, cache);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_MASTER_CFG_ADDR, cache);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x MCR error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -109,8 +111,9 @@ static int enable_i2c_pass_through(const struct motion_sensor_t *s,
* Wait is for any pending bus activity(probably read) to settle down
* so that there is no bus contention.
*/
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_MASTER_CFG_ADDR,
- *cache | LSM6DSM_EXT_TRIGGER_EN);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_MASTER_CFG_ADDR,
+ *cache | LSM6DSM_EXT_TRIGGER_EN);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x MCETEN error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -118,8 +121,10 @@ static int enable_i2c_pass_through(const struct motion_sensor_t *s,
}
msleep(10);
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_MASTER_CFG_ADDR,
- *cache & ~(LSM6DSM_EXT_TRIGGER_EN | LSM6DSM_I2C_MASTER_ON));
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_MASTER_CFG_ADDR,
+ *cache & ~(LSM6DSM_EXT_TRIGGER_EN
+ | LSM6DSM_I2C_MASTER_ON));
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x MCC error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -127,7 +132,7 @@ static int enable_i2c_pass_through(const struct motion_sensor_t *s,
return ret;
}
- return st_raw_write8(s->port, s->addr,
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
LSM6DSM_MASTER_CFG_ADDR, LSM6DSM_I2C_PASS_THRU_MODE);
}
@@ -136,37 +141,43 @@ static inline int power_down_accel(const struct motion_sensor_t *s,
{
int ret;
- ret = st_raw_read8(s->port, s->addr, LSM6DSM_CTRL1_ADDR, cache);
+ ret = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_CTRL1_ADDR, cache);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x CTRL1R error ret: %d\n",
__func__, s->name, s->type, ret);
return ret;
}
- return st_raw_write8(s->port, s->addr, LSM6DSM_CTRL1_ADDR,
- *cache & ~LSM6DSM_XL_ODR_MASK);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_CTRL1_ADDR,
+ *cache & ~LSM6DSM_XL_ODR_MASK);
}
static inline int restore_ctrl1(const struct motion_sensor_t *s, int cache)
{
- return st_raw_write8(s->port, s->addr,
- LSM6DSM_CTRL1_ADDR, cache);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_CTRL1_ADDR, cache);
}
-static int config_slv0_read(const struct motion_sensor_t *s, uint8_t addr,
- uint8_t reg, uint8_t len)
+static int config_slv0_read__7bf(const struct motion_sensor_t *s,
+ const uint16_t slv_addr__7bf,
+ uint16_t reg, uint8_t len)
{
int ret;
+ uint16_t addr__8b = I2C_GET_ADDR__7b(slv_addr__7bf) << 1;
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_SLV0_ADD_ADDR,
- (addr | LSM6DSM_SLV0_RD_BIT));
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_SLV0_ADD_ADDR,
+ (addr__8b | LSM6DSM_SLV0_RD_BIT));
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x SA error ret: %d\n",
__func__, s->name, s->type, ret);
return ret;
}
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_SLV0_SUBADD_ADDR, reg);
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_SLV0_SUBADD_ADDR, reg);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x RA error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -177,8 +188,9 @@ static int config_slv0_read(const struct motion_sensor_t *s, uint8_t addr,
* No decimation for external sensor 0,
* Number of sensors connected to external sensor hub 1
*/
- ret = st_raw_write8(s->port, s->addr, LSM6DSM_SLV0_CONFIG_ADDR,
- (len & LSM6DSM_SLV0_NUM_OPS_MASK));
+ ret = st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_SLV0_CONFIG_ADDR,
+ (len & LSM6DSM_SLV0_NUM_OPS_MASK));
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x CFG error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -188,8 +200,9 @@ static int config_slv0_read(const struct motion_sensor_t *s, uint8_t addr,
return EC_SUCCESS;
}
-int sensorhub_config_ext_reg(const struct motion_sensor_t *s,
- uint8_t slv_addr, uint8_t reg, uint8_t val)
+int sensorhub_config_ext_reg__7bf(const struct motion_sensor_t *s,
+ const uint16_t slv_addr__7bf,
+ uint8_t reg, uint8_t val)
{
int ret;
int tmp;
@@ -201,13 +214,13 @@ int sensorhub_config_ext_reg(const struct motion_sensor_t *s,
return ret;
}
- ret = st_raw_write8(s->port, slv_addr, reg, val);
+ ret = st_raw_write8__7bf(s->port, slv_addr__7bf, reg, val);
restore_master_cfg(s, tmp);
return ret;
}
-int sensorhub_config_slv0_read(const struct motion_sensor_t *s,
- uint8_t slv_addr, uint8_t reg, int len)
+int sensorhub_config_slv0_read__7bf(const struct motion_sensor_t *s,
+ uint16_t slv_addr__7bf, uint8_t reg, int len)
{
int tmp_xl_cfg;
int ret;
@@ -232,7 +245,7 @@ int sensorhub_config_slv0_read(const struct motion_sensor_t *s,
goto out_restore_ctrl1;
}
- ret = config_slv0_read(s, slv_addr, reg, len);
+ ret = config_slv0_read__7bf(s, slv_addr__7bf, reg, len);
disable_ereg_bank_acc(s);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x CS0R error ret: %d\n",
@@ -267,8 +280,9 @@ int sensorhub_slv0_data_read(const struct motion_sensor_t *s, uint8_t *raw)
* register as soon as the accel is in power-up mode. So return the
* contents of that register.
*/
- ret = st_raw_read_n_noinc(s->port, s->addr, LSM6DSM_SENSORHUB1_REG,
- raw, OUT_XYZ_SIZE);
+ ret = st_raw_read_n_noinc__7bf(s->port, s->i2c_spi_addr__7bf,
+ LSM6DSM_SENSORHUB1_REG,
+ raw, OUT_XYZ_SIZE);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x SH1R error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -277,9 +291,10 @@ int sensorhub_slv0_data_read(const struct motion_sensor_t *s, uint8_t *raw)
return EC_SUCCESS;
}
-int sensorhub_check_and_rst(const struct motion_sensor_t *s, uint8_t slv_addr,
- uint8_t whoami_reg, uint8_t whoami_val,
- uint8_t rst_reg, uint8_t rst_val)
+int sensorhub_check_and_rst__7bf(const struct motion_sensor_t *s,
+ const uint16_t slv_addr__7bf,
+ uint8_t whoami_reg, uint8_t whoami_val,
+ uint8_t rst_reg, uint8_t rst_val)
{
int ret, tmp;
int tmp_master_cfg;
@@ -291,7 +306,7 @@ int sensorhub_check_and_rst(const struct motion_sensor_t *s, uint8_t slv_addr,
return ret;
}
- ret = st_raw_read8(s->port, slv_addr, whoami_reg, &tmp);
+ ret = st_raw_read8__7bf(s->port, slv_addr__7bf, whoami_reg, &tmp);
if (ret != EC_SUCCESS) {
CPRINTF("%s: %s type:0x%x WAIR error ret: %d\n",
__func__, s->name, s->type, ret);
@@ -305,7 +320,7 @@ int sensorhub_check_and_rst(const struct motion_sensor_t *s, uint8_t slv_addr,
goto err_restore_master_cfg;
}
- ret = st_raw_write8(s->port, slv_addr, rst_reg, rst_val);
+ ret = st_raw_write8__7bf(s->port, slv_addr__7bf, rst_reg, rst_val);
err_restore_master_cfg:
restore_master_cfg(s, tmp_master_cfg);
return ret;
diff --git a/driver/sensorhub_lsm6dsm.h b/driver/sensorhub_lsm6dsm.h
index a86ca6f9c3..0eaef61c32 100644
--- a/driver/sensorhub_lsm6dsm.h
+++ b/driver/sensorhub_lsm6dsm.h
@@ -24,8 +24,9 @@
* @param val Value to be written into the external sensor register.
* @return EC_SUCCESS on success, EC error codes on failure.
*/
-int sensorhub_config_ext_reg(const struct motion_sensor_t *s,
- uint8_t slv_addr, uint8_t reg, uint8_t val);
+int sensorhub_config_ext_reg__7bf(const struct motion_sensor_t *s,
+ const uint16_t slv_addr__7bf,
+ uint8_t reg, uint8_t val);
/**
* Configure the sensor hub to read data from a specific register of an
@@ -37,8 +38,9 @@ int sensorhub_config_ext_reg(const struct motion_sensor_t *s,
* @param len Length of data to be read.
* @return EC_SUCCESS on success, EC error codes on failure.
*/
-int sensorhub_config_slv0_read(const struct motion_sensor_t *s,
- uint8_t slv_addr, uint8_t reg, int len);
+int sensorhub_config_slv0_read__7bf(const struct motion_sensor_t *s,
+ const uint16_t slv_addr__7bf,
+ uint8_t reg, int len);
/**
* Reads the data from the register bank that is associated with the slave0
@@ -62,7 +64,8 @@ int sensorhub_slv0_data_read(const struct motion_sensor_t *s, uint8_t *raw);
* @param rst_val Value to be written to the reset register.
* @return EC_SUCCESS on success, EC error codes on failure.
*/
-int sensorhub_check_and_rst(const struct motion_sensor_t *s, uint8_t slv_addr,
- uint8_t whoami_reg, uint8_t whoami_val,
- uint8_t rst_reg, uint8_t rst_val);
+int sensorhub_check_and_rst__7bf(const struct motion_sensor_t *s,
+ const uint16_t slv_addr__7bf,
+ uint8_t whoami_reg, uint8_t whoami_val,
+ uint8_t rst_reg, uint8_t rst_val);
#endif /* __CROS_EC_SENSORHUB_LSM6DSM_H */
diff --git a/driver/stm_mems_common.c b/driver/stm_mems_common.c
index 00784fc1fc..9341308fb5 100644
--- a/driver/stm_mems_common.c
+++ b/driver/stm_mems_common.c
@@ -11,21 +11,25 @@
/**
* st_raw_read_n - Read n bytes for read
*/
-int st_raw_read_n(const int port, const int addr, const uint8_t reg,
- uint8_t *data_ptr, const int len)
+int st_raw_read_n__7bf(const int port,
+ const uint16_t i2c_addr__7bf,
+ const uint8_t reg, uint8_t *data_ptr, const int len)
{
/* TODO: Implement SPI interface support */
- return i2c_read_block(port, addr, reg | 0x80, data_ptr, len);
+ return i2c_read_block__7bf(port, i2c_addr__7bf,
+ reg | 0x80, data_ptr, len);
}
/**
* st_raw_read_n_noinc - Read n bytes for read (no auto inc address)
*/
-int st_raw_read_n_noinc(const int port, const int addr, const uint8_t reg,
- uint8_t *data_ptr, const int len)
+int st_raw_read_n_noinc__7bf(const int port,
+ const uint16_t i2c_addr__7bf,
+ const uint8_t reg, uint8_t *data_ptr, const int len)
{
/* TODO: Implement SPI interface support */
- return i2c_read_block(port, addr, reg, data_ptr, len);
+ return i2c_read_block__7bf(port, i2c_addr__7bf,
+ reg, data_ptr, len);
}
/**
@@ -41,7 +45,8 @@ int st_write_data_with_mask(const struct motion_sensor_t *s, int reg,
int err;
int new_data = 0x00, old_data = 0x00;
- err = st_raw_read8(s->port, s->addr, reg, &old_data);
+ err = st_raw_read8__7bf(s->port, s->i2c_spi_addr__7bf,
+ reg, &old_data);
if (err != EC_SUCCESS)
return err;
@@ -51,7 +56,8 @@ int st_write_data_with_mask(const struct motion_sensor_t *s, int reg,
if (new_data == old_data)
return EC_SUCCESS;
- return st_raw_write8(s->port, s->addr, reg, new_data);
+ return st_raw_write8__7bf(s->port, s->i2c_spi_addr__7bf,
+ reg, new_data);
}
/**
diff --git a/driver/stm_mems_common.h b/driver/stm_mems_common.h
index e2211480aa..39d718cf1b 100644
--- a/driver/stm_mems_common.h
+++ b/driver/stm_mems_common.h
@@ -34,34 +34,38 @@
/**
* Read single register
*/
-static inline int st_raw_read8(const int port, const int addr, const int reg,
- int *data_ptr)
+static inline int st_raw_read8__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const int reg, int *data_ptr)
{
/* TODO: Implement SPI interface support */
- return i2c_read8(port, addr, reg, data_ptr);
+ return i2c_read8__7bf(port, i2c_spi_addr__7bf, reg, data_ptr);
}
/**
* Write single register
*/
-static inline int st_raw_write8(const int port, const int addr, const int reg,
- int data)
+static inline int st_raw_write8__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const int reg, int data)
{
/* TODO: Implement SPI interface support */
- return i2c_write8(port, addr, reg, data);
+ return i2c_write8__7bf(port, i2c_spi_addr__7bf, reg, data);
}
/**
* st_raw_read_n - Read n bytes for read
*/
-int st_raw_read_n(const int port, const int addr, const uint8_t reg,
- uint8_t *data_ptr, const int len);
+int st_raw_read_n__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const uint8_t reg, uint8_t *data_ptr, const int len);
/**
* st_raw_read_n_noinc - Read n bytes for read (no auto inc address)
*/
-int st_raw_read_n_noinc(const int port, const int addr, const uint8_t reg,
- uint8_t *data_ptr, const int len);
+int st_raw_read_n_noinc__7bf(const int port,
+ const uint16_t i2c_spi_addr__7bf,
+ const uint8_t reg, uint8_t *data_ptr, const int len);
/**
* st_write_data_with_mask - Write register with mask
diff --git a/driver/tcpm/anx7447.c b/driver/tcpm/anx7447.c
index a18aaeb441..0ca4c89fde 100644
--- a/driver/tcpm/anx7447.c
+++ b/driver/tcpm/anx7447.c
@@ -5,6 +5,7 @@
/* ANX7447 port manager */
+#include "common.h"
#include "anx7447.h"
#include "console.h"
#include "hooks.h"
@@ -40,7 +41,7 @@
(((anx7447_get_vbus_voltage(port))) > vsafe0v_max)
struct anx_state {
- int i2c_slave_addr;
+ uint16_t i2c_slave_addr__7bf;
};
struct anx_usb_mux {
@@ -63,18 +64,18 @@ static struct anx_usb_mux mux[CONFIG_USB_PD_PORT_COUNT];
* anx7447_reg_write() and anx7447_reg_read() are implemented here to access
* ANX7447 SPI slave address.
*/
-const struct anx7447_i2c_addr anx7447_i2c_addrs[] = {
- {AN7447_TCPC0_I2C_ADDR, AN7447_SPI0_I2C_ADDR},
- {AN7447_TCPC1_I2C_ADDR, AN7447_SPI1_I2C_ADDR},
- {AN7447_TCPC2_I2C_ADDR, AN7447_SPI2_I2C_ADDR},
- {AN7447_TCPC3_I2C_ADDR, AN7447_SPI3_I2C_ADDR}
+const struct anx7447_i2c_addr anx7447_i2c_addrs__7bf[] = {
+ {AN7447_TCPC0_I2C_ADDR__7bf, AN7447_SPI0_I2C_ADDR__7bf},
+ {AN7447_TCPC1_I2C_ADDR__7bf, AN7447_SPI1_I2C_ADDR__7bf},
+ {AN7447_TCPC2_I2C_ADDR__7bf, AN7447_SPI2_I2C_ADDR__7bf},
+ {AN7447_TCPC3_I2C_ADDR__7bf, AN7447_SPI3_I2C_ADDR__7bf}
};
static inline int anx7447_reg_write(int port, int reg, int val)
{
- int rv = i2c_write8(tcpc_config[port].i2c_info.port,
- anx[port].i2c_slave_addr,
- reg, val);
+ int rv = i2c_write8__7bf(tcpc_config[port].i2c_info.port,
+ anx[port].i2c_slave_addr__7bf,
+ reg, val);
#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
pd_device_accessed(port);
#endif
@@ -83,9 +84,9 @@ static inline int anx7447_reg_write(int port, int reg, int val)
static inline int anx7447_reg_read(int port, int reg, int *val)
{
- int rv = i2c_read8(tcpc_config[port].i2c_info.port,
- anx[port].i2c_slave_addr,
- reg, val);
+ int rv = i2c_read8__7bf(tcpc_config[port].i2c_info.port,
+ anx[port].i2c_slave_addr__7bf,
+ reg, val);
#ifdef CONFIG_USB_PD_TCPC_LOW_POWER
pd_device_accessed(port);
#endif
@@ -290,17 +291,20 @@ static int anx7447_init(int port)
* find corresponding anx7447 SPI slave address according to
* specified TCPC slave address
*/
- for (i = 0; i < ARRAY_SIZE(anx7447_i2c_addrs); i++) {
- if (tcpc_config[port].i2c_info.addr ==
- anx7447_i2c_addrs[i].tcpc_slave_addr) {
- anx[port].i2c_slave_addr =
- anx7447_i2c_addrs[i].spi_slave_addr;
+ for (i = 0; i < ARRAY_SIZE(anx7447_i2c_addrs__7bf); i++) {
+ if (I2C_GET_ADDR__7b(
+ tcpc_config[port].i2c_info.addr__7bf) ==
+ I2C_GET_ADDR__7b(
+ anx7447_i2c_addrs__7bf[i].tcpc_slave_addr__7bf)) {
+ anx[port].i2c_slave_addr__7bf =
+ anx7447_i2c_addrs__7bf[i].spi_slave_addr__7bf;
break;
}
}
- if (!anx[port].i2c_slave_addr) {
+ if (!I2C_GET_ADDR__7b(anx[port].i2c_slave_addr__7bf)) {
ccprintf("TCPC I2C slave addr 0x%x is invalid for ANX7447\n",
- tcpc_config[port].i2c_info.addr);
+ I2C_GET_ADDR__7b(tcpc_config[port]
+ .i2c_info.addr__7bf));
return EC_ERROR_UNKNOWN;
}
diff --git a/driver/tcpm/anx7447.h b/driver/tcpm/anx7447.h
index 093d74238a..32958f0007 100644
--- a/driver/tcpm/anx7447.h
+++ b/driver/tcpm/anx7447.h
@@ -91,19 +91,19 @@
/* End of defines used for CONFIG_USB_PD_TCPM_ANX7447_OCM_ERASE_COMMAND */
struct anx7447_i2c_addr {
- int tcpc_slave_addr;
- int spi_slave_addr;
+ uint16_t tcpc_slave_addr__7bf;
+ uint16_t spi_slave_addr__7bf;
};
-#define AN7447_TCPC0_I2C_ADDR 0x58
-#define AN7447_TCPC1_I2C_ADDR 0x56
-#define AN7447_TCPC2_I2C_ADDR 0x54
-#define AN7447_TCPC3_I2C_ADDR 0x52
+#define AN7447_TCPC0_I2C_ADDR__7bf (0x2C)
+#define AN7447_TCPC1_I2C_ADDR__7bf (0x2B)
+#define AN7447_TCPC2_I2C_ADDR__7bf (0x2A)
+#define AN7447_TCPC3_I2C_ADDR__7bf (0x29)
-#define AN7447_SPI0_I2C_ADDR 0x7E
-#define AN7447_SPI1_I2C_ADDR 0x6E
-#define AN7447_SPI2_I2C_ADDR 0x64
-#define AN7447_SPI3_I2C_ADDR 0x62
+#define AN7447_SPI0_I2C_ADDR__7bf (0x3F)
+#define AN7447_SPI1_I2C_ADDR__7bf (0x37)
+#define AN7447_SPI2_I2C_ADDR__7bf (0x32)
+#define AN7447_SPI3_I2C_ADDR__7bf (0x31)
/*
* Time TEST_R must be held high for a reset
diff --git a/driver/tcpm/anx74xx.c b/driver/tcpm/anx74xx.c
index 0d5fa8ab0a..8bbab47cd0 100644
--- a/driver/tcpm/anx74xx.c
+++ b/driver/tcpm/anx74xx.c
@@ -1126,7 +1126,7 @@ struct i2c_stress_test_dev anx74xx_i2c_stress_test_dev = {
.read_val = ANX74XX_VENDOR_ID & 0xFF,
.write_reg = ANX74XX_REG_CC_SOFTWARE_CTRL,
},
- .i2c_read = &tcpc_i2c_read,
- .i2c_write = &tcpc_i2c_write,
+ .i2c_read__7bf = &tcpc_i2c_read__7bf,
+ .i2c_write__7bf = &tcpc_i2c_write__7bf,
};
#endif /* CONFIG_CMD_I2C_STRESS_TEST_TCPC */
diff --git a/driver/tcpm/anx74xx.h b/driver/tcpm/anx74xx.h
index 1e1cb37275..9b5195444e 100644
--- a/driver/tcpm/anx74xx.h
+++ b/driver/tcpm/anx74xx.h
@@ -11,10 +11,10 @@
#define __CROS_EC_USB_PD_TCPM_ANX74XX_H
/* I2C interface */
-#define ANX74XX_I2C_ADDR1 0x50
-#define ANX74XX_I2C_ADDR2 0x72
-#define ANX74XX_I2C_ADDR3 0x7C
-#define ANX74XX_I2C_ADDR4 0x80
+#define ANX74XX_I2C_ADDR1__7bf 0x28
+#define ANX74XX_I2C_ADDR2__7bf 0x39
+#define ANX74XX_I2C_ADDR3__7bf 0x3E
+#define ANX74XX_I2C_ADDR4__7bf 0x40
#define ANX74XX_REG_IRQ_POL_LOW 0x00
#define ANX74XX_REG_IRQ_POL_HIGH 0x02
diff --git a/driver/tcpm/anx7688.c b/driver/tcpm/anx7688.c
index c9d6045b44..0c85336681 100644
--- a/driver/tcpm/anx7688.c
+++ b/driver/tcpm/anx7688.c
@@ -21,7 +21,7 @@
#define ANX7688_REG_HPD_IRQ (1 << 1)
#define ANX7688_REG_HPD_ENABLE (1 << 2)
-#define ANX7688_USBC_ADDR 0x50
+#define ANX7688_USBC_ADDR__7bf 0x28
#define ANX7688_REG_RAMCTRL 0xe7
#define ANX7688_REG_RAMCTRL_BOOT_DONE (1 << 6)
@@ -39,7 +39,7 @@ static int anx7688_init(int port)
* 100ms to follow cts.
*/
while (1) {
- rv = i2c_read8(I2C_PORT_TCPC, ANX7688_USBC_ADDR,
+ rv = i2c_read8__7bf(I2C_PORT_TCPC, ANX7688_USBC_ADDR__7bf,
ANX7688_REG_RAMCTRL, &mask);
if (rv == EC_SUCCESS && (mask & ANX7688_REG_RAMCTRL_BOOT_DONE))
@@ -174,7 +174,7 @@ static int anx7688_tcpm_get_vbus_level(int port)
* Therefore, we use a proprietary register to read the unfiltered VBus
* value. See crosbug.com/p/55221 .
*/
- i2c_read8(I2C_PORT_TCPC, 0x50, 0x40, &reg);
+ i2c_read8__7bf(I2C_PORT_TCPC, 0x28, 0x40, &reg);
return ((reg & 0x10) ? 1 : 0);
}
#endif
diff --git a/driver/tcpm/fusb302.h b/driver/tcpm/fusb302.h
index 6236e47439..edf1feb8dd 100644
--- a/driver/tcpm/fusb302.h
+++ b/driver/tcpm/fusb302.h
@@ -16,13 +16,13 @@
/* I2C slave address varies by part number */
/* FUSB302BUCX / FUSB302BMPX */
-#define FUSB302_I2C_SLAVE_ADDR 0x44
+#define FUSB302_I2C_SLAVE_ADDR__7bf 0x22
/* FUSB302B01MPX */
-#define FUSB302_I2C_SLAVE_ADDR_B01 0x46
+#define FUSB302_I2C_SLAVE_ADDR_B01__7bf 0x23
/* FUSB302B10MPX */
-#define FUSB302_I2C_SLAVE_ADDR_B10 0x48
+#define FUSB302_I2C_SLAVE_ADDR_B10__7bf 0x24
/* FUSB302B11MPX */
-#define FUSB302_I2C_SLAVE_ADDR_B11 0x4A
+#define FUSB302_I2C_SLAVE_ADDR_B11__7bf 0x25
/* Default retry count for transmitting */
#define PD_RETRY_COUNT 3
diff --git a/driver/tcpm/mt6370.c b/driver/tcpm/mt6370.c
index 5e714c15ab..ff901f6717 100644
--- a/driver/tcpm/mt6370.c
+++ b/driver/tcpm/mt6370.c
@@ -22,8 +22,8 @@
/* i2c_write function which won't wake TCPC from low power mode. */
static int mt6370_i2c_write8(int port, int reg, int val)
{
- return i2c_write8(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, val);
+ return i2c_write8__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf, reg, val);
}
static int mt6370_init(int port)
diff --git a/driver/tcpm/mt6370.h b/driver/tcpm/mt6370.h
index ff9ac569ee..b5e4ee46a5 100644
--- a/driver/tcpm/mt6370.h
+++ b/driver/tcpm/mt6370.h
@@ -48,7 +48,7 @@
#define MT6370_REG_UNLOCK_PW2 0xF0
#define MT6370_REG_UNLOCK_PW1 0xF1
-#define MT6370_TCPC_I2C_ADDR 0x9C
+#define MT6370_TCPC_I2C_ADDR__7bf 0x4E
/*
* MT6370_REG_PHY_CTRL1 0x80
diff --git a/driver/tcpm/nct38xx.h b/driver/tcpm/nct38xx.h
new file mode 100644
index 0000000000..1357d47bab
--- /dev/null
+++ b/driver/tcpm/nct38xx.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Nuvoton Type-C port controller */
+
+#ifndef __CROS_EC_USB_PD_TCPM_NCT38XX_H
+#define __CROS_EC_USB_PD_TCPM_NCT38XX_H
+
+/* I2C interface */
+#define NCT38xx_I2C_ADDR1_1__7bf 0x70
+#define NCT38xx_I2C_ADDR1_2__7bf 0x71
+#define NCT38xx_I2C_ADDR1_3__7bf 0x72
+#define NCT38xx_I2C_ADDR1_4__7bf 0x73
+
+#define NCT38xx_I2C_ADDR2_1__7bf 0x74
+#define NCT38xx_I2C_ADDR2_2__7bf 0x75
+#define NCT38xx_I2C_ADDR2_3__7bf 0x76
+#define NCT38xx_I2C_ADDR2_4__7bf 0x77
+
+#define NCT38XX_REG_VENDOR_ID_L 0x00
+#define NCT38XX_REG_VENDOR_ID_H 0x01
+#define NCT38XX_VENDOR_ID 0x0416
+
+#define NCT38XX_PRODUCT_ID 0xC301
+
+#define NCT38XX_REG_CTRL_OUT_EN 0xD2
+#define NCT38XX_REG_CTRL_OUT_EN_SRCEN (1 << 0)
+#define NCT38XX_REG_CTRL_OUT_EN_FASTEN (1 << 1)
+#define NCT38XX_REG_CTRL_OUT_EN_SNKEN (1 << 2)
+#define NCT38XX_REG_CTRL_OUT_EN_CONNDIREN (1 << 6)
+
+extern const struct tcpm_drv nct38xx_tcpm_drv;
+
+#endif /* defined(__CROS_EC_USB_PD_TCPM_NCT38XX_H) */
diff --git a/driver/tcpm/ps8xxx.c b/driver/tcpm/ps8xxx.c
index 3cb6903e5b..93026f9773 100644
--- a/driver/tcpm/ps8xxx.c
+++ b/driver/tcpm/ps8xxx.c
@@ -202,8 +202,8 @@ struct i2c_stress_test_dev ps8xxx_i2c_stress_test_dev = {
.read_val = PS8XXX_VENDOR_ID & 0xFF,
.write_reg = MUX_IN_HPD_ASSERTION_REG,
},
- .i2c_read = &tcpc_i2c_read,
- .i2c_write = &tcpc_i2c_write,
+ .i2c_read__7bf = &tcpc_i2c_read__7bf,
+ .i2c_write__7bf = &tcpc_i2c_write__7bf,
};
#endif /* CONFIG_CMD_I2C_STRESS_TEST_TCPC */
diff --git a/driver/tcpm/ps8xxx.h b/driver/tcpm/ps8xxx.h
index 6d0faab56f..817042a309 100644
--- a/driver/tcpm/ps8xxx.h
+++ b/driver/tcpm/ps8xxx.h
@@ -9,10 +9,10 @@
#define __CROS_EC_USB_PD_TCPM_PS8XXX_H
/* I2C interface */
-#define PS8751_I2C_ADDR1 0x16
-#define PS8751_I2C_ADDR2 0x36
-#define PS8751_I2C_ADDR3 0x56
-#define PS8751_I2C_ADDR4 0x96
+#define PS8751_I2C_ADDR1__7bf (0x0B)
+#define PS8751_I2C_ADDR2__7bf (0x1B)
+#define PS8751_I2C_ADDR3__7bf (0x2B)
+#define PS8751_I2C_ADDR4__7bf (0x4B)
/* Minimum Delay for reset assertion */
#define PS8XXX_RESET_DELAY_MS 1
diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c
index e0807b656f..882993e599 100644
--- a/driver/tcpm/tcpci.c
+++ b/driver/tcpm/tcpci.c
@@ -36,8 +36,9 @@ int tcpc_write(int port, int reg, int val)
pd_wait_exit_low_power(port);
- rv = i2c_write8(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, val);
+ rv = i2c_write8__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, val);
pd_device_accessed(port);
return rv;
@@ -49,8 +50,9 @@ int tcpc_write16(int port, int reg, int val)
pd_wait_exit_low_power(port);
- rv = i2c_write16(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, val);
+ rv = i2c_write16__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, val);
pd_device_accessed(port);
return rv;
@@ -62,8 +64,9 @@ int tcpc_read(int port, int reg, int *val)
pd_wait_exit_low_power(port);
- rv = i2c_read8(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, val);
+ rv = i2c_read8__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, val);
pd_device_accessed(port);
return rv;
@@ -75,8 +78,9 @@ int tcpc_read16(int port, int reg, int *val)
pd_wait_exit_low_power(port);
- rv = i2c_read16(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, val);
+ rv = i2c_read16__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, val);
pd_device_accessed(port);
return rv;
@@ -88,8 +92,9 @@ int tcpc_read_block(int port, int reg, uint8_t *in, int size)
pd_wait_exit_low_power(port);
- rv = i2c_read_block(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, in, size);
+ rv = i2c_read_block__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, in, size);
pd_device_accessed(port);
return rv;
@@ -101,8 +106,9 @@ int tcpc_write_block(int port, int reg, const uint8_t *out, int size)
pd_wait_exit_low_power(port);
- rv = i2c_write_block(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, out, size);
+ rv = i2c_write_block__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, out, size);
pd_device_accessed(port);
return rv;
@@ -127,9 +133,9 @@ int tcpc_xfer_unlocked(int port, const uint8_t *out, int out_size,
pd_wait_exit_low_power(port);
- rv = i2c_xfer_unlocked(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, out,
- out_size, in, in_size, flags);
+ rv = i2c_xfer_unlocked__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ out, out_size, in, in_size, flags);
pd_device_accessed(port);
return rv;
diff --git a/driver/tcpm/tcpm.h b/driver/tcpm/tcpm.h
index e5fec627c5..fb67eb315b 100644
--- a/driver/tcpm/tcpm.h
+++ b/driver/tcpm/tcpm.h
@@ -27,55 +27,61 @@
#ifndef CONFIG_USB_PD_TCPC_LOW_POWER
static inline int tcpc_write(int port, int reg, int val)
{
- return i2c_write8(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, val);
+ return i2c_write8__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, val);
}
static inline int tcpc_write16(int port, int reg, int val)
{
- return i2c_write16(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, val);
+ return i2c_write16__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, val);
}
static inline int tcpc_read(int port, int reg, int *val)
{
- return i2c_read8(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, val);
+ return i2c_read8__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, val);
}
static inline int tcpc_read16(int port, int reg, int *val)
{
- return i2c_read16(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, val);
+ return i2c_read16__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, val);
}
static inline int tcpc_xfer(int port, const uint8_t *out, int out_size,
uint8_t *in, int in_size)
{
- return i2c_xfer(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, out, out_size, in,
- in_size);
+ return i2c_xfer__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ out, out_size, in, in_size);
}
static inline int tcpc_xfer_unlocked(int port, const uint8_t *out, int out_size,
uint8_t *in, int in_size, int flags)
{
- return i2c_xfer_unlocked(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, out, out_size, in,
- in_size, flags);
+ return i2c_xfer_unlocked__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ out, out_size, in, in_size, flags);
}
static inline int tcpc_read_block(int port, int reg, uint8_t *in, int size)
{
- return i2c_read_block(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, in, size);
+ return i2c_read_block__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, in, size);
}
static inline int tcpc_write_block(int port, int reg,
const uint8_t *out, int size)
{
- return i2c_write_block(tcpc_config[port].i2c_info.port,
- tcpc_config[port].i2c_info.addr, reg, out, size);
+ return i2c_write_block__7bf(tcpc_config[port].i2c_info.port,
+ tcpc_config[port].i2c_info.addr__7bf,
+ reg, out, size);
}
#else /* !CONFIG_USB_PD_TCPC_LOW_POWER */
@@ -219,13 +225,13 @@ static inline int tcpm_enter_low_power_mode(int port)
#endif
#ifdef CONFIG_CMD_I2C_STRESS_TEST_TCPC
-static inline int tcpc_i2c_read(const int port, const int addr,
+static inline int tcpc_i2c_read__7bf(const int port, const uint16_t addr__7bf,
const int reg, int *data)
{
return tcpc_read(port, reg, data);
}
-static inline int tcpc_i2c_write(const int port, const int addr,
+static inline int tcpc_i2c_write__7bf(const int port, const uint16_t addr__7bf,
const int reg, int data)
{
return tcpc_write(port, reg, data);
diff --git a/driver/tcpm/tusb422.h b/driver/tcpm/tusb422.h
new file mode 100644
index 0000000000..524886801c
--- /dev/null
+++ b/driver/tcpm/tusb422.h
@@ -0,0 +1,16 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* TI TUSB422 Type-C port controller */
+
+#ifndef __CROS_EC_USB_PD_TCPM_TUSB422_H
+#define __CROS_EC_USB_PD_TCPM_TUSB422_H
+
+/* I2C interface */
+#define TUSB422_I2C_ADDR__7bf 0x20
+
+extern const struct tcpm_drv tusb422_tcpm_drv;
+
+#endif /* defined(__CROS_EC_USB_PD_TCPM_TUSB422_H) */
diff --git a/driver/temp_sensor/adt7481.c b/driver/temp_sensor/adt7481.c
index 22d7cc5f9a..c724e958e1 100644
--- a/driver/temp_sensor/adt7481.c
+++ b/driver/temp_sensor/adt7481.c
@@ -34,12 +34,14 @@ static int has_power(void)
static int raw_read8(const int offset, int *data_ptr)
{
- return i2c_read8(I2C_PORT_THERMAL, ADT7481_I2C_ADDR, offset, data_ptr);
+ return i2c_read8__7bf(I2C_PORT_THERMAL, ADT7481_I2C_ADDR__7bf,
+ offset, data_ptr);
}
static int raw_write8(const int offset, int data)
{
- return i2c_write8(I2C_PORT_THERMAL, ADT7481_I2C_ADDR, offset, data);
+ return i2c_write8__7bf(I2C_PORT_THERMAL, ADT7481_I2C_ADDR__7bf,
+ offset, data);
}
static int get_temp(const int offset, int *temp_ptr)
diff --git a/driver/temp_sensor/adt7481.h b/driver/temp_sensor/adt7481.h
index 11e9856b9c..96a30786cd 100644
--- a/driver/temp_sensor/adt7481.h
+++ b/driver/temp_sensor/adt7481.h
@@ -8,7 +8,7 @@
#ifndef __CROS_EC_ADT7481_H
#define __CROS_EC_ADT7481_H
-#define ADT7481_I2C_ADDR 0x96 /* 7-bit address is 0x4B */
+#define ADT7481_I2C_ADDR__7bf 0x4B
#define ADT7481_IDX_LOCAL 0
#define ADT7481_IDX_REMOTE1 1
diff --git a/driver/temp_sensor/bd99992gw.c b/driver/temp_sensor/bd99992gw.c
index f2a48eb2d5..890416c666 100644
--- a/driver/temp_sensor/bd99992gw.c
+++ b/driver/temp_sensor/bd99992gw.c
@@ -39,7 +39,8 @@ static enum bd99992gw_adc_channel
static int raw_read8(const int offset, int *data_ptr)
{
int ret;
- ret = i2c_read8(I2C_PORT_THERMAL, BD99992GW_I2C_ADDR, offset, data_ptr);
+ ret = i2c_read8__7bf(I2C_PORT_THERMAL, BD99992GW_I2C_ADDR__7bf,
+ offset, data_ptr);
if (ret != EC_SUCCESS)
CPRINTS("bd99992gw read fail %d\n", ret);
return ret;
@@ -48,7 +49,8 @@ static int raw_read8(const int offset, int *data_ptr)
static int raw_write8(const int offset, int data)
{
int ret;
- ret = i2c_write8(I2C_PORT_THERMAL, BD99992GW_I2C_ADDR, offset, data);
+ ret = i2c_write8__7bf(I2C_PORT_THERMAL, BD99992GW_I2C_ADDR__7bf,
+ offset, data);
if (ret != EC_SUCCESS)
CPRINTS("bd99992gw write fail %d\n", ret);
return ret;
diff --git a/driver/temp_sensor/bd99992gw.h b/driver/temp_sensor/bd99992gw.h
index 27a9943de1..2321bf9e7e 100644
--- a/driver/temp_sensor/bd99992gw.h
+++ b/driver/temp_sensor/bd99992gw.h
@@ -8,7 +8,7 @@
#ifndef __CROS_EC_TEMP_SENSOR_BD99992GW_H
#define __CROS_EC_TEMP_SENSOR_BD99992GW_H
-#define BD99992GW_I2C_ADDR 0x60
+#define BD99992GW_I2C_ADDR__7bf 0x30
/* ADC channels */
enum bd99992gw_adc_channel {
diff --git a/driver/temp_sensor/f75303.c b/driver/temp_sensor/f75303.c
index e2a324f0fb..794d2e865a 100644
--- a/driver/temp_sensor/f75303.c
+++ b/driver/temp_sensor/f75303.c
@@ -20,7 +20,8 @@ static int8_t fake_temp[F75303_IDX_COUNT] = {-1, -1, -1};
*/
static int raw_read8(const int offset, int *data)
{
- return i2c_read8(I2C_PORT_THERMAL, F75303_I2C_ADDR, offset, data);
+ return i2c_read8__7bf(I2C_PORT_THERMAL, F75303_I2C_ADDR__7bf,
+ offset, data);
}
static int get_temp(const int offset, int *temp)
diff --git a/driver/temp_sensor/f75303.h b/driver/temp_sensor/f75303.h
index ada32e75e7..ea2dcdbd79 100644
--- a/driver/temp_sensor/f75303.h
+++ b/driver/temp_sensor/f75303.h
@@ -8,7 +8,7 @@
#ifndef __CROS_EC_F75303_H
#define __CROS_EC_F75303_H
-#define F75303_I2C_ADDR 0x9A /* 7-bit address is 0x4C */
+#define F75303_I2C_ADDR__7bf 0x4C
enum f75303_index {
F75303_IDX_LOCAL = 0,
diff --git a/driver/temp_sensor/g78x.c b/driver/temp_sensor/g78x.c
index 948569da1c..0a71556b27 100644
--- a/driver/temp_sensor/g78x.c
+++ b/driver/temp_sensor/g78x.c
@@ -35,13 +35,15 @@ static int has_power(void)
static int raw_read8(const int offset, int *data_ptr)
{
- return i2c_read8(I2C_PORT_THERMAL, G78X_I2C_ADDR, offset, data_ptr);
+ return i2c_read8__7bf(I2C_PORT_THERMAL, G78X_I2C_ADDR__7bf,
+ offset, data_ptr);
}
#ifdef CONFIG_CMD_TEMP_SENSOR
static int raw_write8(const int offset, int data)
{
- return i2c_write8(I2C_PORT_THERMAL, G78X_I2C_ADDR, offset, data);
+ return i2c_write8__7bf(I2C_PORT_THERMAL, G78X_I2C_ADDR__7bf,
+ offset, data);
}
#endif
diff --git a/driver/temp_sensor/g78x.h b/driver/temp_sensor/g78x.h
index 8fa78ffa83..b056444441 100644
--- a/driver/temp_sensor/g78x.h
+++ b/driver/temp_sensor/g78x.h
@@ -12,7 +12,7 @@
#error Cannot support both G781 and G782 together!
#endif
-#define G78X_I2C_ADDR 0x98 /* 7-bit address is 0x4C */
+#define G78X_I2C_ADDR__7bf 0x4C
#define G78X_IDX_INTERNAL 0
#define G78X_IDX_EXTERNAL1 1
diff --git a/driver/temp_sensor/sb_tsi.c b/driver/temp_sensor/sb_tsi.c
index 9cf42d983f..3de816e1dc 100644
--- a/driver/temp_sensor/sb_tsi.c
+++ b/driver/temp_sensor/sb_tsi.c
@@ -19,7 +19,8 @@
static int raw_read8(const int offset, int *data_ptr)
{
- return i2c_read8(I2C_PORT_THERMAL, SB_TSI_I2C_ADDR, offset, data_ptr);
+ return i2c_read8__7bf(I2C_PORT_THERMAL, SB_TSI_I2C_ADDR__7bf,
+ offset, data_ptr);
}
int sb_tsi_get_val(int idx, int *temp_ptr)
diff --git a/driver/temp_sensor/sb_tsi.h b/driver/temp_sensor/sb_tsi.h
index 3ae11c5dbd..afed1d206f 100644
--- a/driver/temp_sensor/sb_tsi.h
+++ b/driver/temp_sensor/sb_tsi.h
@@ -11,7 +11,7 @@
#ifndef __CROS_EC_SB_TSI_H
#define __CROS_EC_SB_TSI_H
-#define SB_TSI_I2C_ADDR 0x98 /* 7-bit address is 0x4C */
+#define SB_TSI_I2C_ADDR__7bf 0x4C
/* G781 register */
#define SB_TSI_TEMP_H 0x01
diff --git a/driver/temp_sensor/tmp006.c b/driver/temp_sensor/tmp006.c
index 67b31dfa98..382d0b20b6 100644
--- a/driver/temp_sensor/tmp006.c
+++ b/driver/temp_sensor/tmp006.c
@@ -86,7 +86,7 @@ static void tmp006_poll_sensor(int sensor_id)
{
struct tmp006_data_t *tdata = tmp006_data + sensor_id;
int t, v, rv;
- int addr = tmp006_sensors[sensor_id].addr;
+ int addr__7bf = tmp006_sensors__7bf[sensor_id].addr__7bf;
/* Invalidate the filter history if there is any error */
if (tdata->fail) {
@@ -104,7 +104,8 @@ static void tmp006_poll_sensor(int sensor_id)
* data ready; otherwise, we read garbage data.
*/
if (tdata->fail & (FAIL_POWER | FAIL_INIT)) {
- rv = i2c_read16(TMP006_PORT(addr), TMP006_REG(addr),
+ rv = i2c_read16__7bf(TMP006_PORT(addr__7bf),
+ TMP006_REG__7bf(addr__7bf),
TMP006_REG_CONFIG, &v);
if (rv) {
tdata->fail |= FAIL_I2C;
@@ -116,14 +117,16 @@ static void tmp006_poll_sensor(int sensor_id)
}
}
- rv = i2c_read16(TMP006_PORT(addr), TMP006_REG(addr),
+ rv = i2c_read16__7bf(TMP006_PORT(addr__7bf),
+ TMP006_REG__7bf(addr__7bf),
TMP006_REG_TDIE, &t);
if (rv) {
tdata->fail |= FAIL_I2C;
return;
}
- rv = i2c_read16(TMP006_PORT(addr), TMP006_REG(addr),
+ rv = i2c_read16__7bf(TMP006_PORT(addr__7bf),
+ TMP006_REG__7bf(addr__7bf),
TMP006_REG_VOBJ, &v);
if (rv) {
tdata->fail |= FAIL_I2C;
@@ -370,37 +373,42 @@ static int tmp006_print(int idx)
int traw, t;
int rv;
int d;
- int addr = tmp006_sensors[idx].addr;
+ int addr__7bf = tmp006_sensors__7bf[idx].addr__7bf;
- ccprintf("Debug data from %s:\n", tmp006_sensors[idx].name);
+ ccprintf("Debug data from %s:\n", tmp006_sensors__7bf[idx].name);
if (!tmp006_has_power(idx)) {
ccputs("Sensor powered off.\n");
return EC_ERROR_UNKNOWN;
}
- rv = i2c_read16(TMP006_PORT(addr), TMP006_REG(addr),
+ rv = i2c_read16__7bf(TMP006_PORT(addr__7bf),
+ TMP006_REG__7bf(addr__7bf),
TMP006_REG_MANUFACTURER_ID, &d);
if (rv)
return rv;
ccprintf(" Manufacturer ID: 0x%04x\n", d);
- rv = i2c_read16(TMP006_PORT(addr), TMP006_REG(addr),
+ rv = i2c_read16__7bf(TMP006_PORT(addr__7bf),
+ TMP006_REG__7bf(addr__7bf),
TMP006_REG_DEVICE_ID, &d);
ccprintf(" Device ID: 0x%04x\n", d);
- rv = i2c_read16(TMP006_PORT(addr), TMP006_REG(addr),
+ rv = i2c_read16__7bf(TMP006_PORT(addr__7bf),
+ TMP006_REG__7bf(addr__7bf),
TMP006_REG_CONFIG, &d);
ccprintf(" Config: 0x%04x\n", d);
- rv = i2c_read16(TMP006_PORT(addr), TMP006_REG(addr),
+ rv = i2c_read16__7bf(TMP006_PORT(addr__7bf),
+ TMP006_REG__7bf(addr__7bf),
TMP006_REG_VOBJ, &vraw);
v = ((int)vraw * 15625) / 100;
ccprintf(" Voltage: 0x%04x = %d nV\n", vraw, v);
- rv = i2c_read16(TMP006_PORT(addr), TMP006_REG(addr),
+ rv = i2c_read16__7bf(TMP006_PORT(addr__7bf),
+ TMP006_REG__7bf(addr__7bf),
TMP006_REG_TDIE, &traw);
t = (int)traw;
ccprintf(" Temperature: 0x%04x = %d.%02d C\n",
@@ -455,7 +463,7 @@ static int command_t6cal(int argc, char **argv)
tdata = tmp006_data + i;
ccprintf("%d %-11s"
"%7de-17 %7de-8 %7de-10 %7de-12\n",
- i, tmp006_sensors[i].name,
+ i, tmp006_sensors__7bf[i].name,
(int)(tdata->s0 * 1e17f),
(int)(tdata->b0 * 1e8f),
(int)(tdata->b1 * 1e10f),
diff --git a/driver/temp_sensor/tmp006.h b/driver/temp_sensor/tmp006.h
index df99d1c1ca..793e83e8e6 100644
--- a/driver/temp_sensor/tmp006.h
+++ b/driver/temp_sensor/tmp006.h
@@ -16,17 +16,17 @@
#define TMP006_REG_DEVICE_ID 0xff
/* I2C address components */
-#define TMP006_ADDR(PORT,REG) ((PORT << 16) + REG)
-#define TMP006_PORT(ADDR) (ADDR >> 16)
-#define TMP006_REG(ADDR) (ADDR & 0xffff)
+#define TMP006_ADDR__7bf(PORT, REG) ((PORT << 16) + REG)
+#define TMP006_PORT(ADDR__7bf) (ADDR__7bf >> 16)
+#define TMP006_REG__7bf(ADDR__7bf) (ADDR__7bf & 0xffff)
struct tmp006_t {
const char *name;
- int addr; /* I2C address formed by TMP006_ADDR macro. */
+ int addr__7bf; /* I2C address formed by TMP006_ADDR macro. */
};
/* Names and addresses of the sensors we have */
-extern const struct tmp006_t tmp006_sensors[];
+extern const struct tmp006_t tmp006_sensors__7bf[];
/**
* Get the last polled value of a sensor.
diff --git a/driver/temp_sensor/tmp112.c b/driver/temp_sensor/tmp112.c
index f567e2433c..0e35ef55ac 100644
--- a/driver/temp_sensor/tmp112.c
+++ b/driver/temp_sensor/tmp112.c
@@ -20,12 +20,14 @@ static int temp_val_local;
static int raw_read16(const int offset, int *data_ptr)
{
- return i2c_read16(I2C_PORT_THERMAL, TMP112_I2C_ADDR, offset, data_ptr);
+ return i2c_read16__7bf(I2C_PORT_THERMAL, TMP112_I2C_ADDR__7bf,
+ offset, data_ptr);
}
static int raw_write16(const int offset, int data)
{
- return i2c_write16(I2C_PORT_THERMAL, TMP112_I2C_ADDR, offset, data);
+ return i2c_write16__7bf(I2C_PORT_THERMAL, TMP112_I2C_ADDR__7bf,
+ offset, data);
}
static int get_temp(int *temp_ptr)
diff --git a/driver/temp_sensor/tmp112.h b/driver/temp_sensor/tmp112.h
index 14ee56da0c..1d8cc59b66 100644
--- a/driver/temp_sensor/tmp112.h
+++ b/driver/temp_sensor/tmp112.h
@@ -8,7 +8,7 @@
#include "i2c.h"
-#define TMP112_I2C_ADDR 0x90 | I2C_FLAG_BIG_ENDIAN
+#define TMP112_I2C_ADDR__7bf (0x48 | I2C_FLAG_BIG_ENDIAN)
#define TMP112_REG_TEMP 0x00
#define TMP112_REG_CONF 0x01
diff --git a/driver/temp_sensor/tmp411.h b/driver/temp_sensor/tmp411.h
index a0ad95a5d8..6a49c82283 100644
--- a/driver/temp_sensor/tmp411.h
+++ b/driver/temp_sensor/tmp411.h
@@ -8,7 +8,7 @@
#ifndef __CROS_EC_TMP411_H
#define __CROS_EC_TMP411_H
-#define TMP411_I2C_ADDR 0x98 /* 7-bit address is 0x4C */
+#define TMP411_I2C_ADDR__7bf 0x4C
#define TMP411_IDX_LOCAL 0
#define TMP411_IDX_REMOTE1 1
diff --git a/driver/temp_sensor/tmp432.c b/driver/temp_sensor/tmp432.c
index 0874da74b6..e97804565c 100644
--- a/driver/temp_sensor/tmp432.c
+++ b/driver/temp_sensor/tmp432.c
@@ -35,12 +35,14 @@ static int has_power(void)
static int raw_read8(const int offset, int *data_ptr)
{
- return i2c_read8(I2C_PORT_THERMAL, TMP432_I2C_ADDR, offset, data_ptr);
+ return i2c_read8__7bf(I2C_PORT_THERMAL, TMP432_I2C_ADDR__7bf,
+ offset, data_ptr);
}
static int raw_write8(const int offset, int data)
{
- return i2c_write8(I2C_PORT_THERMAL, TMP432_I2C_ADDR, offset, data);
+ return i2c_write8__7bf(I2C_PORT_THERMAL, TMP432_I2C_ADDR__7bf,
+ offset, data);
}
static int get_temp(const int offset, int *temp_ptr)
diff --git a/driver/temp_sensor/tmp432.h b/driver/temp_sensor/tmp432.h
index 2d8d2515dc..c1b2e5e877 100644
--- a/driver/temp_sensor/tmp432.h
+++ b/driver/temp_sensor/tmp432.h
@@ -8,7 +8,7 @@
#ifndef __CROS_EC_TMP432_H
#define __CROS_EC_TMP432_H
-#define TMP432_I2C_ADDR 0x98 /* 7-bit address is 0x4C */
+#define TMP432_I2C_ADDR__7bf 0x4C
#define TMP432_IDX_LOCAL 0
#define TMP432_IDX_REMOTE1 1
diff --git a/driver/temp_sensor/tmp468.c b/driver/temp_sensor/tmp468.c
new file mode 100644
index 0000000000..444a1d5dc8
--- /dev/null
+++ b/driver/temp_sensor/tmp468.c
@@ -0,0 +1,101 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* TMP468 temperature sensor module for Chrome EC */
+
+#include "common.h"
+#include "console.h"
+#include "tmp432.h"
+#include "gpio.h"
+#include "i2c.h"
+#include "hooks.h"
+#include "util.h"
+
+#include "tmp468.h"
+
+
+static int fake_temp[TMP468_CHANNEL_COUNT] = {-1, -1, -1, -1, -1, -1, -1 , -1, -1};
+static int temp_val[TMP468_CHANNEL_COUNT] = {0, 0, 0, 0, 0, 0, 0 , 0, 0};
+static uint8_t is_sensor_shutdown;
+
+static int has_power(void)
+{
+ return !is_sensor_shutdown;
+}
+
+static int raw_read16(const int offset, int *data_ptr)
+{
+ return i2c_read16__7bf(I2C_PORT_THERMAL, TMP468_I2C_ADDR__7bf,
+ offset, data_ptr);
+}
+
+static int raw_write16(const int offset, int data_ptr)
+{
+ return i2c_write16__7bf(I2C_PORT_THERMAL, TMP468_I2C_ADDR__7bf,
+ offset, data_ptr);
+}
+
+static int tmp468_shutdown(uint8_t want_shutdown)
+{
+ int ret, value;
+
+ if (want_shutdown == is_sensor_shutdown)
+ return EC_SUCCESS;
+
+ ret = raw_read16(TMP468_CONFIGURATION, &value);
+ if (ret < 0) {
+ ccprintf("ERROR: Temp sensor I2C read16 error.\n");
+ return ret;
+ }
+
+ if (want_shutdown)
+ value |= TMP468_SHUTDOWN;
+ else
+ value &= ~TMP468_SHUTDOWN;
+
+ ret = raw_write16(TMP468_CONFIGURATION, value);
+ if (ret == EC_SUCCESS)
+ is_sensor_shutdown = want_shutdown;
+
+ return EC_SUCCESS;
+}
+
+int tmp468_get_val(int idx, int *temp_ptr)
+{
+ if(!has_power())
+ return EC_ERROR_NOT_POWERED;
+
+ if (idx < TMP468_CHANNEL_COUNT) {
+ *temp_ptr = C_TO_K(temp_val[idx]);
+ return EC_SUCCESS;
+ }
+
+ return EC_ERROR_INVAL;
+}
+
+static void temp_sensor_poll(void)
+{
+ int i, ret;
+
+ if (!has_power())
+ return;
+
+ for (i = 0; i < TMP468_CHANNEL_COUNT; i++)
+ if (fake_temp[i] != -1) {
+ temp_val[i] = fake_temp[i];
+ } else {
+ ret = raw_read16(TMP468_LOCAL + i, &temp_val[i]);
+ if (ret < 0)
+ return;
+ temp_val[i] >>= TMP468_SHIFT1;
+ }
+}
+DECLARE_HOOK(HOOK_SECOND, temp_sensor_poll, HOOK_PRIO_TEMP_SENSOR);
+
+int tmp468_set_power(enum tmp468_power_state power_on)
+{
+ uint8_t shutdown = (power_on == TMP468_POWER_OFF) ? 1 : 0;
+ return tmp468_shutdown(shutdown);
+}
diff --git a/driver/temp_sensor/tmp468.h b/driver/temp_sensor/tmp468.h
new file mode 100644
index 0000000000..f8f4337d8a
--- /dev/null
+++ b/driver/temp_sensor/tmp468.h
@@ -0,0 +1,126 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* TMP468 temperature sensor module for Chrome EC */
+
+#ifndef __CROS_EC_TMP468_H
+#define __CROS_EC_TMP468_H
+
+#define TMP468_I2C_ADDR__7bf (0x48 | I2C_FLAG_BIG_ENDIAN)
+#define TMP468_SHIFT1 7
+
+#define TMP468_LOCAL 0x00
+#define TMP468_REMOTE1 0x01
+#define TMP468_REMOTE2 0x02
+#define TMP468_REMOTE3 0x03
+#define TMP468_REMOTE4 0x04
+#define TMP468_REMOTE5 0x05
+#define TMP468_REMOTE6 0x06
+#define TMP468_REMOTE7 0x07
+#define TMP468_REMOTE8 0x08
+
+#define TMP468_SRST 0x20
+#define TMP468_THERM 0x21
+#define TMP468_THERM2 0x22
+#define TMP468_ROPEN 0x23
+
+#define TMP468_CONFIGURATION 0x30
+#define TMP468_THERM_HYST 0x38
+
+#define TMP468_LOCAL_LOW_LIMIT 0x39
+#define TMP468_LOCAL_HIGH_LIMT 0x3a
+
+#define TMP468_REMOTE1_OFFSET 0x40
+#define TMP468_REMOTE1_NFACTOR 0x41
+#define TMP468_REMOTE1_LOW_LIMIT 0x41
+#define TMP468_REMOTE1_HIGH_LIMIT 0x42
+
+#define TMP468_REMOTE2_OFFSET 0x48
+#define TMP468_REMOTE2_NFACTOR 0x49
+#define TMP468_REMOTE2_LOW_LIMIT 0x4a
+#define TMP468_REMOTE2_HIGH_LIMIT 0x4b
+
+#define TMP468_REMOTE3_OFFSET 0x50
+#define TMP468_REMOTE3_NFACTOR 0x51
+#define TMP468_REMOTE3_LOW_LIMIT 0x52
+#define TMP468_REMOTE3_HIGH_LIMIT 0x53
+
+#define TMP468_REMOTE4_OFFSET 0x58
+#define TMP468_REMOTE4_NFACTOR 0x59
+#define TMP468_REMOTE4_LOW_LIMIT 0x59
+#define TMP468_REMOTE4_HIGH_LIMIT 0x5a
+
+#define TMP468_REMOTE5_OFFSET 0x60
+#define TMP468_REMOTE5_NFACTOR 0x61
+#define TMP468_REMOTE5_LOW_LIMIT 0x62
+#define TMP468_REMOTE5_HIGH_LIMIT 0x63
+
+#define TMP468_REMOTE6_OFFSET 0x68
+#define TMP468_REMOTE6_NFACTOR 0x69
+#define TMP468_REMOTE6_LOW_LIMIT 0x6a
+#define TMP468_REMOTE6_HIGH_LIMIT 0x6b
+
+#define TMP468_REMOTE7_OFFSET 0x70
+#define TMP468_REMOTE7_NFACTOR 0x71
+#define TMP468_REMOTE7_LOW_LIMIT 0x72
+#define TMP468_REMOTE7_HIGH_LIMIT 0x73
+
+#define TMP468_REMOTE8_OFFSET 0x78
+#define TMP468_REMOTE8_NFACTOR 0x79
+#define TMP468_REMOTE8_LOW_LIMIT 0x7a
+#define TMP468_REMOTE8_HIGH_LIMIT 0x7b
+
+#define TMP468_LOCK 0xc4
+
+#define TMP468_DEVICE_ID 0xfd
+#define TMP468_MANUFACTURER_ID 0xfe
+
+#define TMP468_SHUTDOWN BIT(5)
+
+enum tmp468_channel_id {
+ TMP468_CHANNEL_LOCAL,
+
+ TMP468_CHANNEL_REMOTE1,
+ TMP468_CHANNEL_REMOTE2,
+ TMP468_CHANNEL_REMOTE3,
+ TMP468_CHANNEL_REMOTE4,
+ TMP468_CHANNEL_REMOTE5,
+ TMP468_CHANNEL_REMOTE6,
+ TMP468_CHANNEL_REMOTE7,
+ TMP468_CHANNEL_REMOTE8,
+
+ TMP468_CHANNEL_COUNT
+};
+
+enum tmp468_power_state {
+ TMP468_POWER_OFF = 0,
+ TMP468_POWER_ON,
+
+ TMP468_POWER_COUNT
+};
+
+
+/**
+ * Get the last polled value of a sensor.
+ *
+ * @param idx Index to read. Idx indicates whether to read die
+ * temperature or external temperature.
+ * @param temp_ptr Destination for temperature in K.
+ *
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+int tmp468_get_val(int idx, int *temp_ptr);
+
+/**
+ * Power control function of tmp432 temperature sensor.
+ *
+ * @param power_on TMP468_POWER_ON: turn tmp468 sensor on.
+ * TMP468_POWER_OFF: shut tmp468 sensor down.
+ *
+ * @return EC_SUCCESS if successful, non-zero if error.
+ */
+int tmp468_set_power(enum tmp468_power_state power_on);
+
+#endif /* __CROS_EC_TMP468_H */
diff --git a/driver/touchpad_elan.c b/driver/touchpad_elan.c
index 712125a021..112860f689 100644
--- a/driver/touchpad_elan.c
+++ b/driver/touchpad_elan.c
@@ -115,8 +115,9 @@ static int elan_tp_read_cmd(uint16_t reg, uint16_t *val)
buf[0] = reg;
buf[1] = reg >> 8;
- return i2c_xfer(CONFIG_TOUCHPAD_I2C_PORT, CONFIG_TOUCHPAD_I2C_ADDR,
- buf, sizeof(buf), (uint8_t *)val, sizeof(*val));
+ return i2c_xfer__7bf(CONFIG_TOUCHPAD_I2C_PORT,
+ CONFIG_TOUCHPAD_I2C_ADDR__7BF,
+ buf, sizeof(buf), (uint8_t *)val, sizeof(*val));
}
static int elan_tp_write_cmd(uint16_t reg, uint16_t val)
@@ -128,8 +129,9 @@ static int elan_tp_write_cmd(uint16_t reg, uint16_t val)
buf[2] = val;
buf[3] = val >> 8;
- return i2c_xfer(CONFIG_TOUCHPAD_I2C_PORT, CONFIG_TOUCHPAD_I2C_ADDR,
- buf, sizeof(buf), NULL, 0);
+ return i2c_xfer__7bf(CONFIG_TOUCHPAD_I2C_PORT,
+ CONFIG_TOUCHPAD_I2C_ADDR__7BF,
+ buf, sizeof(buf), NULL, 0);
}
/* Power is on by default. */
@@ -189,7 +191,8 @@ static int elan_tp_read_report(void)
/* Compute and save timestamp early in case another interrupt comes. */
timestamp = irq_ts / USB_HID_TOUCHPAD_TIMESTAMP_UNIT;
- rv = i2c_xfer(CONFIG_TOUCHPAD_I2C_PORT, CONFIG_TOUCHPAD_I2C_ADDR,
+ rv = i2c_xfer__7bf(CONFIG_TOUCHPAD_I2C_PORT,
+ CONFIG_TOUCHPAD_I2C_ADDR__7BF,
NULL, 0, tp_buf, ETP_I2C_REPORT_LEN);
if (rv) {
@@ -275,7 +278,8 @@ static void elan_tp_init(void)
elan_tp_write_cmd(ETP_I2C_STAND_CMD, ETP_I2C_RESET);
msleep(100);
- rv = i2c_xfer(CONFIG_TOUCHPAD_I2C_PORT, CONFIG_TOUCHPAD_I2C_ADDR,
+ rv = i2c_xfer__7bf(CONFIG_TOUCHPAD_I2C_PORT,
+ CONFIG_TOUCHPAD_I2C_ADDR__7BF,
NULL, 0, val, sizeof(val));
CPRINTS("reset rv %d buf=%04x", rv, *((uint16_t *)val));
@@ -465,7 +469,8 @@ static int touchpad_update_page(const uint8_t *data)
page_store[FW_PAGE_SIZE + 2 + 0] = checksum & 0xff;
page_store[FW_PAGE_SIZE + 2 + 1] = (checksum >> 8) & 0xff;
- rv = i2c_xfer(CONFIG_TOUCHPAD_I2C_PORT, CONFIG_TOUCHPAD_I2C_ADDR,
+ rv = i2c_xfer__7bf(CONFIG_TOUCHPAD_I2C_PORT,
+ CONFIG_TOUCHPAD_I2C_ADDR__7BF,
page_store, sizeof(page_store), NULL, 0);
if (rv)
return rv;
@@ -629,8 +634,8 @@ int touchpad_debug(const uint8_t *param, unsigned int param_size,
memset(buffer, 0, buffer_size);
}
- rv = i2c_xfer(CONFIG_TOUCHPAD_I2C_PORT,
- CONFIG_TOUCHPAD_I2C_ADDR,
+ rv = i2c_xfer__7bf(CONFIG_TOUCHPAD_I2C_PORT,
+ CONFIG_TOUCHPAD_I2C_ADDR__7BF,
&param[offset], write_length,
buffer, read_length);
diff --git a/driver/usb_mux_it5205.c b/driver/usb_mux_it5205.c
index 4c2f274c88..e5783e0a59 100644
--- a/driver/usb_mux_it5205.c
+++ b/driver/usb_mux_it5205.c
@@ -16,12 +16,12 @@
static int it5205_read(int port, uint8_t reg, int *val)
{
- return i2c_read8(I2C_PORT_USB_MUX, MUX_ADDR(port), reg, val);
+ return i2c_read8__7bf(I2C_PORT_USB_MUX, MUX_ADDR__7bf(port), reg, val);
}
static int it5205_write(int port, uint8_t reg, uint8_t val)
{
- return i2c_write8(I2C_PORT_USB_MUX, MUX_ADDR(port), reg, val);
+ return i2c_write8__7bf(I2C_PORT_USB_MUX, MUX_ADDR__7bf(port), reg, val);
}
struct mux_chip_id_t {
diff --git a/driver/usb_mux_it5205.h b/driver/usb_mux_it5205.h
index 2c26f7ca41..5da3a53c3f 100644
--- a/driver/usb_mux_it5205.h
+++ b/driver/usb_mux_it5205.h
@@ -9,8 +9,8 @@
#define __CROS_EC_USB_MUX_IT5205_H
/* I2C interface */
-#define IT5205_I2C_ADDR1 (0x48 << 1)
-#define IT5205_I2C_ADDR2 (0x58 << 1)
+#define IT5205_I2C_ADDR1__7bf (0x48)
+#define IT5205_I2C_ADDR2__7bf (0x58)
/* Chip ID registers */
#define IT5205_REG_CHIP_ID3 0x4
diff --git a/driver/usb_mux_pi3usb30532.c b/driver/usb_mux_pi3usb30532.c
index 54d6f49fe7..24f9cbd095 100644
--- a/driver/usb_mux_pi3usb30532.c
+++ b/driver/usb_mux_pi3usb30532.c
@@ -20,7 +20,9 @@ static int pi3usb30532_read(int port, uint8_t reg, uint8_t *val)
* Second byte read will be vendor ID.
* Third byte read will be selection control.
*/
- res = i2c_read16(I2C_PORT_USB_MUX, MUX_ADDR(port), 0, &read);
+ res = i2c_read16__7bf(I2C_PORT_USB_MUX,
+ MUX_ADDR__7bf(port),
+ 0, &read);
if (res)
return res;
@@ -37,7 +39,9 @@ static int pi3usb30532_write(int port, uint8_t reg, uint8_t val)
if (reg != PI3USB30532_REG_CONTROL)
return EC_ERROR_UNKNOWN;
- return i2c_write8(I2C_PORT_USB_MUX, MUX_ADDR(port), 0, val);
+ return i2c_write8__7bf(I2C_PORT_USB_MUX,
+ MUX_ADDR__7bf(port),
+ 0, val);
}
static int pi3usb30532_reset(int port)
diff --git a/driver/usb_mux_ps874x.c b/driver/usb_mux_ps874x.c
index b560329c2a..d886641923 100644
--- a/driver/usb_mux_ps874x.c
+++ b/driver/usb_mux_ps874x.c
@@ -13,12 +13,16 @@
static inline int ps874x_read(int port, uint8_t reg, int *val)
{
- return i2c_read8(I2C_PORT_USB_MUX, MUX_ADDR(port), reg, val);
+ return i2c_read8__7bf(I2C_PORT_USB_MUX,
+ MUX_ADDR__7bf(port),
+ reg, val);
}
static inline int ps874x_write(int port, uint8_t reg, uint8_t val)
{
- return i2c_write8(I2C_PORT_USB_MUX, MUX_ADDR(port), reg, val);
+ return i2c_write8__7bf(I2C_PORT_USB_MUX,
+ MUX_ADDR__7bf(port),
+ reg, val);
}
static int ps874x_init(int port)
diff --git a/driver/wpc/p9221.c b/driver/wpc/p9221.c
new file mode 100644
index 0000000000..948734aba1
--- /dev/null
+++ b/driver/wpc/p9221.c
@@ -0,0 +1,806 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/*
+ * IDT P9221-R7 Wireless Power Receiver driver.
+ */
+
+#include "p9221.h"
+#include "charge_manager.h"
+#include "chipset.h"
+#include "common.h"
+#include "console.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "power.h"
+#include "tcpm.h"
+#include "timer.h"
+#include "usb_charge.h"
+#include "usb_pd.h"
+#include "util.h"
+#include <stdbool.h>
+#include "printf.h"
+
+#define CPRINTS(format, args...) cprints(CC_USBPD, "WPC " format, ## args)
+
+#define P9221_TX_TIMEOUT_MS (20 * 1000*1000)
+#define P9221_DCIN_TIMEOUT_MS (2 * 1000*1000)
+#define P9221_VRECT_TIMEOUT_MS (2 * 1000*1000)
+#define P9221_NOTIFIER_DELAY_MS (80*1000)
+#define P9221R7_ILIM_MAX_UA (1600 * 1000)
+#define P9221R7_OVER_CHECK_NUM 3
+
+#define OVC_LIMIT 1
+#define OVC_THRESHOLD 1400000
+#define OVC_BACKOFF_LIMIT 900000
+#define OVC_BACKOFF_AMOUNT 100000
+
+/* P9221 parameters */
+static struct wpc_charger_info p9221_charger_info = {
+ .online = false,
+ .i2c_port = I2C_PORT_WPC,
+ .pp_buf_valid = false,
+};
+
+static struct wpc_charger_info *wpc = &p9221_charger_info;
+
+static void p9221_set_offline(void);
+
+static const uint32_t p9221_ov_set_lut[] = {
+ 17000000, 20000000, 15000000, 13000000,
+ 11000000, 11000000, 11000000, 11000000
+};
+
+static int p9221_reg_is_8_bit(uint16_t reg)
+{
+ switch (reg) {
+ case P9221_CHIP_REVISION_REG:
+ case P9221R7_VOUT_SET_REG:
+ case P9221R7_ILIM_SET_REG:
+ case P9221R7_CHARGE_STAT_REG:
+ case P9221R7_EPT_REG:
+ case P9221R7_SYSTEM_MODE_REG:
+ case P9221R7_COM_CHAN_RESET_REG:
+ case P9221R7_COM_CHAN_SEND_SIZE_REG:
+ case P9221R7_COM_CHAN_SEND_IDX_REG:
+ case P9221R7_COM_CHAN_RECV_SIZE_REG:
+ case P9221R7_COM_CHAN_RECV_IDX_REG:
+ case P9221R7_DEBUG_REG:
+ case P9221R7_EPP_Q_FACTOR_REG:
+ case P9221R7_EPP_TX_GUARANTEED_POWER_REG:
+ case P9221R7_EPP_TX_POTENTIAL_POWER_REG:
+ case P9221R7_EPP_TX_CAPABILITY_FLAGS_REG:
+ case P9221R7_EPP_RENEGOTIATION_REG:
+ case P9221R7_EPP_CUR_RPP_HEADER_REG:
+ case P9221R7_EPP_CUR_NEGOTIATED_POWER_REG:
+ case P9221R7_EPP_CUR_MAXIMUM_POWER_REG:
+ case P9221R7_EPP_CUR_FSK_MODULATION_REG:
+ case P9221R7_EPP_REQ_RPP_HEADER_REG:
+ case P9221R7_EPP_REQ_NEGOTIATED_POWER_REG:
+ case P9221R7_EPP_REQ_MAXIMUM_POWER_REG:
+ case P9221R7_EPP_REQ_FSK_MODULATION_REG:
+ case P9221R7_VRECT_TARGET_REG:
+ case P9221R7_VRECT_KNEE_REG:
+ case P9221R7_FOD_SECTION_REG:
+ case P9221R7_VRECT_ADJ_REG:
+ case P9221R7_ALIGN_X_ADC_REG:
+ case P9221R7_ALIGN_Y_ADC_REG:
+ case P9221R7_ASK_MODULATION_DEPTH_REG:
+ case P9221R7_OVSET_REG:
+ case P9221R7_EPP_TX_SPEC_REV_REG:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static int p9221_read8(uint16_t reg, int *val)
+{
+ return i2c_read_offset16__7bf(wpc->i2c_port, P9221_R7_ADDR__7bf,
+ reg, val, 1);
+}
+
+static int p9221_write8(uint16_t reg, int val)
+{
+ return i2c_write_offset16__7bf(wpc->i2c_port, P9221_R7_ADDR__7bf,
+ reg, val, 1);
+}
+
+static int p9221_read16(uint16_t reg, int *val)
+{
+ return i2c_read_offset16__7bf(wpc->i2c_port, P9221_R7_ADDR__7bf,
+ reg, val, 2);
+}
+
+static int p9221_write16(uint16_t reg, int val)
+{
+ return i2c_write_offset16__7bf(wpc->i2c_port, P9221_R7_ADDR__7bf,
+ reg, val, 2);
+}
+
+static int p9221_block_read(uint16_t reg, uint8_t *data, int len)
+{
+ return i2c_read_offset16_block__7bf(wpc->i2c_port, P9221_R7_ADDR__7bf,
+ reg, data, len);
+}
+
+static int p9221_block_write(uint16_t reg, uint8_t *data, int len)
+{
+ return i2c_write_offset16_block__7bf(wpc->i2c_port, P9221_R7_ADDR__7bf,
+ reg, data, len);
+}
+
+static int p9221_set_cmd_reg(uint8_t cmd)
+{
+ int cur_cmd;
+ int retry;
+ int ret;
+
+ for (retry = 0; retry < P9221_COM_CHAN_RETRIES; retry++) {
+ ret = p9221_read8(P9221_COM_REG, &cur_cmd);
+ if (ret == EC_SUCCESS && cur_cmd == 0)
+ break;
+ msleep(25);
+ }
+
+ if (retry >= P9221_COM_CHAN_RETRIES) {
+ CPRINTS("Failed to wait for cmd free %02x", cur_cmd);
+ return EC_ERROR_TIMEOUT;
+ }
+
+ ret = p9221_write8(P9221_COM_REG, cmd);
+ if (ret)
+ CPRINTS("Failed to set cmd reg %02x: %d", cmd, ret);
+
+ return ret;
+}
+
+/* Convert a register value to uV, Hz, or uA */
+static int p9221_convert_reg_r7(uint16_t reg, uint16_t raw_data, uint32_t *val)
+{
+ switch (reg) {
+ case P9221R7_ALIGN_X_ADC_REG: /* raw */
+ case P9221R7_ALIGN_Y_ADC_REG: /* raw */
+ *val = raw_data;
+ break;
+ case P9221R7_VOUT_ADC_REG: /* 12-bit ADC raw */
+ case P9221R7_IOUT_ADC_REG: /* 12-bit ADC raw */
+ case P9221R7_DIE_TEMP_ADC_REG: /* 12-bit ADC raw */
+ case P9221R7_EXT_TEMP_REG:
+ *val = raw_data & 0xFFF;
+ break;
+ case P9221R7_VOUT_SET_REG: /* 0.1V -> uV */
+ *val = raw_data * 100 * 1000;
+ break;
+ case P9221R7_IOUT_REG: /* mA -> uA */
+ case P9221R7_VRECT_REG: /* mV -> uV */
+ case P9221R7_VOUT_REG: /* mV -> uV */
+ case P9221R7_OP_FREQ_REG: /* kHz -> Hz */
+ case P9221R7_TX_PINGFREQ_REG: /* kHz -> Hz */
+ *val = raw_data * 1000;
+ break;
+ case P9221R7_ILIM_SET_REG: /* 100mA -> uA, 200mA offset */
+ *val = ((raw_data * 100) + 200) * 1000;
+ break;
+ case P9221R7_OVSET_REG: /* uV */
+ raw_data &= P9221R7_OVSET_MASK;
+ *val = p9221_ov_set_lut[raw_data];
+ break;
+ default:
+ return -2;
+ }
+
+ return 0;
+}
+
+static int p9221_reg_read_converted(uint16_t reg, uint32_t *val)
+{
+ int ret;
+ int data;
+
+ if (p9221_reg_is_8_bit(reg))
+ ret = p9221_read8(reg, &data);
+ else
+ ret = p9221_read16(reg, &data);
+
+ if (ret)
+ return ret;
+
+ return p9221_convert_reg_r7(reg, data, val);
+}
+
+static int p9221_is_online(void)
+{
+ int chip_id;
+
+ if (p9221_read16(P9221_CHIP_ID_REG, &chip_id)
+ || chip_id != P9221_CHIP_ID)
+ return false;
+ else
+ return true;
+}
+
+int wpc_chip_is_online(void)
+{
+ return p9221_is_online();
+}
+
+
+void p9221_interrupt(enum gpio_signal signal)
+{
+ task_wake(TASK_ID_WPC);
+}
+
+static int p9221r7_clear_interrupts(uint16_t mask)
+{
+ int ret;
+
+ ret = p9221_write16(P9221R7_INT_CLEAR_REG, mask);
+ if (ret) {
+ CPRINTS("Failed to clear INT reg: %d", ret);
+ return ret;
+ }
+
+ ret = p9221_set_cmd_reg(P9221_COM_CLEAR_INT_MASK);
+ if (ret)
+ CPRINTS("Failed to reset INT: %d", ret);
+
+ return ret;
+}
+
+/*
+ * Enable interrupts on the P9221 R7, note we don't really need to disable
+ * interrupts since when the device goes out of field, the P9221 is reset.
+ */
+static int p9221_enable_interrupts_r7(void)
+{
+ uint16_t mask = 0;
+ int ret;
+
+ CPRINTS("Enable interrupts");
+
+ mask = P9221R7_STAT_LIMIT_MASK | P9221R7_STAT_CC_MASK
+ | P9221_STAT_VRECT;
+
+ p9221r7_clear_interrupts(mask);
+
+ ret = p9221_write8(P9221_INT_ENABLE_REG, mask);
+ if (ret)
+ CPRINTS("Failed to enable INTs: %d", ret);
+ return ret;
+}
+
+static int p9221_send_csp(uint8_t status)
+{
+ int ret;
+
+ CPRINTS("Send CSP=%d", status);
+ mutex_lock(&wpc->cmd_lock);
+
+ ret = p9221_write8(P9221R7_CHARGE_STAT_REG, status);
+ if (ret == EC_SUCCESS)
+ ret = p9221_set_cmd_reg(P9221R7_COM_SENDCSP);
+
+ mutex_unlock(&wpc->cmd_lock);
+ return ret;
+}
+
+static int p9221_send_eop(uint8_t reason)
+{
+ int rv;
+
+ CPRINTS("Send EOP reason=%d", reason);
+ mutex_lock(&wpc->cmd_lock);
+
+ rv = p9221_write8(P9221R7_EPT_REG, reason);
+ if (rv == EC_SUCCESS)
+ rv = p9221_set_cmd_reg(P9221R7_COM_SENDEPT);
+
+ mutex_unlock(&wpc->cmd_lock);
+ return rv;
+}
+
+static void print_current_samples(uint32_t *iout_val, int count)
+{
+ int i;
+ char temp[P9221R7_OVER_CHECK_NUM * 9 + 1] = { 0 };
+
+ for (i = 0; i < count ; i++)
+ snprintf(temp + i * 9, sizeof(temp) - i * 9,
+ "%08x ", iout_val[i]);
+ CPRINTS("OVER IOUT_SAMPLES: %s", temp);
+}
+
+
+/*
+ * Number of times to poll the status to see if the current limit condition
+ * was transient or not.
+ */
+static void p9221_limit_handler_r7(uint16_t orign_irq_src)
+{
+ uint8_t reason;
+ int i;
+ int ret;
+ int ovc_count = 0;
+ uint32_t iout_val[P9221R7_OVER_CHECK_NUM] = { 0 };
+ int irq_src = (int)orign_irq_src;
+
+ CPRINTS("OVER INT: %02x", irq_src);
+
+ if (irq_src & P9221R7_STAT_OVV) {
+ reason = P9221_EOP_OVER_VOLT;
+ goto send_eop;
+ }
+
+ if (irq_src & P9221R7_STAT_OVT) {
+ reason = P9221_EOP_OVER_TEMP;
+ goto send_eop;
+ }
+
+ if ((irq_src & P9221R7_STAT_UV) && !(irq_src & P9221R7_STAT_OVC))
+ return;
+
+ reason = P9221_EOP_OVER_CURRENT;
+ for (i = 0; i < P9221R7_OVER_CHECK_NUM; i++) {
+ ret = p9221r7_clear_interrupts(
+ irq_src & P9221R7_STAT_LIMIT_MASK);
+ msleep(50);
+ if (ret)
+ continue;
+
+ ret = p9221_reg_read_converted(P9221R7_IOUT_REG, &iout_val[i]);
+ if (ret) {
+ CPRINTS("Failed to read IOUT[%d]: %d", i, ret);
+ continue;
+ } else if (iout_val[i] > OVC_THRESHOLD) {
+ ovc_count++;
+ }
+
+ ret = p9221_read16(P9221_STATUS_REG, &irq_src);
+ if (ret) {
+ CPRINTS("Failed to read status: %d", ret);
+ continue;
+ }
+
+ if ((irq_src & P9221R7_STAT_OVC) == 0) {
+ print_current_samples(iout_val, i + 1);
+ CPRINTS("OVER condition %04x cleared after %d tries",
+ irq_src, i);
+ return;
+ }
+
+ CPRINTS("OVER status is still %04x, retry", irq_src);
+ }
+
+ if (ovc_count < OVC_LIMIT) {
+ print_current_samples(iout_val, P9221R7_OVER_CHECK_NUM);
+ CPRINTS("ovc_threshold=%d, ovc_count=%d, ovc_limit=%d",
+ OVC_THRESHOLD, ovc_count, OVC_LIMIT);
+ return;
+ }
+
+send_eop:
+ CPRINTS("OVER is %04x, sending EOP %d", irq_src, reason);
+
+ ret = p9221_send_eop(reason);
+ if (ret)
+ CPRINTS("Failed to send EOP %d: %d", reason, ret);
+}
+
+static void p9221_abort_transfers(void)
+{
+ wpc->tx_busy = false;
+ wpc->tx_done = true;
+ wpc->rx_done = true;
+ wpc->rx_len = 0;
+}
+
+/* Handler for r7 and R7 chips */
+static void p9221r7_irq_handler(uint16_t irq_src)
+{
+ int res;
+
+ if (irq_src & P9221R7_STAT_LIMIT_MASK)
+ p9221_limit_handler_r7(irq_src);
+
+ /* Receive complete */
+ if (irq_src & P9221R7_STAT_CCDATARCVD) {
+ int rxlen = 0;
+
+ res = p9221_read8(P9221R7_COM_CHAN_RECV_SIZE_REG, &rxlen);
+ if (res)
+ CPRINTS("Failed to read len: %d", res);
+
+ if (rxlen) {
+ res = p9221_block_read(P9221R7_DATA_RECV_BUF_START,
+ wpc->rx_buf, rxlen);
+ if (res) {
+ CPRINTS("Failed to read CC data: %d", res);
+ rxlen = 0;
+ }
+
+ wpc->rx_len = rxlen;
+ wpc->rx_done = true;
+ }
+ }
+
+ /* Send complete */
+ if (irq_src & P9221R7_STAT_CCSENDBUSY) {
+ wpc->tx_busy = false;
+ wpc->tx_done = true;
+ }
+
+ /* Proprietary packet */
+ if (irq_src & P9221R7_STAT_PPRCVD) {
+ res = p9221_block_read(P9221R7_DATA_RECV_BUF_START,
+ wpc->pp_buf, sizeof(wpc->pp_buf));
+ if (res) {
+ CPRINTS("Failed to read PP: %d", res);
+ wpc->pp_buf_valid = false;
+ return;
+ }
+
+ /* We only care about PP which come with 0x4F header */
+ wpc->pp_buf_valid = (wpc->pp_buf[0] == 0x4F);
+
+ hexdump(wpc->pp_buf, sizeof(wpc->pp_buf));
+ }
+
+ /* CC Reset complete */
+ if (irq_src & P9221R7_STAT_CCRESET)
+ p9221_abort_transfers();
+}
+
+static int p9221_is_epp(void)
+{
+ int ret, reg;
+ uint32_t vout_uv;
+
+ if (p9221_read8(P9221R7_SYSTEM_MODE_REG, &reg) == EC_SUCCESS)
+ return reg & P9221R7_SYSTEM_MODE_EXTENDED_MASK;
+
+ /* Check based on power supply voltage */
+ ret = p9221_reg_read_converted(P9221R7_VOUT_ADC_REG, &vout_uv);
+ if (ret) {
+ CPRINTS("Failed to read VOUT_ADC: %d", ret);
+ return false;
+ }
+
+ CPRINTS("Voltage is %duV", vout_uv);
+ if (vout_uv > P9221_EPP_THRESHOLD_UV)
+ return true;
+
+ return false;
+}
+
+static void p9221_config_fod(void)
+{
+
+ int epp;
+ uint8_t *fod;
+ int fod_len;
+ int ret;
+ int retries = 3;
+
+ CPRINTS("Config FOD");
+
+ epp = p9221_is_epp();
+ fod_len = epp ? board_get_epp_fod(&fod) : board_get_fod(&fod);
+ if (!fod_len || !fod) {
+ CPRINTS("FOD data not found");
+ return;
+ }
+
+ while (retries) {
+ uint8_t fod_read[fod_len];
+
+ CPRINTS("Writing %s FOD (n=%d try=%d)",
+ epp ? "EPP" : "BPP", fod_len, retries);
+
+ ret = p9221_block_write(P9221R7_FOD_REG, fod, fod_len);
+ if (ret)
+ goto no_fod;
+
+ /* Verify the FOD has been written properly */
+ ret = p9221_block_read(P9221R7_FOD_REG, fod_read, fod_len);
+ if (ret)
+ goto no_fod;
+
+ if (memcmp(fod, fod_read, fod_len) == 0)
+ return;
+
+ hexdump(fod_read, fod_len);
+
+ retries--;
+ msleep(100);
+ }
+
+no_fod:
+ CPRINTS("Failed to set FOD. retries:%d ret:%d", retries, ret);
+}
+
+static void p9221_set_online(void)
+{
+ int ret;
+
+ CPRINTS("Set online");
+
+ wpc->online = true;
+
+ wpc->tx_busy = false;
+ wpc->tx_done = true;
+ wpc->rx_done = false;
+ wpc->charge_supplier = CHARGE_SUPPLIER_WPC_BPP;
+
+ ret = p9221_enable_interrupts_r7();
+ if (ret)
+ CPRINTS("Failed to enable INT: %d", ret);
+
+ /* NOTE: depends on _is_epp() which is not valid until DC_IN */
+ p9221_config_fod();
+}
+
+static void p9221_vbus_check_timeout(void)
+{
+ CPRINTS("Timeout VBUS, online=%d", wpc->online);
+ if (wpc->online)
+ p9221_set_offline();
+
+}
+DECLARE_DEFERRED(p9221_vbus_check_timeout);
+
+static void p9221_set_offline(void)
+{
+ CPRINTS("Set offline");
+
+ wpc->online = false;
+ /* Reset PP buf so we can get a new serial number next time around */
+ wpc->pp_buf_valid = false;
+
+ p9221_abort_transfers();
+
+ hook_call_deferred(&p9221_vbus_check_timeout_data, -1);
+}
+
+/* P9221_NOTIFIER_DELAY_MS from VRECTON */
+static int p9221_notifier_check_det(void)
+{
+ if (wpc->online)
+ goto done;
+
+ /* send out a FOD but is_epp() is still invalid */
+ p9221_set_online();
+
+ /* Give the vbus 2 seconds to come up. */
+ CPRINTS("Waiting VBUS");
+ hook_call_deferred(&p9221_vbus_check_timeout_data, -1);
+ hook_call_deferred(&p9221_vbus_check_timeout_data,
+ P9221_DCIN_TIMEOUT_MS);
+
+done:
+ wpc->p9221_check_det = false;
+ return 0;
+}
+
+static int p9221_get_charge_supplier(void)
+{
+ uint32_t tx_id;
+ int txmf_id;
+
+ if (!wpc->online)
+ return EC_ERROR_UNKNOWN;
+
+ if (p9221_is_epp()) {
+ int ret;
+ wpc->charge_supplier = CHARGE_SUPPLIER_WPC_EPP;
+
+ ret = p9221_read16(P9221R7_EPP_TX_MFG_CODE_REG, &txmf_id);
+ if (ret || txmf_id != P9221_GPP_TX_MF_ID)
+ return ret;
+
+ ret = p9221_block_read(P9221R7_PROP_TX_ID_REG,
+ (uint8_t *) &tx_id,
+ P9221R7_PROP_TX_ID_SIZE);
+ if (ret)
+ return ret;
+
+ if (tx_id & P9221R7_PROP_TX_ID_GPP_MASK)
+ wpc->charge_supplier = CHARGE_SUPPLIER_WPC_GPP;
+ } else {
+ wpc->charge_supplier = CHARGE_SUPPLIER_WPC_BPP;
+ }
+
+ CPRINTS("txmf_id=0x%04x tx_id=0x%08x supplier=%d",
+ txmf_id, tx_id, wpc->charge_supplier);
+ return EC_SUCCESS;
+}
+
+static int p9221_get_icl(int charge_supplier)
+{
+ switch (charge_supplier) {
+ case CHARGE_SUPPLIER_WPC_EPP:
+ case CHARGE_SUPPLIER_WPC_GPP:
+ return P9221_DC_ICL_EPP_MA;
+ case CHARGE_SUPPLIER_WPC_BPP:
+ default:
+ return P9221_DC_ICL_BPP_MA;
+ }
+}
+
+static int p9221_get_ivl(int charge_supplier)
+{
+ switch (charge_supplier) {
+ case CHARGE_SUPPLIER_WPC_EPP:
+ case CHARGE_SUPPLIER_WPC_GPP:
+ return P9221_DC_IVL_EPP_MV;
+ case CHARGE_SUPPLIER_WPC_BPP:
+ default:
+ return P9221_DC_IVL_BPP_MV;
+ }
+}
+
+static void p9221_update_charger(int type, struct charge_port_info *chg)
+{
+ if (!chg)
+ charge_manager_update_dualrole(0, CAP_UNKNOWN);
+ else
+ charge_manager_update_dualrole(0, CAP_DEDICATED);
+
+ charge_manager_update_charge(type, 0, chg);
+}
+
+static int p9221_reg_write_converted_r7(uint16_t reg, uint32_t val)
+{
+ int ret = 0;
+ uint16_t data;
+ int i;
+ /* Do the appropriate conversion */
+ switch (reg) {
+ case P9221R7_ILIM_SET_REG:
+ /* uA -> 0.1A, offset 0.2A */
+ if ((val < 200000) || (val > 1600000))
+ return -EC_ERROR_INVAL;
+ data = (val / (100 * 1000)) - 2;
+ break;
+ case P9221R7_VOUT_SET_REG:
+ /* uV -> 0.1V */
+ val /= 1000;
+ if (val < 3500 || val > 9000)
+ return -EC_ERROR_INVAL;
+ data = val / 100;
+ break;
+ case P9221R7_OVSET_REG:
+ /* uV */
+ for (i = 0; i < ARRAY_SIZE(p9221_ov_set_lut); i++) {
+ if (val == p9221_ov_set_lut[i])
+ break;
+ }
+ if (i == ARRAY_SIZE(p9221_ov_set_lut))
+ return -EC_ERROR_INVAL;
+ data = i;
+ break;
+ default:
+ return -EC_ERROR_INVAL;
+ }
+ if (p9221_reg_is_8_bit(reg))
+ ret = p9221_write8(reg, data);
+ else
+ ret = p9221_write16(reg, data);
+ return ret;
+}
+
+static int p9221_set_dc_icl(void)
+{
+ /* Increase the IOUT limit */
+ if (p9221_reg_write_converted_r7(P9221R7_ILIM_SET_REG,
+ P9221R7_ILIM_MAX_UA))
+ CPRINTS("%s set rx_iout limit fail.", __func__);
+
+ return EC_SUCCESS;
+}
+
+
+static void p9221_notifier_check_vbus(void)
+{
+ struct charge_port_info chg;
+
+ wpc->p9221_check_vbus = false;
+
+ CPRINTS("%s online:%d vbus:%d is_online:%d", __func__, wpc->online,
+ wpc->vbus_status);
+
+ /*
+ * We now have confirmation from DC_IN, kill the timer, p9221_online
+ * will be set by this function.
+ */
+ hook_call_deferred(&p9221_vbus_check_timeout_data, -1);
+
+ if (wpc->vbus_status) {
+ /* WPC VBUS on ,Always write FOD, check dc_icl, send CSP */
+ p9221_set_dc_icl();
+ p9221_config_fod();
+
+ p9221_send_csp(1);
+
+ /* when wpc vbus attached after 2s, set wpc online */
+ if (!wpc->online)
+ p9221_set_online();
+
+ /* WPC VBUS on , update charge voltage and current */
+ p9221_get_charge_supplier();
+ chg.voltage = p9221_get_ivl(wpc->charge_supplier);
+ chg.current = p9221_get_icl(wpc->charge_supplier);
+
+ p9221_update_charger(wpc->charge_supplier, &chg);
+ } else {
+ /*
+ * Vbus detached, set wpc offline and update wpc charge voltage
+ * and current to zero.
+ */
+ if (wpc->online) {
+ p9221_set_offline();
+ p9221_update_charger(wpc->charge_supplier, NULL);
+ }
+ }
+
+ CPRINTS("check_vbus changed on:%d vbus:%d", wpc->online,
+ wpc->vbus_status);
+
+}
+
+static void p9221_detect_work(void)
+{
+
+ CPRINTS("%s online:%d check_vbus:%d check_det:%d vbus:%d", __func__,
+ wpc->online, wpc->p9221_check_vbus, wpc->p9221_check_det,
+ wpc->vbus_status);
+
+ /* Step 1 */
+ if (wpc->p9221_check_det)
+ p9221_notifier_check_det();
+
+ /* Step 2 */
+ if (wpc->p9221_check_vbus)
+ p9221_notifier_check_vbus();
+
+}
+DECLARE_DEFERRED(p9221_detect_work);
+
+void p9221_notify_vbus_change(int vbus)
+{
+ wpc->p9221_check_vbus = true;
+ wpc->vbus_status = vbus;
+ hook_call_deferred(&p9221_detect_work_data, P9221_NOTIFIER_DELAY_MS);
+}
+
+void wireless_power_charger_task(void *u)
+{
+ while (1) {
+ int ret, irq_src;
+ task_wait_event(-1);
+
+ ret = p9221_read16(P9221_INT_REG, &irq_src);
+ if (ret) {
+ CPRINTS("Failed to read INT REG");
+ continue;
+ }
+
+ CPRINTS("INT SRC 0x%04x", irq_src);
+
+ if (p9221r7_clear_interrupts(irq_src))
+ continue;
+
+ if (irq_src & P9221_STAT_VRECT) {
+ CPRINTS("VRECTON, online=%d", wpc->online);
+ if (!wpc->online) {
+ wpc->p9221_check_det = true;
+ hook_call_deferred(&p9221_detect_work_data,
+ P9221_NOTIFIER_DELAY_MS);
+ }
+ }
+
+ p9221r7_irq_handler(irq_src);
+ }
+}
diff --git a/driver/wpc/p9221.h b/driver/wpc/p9221.h
new file mode 100644
index 0000000000..b590a5c1c7
--- /dev/null
+++ b/driver/wpc/p9221.h
@@ -0,0 +1,323 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+/*
+ * IDT P9221-R7 Wireless Power Receiver driver definitions.
+ */
+
+#ifndef __P9221_R7_H
+#define __P9221_R7_H
+
+#include "common.h"
+#include "gpio.h"
+#include "charge_manager.h"
+#include "task.h"
+
+
+/* ========== Variant-specific configuration ============ */
+
+#define P9221_R7_ADDR__7bf 0x61
+
+/*
+ * P9221 common registers
+ */
+#define P9221_CHIP_ID_REG 0x00
+#define P9221_CHIP_ID 0x9220
+#define P9221_CHIP_REVISION_REG 0x02
+#define P9221_CUSTOMER_ID_REG 0x03
+#define P9221R7_CUSTOMER_ID_VAL 0x05
+#define P9221_OTP_FW_MAJOR_REV_REG 0x04
+#define P9221_OTP_FW_MINOR_REV_REG 0x06
+#define P9221_OTP_FW_DATE_REG 0x08
+#define P9221_OTP_FW_DATE_SIZE 12
+#define P9221_OTP_FW_TIME_REG 0x14
+#define P9221_OTP_FW_TIME_SIZE 8
+#define P9221_SRAM_FW_MAJOR_REV_REG 0x1C
+#define P9221_SRAM_FW_MINOR_REV_REG 0x1E
+#define P9221_SRAM_FW_DATE_REG 0x20
+#define P9221_SRAM_FW_DATE_SIZE 12
+#define P9221_SRAM_FW_TIME_REG 0x2C
+#define P9221_SRAM_FW_TIME_SIZE 8
+#define P9221_STATUS_REG 0x34
+#define P9221_INT_REG 0x36
+#define P9221_INT_MASK 0xF7
+#define P9221_INT_ENABLE_REG 0x38
+#define P9221_GPP_TX_MF_ID 0x0072
+
+/*
+ * P9221 Rx registers (x != 5)
+ */
+#define P9221_CHARGE_STAT_REG 0x3A
+#define P9221_EPT_REG 0x3B
+#define P9221_VOUT_ADC_REG 0x3C
+#define P9221_VOUT_ADC_MASK 0x0FFF
+#define P9221_VOUT_SET_REG 0x3E
+#define P9221_MAX_VOUT_SET_MV_DEFAULT 9000
+#define P9221_VRECT_ADC_REG 0x40
+#define P9221_VRECT_ADC_MASK 0x0FFF
+#define P9221_OVSET_REG 0x42
+#define P9221_OVSET_MASK 0x70
+#define P9221_OVSET_SHIFT 4
+#define P9221_RX_IOUT_REG 0x44
+#define P9221_DIE_TEMP_ADC_REG 0x46
+#define P9221_DIE_TEMP_ADC_MASK 0x0FFF
+#define P9221_OP_FREQ_REG 0x48
+#define P9221_ILIM_SET_REG 0x4A
+#define P9221_ALIGN_X_ADC_REG 0x4B
+#define P9221_ALIGN_Y_ADC_REG 0x4C
+#define P9221_OP_MODE_REG 0x4D
+#define P9221_COM_REG 0x4E
+#define P9221_FW_SWITCH_KEY_REG 0x4F
+#define P9221_INT_CLEAR_REG 0x56
+#define P9221_RXID_REG 0x5C
+#define P9221_RXID_LEN 6
+#define P9221_MPREQ_REG 0x5C
+#define P9221_MPREQ_LEN 6
+#define P9221_FOD_REG 0x68
+#define P9221_NUM_FOD 16
+#define P9221_RX_RAWIOUT_REG 0x7A
+#define P9221_RX_RAWIOUT_MASK 0xFFF
+#define P9221_PMA_AD_REG 0x7C
+#define P9221_RX_PINGFREQ_REG 0xFC
+#define P9221_RX_PINGFREQ_MASK 0xFFF
+#define P9221_LAST_REG 0xFF
+
+/*
+ * P9221R7 unique registers
+ */
+#define P9221R7_INT_CLEAR_REG 0x3A
+#define P9221R7_VOUT_SET_REG 0x3C
+#define P9221R7_ILIM_SET_REG 0x3D
+#define P9221R7_ILIM_SET_MAX 0x0E /* 0x0E = 1.6A */
+#define P9221R7_CHARGE_STAT_REG 0x3E
+#define P9221R7_EPT_REG 0x3F
+#define P9221R7_VRECT_REG 0x40
+#define P9221R7_VOUT_REG 0x42
+#define P9221R7_IOUT_REG 0x44
+#define P9221R7_OP_FREQ_REG 0x48
+#define P9221R7_SYSTEM_MODE_REG 0x4C
+#define P9221R7_COM_CHAN_RESET_REG 0x50
+#define P9221R7_COM_CHAN_SEND_SIZE_REG 0x58
+#define P9221R7_COM_CHAN_SEND_IDX_REG 0x59
+#define P9221R7_COM_CHAN_RECV_SIZE_REG 0x5A
+#define P9221R7_COM_CHAN_RECV_IDX_REG 0x5B
+#define P9221R7_VRECT_ADC_REG 0x60
+#define P9221R7_VOUT_ADC_REG 0x62
+#define P9221R7_VOUT_ADC_MASK 0xFFF
+#define P9221R7_IOUT_ADC_REG 0x64
+#define P9221R7_IOUT_ADC_MASK 0xFFF
+#define P9221R7_DIE_TEMP_ADC_REG 0x66
+#define P9221R7_DIE_TEMP_ADC_MASK 0xFFF
+#define P9221R7_AC_PERIOD_REG 0x68
+#define P9221R7_TX_PINGFREQ_REG 0x6A
+#define P9221R7_EXT_TEMP_REG 0x6C
+#define P9221R7_EXT_TEMP_MASK 0xFFF
+#define P9221R7_FOD_REG 0x70
+#define P9221R7_NUM_FOD 16
+#define P9221R7_DEBUG_REG 0x80
+#define P9221R7_EPP_Q_FACTOR_REG 0x83
+#define P9221R7_EPP_TX_GUARANTEED_POWER_REG 0x84
+#define P9221R7_EPP_TX_POTENTIAL_POWER_REG 0x85
+#define P9221R7_EPP_TX_CAPABILITY_FLAGS_REG 0x86
+#define P9221R7_EPP_RENEGOTIATION_REG 0x87
+#define P9221R7_EPP_CUR_RPP_HEADER_REG 0x88
+#define P9221R7_EPP_CUR_NEGOTIATED_POWER_REG 0x89
+#define P9221R7_EPP_CUR_MAXIMUM_POWER_REG 0x8A
+#define P9221R7_EPP_CUR_FSK_MODULATION_REG 0x8B
+#define P9221R7_EPP_REQ_RPP_HEADER_REG 0x8C
+#define P9221R7_EPP_REQ_NEGOTIATED_POWER_REG 0x8D
+#define P9221R7_EPP_REQ_MAXIMUM_POWER_REG 0x8E
+#define P9221R7_EPP_REQ_FSK_MODULATION_REG 0x8F
+#define P9221R7_VRECT_TARGET_REG 0x90
+#define P9221R7_VRECT_KNEE_REG 0x92
+#define P9221R7_VRECT_CORRECTION_FACTOR_REG 0x93
+#define P9221R7_VRECT_MAX_CORRECTION_FACTOR_REG 0x94
+#define P9221R7_VRECT_MIN_CORRECTION_FACTOR_REG 0x96
+#define P9221R7_FOD_SECTION_REG 0x99
+#define P9221R7_VRECT_ADJ_REG 0x9E
+#define P9221R7_ALIGN_X_ADC_REG 0xA0
+#define P9221R7_ALIGN_Y_ADC_REG 0xA1
+#define P9221R7_ASK_MODULATION_DEPTH_REG 0xA2
+#define P9221R7_OVSET_REG 0xA3
+#define P9221R7_OVSET_MASK 0x7
+#define P9221R7_EPP_TX_SPEC_REV_REG 0xA9
+#define P9221R7_EPP_TX_MFG_CODE_REG 0xAA
+#define P9221R7_GP0_RESET_VOLT_REG 0xAC
+#define P9221R7_GP1_RESET_VOLT_REG 0xAE
+#define P9221R7_GP2_RESET_VOLT_REG 0xB0
+#define P9221R7_GP3_RESET_VOLT_REG 0xB2
+#define P9221R7_PROP_TX_ID_REG 0xB4
+#define P9221R7_PROP_TX_ID_SIZE 4
+#define P9221R7_DATA_SEND_BUF_START 0x100
+#define P9221R7_DATA_SEND_BUF_SIZE 0x80
+#define P9221R7_DATA_RECV_BUF_START 0x180
+#define P9221R7_DATA_RECV_BUF_SIZE 0x80
+#define P9221R7_MAX_PP_BUF_SIZE 16
+#define P9221R7_LAST_REG 0x1FF
+
+/*
+ * System Mode Mask (r7+/0x4C)
+ */
+#define P9221R7_SYSTEM_MODE_EXTENDED_MASK (1 << 3)
+
+/*
+ * TX ID GPP Mask (r7+/0xB4->0xB7)
+ */
+#define P9221R7_PROP_TX_ID_GPP_MASK (1 << 29)
+
+/*
+ * Com Channel Commands
+ */
+#define P9221R7_COM_CHAN_CCRESET BIT(7)
+#define P9221_COM_CHAN_RETRIES 5
+
+/*
+ * End of Power packet types
+ */
+#define P9221_EOP_UNKNOWN 0x00
+#define P9221_EOP_EOC 0x01
+#define P9221_EOP_INTERNAL_FAULT 0x02
+#define P9221_EOP_OVER_TEMP 0x03
+#define P9221_EOP_OVER_VOLT 0x04
+#define P9221_EOP_OVER_CURRENT 0x05
+#define P9221_EOP_BATT_FAIL 0x06
+#define P9221_EOP_RECONFIG 0x07
+#define P9221_EOP_NO_RESPONSE 0x08
+#define P9221_EOP_NEGOTIATION_FAIL 0x0A
+#define P9221_EOP_RESTART_POWER 0x0B
+
+/*
+ * Command flags
+ */
+#define P9221R7_COM_RENEGOTIATE P9221_COM_RENEGOTIATE
+#define P9221R7_COM_SWITCH2RAM P9221_COM_SWITCH_TO_RAM_MASK
+#define P9221R7_COM_CLRINT P9221_COM_CLEAR_INT_MASK
+#define P9221R7_COM_SENDCSP P9221_COM_SEND_CHG_STAT_MASK
+#define P9221R7_COM_SENDEPT P9221_COM_SEND_EOP_MASK
+#define P9221R7_COM_LDOTGL P9221_COM_LDO_TOGGLE
+#define P9221R7_COM_CCACTIVATE BIT(0)
+
+#define P9221_COM_RENEGOTIATE BIT(7)
+#define P9221_COM_SWITCH_TO_RAM_MASK BIT(6)
+#define P9221_COM_CLEAR_INT_MASK BIT(5)
+#define P9221_COM_SEND_CHG_STAT_MASK BIT(4)
+#define P9221_COM_SEND_EOP_MASK BIT(3)
+#define P9221_COM_LDO_TOGGLE BIT(1)
+
+/*
+ * Interrupt/Status flags for P9221
+ */
+#define P9221_STAT_VOUT BIT(7)
+#define P9221_STAT_VRECT BIT(6)
+#define P9221_STAT_ACMISSING BIT(5)
+#define P9221_STAT_OV_TEMP BIT(2)
+#define P9221_STAT_OV_VOLT BIT(1)
+#define P9221_STAT_OV_CURRENT BIT(0)
+#define P9221_STAT_LIMIT_MASK (P9221_STAT_OV_TEMP | \
+ P9221_STAT_OV_VOLT | \
+ P9221_STAT_OV_CURRENT)
+/*
+ * Interrupt/Status flags for P9221R7
+ */
+#define P9221R7_STAT_CCRESET BIT(12)
+#define P9221R7_STAT_CCERROR BIT(11)
+#define P9221R7_STAT_PPRCVD BIT(10)
+#define P9221R7_STAT_CCDATARCVD BIT(9)
+#define P9221R7_STAT_CCSENDBUSY BIT(8)
+#define P9221R7_STAT_VOUTCHANGED BIT(7)
+#define P9221R7_STAT_VRECTON BIT(6)
+#define P9221R7_STAT_MODECHANGED BIT(5)
+#define P9221R7_STAT_UV BIT(3)
+#define P9221R7_STAT_OVT BIT(2)
+#define P9221R7_STAT_OVV BIT(1)
+#define P9221R7_STAT_OVC BIT(0)
+#define P9221R7_STAT_MASK 0x1FFF
+#define P9221R7_STAT_CC_MASK (P9221R7_STAT_CCRESET | \
+ P9221R7_STAT_PPRCVD | \
+ P9221R7_STAT_CCERROR | \
+ P9221R7_STAT_CCDATARCVD | \
+ P9221R7_STAT_CCSENDBUSY)
+#define P9221R7_STAT_LIMIT_MASK (P9221R7_STAT_UV | \
+ P9221R7_STAT_OVV | \
+ P9221R7_STAT_OVT | \
+ P9221R7_STAT_OVC)
+
+#define P9221_DC_ICL_BPP_MA 1000
+#define P9221_DC_ICL_EPP_MA 1100
+#define P9221_DC_IVL_BPP_MV 5000
+#define P9221_DC_IVL_EPP_MV 9000
+#define P9221_EPP_THRESHOLD_UV 7000000
+
+#define true 1
+#define false 0
+
+struct wpc_charger_info {
+ uint8_t online; /* wpc is online */
+ uint8_t cust_id; /* customer id */
+ uint8_t i2c_port; /* i2c port */
+ /* Proprietary Packets receive buffer, to get Proprietary data from TX*/
+ uint8_t pp_buf[P9221R7_MAX_PP_BUF_SIZE];
+ uint8_t pp_buf_valid;
+ /* Common message Packets receive buffer, for get data from TX */
+ uint8_t rx_buf[P9221R7_DATA_RECV_BUF_SIZE];
+ uint8_t rx_len;
+ uint8_t rx_done;
+ /* Message packets send buffer, used when send messages from RX to TX*/
+ uint8_t tx_buf[P9221R7_DATA_SEND_BUF_SIZE];
+ uint8_t tx_id; /* TX device id */
+ uint8_t tx_len; /* The data size need send to TX */
+ uint8_t tx_done; /* TX data send has done */
+ uint8_t tx_busy; /* when tx_busy=1, can't transfer data from RX to TX */
+ /* p9221_check_vbus=1 when VBUS has changed, need update charge state */
+ uint8_t p9221_check_vbus;
+ /* p9221_check_det=1 when TX device has detected */
+ uint8_t p9221_check_det;
+ /* vbus_status is 1 when VBUS attached and is 0 when VBUS detached*/
+ uint8_t vbus_status;
+ /* supplier type of wireless charger */
+ uint8_t charge_supplier;
+ /* lock of send command to p9221 */
+ struct mutex cmd_lock;
+};
+
+/* Interrupt handler for p9221 */
+void p9221_interrupt(enum gpio_signal signal);
+
+/**
+ * notify p9221 detect update charger status when VBUS changed
+ *
+ * @param vbus: new status of VBUS, 1 if VBUS on, 0 if VBUS off.
+ */
+void p9221_notify_vbus_change(int vbus);
+
+/**
+ * get the fod (foreign-object detection) parameters for bpp charger type
+ *
+ * @param fod: return the real value of fod paramerters,
+ * return NULL if fod paramerters not set.
+ *
+ * @return the count bytes of fod paramerters.
+ */
+int board_get_fod(uint8_t **fod);
+
+/**
+ * get the fod (foreign-object detection) parameters for epp chager type
+ *
+ * @param fod: return the real value of fod paramerters,
+ * return NULL if fod paramerters not set.
+ *
+ * @return the count bytes of fod paramerters.
+ */
+int board_get_epp_fod(uint8_t **fod);
+
+/**
+ * return the wireless charge online status
+ *
+ * @return true if online, false if offline.
+ */
+int wpc_chip_is_online(void);
+
+#endif
diff --git a/include/battery_smart.h b/include/battery_smart.h
index 2a36c45d7f..5f017caa22 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 e3a43d8bcf..52fd59560b 100644
--- a/include/charge_state_v2.h
+++ b/include/charge_state_v2.h
@@ -13,7 +13,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 d9d8ce5025..b9a8215507 100644
--- a/include/config.h
+++ b/include/config.h
@@ -118,7 +118,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
@@ -541,7 +541,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
@@ -1859,7 +1859,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.
@@ -2028,7 +2028,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
/*
@@ -3089,9 +3089,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
@@ -3304,7 +3304,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
@@ -3403,7 +3403,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
@@ -4243,7 +4243,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
@@ -4252,7 +4252,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 cd408abd54..2958b8e037 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -3948,7 +3948,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;
@@ -5175,8 +5178,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 5257e1354c..a49d47443f 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 352301a892..a3e297e726 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 c85986b229..c98065b11b 100644
--- a/include/test_util.h
+++ b/include/test_util.h
@@ -215,20 +215,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);
};
/**
@@ -255,7 +256,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.
@@ -265,6 +266,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 e483954733..1e19b599aa 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 812a194a85..d3cdce5dd1 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
/**
diff --git a/test/battery_get_params_smart.c b/test/battery_get_params_smart.c
index 7c86252b23..5bcbbafe7e 100644
--- a/test/battery_get_params_smart.c
+++ b/test/battery_get_params_smart.c
@@ -35,12 +35,14 @@ int sb_read(int cmd, int *param)
if (read_count >= fail_on_first && read_count <= fail_on_last)
return EC_ERROR_UNKNOWN;
- return i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param);
+ return i2c_read16__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ cmd, param);
}
int sb_write(int cmd, int param)
{
write_count++;
- return i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param);
+ return i2c_write16__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf,
+ cmd, param);
}
diff --git a/test/sbs_charging_v2.c b/test/sbs_charging_v2.c
index e266e59215..f80cd43e46 100644
--- a/test/sbs_charging_v2.c
+++ b/test/sbs_charging_v2.c
@@ -175,7 +175,7 @@ static int test_charge_state(void)
/* Detach battery, charging error */
ccprintf("[CHARGING TEST] Detach battery\n");
- TEST_ASSERT(test_detach_i2c(I2C_PORT_BATTERY, BATTERY_ADDR) ==
+ TEST_ASSERT(test_detach_i2c__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf) ==
EC_SUCCESS);
msleep(BATTERY_DETACH_DELAY);
state = wait_charging_state();
@@ -183,7 +183,7 @@ static int test_charge_state(void)
/* Attach battery again, charging */
ccprintf("[CHARGING TEST] Attach battery\n");
- test_attach_i2c(I2C_PORT_BATTERY, BATTERY_ADDR);
+ test_attach_i2c__7bf(I2C_PORT_BATTERY, BATTERY_ADDR__7bf);
/* And changing full capacity should trigger a host event */
ev_clear(EC_HOST_EVENT_BATTERY);
sb_write(SB_FULL_CHARGE_CAPACITY, 0xeff0);
diff --git a/util/ectool.c b/util/ectool.c
index d01e995226..3f56aeb6b7 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -24,6 +24,7 @@
#include "ec_flash.h"
#include "ec_version.h"
#include "ectool.h"
+#include "i2c.h"
#include "lightbar.h"
#include "lock/gec_lock.h"
#include "misc_util.h"
@@ -6145,7 +6146,8 @@ int cmd_locate_chip(int argc, char *argv[])
* (firmware_ECCbiEeprom) still passes. It may silently skip the test.
*/
printf("Bus: %s; Port: %d; Address: 0x%02x (7-bit format)\n",
- bus_type[r.bus_type], r.i2c_info.port, r.i2c_info.addr);
+ bus_type[r.bus_type], r.i2c_info.port,
+ I2C_GET_ADDR(r.i2c_info.addr_flags));
printf("reserved: 0x%x\n", r.reserved);