ARM: OMAP2+: Export SoC information to userspace
authorRuslan Bilovol <ruslan.bilovol@ti.com>
Thu, 14 Feb 2013 11:55:24 +0000 (13:55 +0200)
committerTony Lindgren <tony@atomide.com>
Mon, 8 Apr 2013 23:04:25 +0000 (16:04 -0700)
In some situations it is useful for userspace to
know some SoC-specific information. For example,
this may be used for deciding what kernel module to
use or how to better configure some settings etc.
This patch exports OMAP SoC information to userspace
using existing in Linux kernel SoC infrastructure.

This information can be read under
/sys/devices/socX directory

Signed-off-by: Ruslan Bilovol <ruslan.bilovol@ti.com>
[tony@atomide.com: updated for multiplatform changes]
Signed-off-by: Tony Lindgren <tony@atomide.com>
arch/arm/mach-omap2/Kconfig
arch/arm/mach-omap2/common.h
arch/arm/mach-omap2/id.c
arch/arm/mach-omap2/io.c

index 8111cd9ff3e5201d9c92a66a90a24e30823d7074..68b1802879e2922440729491f484891384cfdf6e 100644 (file)
@@ -15,6 +15,7 @@ config ARCH_OMAP2PLUS
        select OMAP_DM_TIMER
        select PINCTRL
        select PROC_DEVICETREE if PROC_FS
+       select SOC_BUS
        select SPARSE_IRQ
        select USE_OF
        help
index d6ba13e1c540f6ecc186a164f441ca48b2540a1e..1ddd0cb5fab9181dd1aa125e7cb4c1f149908f76 100644 (file)
@@ -110,6 +110,14 @@ void am35xx_init_late(void);
 void ti81xx_init_late(void);
 int omap2_common_pm_late_init(void);
 
+#ifdef CONFIG_SOC_BUS
+void omap_soc_device_init(void);
+#else
+static inline void omap_soc_device_init(void)
+{
+}
+#endif
+
 #if defined(CONFIG_SOC_OMAP2420) || defined(CONFIG_SOC_OMAP2430)
 void omap2xxx_restart(char mode, const char *cmd);
 #else
index 3737700529fed384717eab8c7d8abe2deb02d363..098e94e3133608128bf8c14242c7a07a53fc83ff 100644 (file)
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/slab.h>
+
+#ifdef CONFIG_SOC_BUS
+#include <linux/sys_soc.h>
+#endif
 
 #include <asm/cputype.h>
 
@@ -583,3 +588,63 @@ void __init omap2_set_globals_tap(u32 class, void __iomem *tap)
        else
                tap_prod_id = 0x0208;
 }
+
+#ifdef CONFIG_SOC_BUS
+
+static const char const *omap_types[] = {
+       [OMAP2_DEVICE_TYPE_TEST]        = "TST",
+       [OMAP2_DEVICE_TYPE_EMU]         = "EMU",
+       [OMAP2_DEVICE_TYPE_SEC]         = "HS",
+       [OMAP2_DEVICE_TYPE_GP]          = "GP",
+       [OMAP2_DEVICE_TYPE_BAD]         = "BAD",
+};
+
+static const char * __init omap_get_family(void)
+{
+       if (cpu_is_omap24xx())
+               return kasprintf(GFP_KERNEL, "OMAP2");
+       else if (cpu_is_omap34xx())
+               return kasprintf(GFP_KERNEL, "OMAP3");
+       else if (cpu_is_omap44xx())
+               return kasprintf(GFP_KERNEL, "OMAP4");
+       else if (soc_is_omap54xx())
+               return kasprintf(GFP_KERNEL, "OMAP5");
+       else
+               return kasprintf(GFP_KERNEL, "Unknown");
+}
+
+static ssize_t omap_get_type(struct device *dev,
+                                       struct device_attribute *attr,
+                                       char *buf)
+{
+       return sprintf(buf, "%s\n", omap_types[omap_type()]);
+}
+
+static struct device_attribute omap_soc_attr =
+       __ATTR(type,  S_IRUGO, omap_get_type,  NULL);
+
+void __init omap_soc_device_init(void)
+{
+       struct device *parent;
+       struct soc_device *soc_dev;
+       struct soc_device_attribute *soc_dev_attr;
+
+       soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+       if (!soc_dev_attr)
+               return;
+
+       soc_dev_attr->machine  = soc_name;
+       soc_dev_attr->family   = omap_get_family();
+       soc_dev_attr->revision = soc_rev;
+
+       soc_dev = soc_device_register(soc_dev_attr);
+       if (IS_ERR_OR_NULL(soc_dev)) {
+               kfree(soc_dev_attr);
+               return;
+       }
+
+       parent = soc_device_to_device(soc_dev);
+       if (!IS_ERR_OR_NULL(parent))
+               device_create_file(parent, &omap_soc_attr);
+}
+#endif /* CONFIG_SOC_BUS */
index 865688e693301ad8134c1ea4592e9f6daa4ae0c3..3241f23afe098b04c79d765dd3b1ea9be1af469d 100644 (file)
@@ -389,6 +389,7 @@ static void __init omap_common_late_init(void)
 {
        omap_mux_late_init();
        omap2_common_pm_late_init();
+       omap_soc_device_init();
 }
 
 #ifdef CONFIG_SOC_OMAP2420
This page took 0.028105 seconds and 5 git commands to generate.