diff options
-rw-r--r-- | chip/g/i2cm.c | 9 | ||||
-rw-r--r-- | chip/host/i2c.c | 5 | ||||
-rw-r--r-- | chip/ish/i2c.c | 3 | ||||
-rw-r--r-- | chip/it83xx/i2c.c | 3 | ||||
-rw-r--r-- | chip/lm4/i2c.c | 3 | ||||
-rw-r--r-- | chip/max32660/i2c_chip.c | 3 | ||||
-rw-r--r-- | chip/mchp/i2c.c | 4 | ||||
-rw-r--r-- | chip/mec1322/i2c.c | 3 | ||||
-rw-r--r-- | chip/npcx/i2c.c | 3 | ||||
-rw-r--r-- | chip/nrf51/i2c.c | 3 | ||||
-rw-r--r-- | chip/stm32/i2c-stm32f0.c | 3 | ||||
-rw-r--r-- | chip/stm32/i2c-stm32f4.c | 3 | ||||
-rw-r--r-- | chip/stm32/i2c-stm32l.c | 3 | ||||
-rw-r--r-- | chip/stm32/i2c-stm32l4.c | 3 | ||||
-rw-r--r-- | common/main.c | 8 | ||||
-rw-r--r-- | include/config.h | 6 | ||||
-rw-r--r-- | include/hooks.h | 7 | ||||
-rw-r--r-- | include/i2c.h | 8 |
18 files changed, 53 insertions, 27 deletions
diff --git a/chip/g/i2cm.c b/chip/g/i2cm.c index 44a0fbb844..4959cdbba0 100644 --- a/chip/g/i2cm.c +++ b/chip/g/i2cm.c @@ -460,3 +460,12 @@ void i2cm_init(void) i2cm_init_port(p); } + +void i2c_init(void) +{ + /* + * Stub init function to be called at boot. + * We only want this controller active in certain cases, + * but we still need to let main.c call something. + */ +} diff --git a/chip/host/i2c.c b/chip/host/i2c.c index 28a6f5f158..5b863c1d41 100644 --- a/chip/host/i2c.c +++ b/chip/host/i2c.c @@ -109,3 +109,8 @@ int i2c_get_line_levels(int port) { return 0; } + +void i2c_init(void) +{ + /* We don't actually need to initialize anything here for host tests */ +} diff --git a/chip/ish/i2c.c b/chip/ish/i2c.c index b4cc32f0ad..d8dbd6a003 100644 --- a/chip/ish/i2c.c +++ b/chip/ish/i2c.c @@ -521,7 +521,7 @@ static void i2c_initial_board_config(struct i2c_context *ctx) bus_info->high_speed.lcnt = default_lcnt_scl_hs[freq]; } -static void i2c_init(void) +void i2c_init(void) { int i; @@ -537,4 +537,3 @@ static void i2c_init(void) CPRINTS("Done i2c_init"); } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); diff --git a/chip/it83xx/i2c.c b/chip/it83xx/i2c.c index 4fe5ee62cc..1160b1bd2c 100644 --- a/chip/it83xx/i2c.c +++ b/chip/it83xx/i2c.c @@ -822,7 +822,7 @@ static void i2c_freq_changed(void) } DECLARE_HOOK(HOOK_FREQ_CHANGE, i2c_freq_changed, HOOK_PRIO_DEFAULT); -static void i2c_init(void) +void i2c_init(void) { int i, p, p_ch; @@ -897,4 +897,3 @@ static void i2c_init(void) i2c_set_timeout(i, 0); } } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); diff --git a/chip/lm4/i2c.c b/chip/lm4/i2c.c index b95fcba0b0..7cd06c430f 100644 --- a/chip/lm4/i2c.c +++ b/chip/lm4/i2c.c @@ -343,7 +343,7 @@ static void i2c_freq_changed(void) } DECLARE_HOOK(HOOK_FREQ_CHANGE, i2c_freq_changed, HOOK_PRIO_DEFAULT); -static void i2c_init(void) +void i2c_init(void) { uint32_t mask = 0; int i; @@ -374,7 +374,6 @@ static void i2c_init(void) i2c_set_timeout(i, 0); } } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); /** * Handle an interrupt on the specified port. diff --git a/chip/max32660/i2c_chip.c b/chip/max32660/i2c_chip.c index 2069cf7921..4ee6117656 100644 --- a/chip/max32660/i2c_chip.c +++ b/chip/max32660/i2c_chip.c @@ -260,7 +260,7 @@ void i2c_set_timeout(int port, uint32_t timeout) /** * i2c_init() - Initialize the I2C ports used on device. */ -static void i2c_init(void) +void i2c_init(void) { int i; int port; @@ -281,7 +281,6 @@ static void i2c_init(void) init_i2cs(I2C_PORT_EC); #endif } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); /** * I2C Slave Implentation diff --git a/chip/mchp/i2c.c b/chip/mchp/i2c.c index c75712bc37..ab2c75c754 100644 --- a/chip/mchp/i2c.c +++ b/chip/mchp/i2c.c @@ -878,7 +878,7 @@ void i2c_set_timeout(int port, uint32_t timeout) * If multiple ports are mapped to the same controller choose the * lowest speed. */ -static void i2c_init(void) +void i2c_init(void) { int i, controller, kbps; int controller_kbps[MCHP_I2C_CTRL_MAX]; @@ -923,7 +923,7 @@ static void i2c_init(void) i2c_set_timeout(i2c_ports[i].port, 0); } } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); + /* * Handle I2C interrupts. * I2C controller is configured to fire interrupts on diff --git a/chip/mec1322/i2c.c b/chip/mec1322/i2c.c index 6a0fa0a5cc..fe72b870ef 100644 --- a/chip/mec1322/i2c.c +++ b/chip/mec1322/i2c.c @@ -469,7 +469,7 @@ void i2c_set_timeout(int port, uint32_t timeout) timeout ? timeout : I2C_TIMEOUT_DEFAULT_US; } -static void i2c_init(void) +void i2c_init(void) { int i; int controller; @@ -500,7 +500,6 @@ static void i2c_init(void) i2c_set_timeout(i2c_ports[i].port, 0); } } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); static void handle_interrupt(int controller) { diff --git a/chip/npcx/i2c.c b/chip/npcx/i2c.c index 6b87c3f4e0..81e69a3d64 100644 --- a/chip/npcx/i2c.c +++ b/chip/npcx/i2c.c @@ -815,7 +815,7 @@ static void i2c_freq_changed(void) } DECLARE_HOOK(HOOK_FREQ_CHANGE, i2c_freq_changed, HOOK_PRIO_DEFAULT); -static void i2c_init(void) +void i2c_init(void) { int i; @@ -859,5 +859,4 @@ static void i2c_init(void) i2c_init_bus(ctrl); } } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); diff --git a/chip/nrf51/i2c.c b/chip/nrf51/i2c.c index ab20b2a16b..09a4a210e6 100644 --- a/chip/nrf51/i2c.c +++ b/chip/nrf51/i2c.c @@ -57,7 +57,7 @@ static void i2c_init_port(unsigned int port) CPRINTF("port %d could be wedged\n", port); } -static void i2c_init(void) +void i2c_init(void) { int i, rv; @@ -72,7 +72,6 @@ static void i2c_init(void) } } } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); static void dump_i2c_reg(int port) { diff --git a/chip/stm32/i2c-stm32f0.c b/chip/stm32/i2c-stm32f0.c index 49be4833c5..a4db7ee456 100644 --- a/chip/stm32/i2c-stm32f0.c +++ b/chip/stm32/i2c-stm32f0.c @@ -597,7 +597,7 @@ int i2c_get_line_levels(int port) (i2c_raw_get_scl(port) ? I2C_LINE_SCL_HIGH : 0); } -static void i2c_init(void) +void i2c_init(void) { const struct i2c_port_t *p = i2c_ports; int i; @@ -630,5 +630,4 @@ static void i2c_init(void) task_enable_irq(IRQ_SLAVE); #endif } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); diff --git a/chip/stm32/i2c-stm32f4.c b/chip/stm32/i2c-stm32f4.c index aa4a363e54..8c08395edd 100644 --- a/chip/stm32/i2c-stm32f4.c +++ b/chip/stm32/i2c-stm32f4.c @@ -982,7 +982,7 @@ DECLARE_IRQ(IRQ_SLAVE_ER, i2c_event_interrupt, 2); /* Init all available i2c ports */ -static void i2c_init(void) +void i2c_init(void) { const struct i2c_port_t *p = i2c_ports; int i; @@ -1008,4 +1008,3 @@ static void i2c_init(void) task_enable_irq(IRQ_SLAVE_ER); #endif } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); diff --git a/chip/stm32/i2c-stm32l.c b/chip/stm32/i2c-stm32l.c index ce1fa92758..80d3434c74 100644 --- a/chip/stm32/i2c-stm32l.c +++ b/chip/stm32/i2c-stm32l.c @@ -402,7 +402,7 @@ static void i2c_freq_change_hook(void) } DECLARE_HOOK(HOOK_FREQ_CHANGE, i2c_freq_change_hook, HOOK_PRIO_DEFAULT); -static void i2c_init(void) +void i2c_init(void) { const struct i2c_port_t *p = i2c_ports; int i; @@ -410,7 +410,6 @@ static void i2c_init(void) for (i = 0; i < i2c_ports_used; i++, p++) i2c_init_port(p); } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); /*****************************************************************************/ /* Console commands */ diff --git a/chip/stm32/i2c-stm32l4.c b/chip/stm32/i2c-stm32l4.c index d30bcded0c..66bd063499 100644 --- a/chip/stm32/i2c-stm32l4.c +++ b/chip/stm32/i2c-stm32l4.c @@ -445,7 +445,7 @@ int i2c_get_line_levels(int port) (i2c_raw_get_scl(port) ? I2C_LINE_SCL_HIGH : 0); } -static void i2c_init(void) +void i2c_init(void) { const struct i2c_port_t *p = i2c_ports; int i; @@ -462,4 +462,3 @@ static void i2c_init(void) task_enable_irq(IRQ_SLAVE); #endif } -DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_INIT_I2C); diff --git a/common/main.c b/common/main.c index d7a3935b2f..5bbe6f8a55 100644 --- a/common/main.c +++ b/common/main.c @@ -17,6 +17,7 @@ #include "flash.h" #include "gpio.h" #include "hooks.h" +#include "i2c.h" #include "keyboard_scan.h" #include "link_defs.h" #include "lpc.h" @@ -180,6 +181,13 @@ test_mockable __keep int main(void) #ifdef CONFIG_HOSTCMD_X86 lpc_init_mask(); #endif + if (IS_ENABLED(CONFIG_I2C_MASTER)) { + /* + * Some devices (like the I2C keyboards, CBI) need I2C access + * pretty early, so let's initialize the controller now. + */ + i2c_init(); + } #ifdef HAS_TASK_KEYSCAN keyboard_scan_init(); #endif diff --git a/include/config.h b/include/config.h index c9754bc649..a0a5bf6f47 100644 --- a/include/config.h +++ b/include/config.h @@ -2237,7 +2237,11 @@ */ #undef CONFIG_I2C_XFER_BOARD_CALLBACK -/* EC uses an I2C master interface */ +/* + * EC uses an I2C master interface. + * Note: if this is defined, i2c_init() will be called + * automatically at board boot. + */ #undef CONFIG_I2C_MASTER /* EC uses an I2C slave interface */ diff --git a/include/hooks.h b/include/hooks.h index c28e2e58d8..e30c420fbb 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -21,7 +21,12 @@ enum hook_priority { HOOK_PRIO_INIT_DMA = HOOK_PRIO_FIRST + 1, /* LPC inits before modules which need memory-mapped I/O */ HOOK_PRIO_INIT_LPC = HOOK_PRIO_FIRST + 1, - /* I2C is needed before chipset inits (battery communications). */ + /* + * I2C dependents (battery, sensors, etc), everything but the + * controllers. I2C controller is now initialized in main.c + * TODO(b/138384267): Split this hook up and name the resulting + * ones more semantically. + */ HOOK_PRIO_INIT_I2C = HOOK_PRIO_FIRST + 2, /* Chipset inits before modules which need to know its initial state. */ HOOK_PRIO_INIT_CHIPSET = HOOK_PRIO_FIRST + 3, diff --git a/include/i2c.h b/include/i2c.h index dd237e5354..0d68b5bc90 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -447,9 +447,15 @@ enum ec_status i2c_get_protocol_info(struct host_cmd_handler_args *args); void i2c_data_received(int port, uint8_t *buf, int len); int i2c_set_response(int port, uint8_t *buf, int len); +/* + * Initialize i2c master controller. Automatically called at board boot + * if CONFIG_I2C_MASTER is defined. + */ +void i2c_init(void); + /** * Initialize i2c master ports. This function can be called for cases where i2c - * ports are not initialized by default via a hook call. + * ports are not initialized by default from main.c. */ void i2cm_init(void); |