From 7d2249e98d304181b3deaa806ee475873e822328 Mon Sep 17 00:00:00 2001
From: Francesco Virlinzi <francesco.virlinzi@st.com>
Date: Tue, 10 Mar 2009 10:23:23 +0100
Subject: [PATCH] sh_clk: Added clks sysdevice to support hibernation
This patch adds the clk_sysdev device to restore the right clocks
setting after a resume from hibernation.
Signed-off-by: Francesco Virlinzi <francesco.virlinzi@st.com>
---
arch/sh/kernel/cpu/clock.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 62 insertions(+), 0 deletions(-)
@@ -20,6 +20,8 @@
#include <linux/mutex.h>
#include <linux/list.h>
#include <linux/kref.h>
+#include <linux/kobject.h>
+#include <linux/sysdev.h>
#include <linux/seq_file.h>
#include <linux/err.h>
#include <linux/platform_device.h>
@@ -382,6 +384,56 @@ static int show_clocks(char *buf, char **start, off_t off,
return p - buf;
}
+static int clks_suspend(struct sys_device *dev, pm_message_t state)
+{
+ static pm_message_t prev_state;
+ struct clk *clkp;
+
+ switch (state.event) {
+ case PM_EVENT_ON:
+ /* Resumeing from hibernation */
+ if (prev_state.event == PM_EVENT_FREEZE) {
+ list_for_each_entry(clkp, &clock_list, node)
+ if (likely(clkp->ops)) {
+ if (likely(clkp->ops->set_parent))
+ clkp->ops->set_parent(clkp,
+ clkp->parent);
+ if (likely(clkp->ops->set_rate))
+ clkp->ops->set_rate(clkp,
+ clkp->rate, NO_CHANGE);
+ if (likely(clkp->ops->recalc))
+ clkp->ops->recalc(clkp);
+ }
+ }
+ break;
+ case PM_EVENT_FREEZE:
+ break;
+ case PM_EVENT_SUSPEND:
+ break;
+ }
+
+ prev_state = state;
+ return 0;
+}
+
+static int clks_resume(struct sys_device *dev)
+{
+ return clks_suspend(dev, PMSG_ON);
+}
+
+static struct sysdev_class clks_class = {
+ .kset.kobj.name = "clks",
+};
+
+static struct sysdev_driver clks_driver = {
+ .suspend = clks_suspend,
+ .resume = clks_resume,
+};
+
+static struct sys_device clks_dev = {
+ .cls = &clks_class,
+};
+
int __init clk_init(void)
{
int i, ret = 0;
@@ -404,6 +456,16 @@ int __init clk_init(void)
return ret;
}
+static int __init clk_sysdev_init(void)
+{
+
+ sysdev_class_register(&clks_class);
+ sysdev_driver_register(&clks_class, &clks_driver);
+ sysdev_register(&clks_dev);
+ return 0;
+}
+subsys_initcall(clk_sysdev_init);
+
static int __init clk_proc_init(void)
{
struct proc_dir_entry *p;
--
1.5.6.6