From: Dirk Brandewie <dirk.j.brandewie(a)intel.com>
Suspend and resume are generic functions that each device should
support. Move the suspend/resume API functions to the top level
device structure. This change allows for the application to call
suspend/resume without needing to know device type.
Change-Id: I2fa7b13f75faeb83106ced83cd07ddbae4c915d6
Signed-off-by: Dirk Brandewie <dirk.j.brandewie(a)intel.com>
---
include/device.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/include/device.h b/include/device.h
index e2e657d..64b1e6f 100644
--- a/include/device.h
+++ b/include/device.h
@@ -147,6 +147,70 @@ extern "C" {
*/
#define DEVICE_DECLARE(name) extern struct device DEVICE_NAME_GET(name)
+/**
+ * @def DEVICE_INIT_PM
+ *
+ * @brief create device object and set it up for boot time initialization
+ *
+ * @details This macro defines a device object that is automatically
+ * configured by the kernel during system initialization.
+ *
+ * @param dev_name Device name.
+ *
+ * @param drv_name The name this instance of the driver exposes to
+ * the system.
+ *
+ * @param init_fn Address to the init function of the driver.
+ *
+ * @param device_fn Address of device_ops structure for device.
+ *
+ * @param data Pointer to the device's configuration data.
+ *
+ * @param cfg_info The address to the structure containing the
+ * configuration information for this instance of the driver.
+ *
+ * @param level The initialization level at which configuration occurs.
+ * Must be one of the following symbols, which are listed in the order
+ * they are performed by the kernel:
+ *
+ * PRIMARY: Used for devices that have no dependencies, such as those
+ * that rely solely on hardware present in the processor/SOC. These devices
+ * cannot use any kernel services during configuration, since they are not
+ * yet available.
+ *
+ * SECONDARY: Used for devices that rely on the initialization of devices
+ * initialized as part of the PRIMARY level. These devices cannot use any
+ * kernel services during configuration, since they are not yet available.
+ *
+ * NANOKERNEL: Used for devices that require nanokernel services during
+ * configuration.
+ *
+ * MICROKERNEL: Used for devices that require microkernel services during
+ * configuration.
+ *
+ * APPLICATION: Used for application components (i.e. non-kernel components)
+ * that need automatic configuration. These devices can use all services
+ * provided by the kernel during configuration.
+ *
+ * @param prio The initialization priority of the device, relative to
+ * other devices of the same initialization level. Specified as an integer
+ * value in the range 0 to 99; lower values indicate earlier initialization.
+ * Must be a decimal integer literal without leading zeroes or sign (e.g. 32),
+ * or an equivalent symbolic name (e.g. #define MY_INIT_PRIO 32); symbolic
+ * expressions are *not* permitted
+ * (e.g. CONFIG_KERNEL_INIT_PRIORITY_DEFAULT + 5).
+ */
+
+#define DECLARE_INIT_PM(cfg_name, drv_name, init_fn, \
+ device_fn, config)\
+ static struct device_config config_##cfg_name __used \
+ __attribute__((__section__(".devconfig.init"))) = { \
+ .name = drv_name, .init = (init_fn), \
+ .dev_ops = device_fn, \
+ .config_info = (config) \
+ }
+
+
/* Common Error Codes devices can provide */
#define DEV_OK 0 /* No error */
#define DEV_FAIL 1 /* General operation failure */
@@ -160,6 +224,15 @@ extern "C" {
struct device;
/**
+ * @brief Specify the operations common across all devices
+ * @param init init function for the driver
+ */
+struct device_ops {
+ int (*suspend)(struct device *device);
+ int (*resume)(struct device *device);
+};
+
+/**
* @brief Static device information (In ROM) Per driver instance
* @param name name of the device
* @param init init function for the driver
@@ -168,6 +241,7 @@ struct device;
struct device_config {
char *name;
int (*init)(struct device *device);
+ struct device_ops *dev_ops;
void *config_info;
};
--
2.4.3