summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-04-18 13:03:38 -0700
committerRandall Spangler <rspangler@chromium.org>2012-04-19 08:39:41 -0700
commit70f3fcaf8648230a5cd27a9da151494d6df3016f (patch)
treec67e9ff911914f7eaef7af6c9e95874cf8d0cce2 /include
parent6ecbb86b6392fa0b11514903a9fb3d3a3b704391 (diff)
downloadchrome-ec-70f3fcaf8648230a5cd27a9da151494d6df3016f.tar.gz
Add hooks module so modules can be notified of system-level events.
This will be used for sleep/wake/sysjump/etc. For now it's just wired up to clock frequency changing. Signed-off-by: Randall Spangler <rspangler@chromium.org> BUG=none TEST=manual: use nopll command, should still work Change-Id: Iedcea5830bc18eacfd955c29b8f793aba8905dd8
Diffstat (limited to 'include')
-rw-r--r--include/hooks.h48
-rw-r--r--include/hwtimer.h9
-rw-r--r--include/i2c.h25
-rw-r--r--include/peci.h11
-rw-r--r--include/watchdog.h3
5 files changed, 63 insertions, 33 deletions
diff --git a/include/hooks.h b/include/hooks.h
new file mode 100644
index 0000000000..3d3a834e25
--- /dev/null
+++ b/include/hooks.h
@@ -0,0 +1,48 @@
+/* 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.
+ */
+
+/* System hooks for Chrome EC */
+
+#ifndef __CROS_EC_HOOKS_H
+#define __CROS_EC_HOOKS_H
+
+#include "common.h"
+
+enum hook_priority {
+ HOOK_PRIO_FIRST = 1, /* Highest priority */
+ HOOK_PRIO_DEFAULT = 5000, /* Default priority */
+ HOOK_PRIO_LAST = 9999 /* Lowest priority */
+};
+
+enum hook_type {
+ HOOK_FREQ_CHANGE, /* System clock changed frequency */
+};
+
+
+struct hook_data {
+ /* Hook processing routine; returns EC error code. */
+ int (*routine)(void);
+ /* Priority; low numbers = higher priority. */
+ int priority;
+};
+
+
+/* Call all the hook routines of a specified type. If stop_on_error, stops on
+ * the first non-EC_SUCCESS return code. Returns the first non-EC_SUCCESS
+ * return code, if any, or EC_SUCCESS if all hooks returned EC_SUCCESS. */
+int hook_notify(enum hook_type type, int stop_on_error);
+
+
+/* Register a hook routine. <hooktype> should be one of enum hook_type.
+ * <routine> should be int routine(void), and should return an error code or
+ * EC_SUCCESS if no error. <priority> should be between HOOK_PRIO_FIRST and
+ * HOOK_PRIO_LAST, and should be HOOK_PRIO_DEFAULT unless there's a compelling
+ * reason to care about the order in which hooks are called. */
+#define DECLARE_HOOK(hooktype, routine, priority) \
+ const struct hook_data __hook_##hooktype##_##routine \
+ __attribute__((section(".rodata." #hooktype))) \
+ = {routine, priority}
+
+#endif /* __CROS_EC_HOOKS_H */
diff --git a/include/hwtimer.h b/include/hwtimer.h
index 5fee466b7c..ae0c634163 100644
--- a/include/hwtimer.h
+++ b/include/hwtimer.h
@@ -5,8 +5,8 @@
/* Hardware timer driver API */
-#ifndef __EC_HWTIMER_H
-#define __EC_HWTIMER_H
+#ifndef __CROS_EC_HWTIMER_H
+#define __CROS_EC_HWTIMER_H
/**
* Programs when the next timer should fire an interrupt.
@@ -30,9 +30,6 @@ uint32_t __hw_clock_source_read(void);
*/
int __hw_clock_source_init(void);
-/* Notifies the module the system clock frequency has changed to <freq>. */
-void hwtimer_clock_changed(int freq);
-
/**
* Searches the next deadline and program it in the timer hardware.
*
@@ -43,4 +40,4 @@ void hwtimer_clock_changed(int freq);
*/
void process_timers(int overflow);
-#endif /* __EC_HWTIMER_H */
+#endif /* __CROS_EC_HWTIMER_H */
diff --git a/include/i2c.h b/include/i2c.h
index 22ab18adcf..7543d8cb25 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -13,30 +13,23 @@
/* Flags for slave address field, in addition to the 8-bit address */
#define I2C_FLAG_BIG_ENDIAN 0x100 /* 16 byte values are MSB-first */
-/* Initializes the module. */
+/* Initialize the module. */
int i2c_init(void);
-/* Notifies the module the system clock frequency has changed to <freq>. */
-void i2c_clock_changed(int freq);
-
-/* Reads 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. */
+/* 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);
-/* Writes a 16-bit register to the slave at 8-bit slave address
- * <slaveaddr>, at the specified 8-bit <offset> in the slave's address
- * space. */
+/* Write a 16-bit register to the slave at 8-bit slave address <slaveaddr>, at
+ * the specified 8-bit <offset> in the slave's address space. */
int i2c_write16(int port, int slave_addr, int offset, int data);
-/* Reads an 8-bit register from the slave at 8-bit slave address
- * <slaveaddr>, at the specified 8-bit <offset> in the slave's address
- * space. */
+/* Read an 8-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_read8(int port, int slave_addr, int offset, int* data);
-/* Writes an 8-bit register to the slave at 8-bit slave address
- * <slaveaddr>, at the specified 8-bit <offset> in the slave's address
- * space. */
+/* Write an 8-bit register to the slave at 8-bit slave address <slaveaddr>, at
+ * the specified 8-bit <offset> in the slave's address space. */
int i2c_write8(int port, int slave_addr, int offset, int data);
/* Read ascii string using smbus read block protocol.
diff --git a/include/peci.h b/include/peci.h
index 7a98a24991..1ad0d92bad 100644
--- a/include/peci.h
+++ b/include/peci.h
@@ -10,21 +10,16 @@
#include "common.h"
-struct temp_sensor_t;
-
-/* Initializes the module. */
+/* Initialize the module. */
int peci_init(void);
-/* Notifies the module the system clock frequency has changed to <freq>. */
-void peci_clock_changed(int freq);
-
-/* Returns the current CPU temperature in degrees K, or -1 if error.
+/* 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
* error, retry a bit later. */
int peci_get_cpu_temp(void);
-/* Reads the CPU temperature sensor via PECI. This interface is for the
+/* Read the CPU temperature sensor via PECI. This interface is for the
* temperature sensor module. Returns the temperature in degrees K, or -1 if
* error. */
int peci_temp_sensor_get_val(int idx);
diff --git a/include/watchdog.h b/include/watchdog.h
index 569352bc6a..68ac7b917e 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -15,7 +15,4 @@ int watchdog_init(int period_ms);
/* Reload the watchdog counter */
void watchdog_reload(void);
-/* Notifies the module the system clock frequency has changed to <freq>. */
-void watchdog_clock_changed(int freq);
-
#endif /* __CROS_EC_WATCHDOG_H */