All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tero Kristo <t-kristo@ti.com>
To: linux-omap@vger.kernel.org, tony@atomide.com, paul@pwsan.com
Cc: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv4 24/35] ARM: OMAP2+: control: add syscon support for register accesses
Date: Wed, 18 Mar 2015 16:44:09 +0200	[thread overview]
Message-ID: <1426689860-17537-25-git-send-email-t-kristo@ti.com> (raw)
In-Reply-To: <1426689860-17537-1-git-send-email-t-kristo@ti.com>

Control module driver needs to support syscon for register accesses, as
the DT hierarchy for control module driver is going to be changed. All
the control module related features will be moved under control module
node, including clocks, pinctrl, and generic configuration register
access. Temporary iomap is still provided very early in the boot for
access while syscon is not yet ready.

Signed-off-by: Tero Kristo <t-kristo@ti.com>
---
 arch/arm/mach-omap2/control.c |  101 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 84 insertions(+), 17 deletions(-)

diff --git a/arch/arm/mach-omap2/control.c b/arch/arm/mach-omap2/control.c
index a9aee85..edc0f26 100644
--- a/arch/arm/mach-omap2/control.c
+++ b/arch/arm/mach-omap2/control.c
@@ -15,6 +15,8 @@
 #include <linux/kernel.h>
 #include <linux/io.h>
 #include <linux/of_address.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
 
 #include "soc.h"
 #include "iomap.h"
@@ -33,7 +35,9 @@
 #define PADCONF_SAVE_DONE		0x1
 
 static void __iomem *omap2_ctrl_base;
+static s16 omap2_ctrl_offset;
 static void __iomem *omap4_ctrl_pad_base;
+static struct regmap *omap2_ctrl_syscon;
 
 #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
 struct omap3_scratchpad {
@@ -135,7 +139,6 @@ struct omap3_control_regs {
 static struct omap3_control_regs control_context;
 #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
 
-#define OMAP_CTRL_REGADDR(reg)		(omap2_ctrl_base + (reg))
 #define OMAP4_CTRL_PAD_REGADDR(reg)	(omap4_ctrl_pad_base + (reg))
 
 void __init omap2_set_globals_control(void __iomem *ctrl,
@@ -147,32 +150,72 @@ void __init omap2_set_globals_control(void __iomem *ctrl,
 
 u8 omap_ctrl_readb(u16 offset)
 {
-	return readb_relaxed(OMAP_CTRL_REGADDR(offset));
+	u32 val;
+	u8 byte_offset = offset & 0x3;
+
+	val = omap_ctrl_readl(offset);
+
+	return (val >> (byte_offset * 8)) & 0xff;
 }
 
 u16 omap_ctrl_readw(u16 offset)
 {
-	return readw_relaxed(OMAP_CTRL_REGADDR(offset));
+	u32 val;
+	u16 byte_offset = offset & 0x2;
+
+	val = omap_ctrl_readl(offset);
+
+	return (val >> (byte_offset * 8)) & 0xffff;
 }
 
 u32 omap_ctrl_readl(u16 offset)
 {
-	return readl_relaxed(OMAP_CTRL_REGADDR(offset));
+	u32 val;
+
+	offset &= 0xfffc;
+	if (!omap2_ctrl_syscon)
+		val = readl_relaxed(omap2_ctrl_base + offset);
+	else
+		regmap_read(omap2_ctrl_syscon, omap2_ctrl_offset + offset,
+			    &val);
+
+	return val;
 }
 
 void omap_ctrl_writeb(u8 val, u16 offset)
 {
-	writeb_relaxed(val, OMAP_CTRL_REGADDR(offset));
+	u32 tmp;
+	u8 byte_offset = offset & 0x3;
+
+	tmp = omap_ctrl_readl(offset);
+
+	tmp &= 0xffffffff ^ (0xff << (byte_offset * 8));
+	tmp |= val << (byte_offset * 8);
+
+	omap_ctrl_writel(tmp, offset);
 }
 
 void omap_ctrl_writew(u16 val, u16 offset)
 {
-	writew_relaxed(val, OMAP_CTRL_REGADDR(offset));
+	u32 tmp;
+	u8 byte_offset = offset & 0x2;
+
+	tmp = omap_ctrl_readl(offset);
+
+	tmp &= 0xffffffff ^ (0xffff << (byte_offset * 8));
+	tmp |= val << (byte_offset * 8);
+
+	omap_ctrl_writel(tmp, offset);
 }
 
 void omap_ctrl_writel(u32 val, u16 offset)
 {
-	writel_relaxed(val, OMAP_CTRL_REGADDR(offset));
+	offset &= 0xfffc;
+	if (!omap2_ctrl_syscon)
+		writel_relaxed(val, omap2_ctrl_base + offset);
+	else
+		regmap_write(omap2_ctrl_syscon, omap2_ctrl_offset + offset,
+			     val);
 }
 
 /*
@@ -611,7 +654,7 @@ void __init omap3_ctrl_init(void)
 
 struct control_init_data {
 	int index;
-	void __iomem *mem;
+	s16 offset;
 };
 
 static struct control_init_data ctrl_data = {
@@ -638,17 +681,15 @@ int __init omap2_control_base_init(void)
 	struct device_node *np;
 	const struct of_device_id *match;
 	struct control_init_data *data;
-	void __iomem *mem;
 
 	for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) {
 		data = (struct control_init_data *)match->data;
 
-		mem = of_iomap(np, 0);
-		if (!mem)
+		omap2_ctrl_base = of_iomap(np, 0);
+		if (!omap2_ctrl_base)
 			return -ENOMEM;
 
-		omap2_ctrl_base = mem;
-		data->mem = mem;
+		omap2_ctrl_offset = data->offset;
 	}
 
 	return 0;
@@ -662,17 +703,43 @@ int __init omap2_control_base_init(void)
  */
 int __init omap_control_init(void)
 {
-	struct device_node *np;
+	struct device_node *np, *scm_conf;
 	const struct of_device_id *match;
 	const struct omap_prcm_init_data *data;
 	int ret;
+	struct regmap *syscon;
 
 	for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) {
 		data = match->data;
 
-		ret = omap2_clk_provider_init(np, data->index, NULL, data->mem);
-		if (ret)
-			return ret;
+		/*
+		 * Check if we have scm_conf node, if yes, use this to
+		 * access clock registers.
+		 */
+		scm_conf = of_get_child_by_name(np, "scm_conf");
+
+		if (scm_conf) {
+			syscon = syscon_node_to_regmap(scm_conf);
+
+			if (IS_ERR(syscon))
+				return PTR_ERR(syscon);
+
+			omap2_ctrl_syscon = syscon;
+
+			ret = omap2_clk_provider_init(scm_conf, data->index,
+						      syscon, NULL);
+			if (ret)
+				return ret;
+
+			iounmap(omap2_ctrl_base);
+			omap2_ctrl_base = NULL;
+		} else {
+			/* No scm_conf found, direct access */
+			ret = omap2_clk_provider_init(np, data->index, NULL,
+						      omap2_ctrl_base);
+			if (ret)
+				return ret;
+		}
 	}
 
 	return 0;
-- 
1.7.9.5


WARNING: multiple messages have this Message-ID (diff)
From: t-kristo@ti.com (Tero Kristo)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv4 24/35] ARM: OMAP2+: control: add syscon support for register accesses
Date: Wed, 18 Mar 2015 16:44:09 +0200	[thread overview]
Message-ID: <1426689860-17537-25-git-send-email-t-kristo@ti.com> (raw)
In-Reply-To: <1426689860-17537-1-git-send-email-t-kristo@ti.com>

Control module driver needs to support syscon for register accesses, as
the DT hierarchy for control module driver is going to be changed. All
the control module related features will be moved under control module
node, including clocks, pinctrl, and generic configuration register
access. Temporary iomap is still provided very early in the boot for
access while syscon is not yet ready.

Signed-off-by: Tero Kristo <t-kristo@ti.com>
---
 arch/arm/mach-omap2/control.c |  101 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 84 insertions(+), 17 deletions(-)

diff --git a/arch/arm/mach-omap2/control.c b/arch/arm/mach-omap2/control.c
index a9aee85..edc0f26 100644
--- a/arch/arm/mach-omap2/control.c
+++ b/arch/arm/mach-omap2/control.c
@@ -15,6 +15,8 @@
 #include <linux/kernel.h>
 #include <linux/io.h>
 #include <linux/of_address.h>
+#include <linux/regmap.h>
+#include <linux/mfd/syscon.h>
 
 #include "soc.h"
 #include "iomap.h"
@@ -33,7 +35,9 @@
 #define PADCONF_SAVE_DONE		0x1
 
 static void __iomem *omap2_ctrl_base;
+static s16 omap2_ctrl_offset;
 static void __iomem *omap4_ctrl_pad_base;
+static struct regmap *omap2_ctrl_syscon;
 
 #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
 struct omap3_scratchpad {
@@ -135,7 +139,6 @@ struct omap3_control_regs {
 static struct omap3_control_regs control_context;
 #endif /* CONFIG_ARCH_OMAP3 && CONFIG_PM */
 
-#define OMAP_CTRL_REGADDR(reg)		(omap2_ctrl_base + (reg))
 #define OMAP4_CTRL_PAD_REGADDR(reg)	(omap4_ctrl_pad_base + (reg))
 
 void __init omap2_set_globals_control(void __iomem *ctrl,
@@ -147,32 +150,72 @@ void __init omap2_set_globals_control(void __iomem *ctrl,
 
 u8 omap_ctrl_readb(u16 offset)
 {
-	return readb_relaxed(OMAP_CTRL_REGADDR(offset));
+	u32 val;
+	u8 byte_offset = offset & 0x3;
+
+	val = omap_ctrl_readl(offset);
+
+	return (val >> (byte_offset * 8)) & 0xff;
 }
 
 u16 omap_ctrl_readw(u16 offset)
 {
-	return readw_relaxed(OMAP_CTRL_REGADDR(offset));
+	u32 val;
+	u16 byte_offset = offset & 0x2;
+
+	val = omap_ctrl_readl(offset);
+
+	return (val >> (byte_offset * 8)) & 0xffff;
 }
 
 u32 omap_ctrl_readl(u16 offset)
 {
-	return readl_relaxed(OMAP_CTRL_REGADDR(offset));
+	u32 val;
+
+	offset &= 0xfffc;
+	if (!omap2_ctrl_syscon)
+		val = readl_relaxed(omap2_ctrl_base + offset);
+	else
+		regmap_read(omap2_ctrl_syscon, omap2_ctrl_offset + offset,
+			    &val);
+
+	return val;
 }
 
 void omap_ctrl_writeb(u8 val, u16 offset)
 {
-	writeb_relaxed(val, OMAP_CTRL_REGADDR(offset));
+	u32 tmp;
+	u8 byte_offset = offset & 0x3;
+
+	tmp = omap_ctrl_readl(offset);
+
+	tmp &= 0xffffffff ^ (0xff << (byte_offset * 8));
+	tmp |= val << (byte_offset * 8);
+
+	omap_ctrl_writel(tmp, offset);
 }
 
 void omap_ctrl_writew(u16 val, u16 offset)
 {
-	writew_relaxed(val, OMAP_CTRL_REGADDR(offset));
+	u32 tmp;
+	u8 byte_offset = offset & 0x2;
+
+	tmp = omap_ctrl_readl(offset);
+
+	tmp &= 0xffffffff ^ (0xffff << (byte_offset * 8));
+	tmp |= val << (byte_offset * 8);
+
+	omap_ctrl_writel(tmp, offset);
 }
 
 void omap_ctrl_writel(u32 val, u16 offset)
 {
-	writel_relaxed(val, OMAP_CTRL_REGADDR(offset));
+	offset &= 0xfffc;
+	if (!omap2_ctrl_syscon)
+		writel_relaxed(val, omap2_ctrl_base + offset);
+	else
+		regmap_write(omap2_ctrl_syscon, omap2_ctrl_offset + offset,
+			     val);
 }
 
 /*
@@ -611,7 +654,7 @@ void __init omap3_ctrl_init(void)
 
 struct control_init_data {
 	int index;
-	void __iomem *mem;
+	s16 offset;
 };
 
 static struct control_init_data ctrl_data = {
@@ -638,17 +681,15 @@ int __init omap2_control_base_init(void)
 	struct device_node *np;
 	const struct of_device_id *match;
 	struct control_init_data *data;
-	void __iomem *mem;
 
 	for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) {
 		data = (struct control_init_data *)match->data;
 
-		mem = of_iomap(np, 0);
-		if (!mem)
+		omap2_ctrl_base = of_iomap(np, 0);
+		if (!omap2_ctrl_base)
 			return -ENOMEM;
 
-		omap2_ctrl_base = mem;
-		data->mem = mem;
+		omap2_ctrl_offset = data->offset;
 	}
 
 	return 0;
@@ -662,17 +703,43 @@ int __init omap2_control_base_init(void)
  */
 int __init omap_control_init(void)
 {
-	struct device_node *np;
+	struct device_node *np, *scm_conf;
 	const struct of_device_id *match;
 	const struct omap_prcm_init_data *data;
 	int ret;
+	struct regmap *syscon;
 
 	for_each_matching_node_and_match(np, omap_scrm_dt_match_table, &match) {
 		data = match->data;
 
-		ret = omap2_clk_provider_init(np, data->index, NULL, data->mem);
-		if (ret)
-			return ret;
+		/*
+		 * Check if we have scm_conf node, if yes, use this to
+		 * access clock registers.
+		 */
+		scm_conf = of_get_child_by_name(np, "scm_conf");
+
+		if (scm_conf) {
+			syscon = syscon_node_to_regmap(scm_conf);
+
+			if (IS_ERR(syscon))
+				return PTR_ERR(syscon);
+
+			omap2_ctrl_syscon = syscon;
+
+			ret = omap2_clk_provider_init(scm_conf, data->index,
+						      syscon, NULL);
+			if (ret)
+				return ret;
+
+			iounmap(omap2_ctrl_base);
+			omap2_ctrl_base = NULL;
+		} else {
+			/* No scm_conf found, direct access */
+			ret = omap2_clk_provider_init(np, data->index, NULL,
+						      omap2_ctrl_base);
+			if (ret)
+				return ret;
+		}
 	}
 
 	return 0;
-- 
1.7.9.5

  parent reply	other threads:[~2015-03-18 14:45 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-18 14:43 [PATCHv4 00/35] ARM: OMAP2+: PRCM / SCM cleanups against 4.0-rc1 Tero Kristo
2015-03-18 14:43 ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 01/35] ARM: OMAP2+: PRCM: rename of_prcm_init to omap_prcm_init Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 02/35] ARM: OMAP3: PRM: invert the wkst_mask for the prm_clear_mod_irqs Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 03/35] ARM: OMAP2+: PRM: add generic API for clear_mod_irqs Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 04/35] ARM: OMAP3+: PRM: add common APIs for prm_vp_check/clear_txdone Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 05/35] ARM: OMAP4+: PRM: move omap_prm_base_init under OMAP4 PRM driver Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 06/35] ARM: OMAP4+: CM: move omap_cm_base_init under OMAP4 CM driver Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 07/35] ARM: OMAP4: PRM: move omap4xxx_prm_init earlier in init order Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 08/35] clk: ti: fix ti_clk_get_reg_addr error handling Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 09/35] Documentation: DT: document PRCM compatible strings for dm81x SoCs Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 10/35] ARM: OMAP2+: PRCM: add support for static clock memmap indices Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 11/35] ARM: OMAP2+: clock: move clock provider infrastructure to clock driver Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 12/35] ARM: OMAP2+: PRCM: split PRCM module init to their own driver files Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 13/35] ARM: OMAP2+: CM: determine CM base address from device tree Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:43 ` [PATCHv4 14/35] ARM: OMAP2+: PRM: determine PRM " Tero Kristo
2015-03-18 14:43   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 15/35] ARM: OMAP2+: control: determine control module base address from DT Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 16/35] ARM: OMAP2+: PRM: move SoC specific init calls within a generic API Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 17/35] ARM: OMAP4+: PRM: determine prm_device_inst based on DT compatibility Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 18/35] ARM: OMAP2+: CM: move SoC specific init calls within a generic API Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 19/35] ARM: OMAP4+: PRM: setup prm_features from the PRM init time flags Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 20/35] ARM: OMAP4+: PRM: get rid of cpu_is_omap44xx calls from interrupt init Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 21/35] ARM: OMAP2+: clock: add low-level support for regmap Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 22/35] ARM: OMAP2+: control: remove API for getting control module base address Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 23/35] ARM: OMAP2+: id: cache omap_type value Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 18:24   ` Sergei Shtylyov
2015-03-18 18:24     ` Sergei Shtylyov
2015-03-19  7:23     ` Tero Kristo
2015-03-19  7:23       ` Tero Kristo
2015-03-18 14:44 ` Tero Kristo [this message]
2015-03-18 14:44   ` [PATCHv4 24/35] ARM: OMAP2+: control: add syscon support for register accesses Tero Kristo
2015-03-18 14:44 ` [PATCHv4 25/35] ARM: dts: omap24xx: merge control module features under scrm node Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 26/35] ARM: dts: omap3: " Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 27/35] ARM: dts: am33xx: " Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 28/35] ARM: dts: am43xx-epos-evm: fix pinmux node layout Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 29/35] ARM: dts: am4372: merge control module features under scrm node Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 30/35] ARM: dts: omap4: add system control module node Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 21:30   ` Tony Lindgren
2015-03-18 21:30     ` Tony Lindgren
2015-03-19 20:25     ` Tony Lindgren
2015-03-19 20:25       ` Tony Lindgren
2015-03-20  6:40       ` Tero Kristo
2015-03-20  6:40         ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 31/35] ARM: OMAP4: display: convert display to use syscon for dsi muxing Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 32/35] ARM: OMAP4+: control: remove support for legacy pad read/write Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 33/35] ARM: dts: omap5: add system control module node Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 34/35] ARM: dts: dra7: " Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 14:44 ` [PATCHv4 35/35] ARM: OMAP4+: control: add support for initializing control module via DT Tero Kristo
2015-03-18 14:44   ` Tero Kristo
2015-03-18 22:07 ` [PATCHv4 00/35] ARM: OMAP2+: PRCM / SCM cleanups against 4.0-rc1 Tony Lindgren
2015-03-18 22:07   ` Tony Lindgren
2015-03-19  7:48   ` Tero Kristo
2015-03-19  7:48     ` Tero Kristo
2015-03-19 16:10     ` Tony Lindgren
2015-03-19 16:10       ` Tony Lindgren
2015-03-19  0:00 ` Sakari Ailus
2015-03-19  0:00   ` Sakari Ailus
2015-03-19  8:05   ` Tero Kristo
2015-03-19  8:05     ` Tero Kristo

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=1426689860-17537-25-git-send-email-t-kristo@ti.com \
    --to=t-kristo@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=paul@pwsan.com \
    --cc=tony@atomide.com \
    /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.