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
This commit is contained in:
Randall Spangler
2012-04-19 12:42:35 -07:00
parent d5d2159c6d
commit f4e772708b
26 changed files with 80 additions and 120 deletions

View File

@@ -8,6 +8,7 @@
#include "adc.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
#include "lm4_adc.h"
#include "registers.h"
#include "task.h"
@@ -47,6 +48,7 @@ const uint32_t ain_port[24][2] = {
{LM4_GPIO_N, (1<<0)},
};
static void configure_gpio(void)
{
int i;
@@ -66,6 +68,7 @@ static void configure_gpio(void)
}
}
int lm4_adc_flush_and_read(enum lm4_adc_sequencer seq)
{
/* TODO: right now we have only a single channel so this is
@@ -107,6 +110,7 @@ int lm4_adc_flush_and_read(enum lm4_adc_sequencer seq)
return LM4_ADC_SSFIFO(seq);
}
int lm4_adc_configure(enum lm4_adc_sequencer seq,
int ain_id,
int ssctl)
@@ -133,6 +137,7 @@ int lm4_adc_configure(enum lm4_adc_sequencer seq,
return EC_SUCCESS;
}
int adc_read_channel(enum adc_channel ch)
{
const struct adc_t *adc = adc_channels + ch;
@@ -181,6 +186,7 @@ static int command_ectemp(int argc, char **argv)
}
DECLARE_CONSOLE_COMMAND(ectemp, command_ectemp);
static int command_adc(int argc, char **argv)
{
int i;
@@ -197,7 +203,7 @@ DECLARE_CONSOLE_COMMAND(adc, command_adc);
/*****************************************************************************/
/* Initialization */
int adc_init(void)
static int adc_init(void)
{
int i;
const struct adc_t *adc;
@@ -231,3 +237,4 @@ int adc_init(void)
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, adc_init, HOOK_PRIO_DEFAULT);

View File

@@ -7,6 +7,7 @@
#include "board.h"
#include "gpio.h"
#include "hooks.h"
#include "power_button.h"
#include "registers.h"
#include "task.h"
@@ -116,7 +117,7 @@ int gpio_pre_init(void)
}
int gpio_init(void)
static int gpio_init(void)
{
/* Enable IRQs now that pins are set up */
task_enable_irq(LM4_IRQ_GPIOA);
@@ -141,6 +142,7 @@ int gpio_init(void)
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, gpio_init, HOOK_PRIO_DEFAULT);
void gpio_set_alternate_function(int port, int mask, int func)

View File

@@ -437,7 +437,7 @@ static void configure_gpio(void)
}
int i2c_init(void)
static int i2c_init(void)
{
volatile uint32_t scratch __attribute__((unused));
int i;
@@ -474,3 +474,4 @@ int i2c_init(void)
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_DEFAULT);

View File

@@ -7,6 +7,7 @@
#include "board.h"
#include "gpio.h"
#include "hooks.h"
#include "host_command.h"
#include "i8042.h"
#include "lpc.h"
@@ -105,7 +106,7 @@ static void lpc_generate_sci(void)
}
int lpc_init(void)
static int lpc_init(void)
{
volatile uint32_t scratch __attribute__((unused));
@@ -200,6 +201,7 @@ int lpc_init(void)
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, lpc_init, HOOK_PRIO_DEFAULT);
uint8_t *lpc_get_host_range(int slot)

View File

@@ -7,8 +7,9 @@
#include "board.h"
#include "gpio.h"
#include "timer.h"
#include "hooks.h"
#include "registers.h"
#include "timer.h"
#define ONEWIRE_PIN (1<<2) /* One-wire pin mask (on GPIO H) */
@@ -131,10 +132,11 @@ static void configure_gpio(void)
}
int onewire_init(void)
static int onewire_init(void)
{
/* Configure GPIOs */
configure_gpio();
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, onewire_init, HOOK_PRIO_DEFAULT);

View File

@@ -114,7 +114,7 @@ DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp);
/*****************************************************************************/
/* Initialization */
int peci_init(void)
static int peci_init(void)
{
volatile uint32_t scratch __attribute__((unused));
@@ -130,3 +130,4 @@ int peci_init(void)
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, peci_init, HOOK_PRIO_DEFAULT);

View File

@@ -9,6 +9,7 @@
#include "console.h"
#include "eoption.h"
#include "gpio.h"
#include "hooks.h"
#include "keyboard.h"
#include "keyboard_scan.h"
#include "lpc.h"
@@ -287,7 +288,7 @@ void power_button_interrupt(enum gpio_signal signal)
}
int power_button_init(void)
static int power_button_init(void)
{
/* Set up memory-mapped switch positions */
memmap_switches = lpc_get_memmap_range() + EC_LPC_MEMMAP_SWITCHES;
@@ -331,6 +332,7 @@ int power_button_init(void)
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, power_button_init, HOOK_PRIO_DEFAULT);
void power_button_task(void)

View File

@@ -8,6 +8,7 @@
#include "board.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
#include "pwm.h"
#include "registers.h"
#include "uart.h"
@@ -272,7 +273,7 @@ DECLARE_CONSOLE_COMMAND(kblight, command_kblight);
/*****************************************************************************/
/* Initialization */
int pwm_init(void)
static int pwm_init(void)
{
volatile uint32_t scratch __attribute__((unused));
@@ -324,3 +325,4 @@ int pwm_init(void)
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, pwm_init, HOOK_PRIO_DEFAULT);

View File

@@ -7,6 +7,7 @@
#include "board.h"
#include "gpio.h"
#include "hooks.h"
#include "registers.h"
#include "task.h"
#include "uart.h"
@@ -66,7 +67,7 @@ int gpio_pre_init(void)
}
int gpio_init(void)
static int gpio_init(void)
{
/* Enable IRQs now that pins are set up */
task_enable_irq(STM32L_IRQ_EXTI0);
@@ -79,6 +80,7 @@ int gpio_init(void)
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, gpio_init, HOOK_PRIO_DEFAULT);
void gpio_set_alternate_function(int port, int mask, int func)

View File

@@ -7,8 +7,9 @@
#include "common.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
#include "i2c.h"
#include <message.h>
#include "message.h"
#include "registers.h"
#include "task.h"
#include "uart.h"
@@ -222,7 +223,8 @@ static int i2c_init2(void)
return EC_SUCCESS;
}
int i2c_init(void)
static int i2c_init(void)
{
int rc = 0;
@@ -230,3 +232,4 @@ int i2c_init(void)
rc |= i2c_init2();
return rc;
}
DECLARE_HOOK(HOOK_INIT, i2c_init, HOOK_PRIO_DEFAULT);

View File

@@ -1,16 +1,16 @@
/*
/* Copyright (c) 2012 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.
*
* SPI driver for Chrome EC.
*
* This uses DMA although not in an optimal way yet.
*
* Copyright (c) 2012 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.
*/
#include "console.h"
#include "dma.h"
#include "gpio.h"
#include "hooks.h"
#include "message.h"
#include "registers.h"
#include "spi.h"
@@ -154,7 +154,7 @@ static void spi1_interrupt(void) { spi_interrupt(STM32L_SPI1_PORT); };
DECLARE_IRQ(STM32L_IRQ_SPI1, spi1_interrupt, 2);
int spi_init(void)
static int spi_init(void)
{
int port;
@@ -186,3 +186,4 @@ int spi_init(void)
#endif
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, spi_init, HOOK_PRIO_DEFAULT);

View File

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

View File

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

View File

@@ -5,11 +5,12 @@
/* USB charging control module for Chrome EC */
#include "usb_charge.h"
#include "board.h"
#include "gpio.h"
#include "uart.h"
#include "console.h"
#include "gpio.h"
#include "hooks.h"
#include "uart.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);

View File

@@ -46,11 +46,13 @@ SECTIONS
__hcmds_end = .;
. = ALIGN(4);
__hooks_init = .;
*(.rodata.HOOK_INIT)
__hooks_init_end = .;
__hooks_freq_change = .;
*(.rodata.HOOK_FREQ_CHANGE)
__hooks_freq_change_end = .;
. = ALIGN(4);
*(.rodata*)
. = ALIGN(4);

View File

@@ -11,9 +11,6 @@
#include "common.h"
#include "board.h"
/* forward declaration */
enum adc_channel;
/* Data structure to define ADC channels. */
struct adc_t
{
@@ -26,9 +23,6 @@ struct adc_t
int flag;
};
/* Initializes the module. */
int adc_init(void);
/* Read ADC channel. */
int adc_read_channel(enum adc_channel ch);

View File

@@ -59,9 +59,6 @@ struct gpio_info {
* set up. */
int gpio_pre_init(void);
/* Initializes the GPIO module. */
int gpio_init(void);
/* Gets the current value of a signal (0=low, 1=hi). */
int gpio_get_level(enum gpio_signal signal);

View File

@@ -16,7 +16,9 @@ enum hook_priority {
HOOK_PRIO_LAST = 9999 /* Lowest priority */
};
enum hook_type {
HOOK_INIT, /* System init */
HOOK_FREQ_CHANGE, /* System clock changed frequency */
};

View File

@@ -13,9 +13,6 @@
/* Flags for slave address field, in addition to the 8-bit address */
#define I2C_FLAG_BIG_ENDIAN 0x100 /* 16 byte values are MSB-first */
/* Initialize the module. */
int i2c_init(void);
/* Read a 16-bit register from the slave at 8-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);

View File

@@ -10,26 +10,22 @@
#include "common.h"
/* Manually generates an IRQ to host.
/* Manually generate an IRQ to host.
* Note that the irq_num == 0 would set the AH bit (Active High).
*/
void lpc_manual_irq(int irq_num);
/* Initializes the LPC module. */
int lpc_init(void);
/* Returns a pointer to the host command data buffer. This buffer
* must only be accessed between a notification to
* host_command_received() and a subsequent call to
* lpc_SendHostResponse(). <slot> is 0 for kernel-originated
* commands, 1 for usermode-originated commands. */
/* Return a pointer to the host command data buffer. This buffer must
* only be accessed between a notification to host_command_received()
* and a subsequent call to lpc_SendHostResponse(). <slot> is 0 for
* kernel-originated commands, 1 for usermode-originated commands. */
uint8_t *lpc_get_host_range(int slot);
/* Returns a pointer to the memory-mapped buffer. This buffer is writable at
/* Return a pointer to the memory-mapped buffer. This buffer is writable at
* any time, and the host can read it at any time. */
uint8_t *lpc_get_memmap_range(void);
/* Sends a result code to a host command. <slot> is 0 for kernel-originated
/* Send a result code to a host command. <slot> is 0 for kernel-originated
* commands, 1 for usermode-originated commands. */
void lpc_send_host_response(int slot, int result);
@@ -39,13 +35,13 @@ int lpc_keyboard_has_char(void);
/* Send a byte to host via port 0x60 and asserts IRQ if specified. */
void lpc_keyboard_put_char(uint8_t chr, int send_irq);
/* Returns non-zero if the COMx interface has received a character. */
/* Return non-zero if the COMx interface has received a character. */
int lpc_comx_has_char(void);
/* Returns the next character pending on the COMx interface. */
/* Return the next character pending on the COMx interface. */
int lpc_comx_get_char(void);
/* Puts a character to the COMx LPC interface. */
/* Put a character to the COMx LPC interface. */
void lpc_comx_put_char(int c);
/* Types of host events */

View File

@@ -17,9 +17,6 @@
#include "common.h"
/* Initialize the module. */
int onewire_init(void);
/* Reset the 1-wire bus. Returns error if presence detect fails. */
int onewire_reset(void);

View File

@@ -10,9 +10,6 @@
#include "common.h"
/* Initialize the module. */
int peci_init(void);
/* Return the current CPU temperature in degrees K, or -1 if error.
*
* Note that the PECI interface is currently a little flaky; if you get an

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
/* Copyright (c) 2012 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.
*/
@@ -11,9 +11,6 @@
#include "common.h"
#include "gpio.h"
/* Initializes the module. */
int power_button_init(void);
/* Interrupt handler for the power button and lid switch. Passed the signal
* which triggered the interrupt. */
void power_button_interrupt(enum gpio_signal signal);

View File

@@ -10,9 +10,6 @@
#include "common.h"
/* Initialize the module. */
int pwm_init(void);
/* Enable/disable the fan. This should be called by whatever function
* enables the power supply to the fan. */
int pwm_enable_fan(int enable);
@@ -35,7 +32,4 @@ int pwm_get_keyboard_backlight(void);
/* Set the keyboard backlight percentage (0=off, 100=max). */
int pwm_set_keyboard_backlight(int percent);
/* Set the power LED brightness to the specified percent (0=off, 100=max). */
int pwm_set_power_led(int percent);
#endif /* __CROS_EC_PWM_H */

View File

@@ -8,7 +8,4 @@
#ifndef __CROS_EC_SPI_H
#define __CROS_EC_SPI_H
/* Initialize the SPI module ready for use */
extern int spi_init(void);
#endif /* __CROS_EC_SPI_H */

View File

@@ -29,6 +29,4 @@ enum usb_charge_mode {
int usb_charge_set_mode(int usb_port_id, enum usb_charge_mode);
int usb_charge_init(void);
#endif /* __CROS_EC_USB_CHARGE_H */