summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/bds/board.c2
-rw-r--r--board/bds/board.h2
-rw-r--r--board/bolt/board.c2
-rw-r--r--board/bolt/board.h2
-rw-r--r--board/daisy/board.c2
-rw-r--r--board/daisy/board.h1
-rw-r--r--board/falco/board.c2
-rw-r--r--board/falco/board.h2
-rw-r--r--board/kirby/board.c2
-rw-r--r--board/kirby/board.h1
-rw-r--r--board/link/board.c2
-rw-r--r--board/link/board.h2
-rw-r--r--board/peppy/board.c2
-rw-r--r--board/peppy/board.h2
-rw-r--r--board/pit/board.c2
-rw-r--r--board/pit/board.h1
-rw-r--r--board/puppy/board.c2
-rw-r--r--board/puppy/board.h1
-rw-r--r--board/rambi/board.c2
-rw-r--r--board/rambi/board.h2
-rw-r--r--board/samus/board.c2
-rw-r--r--board/samus/board.h2
-rw-r--r--board/slippy/board.c2
-rw-r--r--board/slippy/board.h2
-rw-r--r--board/snow/board.c2
-rw-r--r--board/snow/board.h1
-rw-r--r--board/spring/board.c2
-rw-r--r--board/spring/board.h1
-rw-r--r--chip/lm4/i2c.c10
-rw-r--r--chip/stm32/i2c-stm32l.c10
-rw-r--r--common/i2c_common.c2
-rw-r--r--include/i2c.h1
32 files changed, 26 insertions, 47 deletions
diff --git a/board/bds/board.c b/board/bds/board.c
index 915679d4c3..a9c9a16df6 100644
--- a/board/bds/board.c
+++ b/board/bds/board.c
@@ -36,7 +36,7 @@ BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
const struct i2c_port_t i2c_ports[] = {
{"lightbar", I2C_PORT_LIGHTBAR, 400},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* GPIO signal list. Must match order from enum gpio_signal. */
diff --git a/board/bds/board.h b/board/bds/board.h
index f2e7c3d75b..4d83c3c203 100644
--- a/board/bds/board.h
+++ b/board/bds/board.h
@@ -46,8 +46,6 @@ enum pwm_channel {
/* I2C ports */
#define I2C_PORT_LIGHTBAR 5 // port 5 / PA6:7 on link, but PG6:7 on badger
-/* Number of I2C ports used */
-#define I2C_PORTS_USED 1
/* Second UART port */
#define CONFIG_UART_HOST 1
diff --git a/board/bolt/board.c b/board/bolt/board.c
index 0d988c1ad1..1a89534388 100644
--- a/board/bolt/board.c
+++ b/board/bolt/board.c
@@ -196,7 +196,7 @@ const struct i2c_port_t i2c_ports[] = {
{"lightbar", I2C_PORT_LIGHTBAR, 400},
{"thermal", I2C_PORT_THERMAL, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
diff --git a/board/bolt/board.h b/board/bolt/board.h
index bc1d732090..9bfabb0a13 100644
--- a/board/bolt/board.h
+++ b/board/bolt/board.h
@@ -70,8 +70,6 @@ enum module_id {
#define I2C_PORT_CHARGER 0
#define I2C_PORT_LIGHTBAR 1
#define I2C_PORT_THERMAL 5
-/* There are only 3 I2C ports used because battery and charger share a port */
-#define I2C_PORTS_USED 3
/* 13x8 keyboard scanner uses an entire GPIO bank for row inputs */
#define KB_SCAN_ROW_IRQ LM4_IRQ_GPIOK
diff --git a/board/daisy/board.c b/board/daisy/board.c
index b64214cb50..24f4580143 100644
--- a/board/daisy/board.c
+++ b/board/daisy/board.c
@@ -124,7 +124,7 @@ const struct i2c_port_t i2c_ports[] = {
{"0", 0, 100},
{"1", 1, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
void keyboard_suppress_noise(void)
{
diff --git a/board/daisy/board.h b/board/daisy/board.h
index 9643c82ab9..991f0088d9 100644
--- a/board/daisy/board.h
+++ b/board/daisy/board.h
@@ -53,7 +53,6 @@ enum module_id {
#define I2C_PORT_BATTERY I2C_PORT_HOST
#define I2C_PORT_CHARGER I2C_PORT_HOST
#define I2C_PORT_SLAVE 1
-#define I2C_PORTS_USED 2
/* Timer selection */
#define TIM_CLOCK_MSB 3
diff --git a/board/falco/board.c b/board/falco/board.c
index 71fd2acfa7..adc6cbddfb 100644
--- a/board/falco/board.c
+++ b/board/falco/board.c
@@ -198,7 +198,7 @@ const struct i2c_port_t i2c_ports[] = {
{"lvds", I2C_PORT_LVDS, 100},
{"thermal", I2C_PORT_THERMAL, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
const struct temp_sensor_t temp_sensors[] = {
diff --git a/board/falco/board.h b/board/falco/board.h
index 8575f50349..79d245dc43 100644
--- a/board/falco/board.h
+++ b/board/falco/board.h
@@ -55,8 +55,6 @@ enum module_id {
#define I2C_PORT_CHARGER 0
#define I2C_PORT_LVDS 1
#define I2C_PORT_THERMAL 5
-/* Battery and charger share a port. Don't count it twice. */
-#define I2C_PORTS_USED 3
/* 13x8 keyboard scanner uses an entire GPIO bank for row inputs */
#define KB_SCAN_ROW_IRQ LM4_IRQ_GPIOK
diff --git a/board/kirby/board.c b/board/kirby/board.c
index 3ee9acfd7a..4cac7b6d9f 100644
--- a/board/kirby/board.c
+++ b/board/kirby/board.c
@@ -139,7 +139,7 @@ BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
const struct i2c_port_t i2c_ports[] = {
{"host", I2C_PORT_HOST, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
static void board_update_backlight(void)
{
diff --git a/board/kirby/board.h b/board/kirby/board.h
index f5645c577e..1fa62bfa88 100644
--- a/board/kirby/board.h
+++ b/board/kirby/board.h
@@ -60,7 +60,6 @@ enum module_id {
#define I2C_PORT_HOST 0
#define I2C_PORT_BATTERY I2C_PORT_HOST
#define I2C_PORT_CHARGER I2C_PORT_HOST
-#define I2C_PORTS_USED 1
/* Timer selection */
#define TIM_CLOCK_MSB 2
diff --git a/board/link/board.c b/board/link/board.c
index 67284f2471..2b4fb9aeaf 100644
--- a/board/link/board.c
+++ b/board/link/board.c
@@ -197,7 +197,7 @@ const struct i2c_port_t i2c_ports[] = {
{"lightbar", I2C_PORT_LIGHTBAR, 400},
{"thermal", I2C_PORT_THERMAL, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
#define TEMP_PCH_REG_ADDR ((0x41 << 1) | I2C_FLAG_BIG_ENDIAN)
#define TEMP_CHARGER_REG_ADDR ((0x43 << 1) | I2C_FLAG_BIG_ENDIAN)
diff --git a/board/link/board.h b/board/link/board.h
index 4582500620..ce2a9f61e0 100644
--- a/board/link/board.h
+++ b/board/link/board.h
@@ -86,8 +86,6 @@ enum pwm_channel {
#define I2C_PORT_THERMAL 5
#define I2C_PORT_LIGHTBAR 1
#define I2C_PORT_REGULATOR 0
-/* There are only 3 I2C ports used because battery and charger share a port */
-#define I2C_PORTS_USED 3
/* 13x8 keyboard scanner uses an entire GPIO bank for row inputs */
#define KB_SCAN_ROW_IRQ LM4_IRQ_GPION
diff --git a/board/peppy/board.c b/board/peppy/board.c
index 5092357f01..730e1e17d9 100644
--- a/board/peppy/board.c
+++ b/board/peppy/board.c
@@ -189,7 +189,7 @@ const struct i2c_port_t i2c_ports[] = {
{"batt_chg", I2C_PORT_BATTERY, 100},
{"thermal", I2C_PORT_THERMAL, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
const struct temp_sensor_t temp_sensors[] = {
diff --git a/board/peppy/board.h b/board/peppy/board.h
index cf781fd8d8..ff4681aadc 100644
--- a/board/peppy/board.h
+++ b/board/peppy/board.h
@@ -57,8 +57,6 @@ enum module_id {
#define I2C_PORT_BATTERY 0
#define I2C_PORT_CHARGER 0
#define I2C_PORT_THERMAL 5
-/* There are only two I2C ports used because battery and charger share a port */
-#define I2C_PORTS_USED 2
/* 13x8 keyboard scanner uses an entire GPIO bank for row inputs */
#define KB_SCAN_ROW_IRQ LM4_IRQ_GPIOK
diff --git a/board/pit/board.c b/board/pit/board.c
index 8586124bd9..af7d12715f 100644
--- a/board/pit/board.c
+++ b/board/pit/board.c
@@ -109,7 +109,7 @@ const struct battery_temperature_ranges bat_temp_ranges = {
const struct i2c_port_t i2c_ports[] = {
{"host", I2C_PORT_HOST, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
struct keyboard_scan_config keyscan_config = {
.output_settle_us = 40,
diff --git a/board/pit/board.h b/board/pit/board.h
index c62faff1a3..c9c82e5048 100644
--- a/board/pit/board.h
+++ b/board/pit/board.h
@@ -58,7 +58,6 @@ enum module_id {
#define I2C_PORT_BATTERY I2C_PORT_HOST
#define I2C_PORT_CHARGER I2C_PORT_HOST
#define I2C_PORT_SLAVE 1
-#define I2C_PORTS_USED 1
/* Charger sense resistors */
#define CONFIG_CHARGER_SENSE_RESISTOR_AC 12
diff --git a/board/puppy/board.c b/board/puppy/board.c
index ba4184a898..8be5a970a6 100644
--- a/board/puppy/board.c
+++ b/board/puppy/board.c
@@ -107,7 +107,7 @@ const struct battery_temperature_ranges bat_temp_ranges = {
const struct i2c_port_t i2c_ports[] = {
{"host", I2C_PORT_HOST, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* PWM channels */
const struct pwm_t pwm_channels[] = {
diff --git a/board/puppy/board.h b/board/puppy/board.h
index e4e4cb73e7..23d783cdce 100644
--- a/board/puppy/board.h
+++ b/board/puppy/board.h
@@ -56,7 +56,6 @@ enum module_id {
#define I2C_PORT_BATTERY I2C_PORT_HOST
#define I2C_PORT_CHARGER I2C_PORT_HOST
#define I2C_PORT_SLAVE 1
-#define I2C_PORTS_USED 1
/* Timer selection */
#define TIM_CLOCK_MSB 3
diff --git a/board/rambi/board.c b/board/rambi/board.c
index 6c451ebaea..b864de5ef1 100644
--- a/board/rambi/board.c
+++ b/board/rambi/board.c
@@ -165,7 +165,7 @@ const struct i2c_port_t i2c_ports[] = {
{"batt_chg", I2C_PORT_BATTERY, 100},
{"thermal", I2C_PORT_THERMAL, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
const struct temp_sensor_t temp_sensors[] = {
diff --git a/board/rambi/board.h b/board/rambi/board.h
index c062368684..d9f038e850 100644
--- a/board/rambi/board.h
+++ b/board/rambi/board.h
@@ -55,8 +55,6 @@ enum module_id {
#define I2C_PORT_BATTERY 0
#define I2C_PORT_CHARGER 0
#define I2C_PORT_THERMAL 5
-/* There are only two I2C ports used because battery and charger share a port */
-#define I2C_PORTS_USED 2
/* 13x8 keyboard scanner uses an entire GPIO bank for row inputs */
#define KB_SCAN_ROW_IRQ LM4_IRQ_GPIOK
diff --git a/board/samus/board.c b/board/samus/board.c
index ddb8c97450..e649836b89 100644
--- a/board/samus/board.c
+++ b/board/samus/board.c
@@ -195,7 +195,7 @@ const struct i2c_port_t i2c_ports[] = {
{"lightbar", I2C_PORT_LIGHTBAR, 400},
{"thermal", I2C_PORT_THERMAL, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
diff --git a/board/samus/board.h b/board/samus/board.h
index 1e2e6e7402..d19c744def 100644
--- a/board/samus/board.h
+++ b/board/samus/board.h
@@ -67,8 +67,6 @@ enum module_id {
#define I2C_PORT_CHARGER 0
#define I2C_PORT_LIGHTBAR 1
#define I2C_PORT_THERMAL 5
-/* There are only 3 I2C ports used because battery and charger share a port */
-#define I2C_PORTS_USED 3
/* 13x8 keyboard scanner uses an entire GPIO bank for row inputs */
#define KB_SCAN_ROW_IRQ LM4_IRQ_GPIOK
diff --git a/board/slippy/board.c b/board/slippy/board.c
index bf8ec43dda..df46ddfb02 100644
--- a/board/slippy/board.c
+++ b/board/slippy/board.c
@@ -187,7 +187,7 @@ const struct i2c_port_t i2c_ports[] = {
{"batt_chg", I2C_PORT_BATTERY, 100},
{"thermal", I2C_PORT_THERMAL, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* Temperature sensors data; must be in same order as enum temp_sensor_id. */
const struct temp_sensor_t temp_sensors[] = {
diff --git a/board/slippy/board.h b/board/slippy/board.h
index 9fcd0318f8..7dc2cb1bd9 100644
--- a/board/slippy/board.h
+++ b/board/slippy/board.h
@@ -56,8 +56,6 @@ enum module_id {
#define I2C_PORT_BATTERY 0
#define I2C_PORT_CHARGER 0
#define I2C_PORT_THERMAL 5
-/* There are only two I2C ports used because battery and charger share a port */
-#define I2C_PORTS_USED 2
/* 13x8 keyboard scanner uses an entire GPIO bank for row inputs */
#define KB_SCAN_ROW_IRQ LM4_IRQ_GPIOK
diff --git a/board/snow/board.c b/board/snow/board.c
index 1d1e22d8d0..4369956924 100644
--- a/board/snow/board.c
+++ b/board/snow/board.c
@@ -120,7 +120,7 @@ const struct battery_temperature_ranges bat_temp_ranges = {
const struct i2c_port_t i2c_ports[] = {
{"host", I2C_PORT_HOST, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
/* PWM channels */
const struct pwm_t pwm_channels[] = {
diff --git a/board/snow/board.h b/board/snow/board.h
index 016393e55b..af5dbe073f 100644
--- a/board/snow/board.h
+++ b/board/snow/board.h
@@ -54,7 +54,6 @@ enum module_id {
#define I2C_PORT_BATTERY I2C_PORT_HOST
#define I2C_PORT_CHARGER I2C_PORT_HOST
#define I2C_PORT_SLAVE 1
-#define I2C_PORTS_USED 1
#define GPIO_AP_CLAIM GPIO_SPI1_NSS /* AP claims bus */
#define GPIO_EC_CLAIM GPIO_SPI1_MISO /* EC claims bus */
diff --git a/board/spring/board.c b/board/spring/board.c
index ef927fc01b..58cb4ed9bd 100644
--- a/board/spring/board.c
+++ b/board/spring/board.c
@@ -142,7 +142,7 @@ BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
const struct i2c_port_t i2c_ports[] = {
{"host", I2C_PORT_HOST, 100},
};
-BUILD_ASSERT(ARRAY_SIZE(i2c_ports) == I2C_PORTS_USED);
+const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
void board_config_pre_init(void)
{
diff --git a/board/spring/board.h b/board/spring/board.h
index 242ba2b1b3..82d86d6034 100644
--- a/board/spring/board.h
+++ b/board/spring/board.h
@@ -56,7 +56,6 @@ enum module_id {
#define I2C_PORT_BATTERY I2C_PORT_HOST
#define I2C_PORT_CHARGER I2C_PORT_HOST
#define I2C_PORT_SLAVE 1
-#define I2C_PORTS_USED 1
/* Low battery threshold. In mAh. */
#define BATTERY_AP_OFF_LEVEL 1
diff --git a/chip/lm4/i2c.c b/chip/lm4/i2c.c
index 8fc1591338..cf2ff5a690 100644
--- a/chip/lm4/i2c.c
+++ b/chip/lm4/i2c.c
@@ -244,7 +244,7 @@ static void i2c_freq_changed(void)
int freq = clock_get_freq();
int i;
- for (i = 0; i < I2C_PORTS_USED; i++) {
+ for (i = 0; i < i2c_ports_used; i++) {
/*
* From datasheet:
* SCL_PRD = 2 * (1 + TPR) * (SCL_LP + SCL_HP) * CLK_PRD
@@ -277,7 +277,7 @@ static void i2c_init(void)
int i;
/* Enable I2C modules and delay a few clocks */
- for (i = 0; i < I2C_PORTS_USED; i++)
+ for (i = 0; i < i2c_ports_used; i++)
mask |= 1 << i2c_ports[i].port;
LM4_SYSTEM_RCGCI2C |= mask;
@@ -291,7 +291,7 @@ static void i2c_init(void)
task_waiting_on_port[i] = TASK_ID_INVALID;
/* Initialize ports as master, with interrupts enabled */
- for (i = 0; i < I2C_PORTS_USED; i++)
+ for (i = 0; i < i2c_ports_used; i++)
LM4_I2C_MCR(i2c_ports[i].port) = 0x10;
/* Set initial clock frequency */
@@ -355,9 +355,9 @@ static int command_i2cread(int argc, char **argv)
if (*e)
return EC_ERROR_PARAM1;
- for (i = 0; i < I2C_PORTS_USED && port != i2c_ports[i].port; i++)
+ for (i = 0; i < i2c_ports_used && port != i2c_ports[i].port; i++)
;
- if (i >= I2C_PORTS_USED)
+ if (i >= i2c_ports_used)
return EC_ERROR_PARAM1;
addr = strtoi(argv[2], &e, 0);
diff --git a/chip/stm32/i2c-stm32l.c b/chip/stm32/i2c-stm32l.c
index 778e8bc1bb..71b93a2953 100644
--- a/chip/stm32/i2c-stm32l.c
+++ b/chip/stm32/i2c-stm32l.c
@@ -402,7 +402,7 @@ int i2c_xfer(int port, int slave_addr, const uint8_t *out, int out_bytes,
const struct i2c_port_t *p = i2c_ports;
CPRINTF("[%T i2c_xfer start error; "
"try resetting i2c%d to unwedge.\n", port);
- for (i = 0; i < I2C_PORTS_USED; i++, p++) {
+ for (i = 0; i < i2c_ports_used; i++, p++) {
if (p->port == port) {
i2c_init_port(p, 1); /* force unwedge */
break;
@@ -492,7 +492,7 @@ static void i2c_freq_change(void)
const struct i2c_port_t *p = i2c_ports;
int i;
- for (i = 0; i < I2C_PORTS_USED; i++, p++)
+ for (i = 0; i < i2c_ports_used; i++, p++)
i2c_set_freq_port(p);
}
@@ -502,7 +502,7 @@ static void i2c_pre_freq_change_hook(void)
int i;
/* Lock I2C ports so freq change can't interrupt an I2C transaction */
- for (i = 0; i < I2C_PORTS_USED; i++, p++)
+ for (i = 0; i < i2c_ports_used; i++, p++)
i2c_lock(p->port, 1);
}
DECLARE_HOOK(HOOK_PRE_FREQ_CHANGE, i2c_pre_freq_change_hook, HOOK_PRIO_DEFAULT);
@@ -514,7 +514,7 @@ static void i2c_freq_change_hook(void)
i2c_freq_change();
/* Unlock I2C ports we locked in pre-freq change hook */
- for (i = 0; i < I2C_PORTS_USED; i++, p++)
+ for (i = 0; i < i2c_ports_used; i++, p++)
i2c_lock(p->port, 0);
}
DECLARE_HOOK(HOOK_FREQ_CHANGE, i2c_freq_change_hook, HOOK_PRIO_DEFAULT);
@@ -524,7 +524,7 @@ static void i2c_init(void)
const struct i2c_port_t *p = i2c_ports;
int i;
- for (i = 0; i < I2C_PORTS_USED; i++, p++)
+ for (i = 0; i < i2c_ports_used; i++, p++)
i2c_init_port(p, 0); /* do not force unwedged */
}
DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_DEFAULT);
diff --git a/common/i2c_common.c b/common/i2c_common.c
index f18c8004f8..a291d5caa4 100644
--- a/common/i2c_common.c
+++ b/common/i2c_common.c
@@ -368,7 +368,7 @@ static int command_scan(int argc, char **argv)
{
int i;
- for (i = 0; i < I2C_PORTS_USED; i++)
+ for (i = 0; i < i2c_ports_used; i++)
scan_bus(i2c_ports[i].port, i2c_ports[i].name);
return EC_SUCCESS;
}
diff --git a/include/i2c.h b/include/i2c.h
index 747967b3a6..6367c87079 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -21,6 +21,7 @@ struct i2c_port_t {
};
extern const struct i2c_port_t i2c_ports[];
+extern const unsigned int i2c_ports_used;
/* Flags for i2c_xfer() */
#define I2C_XFER_START (1 << 0) /* Start smbus session from idle state */