From patchwork Wed May 25 07:58:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Dubey X-Patchwork-Id: 9134951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 354876075C for ; Wed, 25 May 2016 07:58:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2615D1FE95 for ; Wed, 25 May 2016 07:58:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1ADFB282BE; Wed, 25 May 2016 07:58:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8B94B1FE95 for ; Wed, 25 May 2016 07:58:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b5Tgd-0000Qz-Mp; Wed, 25 May 2016 07:57:03 +0000 Received: from mailout3.samsung.com ([203.254.224.33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b5TgS-0000KV-He for linux-arm-kernel@lists.infradead.org; Wed, 25 May 2016 07:56:53 +0000 Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O7Q02SJK3E5TSE0@mailout3.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 25 May 2016 16:56:29 +0900 (KST) Received: from epcpsbgm1new.samsung.com ( [172.20.52.135]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 92.04.05251.DAA55475; Wed, 25 May 2016 16:56:29 +0900 (KST) X-AuditID: cbfee691-f79196d000001483-a8-57455aade353 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1new.samsung.com (EPCPMTA) with SMTP id 6E.C3.06657.CAA55475; Wed, 25 May 2016 16:56:29 +0900 (KST) Received: from pankaj.sisodomain.com ([107.108.83.125]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O7Q0082K3DX0M60@mmp2.samsung.com>; Wed, 25 May 2016 16:56:28 +0900 (KST) From: Pankaj Dubey To: linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v6 1/2] soc: samsung: add exynos chipid driver support Date: Wed, 25 May 2016 13:28:23 +0530 Message-id: <1464163104-8163-2-git-send-email-pankaj.dubey@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1464163104-8163-1-git-send-email-pankaj.dubey@samsung.com> References: <1464163104-8163-1-git-send-email-pankaj.dubey@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMLMWRmVeSWpSXmKPExsWyRsSkXXdtlGu4wYdLPBZ/Jx1jtzjwZwej xesXhhb9j18zW0z5s5zJYtPja6wWl3fNYbOYcX4fk8WirV/YLVr3HmG36FjG6MDt8fvXJEaP Tas62TzuXNvD5rF5Sb1H35ZVjB6fN8kFsEVx2aSk5mSWpRbp2yVwZWz9dYK54I5dxawf2xgb GNebdDFyckgImEh83LmDGcIWk7hwbz1bFyMXh5DACkaJyxOOscAUrdl7nBkiMYtRouH4MyYI 5yejxL0pl5lAqtgEdCWevJ8LNkpEIFviSuN9sA5mgW+MEoeXT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R7eHatdwoVY E8uKK3MPMUpwMCuJ8O4LcQ0X4k1JrKxKLcqPLyrNSS0+xGgKdNhEZinR5HxgWsgriTc0NjEz sjQyszAyMTdXEud9/H9dmJBAemJJanZqakFqEUwfEwenVANjUp/SQ5GHt1Y+cLCz356/NHit uiZ7x5IjcgaiZmtZvkfN+11YGfntecXdxhfMTDdnWhjt/ryEu/pYbln4uscyNx8ufTG5W+/R zaM/Fj5afsxy85s3CyZGeB70U9Tiso56Kuzy+OOu2olWOh9lj9gyH3p32tY1ncvhFsOyBzU5 QaZMU2WentiZqcRSnJFoqMVcVJwIAJYxwJvTAgAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160525_005652_736918_6BC649B9 X-CRM114-Status: GOOD ( 21.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: k.kozlowski@samsung.com, arnd@arndb.de, Pankaj Dubey , Linus Walleij , Rob Herring , thomas.ab@samsung.com, kgene@kernel.org, Grant Likely MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Exynos SoCs have Chipid, for identification of product IDs and SoC revisions. This patch intends to provide initialization code for all these functionalities, at the same time it provides some sysfs entries for accessing these information to user-space. This driver uses existing binding for exynos-chipid. CC: Grant Likely CC: Rob Herring CC: Linus Walleij Signed-off-by: Pankaj Dubey --- drivers/soc/samsung/Kconfig | 5 + drivers/soc/samsung/Makefile | 1 + drivers/soc/samsung/exynos-chipid.c | 172 +++++++++++++++++++++++++++++++++ include/linux/soc/samsung/exynos-soc.h | 51 ++++++++++ 4 files changed, 229 insertions(+) create mode 100644 drivers/soc/samsung/exynos-chipid.c create mode 100644 include/linux/soc/samsung/exynos-soc.h diff --git a/drivers/soc/samsung/Kconfig b/drivers/soc/samsung/Kconfig index d7fc123..fc793f3 100644 --- a/drivers/soc/samsung/Kconfig +++ b/drivers/soc/samsung/Kconfig @@ -10,4 +10,9 @@ config EXYNOS_PMU bool "Exynos PMU controller driver" if COMPILE_TEST depends on (ARM && ARCH_EXYNOS) || ((ARM || ARM64) && COMPILE_TEST) +config EXYNOS_CHIPID + bool "Exynos Chipid controller driver" if COMPILE_TEST + depends on (ARM && ARCH_EXYNOS) || ((ARM || ARM64) && COMPILE_TEST) + select SOC_BUS + endif diff --git a/drivers/soc/samsung/Makefile b/drivers/soc/samsung/Makefile index f64ac4d..81023ed 100644 --- a/drivers/soc/samsung/Makefile +++ b/drivers/soc/samsung/Makefile @@ -1,2 +1,3 @@ obj-$(CONFIG_EXYNOS_PMU) += exynos-pmu.o exynos3250-pmu.o exynos4-pmu.o \ exynos5250-pmu.o exynos5420-pmu.o +obj-$(CONFIG_EXYNOS_CHIPID) += exynos-chipid.o diff --git a/drivers/soc/samsung/exynos-chipid.c b/drivers/soc/samsung/exynos-chipid.c new file mode 100644 index 0000000..fa20fdd --- /dev/null +++ b/drivers/soc/samsung/exynos-chipid.c @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * http://www.samsung.com/ + * + * EXYNOS - CHIP ID support + * Author: Pankaj Dubey + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define EXYNOS_SUBREV_MASK (0xF << 4) +#define EXYNOS_MAINREV_MASK (0xF << 0) +#define EXYNOS_REV_MASK (EXYNOS_SUBREV_MASK | EXYNOS_MAINREV_MASK) + +static void __iomem *exynos_chipid_base; + +struct exynos_chipid_info exynos_soc_info; +EXPORT_SYMBOL(exynos_soc_info); + +static const char * __init product_id_to_name(unsigned int product_id) +{ + const char *soc_name; + unsigned int soc_id = product_id & EXYNOS_SOC_MASK; + + switch (soc_id) { + case EXYNOS3250_SOC_ID: + soc_name = "EXYNOS3250"; + break; + case EXYNOS4210_SOC_ID: + soc_name = "EXYNOS4210"; + break; + case EXYNOS4212_SOC_ID: + soc_name = "EXYNOS4212"; + break; + case EXYNOS4412_SOC_ID: + soc_name = "EXYNOS4412"; + break; + case EXYNOS4415_SOC_ID: + soc_name = "EXYNOS4415"; + break; + case EXYNOS5250_SOC_ID: + soc_name = "EXYNOS5250"; + break; + case EXYNOS5260_SOC_ID: + soc_name = "EXYNOS5260"; + break; + case EXYNOS5420_SOC_ID: + soc_name = "EXYNOS5420"; + break; + case EXYNOS5440_SOC_ID: + soc_name = "EXYNOS5440"; + break; + case EXYNOS5800_SOC_ID: + soc_name = "EXYNOS5800"; + break; + default: + soc_name = "UNKNOWN"; + } + return soc_name; +} + +static const struct of_device_id of_exynos_chipid_ids[] = { + { + .compatible = "samsung,exynos4210-chipid", + }, + {}, +}; + +/** + * exynos_chipid_early_init: Early chipid initialization + * @dev: pointer to chipid device + */ +int __init exynos_chipid_early_init(struct device *dev) +{ + struct device_node *np; + const struct of_device_id *match; + + if (exynos_chipid_base) + return 0; + + if (!dev) + np = of_find_matching_node_and_match(NULL, + of_exynos_chipid_ids, &match); + else + np = dev->of_node; + + if (!np) + return -ENODEV; + + exynos_chipid_base = of_iomap(np, 0); + + if (!exynos_chipid_base) + return PTR_ERR(exynos_chipid_base); + + exynos_soc_info.product_id = __raw_readl(exynos_chipid_base); + exynos_soc_info.revision = exynos_soc_info.product_id & EXYNOS_REV_MASK; + + return 0; +} + +static int __init exynos_chipid_probe(struct platform_device *pdev) +{ + struct soc_device_attribute *soc_dev_attr; + struct soc_device *soc_dev; + struct device_node *root; + int ret; + + ret = exynos_chipid_early_init(&pdev->dev); + if (ret) { + dev_dbg(&pdev->dev, "Exynos chipid probe failed: %d\n", ret); + return ret; + } + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return -ENODEV; + + soc_dev_attr->family = "Samsung Exynos"; + + root = of_find_node_by_path("/"); + ret = of_property_read_string(root, "model", &soc_dev_attr->machine); + of_node_put(root); + if (ret) + goto free_soc; + + soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%d", + exynos_soc_info.revision); + if (!soc_dev_attr->revision) + goto free_soc; + + soc_dev_attr->soc_id = product_id_to_name(exynos_soc_info.product_id); + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) + goto free_rev; + + soc_device_to_device(soc_dev); + + dev_info(&pdev->dev, "Exynos: CPU[%s] CPU_REV[0x%x] Detected\n", + product_id_to_name(exynos_soc_info.product_id), + exynos_soc_info.revision); + return 0; +free_rev: + kfree(soc_dev_attr->revision); +free_soc: + kfree(soc_dev_attr); + return -EINVAL; +} + +static struct platform_driver exynos_chipid_driver = { + .driver = { + .name = "exynos-chipid", + .of_match_table = of_exynos_chipid_ids, + }, +}; + +static int __init exynos_chipid_init(void) +{ + return platform_driver_probe(&exynos_chipid_driver, exynos_chipid_probe); +} +device_initcall(exynos_chipid_init); diff --git a/include/linux/soc/samsung/exynos-soc.h b/include/linux/soc/samsung/exynos-soc.h new file mode 100644 index 0000000..38b95ad --- /dev/null +++ b/include/linux/soc/samsung/exynos-soc.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * http://www.samsung.com + * + * Header for EXYNOS SoC Chipid support + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __EXYNOS_SOC_H +#define __EXYNOS_SOC_H + +#define EXYNOS3250_SOC_ID 0xE3472000 +#define EXYNOS4210_SOC_ID 0x43210000 +#define EXYNOS4212_SOC_ID 0x43220000 +#define EXYNOS4412_SOC_ID 0xE4412000 +#define EXYNOS4415_SOC_ID 0xE4415000 +#define EXYNOS5250_SOC_ID 0x43520000 +#define EXYNOS5260_SOC_ID 0xE5260000 +#define EXYNOS5410_SOC_ID 0xE5410000 +#define EXYNOS5420_SOC_ID 0xE5420000 +#define EXYNOS5440_SOC_ID 0xE5440000 +#define EXYNOS5800_SOC_ID 0xE5422000 + +#define EXYNOS_SOC_MASK 0xFFFFF000 + +#define EXYNOS4210_REV_0 0x0 +#define EXYNOS4210_REV_1_0 0x10 +#define EXYNOS4210_REV_1_1 0x11 + +/** + * Struct exynos_chipid_info + * @soc_product_id: product id allocated to exynos SoC + * @soc_revision: revision of exynos SoC + */ + +struct exynos_chipid_info { + u32 product_id; + u32 revision; +}; + +extern struct exynos_chipid_info exynos_soc_info; + +/* Since we need chipid to be initialized as early as possible + * during secondary core bootup adding early initialization function + */ +extern int exynos_chipid_early_init(struct device *dev); + +#endif /* __EXYNOS_SOC_H */