cleanup: Replace awkward I2C_PORTS_USED macro with constant

We only used I2C_PORTS_USED to iterate through the list of hardware ports
actually in use, but we defined it in board.h at the same place where we
matched particular I2C devices to the (possibly shared) buses they're on.

This CL makes I2C_PORTS_USED into a global constant, so it can be set
automatically where we initialize the ports, and doesn't have to be
related to the list of attached devices.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=manual

Build everything, run all tests, should still work.

Change-Id: I65f22f5cadfc4b3afe51af48faa5fb369bc3aa09
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/171884
This commit is contained in:
Bill Richardson
2013-10-04 11:28:48 -07:00
committed by chrome-internal-fetch
parent 616cc446e2
commit 57aaa0267e
32 changed files with 26 additions and 47 deletions

View File

@@ -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. */

View File

@@ -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

View File

@@ -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. */

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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

View File

@@ -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[] = {

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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[] = {

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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[] = {

View File

@@ -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

View File

@@ -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[] = {

View File

@@ -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

View File

@@ -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. */

View File

@@ -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

View File

@@ -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[] = {

View File

@@ -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

View File

@@ -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[] = {

View File

@@ -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 */

View File

@@ -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)
{

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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 */