All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rickard Andersson <rickard.andersson@stericsson.com>
To: rjw@sisk.pl, linux-pm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Cc: hongbo.zhang@linaro.org, ulf.hansson@linaro.org,
	khilman@linaro.org, linus.walleij@stericsson.com,
	daniel.lezcano@linaro.org, rickard.andersson@stericsson.com
Subject: [PATCH V2 06/12] clk: ux500: Add PRCC power management
Date: Thu, 28 Mar 2013 17:11:32 +0100	[thread overview]
Message-ID: <1364487098-10319-7-git-send-email-rickard.andersson@stericsson.com> (raw)
In-Reply-To: <1364487098-10319-1-git-send-email-rickard.andersson@stericsson.com>

When reaching a sleep state where the APE power domain
is being turned off the context of the PRCC block needs
to saved. When the power domain is turned on again the
context is restored in order for the PRCC clocks to
function correctly.

Signed-off-by: Rickard Andersson <rickard.andersson@stericsson.com>
---
 drivers/clk/ux500/clk-prcc.c  | 71 ++++++++++++++++++++++++++++++++++++-
 drivers/clk/ux500/clk.h       |  5 +++
 drivers/clk/ux500/u8500_clk.c | 82 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 157 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/ux500/clk-prcc.c b/drivers/clk/ux500/clk-prcc.c
index 7eee7f7..01739f7 100644
--- a/drivers/clk/ux500/clk-prcc.c
+++ b/drivers/clk/ux500/clk-prcc.c
@@ -3,7 +3,8 @@
  *
  * Copyright (C) 2012 ST-Ericsson SA
  * Author: Ulf Hansson <ulf.hansson@linaro.org>
- *
+ *	   Rickard Andersson <rickard.andersson@stericsson.com>
+ *	   Jonas Aaberg <jonas.aberg@stericsson.com>
  * License terms: GNU General Public License (GPL) version 2
  */
 
@@ -13,10 +14,13 @@
 #include <linux/io.h>
 #include <linux/err.h>
 #include <linux/types.h>
+#include <linux/platform_device.h>
 #include <mach/hardware.h>
 
 #include "clk.h"
 
+#define UX500_NR_PRCC_BANKS 5
+
 #define PRCC_PCKEN			0x000
 #define PRCC_PCKDIS			0x004
 #define PRCC_KCKEN			0x008
@@ -33,6 +37,12 @@ struct clk_prcc {
 	int is_enabled;
 };
 
+static struct {
+	void __iomem *base;
+	u32 bus_clk;
+	u32 kern_clk;
+} context_prcc[UX500_NR_PRCC_BANKS];
+
 /* PRCC clock operations. */
 
 static int clk_prcc_pclk_enable(struct clk_hw *hw)
@@ -162,3 +172,62 @@ struct clk *clk_reg_prcc_kclk(const char *name,
 	return clk_reg_prcc(name, parent_name, phy_base, cg_sel, flags,
 			&clk_prcc_kclk_ops);
 }
+
+void clk_prcc_save_context(void)
+{
+	int i;
+
+	for (i = 0; i < UX500_NR_PRCC_BANKS; i++) {
+		context_prcc[i].bus_clk =
+			readl(context_prcc[i].base + PRCC_PCKSR);
+		context_prcc[i].kern_clk =
+			readl(context_prcc[i].base + PRCC_KCKSR);
+	}
+}
+
+void clk_prcc_restore_context(void)
+{
+	int i;
+
+	for (i = 0; i < UX500_NR_PRCC_BANKS; i++) {
+		writel(~context_prcc[i].bus_clk,
+		       context_prcc[i].base + PRCC_PCKDIS);
+		writel(~context_prcc[i].kern_clk,
+		       context_prcc[i].base + PRCC_KCKDIS);
+
+		writel(context_prcc[i].bus_clk,
+		       context_prcc[i].base + PRCC_PCKEN);
+		writel(context_prcc[i].kern_clk,
+		       context_prcc[i].base + PRCC_KCKEN);
+	}
+}
+
+int __init clk_prcc_init(struct platform_device *pdev)
+{
+	int i;
+	struct resource *res;
+	int ret = 0;
+
+	for (i = 0; i < UX500_NR_PRCC_BANKS; i++) {
+		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
+		if (!res) {
+			ret = -EINVAL;
+			goto err_iounmap;
+		}
+
+		context_prcc[i].base = ioremap(res->start, resource_size(res));
+		if (!context_prcc[i].base) {
+			ret = -ENOMEM;
+			goto err_iounmap;
+		}
+	}
+
+	return ret;
+
+ err_iounmap:
+	for (i = 0; i < UX500_NR_PRCC_BANKS; i++) {
+		if (context_prcc[i].base)
+			iounmap(context_prcc[i].base);
+	}
+	return ret;
+}
diff --git a/drivers/clk/ux500/clk.h b/drivers/clk/ux500/clk.h
index c3e4491..3394fb8 100644
--- a/drivers/clk/ux500/clk.h
+++ b/drivers/clk/ux500/clk.h
@@ -11,6 +11,7 @@
 #define __UX500_CLK_H
 
 #include <linux/clk.h>
+#include <linux/platform_device.h>
 
 struct clk *clk_reg_prcc_pclk(const char *name,
 			      const char *parent_name,
@@ -57,4 +58,8 @@ struct clk *clk_reg_prcmu_opp_volt_scalable(const char *name,
 					    unsigned long rate,
 					    unsigned long flags);
 
+void clk_prcc_save_context(void);
+void clk_prcc_restore_context(void);
+int __init clk_prcc_init(struct platform_device *pdev);
+
 #endif /* __UX500_CLK_H */
diff --git a/drivers/clk/ux500/u8500_clk.c b/drivers/clk/ux500/u8500_clk.c
index 6b889a0..63ed580 100644
--- a/drivers/clk/ux500/u8500_clk.c
+++ b/drivers/clk/ux500/u8500_clk.c
@@ -12,9 +12,19 @@
 #include <linux/clk-provider.h>
 #include <linux/mfd/dbx500-prcmu.h>
 #include <linux/platform_data/clk-ux500.h>
+#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
 #include <mach/db8500-regs.h>
 #include "clk.h"
 
+/*
+ * Number of PRCC parent clocks that needs to be
+ * enabled when saving/restoring PRCC context.
+ */
+#define NR_PRCC_PARENT_CLOCKS 5
+
+struct clk *prcc_context_parent[NR_PRCC_PARENT_CLOCKS];
+
 void u8500_clk_init(void)
 {
 	struct prcmu_fw_version *fw_version;
@@ -522,3 +532,75 @@ void u8500_clk_init(void)
 			U8500_CLKRST6_BASE, BIT(0), CLK_SET_RATE_GATE);
 	clk_register_clkdev(clk, NULL, "rng");
 }
+
+static void prcc_parents_enable(bool enable)
+{
+	int i;
+
+	for (i = 0; i < NR_PRCC_PARENT_CLOCKS; i++) {
+		if (enable)
+			clk_enable(prcc_context_parent[i]);
+		else
+			clk_disable(prcc_context_parent[i]);
+	}
+}
+
+static int prcc_context_call(struct notifier_block *this,
+				 unsigned long event, void *data)
+{
+	bool power_on = (bool)event;
+
+	prcc_parents_enable(true);
+
+	if (power_on)
+		clk_prcc_restore_context();
+	else
+		clk_prcc_save_context();
+
+	prcc_parents_enable(false);
+
+	return 0;
+}
+
+static struct notifier_block prcc_context_notifier = {
+	.notifier_call = prcc_context_call,
+};
+
+static struct platform_driver u8500_clk_plat_driver = {
+	.driver = {
+		.name = "u8500-clk",
+	},
+};
+
+static int __init u8500_clk_probe(struct platform_device *pdev)
+{
+	int ret;
+	int i;
+
+	ret = clk_prcc_init(pdev);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < NR_PRCC_PARENT_CLOCKS; i++) {
+		const int clusters[] = {1, 2, 3, 5, 6};
+		char clkname[10];
+
+		snprintf(clkname, sizeof(clkname), "PERIPH%d", clusters[i]);
+
+		prcc_context_parent[i] = clk_get_sys(clkname, NULL);
+		BUG_ON(IS_ERR(prcc_context_parent[i]));
+		clk_prepare(prcc_context_parent[i]);
+	}
+
+	ret = pm_genpd_register_on_off_notifier(&pdev->dev,
+						&prcc_context_notifier);
+	return ret;
+}
+
+static int __init u8500_clk_arch_init(void)
+{
+	return platform_driver_probe(&u8500_clk_plat_driver,
+				     u8500_clk_probe);
+}
+
+arch_initcall(u8500_clk_arch_init);
-- 
1.8.2

WARNING: multiple messages have this Message-ID (diff)
From: rickard.andersson@stericsson.com (Rickard Andersson)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH V2 06/12] clk: ux500: Add PRCC power management
Date: Thu, 28 Mar 2013 17:11:32 +0100	[thread overview]
Message-ID: <1364487098-10319-7-git-send-email-rickard.andersson@stericsson.com> (raw)
In-Reply-To: <1364487098-10319-1-git-send-email-rickard.andersson@stericsson.com>

When reaching a sleep state where the APE power domain
is being turned off the context of the PRCC block needs
to saved. When the power domain is turned on again the
context is restored in order for the PRCC clocks to
function correctly.

Signed-off-by: Rickard Andersson <rickard.andersson@stericsson.com>
---
 drivers/clk/ux500/clk-prcc.c  | 71 ++++++++++++++++++++++++++++++++++++-
 drivers/clk/ux500/clk.h       |  5 +++
 drivers/clk/ux500/u8500_clk.c | 82 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 157 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/ux500/clk-prcc.c b/drivers/clk/ux500/clk-prcc.c
index 7eee7f7..01739f7 100644
--- a/drivers/clk/ux500/clk-prcc.c
+++ b/drivers/clk/ux500/clk-prcc.c
@@ -3,7 +3,8 @@
  *
  * Copyright (C) 2012 ST-Ericsson SA
  * Author: Ulf Hansson <ulf.hansson@linaro.org>
- *
+ *	   Rickard Andersson <rickard.andersson@stericsson.com>
+ *	   Jonas Aaberg <jonas.aberg@stericsson.com>
  * License terms: GNU General Public License (GPL) version 2
  */
 
@@ -13,10 +14,13 @@
 #include <linux/io.h>
 #include <linux/err.h>
 #include <linux/types.h>
+#include <linux/platform_device.h>
 #include <mach/hardware.h>
 
 #include "clk.h"
 
+#define UX500_NR_PRCC_BANKS 5
+
 #define PRCC_PCKEN			0x000
 #define PRCC_PCKDIS			0x004
 #define PRCC_KCKEN			0x008
@@ -33,6 +37,12 @@ struct clk_prcc {
 	int is_enabled;
 };
 
+static struct {
+	void __iomem *base;
+	u32 bus_clk;
+	u32 kern_clk;
+} context_prcc[UX500_NR_PRCC_BANKS];
+
 /* PRCC clock operations. */
 
 static int clk_prcc_pclk_enable(struct clk_hw *hw)
@@ -162,3 +172,62 @@ struct clk *clk_reg_prcc_kclk(const char *name,
 	return clk_reg_prcc(name, parent_name, phy_base, cg_sel, flags,
 			&clk_prcc_kclk_ops);
 }
+
+void clk_prcc_save_context(void)
+{
+	int i;
+
+	for (i = 0; i < UX500_NR_PRCC_BANKS; i++) {
+		context_prcc[i].bus_clk =
+			readl(context_prcc[i].base + PRCC_PCKSR);
+		context_prcc[i].kern_clk =
+			readl(context_prcc[i].base + PRCC_KCKSR);
+	}
+}
+
+void clk_prcc_restore_context(void)
+{
+	int i;
+
+	for (i = 0; i < UX500_NR_PRCC_BANKS; i++) {
+		writel(~context_prcc[i].bus_clk,
+		       context_prcc[i].base + PRCC_PCKDIS);
+		writel(~context_prcc[i].kern_clk,
+		       context_prcc[i].base + PRCC_KCKDIS);
+
+		writel(context_prcc[i].bus_clk,
+		       context_prcc[i].base + PRCC_PCKEN);
+		writel(context_prcc[i].kern_clk,
+		       context_prcc[i].base + PRCC_KCKEN);
+	}
+}
+
+int __init clk_prcc_init(struct platform_device *pdev)
+{
+	int i;
+	struct resource *res;
+	int ret = 0;
+
+	for (i = 0; i < UX500_NR_PRCC_BANKS; i++) {
+		res = platform_get_resource(pdev, IORESOURCE_MEM, i);
+		if (!res) {
+			ret = -EINVAL;
+			goto err_iounmap;
+		}
+
+		context_prcc[i].base = ioremap(res->start, resource_size(res));
+		if (!context_prcc[i].base) {
+			ret = -ENOMEM;
+			goto err_iounmap;
+		}
+	}
+
+	return ret;
+
+ err_iounmap:
+	for (i = 0; i < UX500_NR_PRCC_BANKS; i++) {
+		if (context_prcc[i].base)
+			iounmap(context_prcc[i].base);
+	}
+	return ret;
+}
diff --git a/drivers/clk/ux500/clk.h b/drivers/clk/ux500/clk.h
index c3e4491..3394fb8 100644
--- a/drivers/clk/ux500/clk.h
+++ b/drivers/clk/ux500/clk.h
@@ -11,6 +11,7 @@
 #define __UX500_CLK_H
 
 #include <linux/clk.h>
+#include <linux/platform_device.h>
 
 struct clk *clk_reg_prcc_pclk(const char *name,
 			      const char *parent_name,
@@ -57,4 +58,8 @@ struct clk *clk_reg_prcmu_opp_volt_scalable(const char *name,
 					    unsigned long rate,
 					    unsigned long flags);
 
+void clk_prcc_save_context(void);
+void clk_prcc_restore_context(void);
+int __init clk_prcc_init(struct platform_device *pdev);
+
 #endif /* __UX500_CLK_H */
diff --git a/drivers/clk/ux500/u8500_clk.c b/drivers/clk/ux500/u8500_clk.c
index 6b889a0..63ed580 100644
--- a/drivers/clk/ux500/u8500_clk.c
+++ b/drivers/clk/ux500/u8500_clk.c
@@ -12,9 +12,19 @@
 #include <linux/clk-provider.h>
 #include <linux/mfd/dbx500-prcmu.h>
 #include <linux/platform_data/clk-ux500.h>
+#include <linux/platform_device.h>
+#include <linux/pm_domain.h>
 #include <mach/db8500-regs.h>
 #include "clk.h"
 
+/*
+ * Number of PRCC parent clocks that needs to be
+ * enabled when saving/restoring PRCC context.
+ */
+#define NR_PRCC_PARENT_CLOCKS 5
+
+struct clk *prcc_context_parent[NR_PRCC_PARENT_CLOCKS];
+
 void u8500_clk_init(void)
 {
 	struct prcmu_fw_version *fw_version;
@@ -522,3 +532,75 @@ void u8500_clk_init(void)
 			U8500_CLKRST6_BASE, BIT(0), CLK_SET_RATE_GATE);
 	clk_register_clkdev(clk, NULL, "rng");
 }
+
+static void prcc_parents_enable(bool enable)
+{
+	int i;
+
+	for (i = 0; i < NR_PRCC_PARENT_CLOCKS; i++) {
+		if (enable)
+			clk_enable(prcc_context_parent[i]);
+		else
+			clk_disable(prcc_context_parent[i]);
+	}
+}
+
+static int prcc_context_call(struct notifier_block *this,
+				 unsigned long event, void *data)
+{
+	bool power_on = (bool)event;
+
+	prcc_parents_enable(true);
+
+	if (power_on)
+		clk_prcc_restore_context();
+	else
+		clk_prcc_save_context();
+
+	prcc_parents_enable(false);
+
+	return 0;
+}
+
+static struct notifier_block prcc_context_notifier = {
+	.notifier_call = prcc_context_call,
+};
+
+static struct platform_driver u8500_clk_plat_driver = {
+	.driver = {
+		.name = "u8500-clk",
+	},
+};
+
+static int __init u8500_clk_probe(struct platform_device *pdev)
+{
+	int ret;
+	int i;
+
+	ret = clk_prcc_init(pdev);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < NR_PRCC_PARENT_CLOCKS; i++) {
+		const int clusters[] = {1, 2, 3, 5, 6};
+		char clkname[10];
+
+		snprintf(clkname, sizeof(clkname), "PERIPH%d", clusters[i]);
+
+		prcc_context_parent[i] = clk_get_sys(clkname, NULL);
+		BUG_ON(IS_ERR(prcc_context_parent[i]));
+		clk_prepare(prcc_context_parent[i]);
+	}
+
+	ret = pm_genpd_register_on_off_notifier(&pdev->dev,
+						&prcc_context_notifier);
+	return ret;
+}
+
+static int __init u8500_clk_arch_init(void)
+{
+	return platform_driver_probe(&u8500_clk_plat_driver,
+				     u8500_clk_probe);
+}
+
+arch_initcall(u8500_clk_arch_init);
-- 
1.8.2

  parent reply	other threads:[~2013-03-28 16:11 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-28 16:11 [PATCH V2 00/12] ux500 suspend-resume Rickard Andersson
2013-03-28 16:11 ` Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 01/12] mfd: db8500: Add IO force function Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 02/12] ARM: ux500: Add platform suspend ops Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 03/12] PM / Domains: Add on-off notifiers Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson
2013-03-30 23:17   ` Rafael J. Wysocki
2013-03-30 23:17     ` Rafael J. Wysocki
2013-04-23 12:26     ` Rickard Andersson
2013-04-23 12:26       ` Rickard Andersson
2013-04-29 12:14       ` Linus Walleij
2013-04-29 12:14         ` Linus Walleij
2013-04-30 12:55         ` Rickard Andersson
2013-04-30 12:55           ` Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 04/12] PM / Domains: Lookup domain by name Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 05/12] ARM: ux500: Create APE generic power domain Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson
2013-03-28 16:11 ` Rickard Andersson [this message]
2013-03-28 16:11   ` [PATCH V2 06/12] clk: ux500: Add PRCC power management Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 07/12] ARM: ux500: Create u8500-clk device Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 08/12] ARM: ux500: Add ApSleep state to suspend Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 09/12] drivers: bus: ux500: Add ICN driver Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 10/12] ARM: ux500: Create ICN device Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 11/12] misc: ux500: Add TPIU driver Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson
2013-03-28 16:11 ` [PATCH V2 12/12] ARM: ux500: Create TPIU device Rickard Andersson
2013-03-28 16:11   ` Rickard Andersson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1364487098-10319-7-git-send-email-rickard.andersson@stericsson.com \
    --to=rickard.andersson@stericsson.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=hongbo.zhang@linaro.org \
    --cc=khilman@linaro.org \
    --cc=linus.walleij@stericsson.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@sisk.pl \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.