summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-04-19 12:42:35 -0700
committerRandall Spangler <rspangler@chromium.org>2012-04-19 13:08:58 -0700
commitf4e772708bde3e4e1d184190a7f0be2417d2029a (patch)
tree4b668c02a9a6dca2704e6d0a8b3cb8e5c9e95b76 /common
parentd5d2159c6d215b3a0feca42d961985cd37603ca8 (diff)
downloadchrome-ec-f4e772708bde3e4e1d184190a7f0be2417d2029a.tar.gz
Added HOOK_INIT for driver module inits
This covers modules which need to initialize before task_start(), but don't particularly care in what order they're initialized. Signed-off-by: Randall Spangler <rspangler@chromium.org> BUG=none TEST=if it boots, it works Change-Id: I69829aac8d1c3c14ee04916a794b84bbf03a09eb
Diffstat (limited to 'common')
-rw-r--r--common/hooks.c6
-rw-r--r--common/main.c54
-rw-r--r--common/usb_charge.c13
3 files changed, 20 insertions, 53 deletions
diff --git a/common/hooks.c b/common/hooks.c
index 94bf2627fb..58ff10546a 100644
--- a/common/hooks.c
+++ b/common/hooks.c
@@ -10,6 +10,8 @@
#include "util.h"
/* Hooks are described in special sections */
+extern const struct hook_data __hooks_init[];
+extern const struct hook_data __hooks_init_end[];
extern const struct hook_data __hooks_freq_change[];
extern const struct hook_data __hooks_freq_change_end[];
@@ -23,6 +25,10 @@ int hook_notify(enum hook_type type, int stop_on_error)
/* Get the start and end pointers for the hook type */
switch (type) {
+ case HOOK_INIT:
+ start = __hooks_init;
+ end = __hooks_init_end;
+ break;
case HOOK_FREQ_CHANGE:
start = __hooks_freq_change;
end = __hooks_freq_change_end;
diff --git a/common/main.c b/common/main.c
index 606a04d830..ce3d6fad68 100644
--- a/common/main.c
+++ b/common/main.c
@@ -5,36 +5,20 @@
* Main routine for Chrome EC
*/
-#include "adc.h"
-#include "charger.h"
-#include "chip_temp_sensor.h"
#include "clock.h"
#include "config.h"
-#include "console.h"
#include "eeprom.h"
#include "eoption.h"
#include "flash.h"
#include "gpio.h"
-#include "i2c.h"
+#include "hooks.h"
#include "jtag.h"
#include "keyboard.h"
#include "keyboard_scan.h"
-#include "lpc.h"
-#include "memory_commands.h"
-#include "onewire.h"
-#include "peci.h"
-#include "port80.h"
-#include "power_button.h"
-#include "powerdemo.h"
-#include "pwm.h"
-#include "spi.h"
#include "system.h"
#include "task.h"
-#include "temp_sensor.h"
-#include "tmp006.h"
#include "timer.h"
#include "uart.h"
-#include "usb_charge.h"
#include "vboot.h"
#include "watchdog.h"
@@ -114,38 +98,12 @@ int main(void)
* RO image and once in the RW image. */
vboot_init();
- /* Initialize driver modules. These can occur in any order. State
- * machines are initialized in their task functions, not here. */
+ /* TODO: reduce core clock now that vboot is done */
- gpio_init();
-
-#ifdef CONFIG_LPC
- lpc_init();
-#endif
-#ifdef CONFIG_SPI
- spi_init();
-#endif
-#ifdef CONFIG_PWM
- pwm_init();
-#endif
-#ifdef CONFIG_I2C
- i2c_init();
-#endif
-#ifdef CONFIG_TASK_POWERBTN
- power_button_init();
-#endif
-#ifdef CONFIG_ADC
- adc_init();
-#endif
-#ifdef CONFIG_ONEWIRE
- onewire_init();
-#endif
-#ifdef CONFIG_PECI
- peci_init();
-#endif
-#ifdef CONFIG_USB_CHARGE
- usb_charge_init();
-#endif
+ /* Initialize other driver modules. These can occur in any order.
+ * Non-driver modules with tasks do their inits from their task
+ * functions, not here. */
+ hook_notify(HOOK_INIT, 0);
/* Print the init time and reset cause. Init time isn't completely
* accurate because it can't take into account the time for the first
diff --git a/common/usb_charge.c b/common/usb_charge.c
index 883bae5039..f14cfe393d 100644
--- a/common/usb_charge.c
+++ b/common/usb_charge.c
@@ -5,11 +5,12 @@
/* USB charging control module for Chrome EC */
-#include "usb_charge.h"
#include "board.h"
+#include "console.h"
#include "gpio.h"
+#include "hooks.h"
#include "uart.h"
-#include "console.h"
+#include "usb_charge.h"
#include "util.h"
static void usb_charge_set_control_mode(int port_id, int mode)
@@ -26,6 +27,7 @@ static void usb_charge_set_control_mode(int port_id, int mode)
}
}
+
static void usb_charge_set_enabled(int port_id, int en)
{
if (port_id == 0)
@@ -34,6 +36,7 @@ static void usb_charge_set_enabled(int port_id, int en)
gpio_set_level(GPIO_USB2_ENABLE, en);
}
+
static void usb_charge_set_ilim(int port_id, int sel)
{
if (port_id == 0)
@@ -42,6 +45,7 @@ static void usb_charge_set_ilim(int port_id, int sel)
gpio_set_level(GPIO_USB2_ILIM_SEL, sel);
}
+
int usb_charge_set_mode(int port_id, enum usb_charge_mode mode)
{
if (port_id >= USB_CHARGE_PORT_COUNT)
@@ -77,7 +81,6 @@ int usb_charge_set_mode(int port_id, enum usb_charge_mode mode)
return EC_SUCCESS;
}
-
/*****************************************************************************/
/* Console commands */
@@ -114,11 +117,10 @@ static int command_set_mode(int argc, char **argv)
}
DECLARE_CONSOLE_COMMAND(usbchargemode, command_set_mode);
-
/*****************************************************************************/
/* Initialization */
-int usb_charge_init(void)
+static int usb_charge_init(void)
{
int i;
@@ -127,3 +129,4 @@ int usb_charge_init(void)
return EC_SUCCESS;
}
+DECLARE_HOOK(HOOK_INIT, usb_charge_init, HOOK_PRIO_DEFAULT);