From patchwork Fri Mar 31 08:47:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 9655669 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 BAD08602BD for ; Fri, 31 Mar 2017 08:48:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF18828621 for ; Fri, 31 Mar 2017 08:48:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A18EA2862D; Fri, 31 Mar 2017 08:48:33 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EDED628621 for ; Fri, 31 Mar 2017 08:48:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=86gBOQ/DZ4pKRYPduG3D/3vlHjkDT6drDPoWH7vaowQ=; b=rpodjtg1n5hPG1ftNokreM4YTr fTqwnFdC5Ah+WcmQ836qx0ZI8LS1ChofYdW3o1nURjSlaaRQH4/Y1h8MAWvts5HZnMGLSfVO4w3qy W2cNbnOuMY+gHjv1bBjH+BTOewc0a8g9QM5NQ0qZ8HkB7Hen4SOxauXGW9jLJ2ul00evw6o4TGxYO L/lVQw5g6oMzHDnrWT9G+0eRDTk1oMWvhKb8T4hZDqregkjRB785AxnbYlGt1/vAp2Il/wvTYpt5n K+m9ipo6YDlqsNt2OcMRliMBKEo2qFKD71SpVp+uexKHtWlM7+BmGRNzoNhKSjCobg1LTvAhMEL64 8ls6pC6Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ctsER-0003Z0-Ri; Fri, 31 Mar 2017 08:48:31 +0000 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctsEM-0003Um-5J for linux-arm-kernel@lists.infradead.org; Fri, 31 Mar 2017 08:48:29 +0000 Received: by mail-wr0-x22a.google.com with SMTP id k6so90175136wre.2 for ; Fri, 31 Mar 2017 01:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GRn+BcO6FeGoTSD5hDHrCr+7jabb3BLGQPPVYCM3b/I=; b=z8rshGNKA4WXNHrMjvlgVYLvSkgI3pSswYePngDKBgJqcIGXQUTV6xG8Mjf7l/Dxrq ieLOUg+6KGwVsEqDi/xEK2lASUgOHjGUvmAyCGGqkFGQLznw7mjxyULAeUSpup6bhElj AKG5hd7XaL0XExoXULGGGmu3ivT2EbEoQujwhfJ9PE6nnfrRuetn891/4Dzaie06C2F+ XZir/wtOpza0GSWDhrvOTYVA+FbOVQXGAV/Kgmb9sNgF6XGzZC9XGXglDM0CTglx+tyj fhGbJKpCo+ttcwr45FkVdRyQuKLWAsf+o1nllDJCvto2Na4vO4CHGc0C3YY+o2GFNCbI 0Tdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GRn+BcO6FeGoTSD5hDHrCr+7jabb3BLGQPPVYCM3b/I=; b=pUjZKKQ0gX1NVOMgfjjel/QB0D0FkF41WcDjsDf9DP9V5t48Tfim7Eo8HEnwd5Ez2s y01Z2+ykcbJdm0CqjjF9RgSN8CbymGGZCD2M0Q96oeDH0SCxArCmdR2fuP+42Weoo88M T+GHJafhSs/eohqD45IHFUrHdNU0H0Cwq019C3LkRSrRuzl1HyG8WZhjcRLLODRpi+BN 8tD8vQG8/nFwqUBdGG27qQePZUDScrvNWdas4JxmDqeY7yRzWKceP9YcAh+c1C6TAyOI m94n+cXU52eaNUK7ZdUB+uB8+zCP/bAZWmPwpctzW4PKHAoO/PttaR9x1kpR9f0fJ0Qg y60A== X-Gm-Message-State: AFeK/H1YKmfBxMOyf52Hj3ANmTdTK3rYYfCtjNVEV01qv5yQ6Z/q7KwFoMegdSHrfqeOsXJm X-Received: by 10.223.172.55 with SMTP id v52mr1890126wrc.131.1490950084361; Fri, 31 Mar 2017 01:48:04 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id w130sm2054999wmg.0.2017.03.31.01.48.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 31 Mar 2017 01:48:03 -0700 (PDT) From: Neil Armstrong To: khilman@baylibre.com, carlo@caione.org Subject: [PATCH 1/3] soc: Add Amlogic SoC Information driver Date: Fri, 31 Mar 2017 10:47:57 +0200 Message-Id: <1490950079-10145-2-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490950079-10145-1-git-send-email-narmstrong@baylibre.com> References: <1490950079-10145-1-git-send-email-narmstrong@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170331_014826_383065_D8430CEF X-CRM114-Status: GOOD ( 19.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong 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 Amlogic SoCs have a SoC information register for SoC type, package type and revision information. This patchs adds support for this register decoding and exposing with the SoC bus infrastructure. Signed-off-by: Neil Armstrong --- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/amlogic/Kconfig | 12 +++ drivers/soc/amlogic/Makefile | 1 + drivers/soc/amlogic/meson-gx-socinfo.c | 158 +++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+) create mode 100644 drivers/soc/amlogic/Kconfig create mode 100644 drivers/soc/amlogic/Makefile create mode 100644 drivers/soc/amlogic/meson-gx-socinfo.c diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index f09023f..0b149a6 100644 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -1,5 +1,6 @@ menu "SOC (System On Chip) specific Drivers" +source "drivers/soc/amlogic/Kconfig" source "drivers/soc/bcm/Kconfig" source "drivers/soc/fsl/Kconfig" source "drivers/soc/mediatek/Kconfig" diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index 05eae52..4c0c776 100644 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_ARCH_DOVE) += dove/ obj-$(CONFIG_MACH_DOVE) += dove/ obj-y += fsl/ obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/ +obj-$(CONFIG_ARCH_MESON) += amlogic/ obj-$(CONFIG_ARCH_QCOM) += qcom/ obj-$(CONFIG_ARCH_RENESAS) += renesas/ obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ diff --git a/drivers/soc/amlogic/Kconfig b/drivers/soc/amlogic/Kconfig new file mode 100644 index 0000000..22acf06 --- /dev/null +++ b/drivers/soc/amlogic/Kconfig @@ -0,0 +1,12 @@ +menu "Amlogic SoC drivers" + +config MESON_GX_SOCINFO + bool "Amlogic Meson GX SoC Information driver" + depends on ARCH_MESON || COMPILE_TEST + default ARCH_MESON + select SOC_BUS + help + Say yes to support decoding of Amlogic Meson GX SoC family + information about the type, package and version. + +endmenu diff --git a/drivers/soc/amlogic/Makefile b/drivers/soc/amlogic/Makefile new file mode 100644 index 0000000..3e85fc4 --- /dev/null +++ b/drivers/soc/amlogic/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_MESON_GX_SOCINFO) += meson-gx-socinfo.o diff --git a/drivers/soc/amlogic/meson-gx-socinfo.c b/drivers/soc/amlogic/meson-gx-socinfo.c new file mode 100644 index 0000000..bfdc644 --- /dev/null +++ b/drivers/soc/amlogic/meson-gx-socinfo.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2017 BayLibre, SAS + * Author: Neil Armstrong + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include +#include + +#define SOCINFO_MAJOR_SHIFT 24 +#define SOCINFO_MINOR_SHIFT 16 +#define SOCINFO_PACK_SHIFT 8 +#define SOCINFO_MISC_SHIFT 0 +#define SOCINFO_MASK 0xff + +static const struct meson_gx_soc_id { + const char *name; + unsigned int id; +} soc_ids[] = { + { "GXBB", 0x1f }, + { "GXTVBB", 0x20 }, + { "GXL", 0x21 }, + { "GXM", 0x22 }, + { "TXL", 0x23 }, +}; + +static const struct meson_gx_package_id { + const char *name; + unsigned int major_id; + unsigned int pack_id; +} soc_packages[] = { + { "S905", 0x1f, 0 }, + { "S905M", 0x1f, 0x20 }, + { "S905D", 0x21, 0 }, + { "S905X", 0x21, 0x80 }, + { "S905L", 0x21, 0xc0 }, + { "S905M2", 0x21, 0xe0 }, + { "S912", 0x22, 0 }, +}; + +static inline unsigned int socinfo_to_major(u32 socinfo) +{ + return (socinfo >> SOCINFO_MAJOR_SHIFT) & SOCINFO_MASK; +} + +static inline unsigned int socinfo_to_minor(u32 socinfo) +{ + return (socinfo >> SOCINFO_MINOR_SHIFT) & SOCINFO_MASK; +} + +static inline unsigned int socinfo_to_pack(u32 socinfo) +{ + return (socinfo >> SOCINFO_PACK_SHIFT) & SOCINFO_MASK; +} + +static inline unsigned int socinfo_to_misc(u32 socinfo) +{ + return (socinfo >> SOCINFO_MISC_SHIFT) & SOCINFO_MASK; +} + +static const char *socinfo_to_package_id(u32 socinfo) +{ + unsigned int pack = socinfo_to_pack(socinfo) & 0xf0; + unsigned int major = socinfo_to_major(socinfo); + int i; + + for (i = 0 ; i < ARRAY_SIZE(soc_packages) ; ++i) { + if (soc_packages[i].major_id == major && + soc_packages[i].pack_id == pack) + return soc_packages[i].name; + } + + return "Unknown"; +} + +static const char *socinfo_to_soc_id(u32 socinfo) +{ + unsigned int id = socinfo_to_major(socinfo); + int i; + + for (i = 0 ; i < ARRAY_SIZE(soc_ids) ; ++i) { + if (soc_ids[i].id == id) + return soc_ids[i].name; + } + + return "Unknown"; +} + +int __init meson_gx_socinfo_init(void) +{ + struct soc_device_attribute *soc_dev_attr; + void __iomem *meson_gx_socinfo_base; + struct soc_device *soc_dev; + struct device_node *root; + struct device_node *np; + struct device *dev; + u32 socinfo; + + /* look up for socinfo node */ + np = of_find_compatible_node(NULL, NULL, "amlogic,meson-gx-socinfo"); + if (!np) + return -ENODEV; + + meson_gx_socinfo_base = of_iomap(np, 0); + of_node_put(np); + + if (!meson_gx_socinfo_base) { + pr_err("%s: failed to map socinfo\n", np->name); + return -ENOMEM; + } + + socinfo = readl_relaxed(meson_gx_socinfo_base); + iounmap(meson_gx_socinfo_base); + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return -ENODEV; + + soc_dev_attr->family = "Amlogic Meson"; + + root = of_find_node_by_path("/"); + of_property_read_string(root, "model", &soc_dev_attr->machine); + of_node_put(root); + + soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%x:%x - %x:%x", + socinfo_to_major(socinfo), + socinfo_to_minor(socinfo), + socinfo_to_pack(socinfo), + socinfo_to_misc(socinfo)); + soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%s (%s)", + socinfo_to_soc_id(socinfo), + socinfo_to_package_id(socinfo)); + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + kfree(soc_dev_attr->revision); + kfree_const(soc_dev_attr->soc_id); + kfree(soc_dev_attr); + return PTR_ERR(soc_dev); + } + dev = soc_device_to_device(soc_dev); + + dev_info(dev, "Amlogic Meson %s Revision %x:%x (%x:%x) Detected\n", + soc_dev_attr->soc_id, + socinfo_to_major(socinfo), + socinfo_to_minor(socinfo), + socinfo_to_pack(socinfo), + socinfo_to_misc(socinfo)); + + return 0; +} +core_initcall(meson_gx_socinfo_init);