From patchwork Tue Jun 4 13:18:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 2659091 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork1.kernel.org (Postfix) with ESMTP id DDF1240077 for ; Tue, 4 Jun 2013 13:19:37 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ujr9A-000471-Tk; Tue, 04 Jun 2013 13:19:33 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ujr92-0004sq-Mv; Tue, 04 Jun 2013 13:19:24 +0000 Received: from ch1ehsobe005.messaging.microsoft.com ([216.32.181.185] helo=ch1outboundpool.messaging.microsoft.com) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ujr8z-0004rM-PO for linux-arm-kernel@lists.infradead.org; Tue, 04 Jun 2013 13:19:23 +0000 Received: from mail232-ch1-R.bigfish.com (10.43.68.229) by CH1EHSOBE020.bigfish.com (10.43.70.77) with Microsoft SMTP Server id 14.1.225.23; Tue, 4 Jun 2013 13:18:59 +0000 Received: from mail232-ch1 (localhost [127.0.0.1]) by mail232-ch1-R.bigfish.com (Postfix) with ESMTP id BEBFB3E0205; Tue, 4 Jun 2013 13:18:59 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1f42h1ee6h1de0h1fdah1202h1e76h1d1ah1d2ah1fc6hzz8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1d0ch1d2eh1d3fh1dfeh1dffh1155h) Received: from mail232-ch1 (localhost.localdomain [127.0.0.1]) by mail232-ch1 (MessageSwitch) id 1370351937776122_13675; Tue, 4 Jun 2013 13:18:57 +0000 (UTC) Received: from CH1EHSMHS017.bigfish.com (snatpool3.int.messaging.microsoft.com [10.43.68.225]) by mail232-ch1.bigfish.com (Postfix) with ESMTP id B10E1A8004B; Tue, 4 Jun 2013 13:18:57 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CH1EHSMHS017.bigfish.com (10.43.70.17) with Microsoft SMTP Server (TLS) id 14.1.225.23; Tue, 4 Jun 2013 13:18:56 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server (TLS) id 14.2.328.11; Tue, 4 Jun 2013 13:20:08 +0000 Received: from fabio-Latitude-E6410.am.freescale.net ([10.29.244.119]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id r54DIquw015454; Tue, 4 Jun 2013 06:18:54 -0700 From: Fabio Estevam To: Subject: [PATCH v3 2/2] ARM: mxs: Use soc bus infrastructure Date: Tue, 4 Jun 2013 10:18:45 -0300 Message-ID: <1370351925-27915-2-git-send-email-fabio.estevam@freescale.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1370351925-27915-1-git-send-email-fabio.estevam@freescale.com> References: <1370351925-27915-1-git-send-email-fabio.estevam@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130604_091921_878247_CE8EBD66 X-CRM114-Status: GOOD ( 15.71 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [216.32.181.185 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Fabio Estevam , linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Using the soc bus infrastructure is helpful for reporting several SoC related information such as: family, machine, SoC name and SoC revision. $ cat /sys/bus/soc/devices/soc0/family Freescale MXS Family $ cat /sys/bus/soc/devices/soc0/machine Freescale i.MX28 Evaluation Kit $ cat /sys/bus/soc/devices/soc0/soc_id i.MX28 $ cat /sys/bus/soc/devices/soc0/revision TO1.2 Signed-off-by: Fabio Estevam --- Changes since v2: - Drop static - Use iounmap - Use "Unknown" - Drop blank line Changes since v1: - Read the chipid register only once - Fix the digctl compatible string - Do not check for "if (!root)" - Free 'soc_dev_attr->revision arch/arm/mach-mxs/Kconfig | 1 + arch/arm/mach-mxs/mach-mxs.c | 117 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 1 deletion(-) diff --git a/arch/arm/mach-mxs/Kconfig b/arch/arm/mach-mxs/Kconfig index 4dc2fbb..59c30ef 100644 --- a/arch/arm/mach-mxs/Kconfig +++ b/arch/arm/mach-mxs/Kconfig @@ -25,6 +25,7 @@ config ARCH_MXS select GENERIC_CLOCKEVENTS select HAVE_CLK_PREPARE select PINCTRL + select SOC_BUS select SOC_IMX23 select SOC_IMX28 select STMP_DEVICE diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c index bd225e9..f01abe5 100644 --- a/arch/arm/mach-mxs/mach-mxs.c +++ b/arch/arm/mach-mxs/mach-mxs.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -38,12 +39,28 @@ #define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR0 0x2 #define MXS_DIGCTL_SAIF_CLKMUX_EXTMSTR1 0x3 +#define HW_DIGCTL_CHIPID 0x310 +#define HW_DIGCTL_CHIPID_MASK (0xffff << 16) +#define HW_DIGCTL_REV_MASK 0xff +#define HW_DIGCTL_CHIPID_MX23 (0x3780 << 16) +#define HW_DIGCTL_CHIPID_MX28 (0x2800 << 16) + +#define MXS_CHIP_REVISION_1_0 0x10 +#define MXS_CHIP_REVISION_1_1 0x11 +#define MXS_CHIP_REVISION_1_2 0x12 +#define MXS_CHIP_REVISION_1_3 0x13 +#define MXS_CHIP_REVISION_1_4 0x14 +#define MXS_CHIP_REV_UNKNOWN 0xff + #define MXS_GPIO_NR(bank, nr) ((bank) * 32 + (nr)) #define MXS_SET_ADDR 0x4 #define MXS_CLR_ADDR 0x8 #define MXS_TOG_ADDR 0xc +static u32 chipid; +static u32 socid; + static inline void __mxs_setl(u32 mask, void __iomem *reg) { __raw_writel(mask, reg + MXS_SET_ADDR); @@ -361,8 +378,106 @@ static void __init cfa10037_init(void) update_fec_mac_prop(OUI_CRYSTALFONTZ); } +static const char __init *mxs_get_soc_id(void) +{ + struct device_node *np; + void __iomem *digctl_base; + + np = of_find_compatible_node(NULL, NULL, "fsl,imx23-digctl"); + digctl_base = of_iomap(np, 0); + WARN_ON(!digctl_base); + + chipid = readl(digctl_base + HW_DIGCTL_CHIPID); + socid = chipid & HW_DIGCTL_CHIPID_MASK; + + iounmap(digctl_base); + of_node_put(np); + + switch (socid) { + case HW_DIGCTL_CHIPID_MX23: + return "i.MX23"; + case HW_DIGCTL_CHIPID_MX28: + return "i.MX28"; + default: + return "Unknown"; + } +} + +static u32 __init mxs_get_cpu_rev(void) +{ + u32 rev = chipid & HW_DIGCTL_REV_MASK; + + switch (socid) { + case HW_DIGCTL_CHIPID_MX23: + switch (rev) { + case 0x0: + return MXS_CHIP_REVISION_1_0; + case 0x1: + return MXS_CHIP_REVISION_1_1; + case 0x2: + return MXS_CHIP_REVISION_1_2; + case 0x3: + return MXS_CHIP_REVISION_1_3; + case 0x4: + return MXS_CHIP_REVISION_1_4; + default: + return MXS_CHIP_REV_UNKNOWN; + } + case HW_DIGCTL_CHIPID_MX28: + switch (rev) { + case 0x0: + return MXS_CHIP_REVISION_1_1; + case 0x1: + return MXS_CHIP_REVISION_1_2; + default: + return MXS_CHIP_REV_UNKNOWN; + } + default: + return MXS_CHIP_REV_UNKNOWN; + } +} + +static const char __init *mxs_get_revision(void) +{ + u32 rev = mxs_get_cpu_rev(); + + if (rev != MXS_CHIP_REV_UNKNOWN) + return kasprintf(GFP_KERNEL, "TO%d.%d", (rev >> 4) & 0xf, + rev & 0xf); + else + return kasprintf(GFP_KERNEL, "%s", "Unknown"); +} + static void __init mxs_machine_init(void) { + struct device_node *root; + struct device *parent; + struct soc_device *soc_dev; + struct soc_device_attribute *soc_dev_attr; + int ret; + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return; + + root = of_find_node_by_path("/"); + ret = of_property_read_string(root, "model", &soc_dev_attr->machine); + if (ret) + return; + + soc_dev_attr->family = "Freescale MXS Family"; + soc_dev_attr->soc_id = mxs_get_soc_id(); + soc_dev_attr->revision = mxs_get_revision(); + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + kfree(soc_dev_attr->revision); + kfree(soc_dev_attr); + return; + } + + parent = soc_device_to_device(soc_dev); + if (of_machine_is_compatible("fsl,imx28-evk")) imx28_evk_init(); else if (of_machine_is_compatible("bluegiga,apx4devkit")) @@ -373,7 +488,7 @@ static void __init mxs_machine_init(void) cfa10049_init(); of_platform_populate(NULL, of_default_bus_match_table, - mxs_auxdata_lookup, NULL); + mxs_auxdata_lookup, parent); if (of_machine_is_compatible("karo,tx28")) tx28_post_init();