From patchwork Thu Jan 31 19:24:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ruslan Bilovol X-Patchwork-Id: 2075221 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 424203FCDE for ; Thu, 31 Jan 2013 19:25:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756858Ab3AaTZG (ORCPT ); Thu, 31 Jan 2013 14:25:06 -0500 Received: from mail-ea0-f175.google.com ([209.85.215.175]:45705 "EHLO mail-ea0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756718Ab3AaTY6 (ORCPT ); Thu, 31 Jan 2013 14:24:58 -0500 Received: by mail-ea0-f175.google.com with SMTP id d1so1384841eab.20 for ; Thu, 31 Jan 2013 11:24:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:subject:date:message-id:x-mailer :in-reply-to:references; bh=ijMknWB4e33jLCE7VIjPCSJ2Blg43/m6LF3VtAjjRCg=; b=MQYHW9GsQuGnCpEaXnef0g+V/lWpoJkb4gLIP/cy4iOnKlOSZCmw3qpwVvrJBDWtBE 3dKHTDoDXejJgOkhktFF965cKAU3j/AEYAiAkzY4Op9AUdQBIsJsSHgIS/Crn2z6bEHk V2t3i3RjvvMI6Ow6wxhjXrwC44IBeldg5zBZUsrlqmBIybTseQOIbYlKsMz+rhx/E+m7 65s7WObYZudg/o1ZN/tFXkv3FMCe7w++2YotigBLW6OIOtwax+jCJlfetf2XxjCas+S3 4KZqazWq64/vYSXannjyNz/4MuEIHYLXyW9aCqgeBRU6Xpw1qYnBzqpff/lUq7zgrwDV HFcw== X-Received: by 10.14.198.198 with SMTP id v46mr30687412een.4.1359660296889; Thu, 31 Jan 2013 11:24:56 -0800 (PST) Received: from localhost ([195.238.93.36]) by mx.google.com with ESMTPS id 44sm8873176eek.5.2013.01.31.11.24.54 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 31 Jan 2013 11:24:55 -0800 (PST) From: Ruslan Bilovol To: tony@atomide.com, linux@arm.linux.org.uk, linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] ARM: OMAP2+: Export SoC information to userspace Date: Thu, 31 Jan 2013 21:24:44 +0200 Message-Id: <1359660284-5225-3-git-send-email-ruslan.bilovol@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1359660284-5225-1-git-send-email-ruslan.bilovol@ti.com> References: <1359660284-5225-1-git-send-email-ruslan.bilovol@ti.com> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org 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 --- arch/arm/mach-omap2/Kconfig | 1 + arch/arm/mach-omap2/common.h | 8 ++++++ arch/arm/mach-omap2/id.c | 65 ++++++++++++++++++++++++++++++++++++++++++ arch/arm/mach-omap2/io.c | 1 + 4 files changed, 75 insertions(+) diff --git a/arch/arm/mach-omap2/Kconfig b/arch/arm/mach-omap2/Kconfig index fe926e0..47da0bd 100644 --- a/arch/arm/mach-omap2/Kconfig +++ b/arch/arm/mach-omap2/Kconfig @@ -17,6 +17,7 @@ config ARCH_OMAP2PLUS select PROC_DEVICETREE if PROC_FS select SPARSE_IRQ select USE_OF + select SOC_BUS help Systems based on OMAP2, OMAP3, OMAP4 or OMAP5 diff --git a/arch/arm/mach-omap2/common.h b/arch/arm/mach-omap2/common.h index 948bcaa..2a6f866 100644 --- a/arch/arm/mach-omap2/common.h +++ b/arch/arm/mach-omap2/common.h @@ -111,6 +111,14 @@ void ti81xx_init_late(void); void omap4430_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 diff --git a/arch/arm/mach-omap2/id.c b/arch/arm/mach-omap2/id.c index 436fcf9..5724ee8 100644 --- a/arch/arm/mach-omap2/id.c +++ b/arch/arm/mach-omap2/id.c @@ -18,6 +18,11 @@ #include #include #include +#include + +#ifdef CONFIG_SOC_BUS +#include +#endif #include @@ -572,3 +577,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 = cpu_name; + soc_dev_attr->family = omap_get_family(); + soc_dev_attr->revision = cpu_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 */ diff --git a/arch/arm/mach-omap2/io.c b/arch/arm/mach-omap2/io.c index 2c3fdd6..08003c1 100644 --- a/arch/arm/mach-omap2/io.c +++ b/arch/arm/mach-omap2/io.c @@ -602,6 +602,7 @@ void __init omap4430_init_late(void) omap2_common_pm_late_init(); omap4_pm_init(); omap2_clk_enable_autoidle_all(); + omap_soc_device_init(); } #endif