From patchwork Sat Sep 23 14:14:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9967563 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 2346F602CB for ; Sat, 23 Sep 2017 14:15:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0957429496 for ; Sat, 23 Sep 2017 14:15:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEBDA294A0; Sat, 23 Sep 2017 14:14:59 +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, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED 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 267D129496 for ; Sat, 23 Sep 2017 14:14:58 +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=9ngjwMIo6K9RVco1hEATrV+nfD4mymmy/VynV+VX6Ro=; b=mwQD5+MbLEF79QjwOv/Z+Lj99j sWnJRoUd7RUgWB9nLfczSez2CdFdU16ZZNoLGBNjD9aWIdqsjEYc04s9hqiyHeiqDiETzczq2J+hT oZCFXqMkxaMyGRvHsgSuSgp2ope06brtFZEGaaaag1pJSfTS8pIrtYgJtj5EnkZP4B87QwO0yElj3 MEte36/vs6q3FTvzY/PQ5Q5YpBrpvVV16gPspc/gArVGqgGkaukpis05Q+w/Yed7UurSEOuN7NTW3 rF9XS+ZN1tXuntokzfazd+Z/CwdYrFGVIKraDZbOULXsnANO39PssW9UEBoReIBGbdsLZvWSC6NiZ AYnIM3gA==; 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 1dvlCi-0002t2-Qy; Sat, 23 Sep 2017 14:14:49 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dvlCd-0002ns-PW; Sat, 23 Sep 2017 14:14:46 +0000 Received: by mail-wm0-x244.google.com with SMTP id e64so3528538wmi.2; Sat, 23 Sep 2017 07:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QiFcMmyX1pRAHIZ4Y0+1m3M4L7jggYc2WD5N7sulxdM=; b=dMSzVSLjLV1JDC57cCua91edXc8r9yjnScGtWVfyptyDowh8e92rmZf5NZ8XSQvLKl 599xk6edLvY0BOhyUVQ83svZCKxBTePiHHF9jB0p85KgGMNzHZdHKG1h1avu8LrVCG2T 3u2vh5O7leWOLOlHnSVbi5ZRHGZsT9TKbqavRYQiGU/CS4fzWu+TBOpJN7RLmUZc559O XvZsPSaGwQ4PMN/Eigwfie3uCJos0zxqlMW4MIO6HWtaWxI3Xp8wsXRTs06noqYINxqd 8vsf5EWkXjdP9HqZkzCeDWkgDM4x/GpTPEp8srYoigqqY8/ijDWMeCNVGdl1VNM+Alc8 tU/g== 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=QiFcMmyX1pRAHIZ4Y0+1m3M4L7jggYc2WD5N7sulxdM=; b=Tq9GZXjc6eHnorZfvWGJuUNCqtYEEEwWElqfT96jcX5ev1ZUKbICsFWO4I1XqmP1c8 I09Rk52+P+LrCee0VcmLCCF/ERB5cIB9AzlyBXzeJQwm+lzV9rXAnBDYYnvh171VpmZ5 31dYdWAmb7ixx8CR0YxdmN6qZMsU30Tyr8H0MOz+rEd+Q0ktufMYblAkB4JBoZREVWmj pwJlH+C/22K2NlUvlDVZAaQuJ23k5Nz5WGJaf673kadE1zAgvDdZVRGssCNfxGlGEq1c grAKOC5s7G9o2ZdIS6eD+9mnCRbpcC+ddlfv/9Be9yCxI9FS3wKjTjeWPXvPkCYxw4tT B3YQ== X-Gm-Message-State: AHPjjUggrrMNgiaKcG+7qBzVRiAYjifQYSkT0CAPgX4HYGcdNWnwp9n3 tp6le6XF4TOZF7ltZnL1JTo= X-Google-Smtp-Source: AOwi7QBiHa7a0HAdZnHbB6wFgxRO69WOKSHv/ublFqwPSDVYsKjldTwg7w7jTBsyXH2FG8YUC6laTA== X-Received: by 10.28.61.139 with SMTP id k133mr5712503wma.84.1506176063783; Sat, 23 Sep 2017 07:14:23 -0700 (PDT) Received: from blackbox.darklights.net (p200300DCD3F644048154F1156768CB50.dip0.t-ipconnect.de. [2003:dc:d3f6:4404:8154:f115:6768:cb50]) by smtp.googlemail.com with ESMTPSA id t36sm3719702wrc.28.2017.09.23.07.14.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Sep 2017 07:14:23 -0700 (PDT) From: Martin Blumenstingl To: carlo@caione.org, khilman@baylibre.com, linux-arm-kernel@lists.infradead.org, linux-amlogic@lists.infradead.org, robh+dt@kernel.org, devicetree@vger.kernel.org Subject: [PATCH 2/3] soc: amlogic: Add Meson6/Meson8/Meson8b/Meson8m2 SoC Information driver Date: Sat, 23 Sep 2017 16:14:02 +0200 Message-Id: <20170923141403.20882-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170923141403.20882-1-martin.blumenstingl@googlemail.com> References: <20170923141403.20882-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170923_071444_087887_45346786 X-CRM114-Status: GOOD ( 15.90 ) 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: mark.rutland@arm.com, Martin Blumenstingl , linux@armlinux.org.uk, narmstrong@baylibre.com 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 an information register which contains the SoC type and revision information. This patchs adds support for decoding those registers and exposing the resulting information via the SoC bus infrastructure. Signed-off-by: Martin Blumenstingl --- drivers/soc/amlogic/Kconfig | 10 ++ drivers/soc/amlogic/Makefile | 1 + drivers/soc/amlogic/meson-mx-socinfo.c | 175 +++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 drivers/soc/amlogic/meson-mx-socinfo.c diff --git a/drivers/soc/amlogic/Kconfig b/drivers/soc/amlogic/Kconfig index 22acf064531f..ef0b8f6c53e0 100644 --- a/drivers/soc/amlogic/Kconfig +++ b/drivers/soc/amlogic/Kconfig @@ -9,4 +9,14 @@ config MESON_GX_SOCINFO Say yes to support decoding of Amlogic Meson GX SoC family information about the type, package and version. +config MESON_MX_SOCINFO + bool "Amlogic Meson MX SoC Information driver" + depends on ARCH_MESON || COMPILE_TEST + default ARCH_MESON + select SOC_BUS + help + Say yes to support decoding of Amlogic Meson6, Meson8, + Meson8b and Meson8m2 SoC family information about the type + and version. + endmenu diff --git a/drivers/soc/amlogic/Makefile b/drivers/soc/amlogic/Makefile index 3e85fc462c21..1f5df50ebd73 100644 --- a/drivers/soc/amlogic/Makefile +++ b/drivers/soc/amlogic/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_MESON_GX_SOCINFO) += meson-gx-socinfo.o +obj-$(CONFIG_MESON_MX_SOCINFO) += meson-mx-socinfo.o diff --git a/drivers/soc/amlogic/meson-mx-socinfo.c b/drivers/soc/amlogic/meson-mx-socinfo.c new file mode 100644 index 000000000000..7bfff5ff22a2 --- /dev/null +++ b/drivers/soc/amlogic/meson-mx-socinfo.c @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2017 Martin Blumenstingl + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MESON_SOCINFO_MAJOR_VER_MESON6 0x16 +#define MESON_SOCINFO_MAJOR_VER_MESON8 0x19 +#define MESON_SOCINFO_MAJOR_VER_MESON8B 0x1b + +#define MESON_MX_ASSIST_HW_REV 0x14c + +#define MESON_MX_ANALOG_TOP_METAL_REVISION 0x0 + +#define MESON_MX_BOOTROM_MISC_VER 0x4 + +static const char *meson_mx_socinfo_revision(unsigned int major_ver, + unsigned int misc_ver, + unsigned int metal_rev) +{ + unsigned int minor_ver; + + switch (major_ver) { + case MESON_SOCINFO_MAJOR_VER_MESON6: + minor_ver = 0xa; + break; + + case MESON_SOCINFO_MAJOR_VER_MESON8: + if (metal_rev == 0x11111112) + major_ver = 0x1d; + + if (metal_rev == 0x11111111 || metal_rev == 0x11111112) + minor_ver = 0xa; + else if (metal_rev == 0x11111113) + minor_ver = 0xb; + else if (metal_rev == 0x11111133) + minor_ver = 0xc; + else + minor_ver = 0xd; + + break; + + case MESON_SOCINFO_MAJOR_VER_MESON8B: + if (metal_rev == 0x11111111) + minor_ver = 0xa; + else + minor_ver = 0xb; + + break; + + default: + minor_ver = 0x0; + break; + } + + return kasprintf(GFP_KERNEL, "Rev%X (%x - 0:%X)", minor_ver, major_ver, + misc_ver); +} + +static const char *meson_mx_socinfo_soc_id(unsigned int major_ver, + unsigned int metal_rev) +{ + const char *soc_id; + + switch (major_ver) { + case MESON_SOCINFO_MAJOR_VER_MESON6: + soc_id = "Meson6 (AML8726-MX)"; + break; + + case MESON_SOCINFO_MAJOR_VER_MESON8: + if (metal_rev == 0x11111112) + soc_id = "Meson8m2 (S812)"; + else + soc_id = "Meson8 (S802)"; + + break; + + case MESON_SOCINFO_MAJOR_VER_MESON8B: + soc_id = "Meson8b (S805)"; + break; + + default: + soc_id = "Unknown"; + break; + } + + return kstrdup_const(soc_id, GFP_KERNEL); +} + +static const struct of_device_id meson_mx_socinfo_analog_top_ids[] = { + { .compatible = "amlogic,meson8-analog-top", }, + { .compatible = "amlogic,meson8b-analog-top", }, + { /* sentinel */ } +}; + +int __init meson_mx_socinfo_init(void) +{ + struct soc_device_attribute *soc_dev_attr; + struct soc_device *soc_dev; + struct device_node *np; + struct regmap *assist_regmap, *bootrom_regmap, *analog_top_regmap; + unsigned int major_ver, misc_ver, metal_rev = 0; + int ret; + + assist_regmap = + syscon_regmap_lookup_by_compatible("amlogic,meson-mx-assist"); + if (IS_ERR(assist_regmap)) + return PTR_ERR(assist_regmap); + + bootrom_regmap = + syscon_regmap_lookup_by_compatible("amlogic,meson-mx-bootrom"); + if (IS_ERR(bootrom_regmap)) + return PTR_ERR(bootrom_regmap); + + np = of_find_matching_node(NULL, meson_mx_socinfo_analog_top_ids); + if (np) { + analog_top_regmap = syscon_node_to_regmap(np); + if (IS_ERR(analog_top_regmap)) + return PTR_ERR(analog_top_regmap); + + ret = regmap_read(analog_top_regmap, + MESON_MX_ANALOG_TOP_METAL_REVISION, + &metal_rev); + if (ret) + return ret; + } + + ret = regmap_read(assist_regmap, MESON_MX_ASSIST_HW_REV, &major_ver); + if (ret < 0) + return ret; + + ret = regmap_read(bootrom_regmap, MESON_MX_BOOTROM_MISC_VER, + &misc_ver); + if (ret < 0) + return ret; + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return -ENODEV; + + soc_dev_attr->family = "Amlogic Meson"; + + np = of_find_node_by_path("/"); + of_property_read_string(np, "model", &soc_dev_attr->machine); + of_node_put(np); + + soc_dev_attr->revision = meson_mx_socinfo_revision(major_ver, misc_ver, + metal_rev); + soc_dev_attr->soc_id = meson_mx_socinfo_soc_id(major_ver, metal_rev); + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + kfree_const(soc_dev_attr->revision); + kfree_const(soc_dev_attr->soc_id); + kfree(soc_dev_attr); + return PTR_ERR(soc_dev); + } + + dev_info(soc_device_to_device(soc_dev), "Amlogic %s %s detected\n", + soc_dev_attr->soc_id, soc_dev_attr->revision); + + return 0; +} +device_initcall(meson_mx_socinfo_init);