devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm/dt: Add SoC detection macros
@ 2011-09-09  8:02 Allen Martin
       [not found] ` <1315555339-12685-1-git-send-email-amartin-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Allen Martin @ 2011-09-09  8:02 UTC (permalink / raw)
  To: amartin-DDmLM1+adcrQT0dZR+AlfA
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA,
	devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ

These macros allow runtime query of SoC family and version via
soc_is_*()  If the corresponding SoC is not configured the macro will
evaluate to 0.  If the corresponding SoC is the only architecure
configured, the macro will evaluate to 1.  If multiple architecures
are configured the macro will evaluate to a runtime call to
soc_get_version().

I've added tegra2 and tegra3 SoCs as a starting point.

Signed-off-by: Allen Martin <amartin-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 arch/arm/include/asm/soc.h |   76 ++++++++++++++++++++++++++++++++++++++++++++
 arch/arm/kernel/Makefile   |    1 +
 arch/arm/kernel/setup.c    |    2 +
 arch/arm/kernel/soc.c      |   37 +++++++++++++++++++++
 4 files changed, 116 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/soc.h
 create mode 100644 arch/arm/kernel/soc.c

diff --git a/arch/arm/include/asm/soc.h b/arch/arm/include/asm/soc.h
new file mode 100644
index 0000000..d95f643
--- /dev/null
+++ b/arch/arm/include/asm/soc.h
@@ -0,0 +1,76 @@
+/*
+ * arch/arm/include/asm/soc.h
+ *
+ * Copyright (C) 2011 NVIDIA, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+/* determine if multiple SoCs are enabled */
+#undef MULTI_SOC
+#undef SOC_NAME
+
+#ifdef CONFIG_ARCH_TEGRA_2x_SOC
+# ifdef SOC_NAME
+#  undef MULTI_SOC
+#  define MULTI_SOC
+# else
+#   define SOC_NAME tegra2
+# endif
+#endif
+#ifdef CONFIG_ARCH_TEGRA_3x_SOC
+# ifdef SOC_NAME
+#  undef MULTI_SOC
+#  define MULTI_SOC
+# else
+#   define SOC_NAME tegra3
+# endif
+#endif
+
+#define soc_is_tegra2()			0
+#define soc_is_tegra3()			0
+
+#if defined(MULTI_SOC)
+# if defined(CONFIG_ARCH_TEGRA_2x_SOC)
+#  undef soc_is_tegra2
+#  define soc_is_tegra2()		is_tegra2()
+# endif
+# if defined(CONFIG_ARCH_TEGRA_3x_SOC)
+#  undef soc_is_tegra3
+#  define soc_is_tegra3()		is_tegra3()
+# endif
+#else /* non-multi, only one architecture is on */
+# if defined(CONFIG_ARCH_TEGRA_2x_SOC)
+#  undef soc_is_tegra2
+#  define soc_is_tegra2()		1
+# elif defined(CONFIG_ARCH_TEGRA_3x_SOC)
+#  undef soc_is_tegra3
+#  define soc_is_tegra3()		1
+# endif
+#endif
+
+enum soc_version {
+	SOC_UNKNOWN = 0,
+	TEGRA_T20,
+	TEGRA_T30,
+};
+
+void soc_init_version(void);
+enum soc_version soc_get_version(void);
+
+static inline int is_tegra2(void)
+{
+	return soc_get_version() == TEGRA_T20;
+}
+
+static inline int is_tegra3(void)
+{
+	return soc_get_version() == TEGRA_T30;
+}
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index c687bce..de29477 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_KGDB)		+= kgdb.o
 obj-$(CONFIG_ARM_UNWIND)	+= unwind.o
 obj-$(CONFIG_HAVE_TCM)		+= tcm.o
 obj-$(CONFIG_OF)		+= devtree.o
+obj-$(CONFIG_OF)		+= soc.o
 obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
 obj-$(CONFIG_SWP_EMULATE)	+= swp_emulate.o
 CFLAGS_swp_emulate.o		:= -Wa,-march=armv7-a
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 0ca06f7..63ad6de 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -52,6 +52,7 @@
 #include <asm/mach/time.h>
 #include <asm/traps.h>
 #include <asm/unwind.h>
+#include <asm/soc.h>
 
 #if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
 #include "compat.h"
@@ -922,6 +923,7 @@ void __init setup_arch(char **cmdline_p)
 	request_standard_resources(mdesc);
 
 	unflatten_device_tree();
+	soc_init_version();
 
 #ifdef CONFIG_SMP
 	if (is_smp())
diff --git a/arch/arm/kernel/soc.c b/arch/arm/kernel/soc.c
new file mode 100644
index 0000000..8686468
--- /dev/null
+++ b/arch/arm/kernel/soc.c
@@ -0,0 +1,37 @@
+/*
+ * arch/arm/kernel/soc.c
+ *
+ * Copyright (C) 2011 NVIDIA, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/of.h>
+
+#include <asm/soc.h>
+
+static enum soc_version soc_version;
+
+enum soc_version soc_get_version(void)
+{
+	return soc_version;
+}
+
+void soc_init_version(void)
+{
+	if (of_machine_is_compatible("nvidia,tegra20"))
+		soc_version = TEGRA_T20;
+	else if (of_machine_is_compatible("nvidia,tegra30"))
+		soc_version = TEGRA_T30;
+	else
+		panic("Unknown SoC");
+}
-- 
1.7.4.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-09-19 20:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-09  8:02 [PATCH] arm/dt: Add SoC detection macros Allen Martin
     [not found] ` <1315555339-12685-1-git-send-email-amartin-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2011-09-09 16:45   ` Olof Johansson
2011-09-17 10:28   ` Russell King - ARM Linux
2011-09-17 10:34     ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]       ` <20110917103457.GP28104-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2011-09-17 11:23         ` Russell King - ARM Linux
     [not found]           ` <20110917112321.GE16381-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2011-09-17 18:19             ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]               ` <20110917181907.GA16141-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2011-09-17 20:56                 ` Arnd Bergmann
2011-09-18  0:46                   ` Jean-Christophe PLAGNIOL-VILLARD
     [not found]                     ` <20110918004615.GC16141-RQcB7r2h9QmfDR2tN2SG5Ni2O/JbrIOy@public.gmane.org>
2011-09-18  9:28                       ` Arnd Bergmann
2011-09-19 17:26             ` Allen Martin
     [not found]               ` <3C7A7ACA8617D24290826EC008B5CD083E17B00988-lR+7xdUAJVNDw2glCA4ptUEOCMrvLtNR@public.gmane.org>
2011-09-19 20:08                 ` Olof Johansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).