diff options
author | Doug Anderson <dianders@chromium.org> | 2013-08-27 12:55:09 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-08-27 23:29:55 +0000 |
commit | d84c0dbbf7c5a72917a820e292ecfdfa698d0fb9 (patch) | |
tree | e5439f6eb3529b01816bb4b056e18100f322fb3e | |
parent | ce31fda8695f4db1fa91f5bb224c781cf17f91c0 (diff) | |
download | chrome-ec-d84c0dbbf7c5a72917a820e292ecfdfa698d0fb9.tar.gz |
stm32l: Add a "PRE_FREQ_CHANGE" hook to allow other code to prepare
Before this change drivers had no way of knowing that a frequency
change was coming. This could cause problems for some drivers (like
i2c) that need to make sure that a transaction isn't happening while a
frequency change is happening.
The PRE_FREQ_CHANGE archiecture is very simple here and we don't allow
any way to cancel it.
At the moment, we guarantee:
- We won't call PRE_FREQ_CHANGE with interrupts disabled, so acquiring
locks / sleeping is OK.
- We'll call the actual HOOK_FREQ_CHANGE after the PRE_FREQ_CHANGE.
PRE_FREQ_CHANGE and HOOK_FREQ_CHANGE should not use deferred function
calls.
BRANCH=pit
BUG=chrome-os-partner:22093
TEST=With all patches together:
- on AP: suspend_stress_test
- on EC: battery 10000 50
Change-Id: I2731a3e85d41e749fa571fdb74b5c9b12043cda6
Signed-off-by: Doug Anderson <dianders@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167101
-rw-r--r-- | chip/stm32/clock-stm32l.c | 3 | ||||
-rw-r--r-- | common/hooks.c | 1 | ||||
-rw-r--r-- | core/cortex-m/ec.lds.S | 4 | ||||
-rw-r--r-- | core/host/host_exe.lds | 4 | ||||
-rw-r--r-- | include/hooks.h | 9 | ||||
-rw-r--r-- | include/link_defs.h | 2 |
6 files changed, 21 insertions, 2 deletions
diff --git a/chip/stm32/clock-stm32l.c b/chip/stm32/clock-stm32l.c index 4d5b1babeb..e89c2e3ef5 100644 --- a/chip/stm32/clock-stm32l.c +++ b/chip/stm32/clock-stm32l.c @@ -59,6 +59,9 @@ static void clock_set_osc(enum clock_osc osc) if (osc == current_osc) return; + if (current_osc != OSC_INIT) + hook_notify(HOOK_PRE_FREQ_CHANGE); + switch (osc) { case OSC_HSI: /* Ensure that HSI is ON */ diff --git a/common/hooks.c b/common/hooks.c index 7dbe08b5fe..e173710d43 100644 --- a/common/hooks.c +++ b/common/hooks.c @@ -33,6 +33,7 @@ struct hook_ptrs { */ static const struct hook_ptrs hook_list[] = { {__hooks_init, __hooks_init_end}, + {__hooks_pre_freq_change, __hooks_pre_freq_change_end}, {__hooks_freq_change, __hooks_freq_change_end}, {__hooks_sysjump, __hooks_sysjump_end}, {__hooks_chipset_pre_init, __hooks_chipset_pre_init_end}, diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index 9a8f09c9ba..9ed39b6238 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -60,6 +60,10 @@ SECTIONS *(.rodata.HOOK_INIT) __hooks_init_end = .; + __hooks_pre_freq_change = .; + *(.rodata.HOOK_PRE_FREQ_CHANGE) + __hooks_pre_freq_change_end = .; + __hooks_freq_change = .; *(.rodata.HOOK_FREQ_CHANGE) __hooks_freq_change_end = .; diff --git a/core/host/host_exe.lds b/core/host/host_exe.lds index 40d1001661..f57ec0cb20 100644 --- a/core/host/host_exe.lds +++ b/core/host/host_exe.lds @@ -24,6 +24,10 @@ SECTIONS { *(.rodata.HOOK_INIT) __hooks_init_end = .; + __hooks_pre_freq_change = .; + *(.rodata.HOOK_PRE_FREQ_CHANGE) + __hooks_pre_freq_change_end = .; + __hooks_freq_change = .; *(.rodata.HOOK_FREQ_CHANGE) __hooks_freq_change_end = .; diff --git a/include/hooks.h b/include/hooks.h index 59f982eaee..3e5b45aa9e 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -41,9 +41,14 @@ enum hook_type { /* * System clock changed frequency. * - * Hook routines are called from the context which initiates the - * frequency change. + * The "pre" frequency hook is called before we change the frequency. + * There is no way to cancel. Hook routines are always called from + * a task, so it's OK to lock a mutex here. However, they may be called + * from a deferred task on some platforms so callbacks must make sure + * not to do anything that would require some other deferred task to + * run. */ + HOOK_PRE_FREQ_CHANGE, HOOK_FREQ_CHANGE, /* diff --git a/include/link_defs.h b/include/link_defs.h index a8c54d4afe..14de5be193 100644 --- a/include/link_defs.h +++ b/include/link_defs.h @@ -20,6 +20,8 @@ extern const struct console_command __cmds_end[]; /* Hooks */ extern const struct hook_data __hooks_init[]; extern const struct hook_data __hooks_init_end[]; +extern const struct hook_data __hooks_pre_freq_change[]; +extern const struct hook_data __hooks_pre_freq_change_end[]; extern const struct hook_data __hooks_freq_change[]; extern const struct hook_data __hooks_freq_change_end[]; extern const struct hook_data __hooks_sysjump[]; |