mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/3] ARM: i.MX: adopt cpu_is_* for multiple SoCs
Date: Sun, 23 Jun 2013 23:40:51 +0200	[thread overview]
Message-ID: <1372023651-13725-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1372023651-13725-1-git-send-email-s.hauer@pengutronix.de>

This makes cpu_is_* functions when necessary for upcoming multisoc
support. When only one SoC type is compiled in cpu_is_* still expand
to static values.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/imx.c                  |  36 ++++++++++-
 arch/arm/mach-imx/include/mach/generic.h | 102 +++++++++++++++++++++++++------
 2 files changed, 119 insertions(+), 19 deletions(-)

diff --git a/arch/arm/mach-imx/imx.c b/arch/arm/mach-imx/imx.c
index d6e30a8..6e80bd6 100644
--- a/arch/arm/mach-imx/imx.c
+++ b/arch/arm/mach-imx/imx.c
@@ -32,9 +32,43 @@ void imx_set_silicon_revision(const char *soc, int revision)
 			revision & 0xf);
 }
 
+unsigned int __imx_cpu_type;
+
+static int imx_soc_from_dt(void)
+{
+	if (of_machine_is_compatible("fsl,imx1"))
+		return IMX_CPU_IMX1;
+	if (of_machine_is_compatible("fsl,imx21"))
+		return IMX_CPU_IMX21;
+	if (of_machine_is_compatible("fsl,imx25"))
+		return IMX_CPU_IMX25;
+	if (of_machine_is_compatible("fsl,imx27"))
+		return IMX_CPU_IMX27;
+	if (of_machine_is_compatible("fsl,imx31"))
+		return IMX_CPU_IMX31;
+	if (of_machine_is_compatible("fsl,imx35"))
+		return IMX_CPU_IMX35;
+	if (of_machine_is_compatible("fsl,imx51"))
+		return IMX_CPU_IMX51;
+	if (of_machine_is_compatible("fsl,imx53"))
+		return IMX_CPU_IMX53;
+	if (of_machine_is_compatible("fsl,imx6"))
+		return IMX_CPU_IMX6;
+
+	return 0;
+}
+
 static int imx_init(void)
 {
 	int ret;
+	struct device_node *root;
+
+	root = of_get_root_node();
+	if (root) {
+		__imx_cpu_type = imx_soc_from_dt();
+		if (!__imx_cpu_type)
+			hang();
+	}
 
 	if (cpu_is_mx1())
 		ret = imx1_init();
@@ -57,7 +91,7 @@ static int imx_init(void)
 	else
 		return -EINVAL;
 
-	if (of_get_root_node())
+	if (root)
 		return ret;
 
 	if (cpu_is_mx1())
diff --git a/arch/arm/mach-imx/include/mach/generic.h b/arch/arm/mach-imx/include/mach/generic.h
index 0c5dc8a..506b1da 100644
--- a/arch/arm/mach-imx/include/mach/generic.h
+++ b/arch/arm/mach-imx/include/mach/generic.h
@@ -37,58 +37,124 @@ int imx6_devices_init(void);
 /* range e.g. GPIO_1_5 is gpio 5 under linux */
 #define IMX_GPIO_NR(bank, nr)		(((bank) - 1) * 32 + (nr))
 
+#define IMX_CPU_IMX1	1
+#define IMX_CPU_IMX21	21
+#define IMX_CPU_IMX25	25
+#define IMX_CPU_IMX27	27
+#define IMX_CPU_IMX31	31
+#define IMX_CPU_IMX35	35
+#define IMX_CPU_IMX51	51
+#define IMX_CPU_IMX53	53
+#define IMX_CPU_IMX6	6
+
+extern unsigned int __imx_cpu_type;
+
 #ifdef CONFIG_ARCH_IMX1
-#define cpu_is_mx1()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX1
+# endif
+# define cpu_is_mx1()		(imx_cpu_type == IMX_CPU_IMX1)
 #else
-#define cpu_is_mx1()	(0)
+# define cpu_is_mx1()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX21
-#define cpu_is_mx21()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX21
+# endif
+# define cpu_is_mx21()		(imx_cpu_type == IMX_CPU_IMX21)
 #else
-#define cpu_is_mx21()	(0)
+# define cpu_is_mx21()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX25
-#define cpu_is_mx25()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX25
+# endif
+# define cpu_is_mx25()		(imx_cpu_type == IMX_CPU_IMX25)
 #else
-#define cpu_is_mx25()	(0)
+# define cpu_is_mx25()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX27
-#define cpu_is_mx27()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX27
+# endif
+# define cpu_is_mx27()		(imx_cpu_type == IMX_CPU_IMX27)
 #else
-#define cpu_is_mx27()	(0)
+# define cpu_is_mx27()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX31
-#define cpu_is_mx31()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX31
+# endif
+# define cpu_is_mx31()		(imx_cpu_type == IMX_CPU_IMX31)
 #else
-#define cpu_is_mx31()	(0)
+# define cpu_is_mx31()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX35
-#define cpu_is_mx35()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX35
+# endif
+# define cpu_is_mx35()		(imx_cpu_type == IMX_CPU_IMX35)
 #else
-#define cpu_is_mx35()	(0)
+# define cpu_is_mx35()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX51
-#define cpu_is_mx51()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX51
+# endif
+# define cpu_is_mx51()		(imx_cpu_type == IMX_CPU_IMX51)
 #else
-#define cpu_is_mx51()	(0)
+# define cpu_is_mx51()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX53
-#define cpu_is_mx53()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX53
+# endif
+# define cpu_is_mx53()		(imx_cpu_type == IMX_CPU_IMX53)
 #else
-#define cpu_is_mx53()	(0)
+# define cpu_is_mx53()		(0)
 #endif
 
 #ifdef CONFIG_ARCH_IMX6
-#define cpu_is_mx6()	(1)
+# ifdef imx_cpu_type
+#  undef imx_cpu_type
+#  define imx_cpu_type __imx_cpu_type
+# else
+#  define imx_cpu_type IMX_CPU_IMX6
+# endif
+# define cpu_is_mx6()		(imx_cpu_type == IMX_CPU_IMX6)
 #else
-#define cpu_is_mx6()	(0)
+# define cpu_is_mx6()		(0)
 #endif
 
 #define cpu_is_mx23()	(0)
-- 
1.8.3.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2013-06-23 21:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-23 21:40 [PATCH 1/3] ARM: i.MX: rename initcall functions Sascha Hauer
2013-06-23 21:40 ` [PATCH 2/3] ARM: i.MX: centralize i.MX startup Sascha Hauer
2013-06-23 21:40 ` Sascha Hauer [this message]

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=1372023651-13725-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox