From patchwork Tue Jun 23 02:50:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 11619615 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A13B6C1 for ; Tue, 23 Jun 2020 02:53:56 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E8B6520786 for ; Tue, 23 Jun 2020 02:53:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rUfGN3En"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="jjMY3ise" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E8B6520786 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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=H3FeH7jUheRQANNZmKkbaYwQTPGd9QFXhCkdQzpID5I=; b=rUfGN3EnScAwmKJX9dtm9DQqj C9C/rRFay7a7Mwb3PSXKpPg2qCuEGV+M6vMaqGauOwM4R1Knaorj6CZLrij5NWq+EKzc8SPBu1ktQ rXf7LAglKv33R/BgkWoUmYZuBMg4UMaBE1Mgm48nNJpsnHioA8EZTut+i6QZgXGlUTGBR2G9JziwE kPtE/VkGf73rXjwt7udgko4LyhpMKA25iCkxz96NgbWUQ1yHixjGWcKGdpZJJcMZGnW4mFAYViOvE mz/NUzUEYB/5+sgn45o3ZH7e6mtBXMrvSs41K6O8CUlMHhQ1zIB0Lt4CEbMsopsMl653eDvkQx77l kz3jdnlqw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnZ2O-0001ua-HD; Tue, 23 Jun 2020 02:51:52 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnZ2L-0001tO-Po; Tue, 23 Jun 2020 02:51:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description; bh=MwE8yDT91XWz8mRuonx7XLJE7vkMreGgxn9fHNLQroo=; b=jjMY3ise9ODOVZ/Ov+j8ouqxUD 6UB0I6OSm3MBHY9JqX9aRbsuLUb+vxIgRWp6SucMjdtA2yL8FmVkA1ujvG2KXD/SSet0/g3OaOekZ ulblFKp8vX9xI4b/fSKPMXjDKjVWmgD4i3qhdMZe5Akg4eGrwQb9L0dB1U1zpIeHEqE3l6vAlXZBe VEswJ4fay7h9nQ66mSiEtISYGD1f6ObADGwcGlyQV8J7bll5iVGkeLjM04lZyYFhEctnp98mY0T4y t1820CAuvBU1+sVVmfqWki642jsbUWVjfOfMBv81PGP/mv0WAk5mLdYijREE0qw4Irsp/8AeoUHaD FosPTb6w==; Received: from mx2.suse.de ([195.135.220.15]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnZ2I-0005NZ-GZ; Tue, 23 Jun 2020 02:51:49 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6AA97AE71; Tue, 23 Jun 2020 02:51:30 +0000 (UTC) From: =?utf-8?q?Andreas_F=C3=A4rber?= To: linux-realtek-soc@lists.infradead.org Subject: [PATCH v2 02/29] soc: Add Realtek DHC chip info driver for RTD1195 and RTD1295 Date: Tue, 23 Jun 2020 04:50:39 +0200 Message-Id: <20200623025106.31273-3-afaerber@suse.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200623025106.31273-1-afaerber@suse.de> References: <20200623025106.31273-1-afaerber@suse.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200623_035146_704604_C1BE6C18 X-CRM114-Status: GOOD ( 21.59 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-4.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [195.135.220.15 listed in wl.mailspike.net] -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [195.135.220.15 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?b?SmFtZXMgVGFpIFvmiLTlv5fls7Bd?= , Edgar Lee , linux-kernel@vger.kernel.org, =?utf-8?b?U3RhbmxleSBDaGFuZyBb5piM6IKy5b63XQ==?= , =?utf-8?q?Andreas_F=C3=A4rber?= , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add a soc bus driver to print chip model and revision details. Revisions from downstream drivers/soc/realtek/rtd{119x,129x}/rtk_chip.c. Signed-off-by: Andreas Färber Tested-by: Stanley Chang Reviewed-by: Stanley Chang --- v1 -> v2: * Added entry to MAINTAINERS * Changed chip_id and chip_rev from u32 to u16, based on reg field definitions * Added error return path for get_name for deferred probing, reordered code MAINTAINERS | 1 + drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/realtek/Kconfig | 13 +++ drivers/soc/realtek/Makefile | 2 + drivers/soc/realtek/chip.c | 181 +++++++++++++++++++++++++++++++++++ 6 files changed, 199 insertions(+) create mode 100644 drivers/soc/realtek/Kconfig create mode 100644 drivers/soc/realtek/Makefile create mode 100644 drivers/soc/realtek/chip.c diff --git a/MAINTAINERS b/MAINTAINERS index 78adbc3cc101..ff0ee48fee6f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2311,6 +2311,7 @@ F: Documentation/devicetree/bindings/soc/realtek/ F: arch/arm/boot/dts/rtd* F: arch/arm/mach-realtek/ F: arch/arm64/boot/dts/realtek/ +F: drivers/soc/realtek/ ARM/RENESAS ARM64 ARCHITECTURE M: Geert Uytterhoeven diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index 425ab6f7e375..925647993119 100644 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -11,6 +11,7 @@ source "drivers/soc/imx/Kconfig" source "drivers/soc/ixp4xx/Kconfig" source "drivers/soc/mediatek/Kconfig" source "drivers/soc/qcom/Kconfig" +source "drivers/soc/realtek/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig" source "drivers/soc/samsung/Kconfig" diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index 36452bed86ef..cdcf00bbad10 100644 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -17,6 +17,7 @@ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-y += mediatek/ obj-y += amlogic/ obj-y += qcom/ +obj-y += realtek/ obj-y += renesas/ obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/ obj-$(CONFIG_SOC_SAMSUNG) += samsung/ diff --git a/drivers/soc/realtek/Kconfig b/drivers/soc/realtek/Kconfig new file mode 100644 index 000000000000..be75c1889c61 --- /dev/null +++ b/drivers/soc/realtek/Kconfig @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +if ARCH_REALTEK || COMPILE_TEST + +config REALTEK_SOC + tristate "Realtek chip info" + default ARCH_REALTEK + select SOC_BUS + help + Say 'y' here to enable support for SoC info on Realtek RTD1195 and + RTD1295 SoC families. + If unsure, say 'n'. + +endif diff --git a/drivers/soc/realtek/Makefile b/drivers/soc/realtek/Makefile new file mode 100644 index 000000000000..49900273905b --- /dev/null +++ b/drivers/soc/realtek/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +obj-$(CONFIG_REALTEK_SOC) += chip.o diff --git a/drivers/soc/realtek/chip.c b/drivers/soc/realtek/chip.c new file mode 100644 index 000000000000..c4650d512c91 --- /dev/null +++ b/drivers/soc/realtek/chip.c @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Realtek Digital Home Center System-on-Chip info + * + * Copyright (c) 2017-2020 Andreas Färber + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define REG_SB2_CHIP_ID 0x200 +#define REG_SB2_CHIP_INFO 0x204 + +#define SB2_CHIP_ID_CHIP_ID GENMASK(15, 0) + +#define SB2_CHIP_INFO_REVISE_ID GENMASK(31, 16) + +struct dhc_soc_revision { + const char *name; + u16 chip_rev; +}; + +static const struct dhc_soc_revision rtd1195_revisions[] = { + { "A", 0x0000 }, + { "B", 0x0001 }, + { "C", 0x0002 }, + { "D", 0x0003 }, + { } +}; + +static const struct dhc_soc_revision rtd1295_revisions[] = { + { "A00", 0x0000 }, + { "A01", 0x0001 }, + { "B00", 0x0002 }, + { "B01", 0x0003 }, + { } +}; + +struct dhc_soc { + u16 chip_id; + const char *family; + const char *(*get_name)(struct device *dev, const struct dhc_soc *s); + const struct dhc_soc_revision *revisions; + const char *codename; +}; + +static const char *default_name(struct device *dev, const struct dhc_soc *s) +{ + return s->family; +} + +static const struct dhc_soc dhc_soc_families[] = { + { 0x6329, "RTD1195", default_name, rtd1195_revisions, "Phoenix" }, + { 0x6421, "RTD1295", default_name, rtd1295_revisions, "Kylin" }, +}; + +static const struct dhc_soc *dhc_soc_by_chip_id(u16 chip_id) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(dhc_soc_families); i++) { + const struct dhc_soc *family = &dhc_soc_families[i]; + + if (family->chip_id == chip_id) + return family; + } + return NULL; +} + +static const char *dhc_soc_rev(const struct dhc_soc *family, u16 chip_rev) +{ + if (family) { + const struct dhc_soc_revision *rev = family->revisions; + + while (rev && rev->name) { + if (rev->chip_rev == chip_rev) + return rev->name; + rev++; + } + } + return "unknown"; +} + +static int dhc_soc_probe(struct platform_device *pdev) +{ + const struct dhc_soc *s; + struct soc_device_attribute *soc_dev_attr; + struct soc_device *soc_dev; + struct device_node *node; + struct regmap *regmap; + u16 chip_id, chip_rev; + unsigned int val; + int ret; + + regmap = syscon_node_to_regmap(pdev->dev.of_node->parent); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + ret = regmap_read(regmap, REG_SB2_CHIP_ID, &val); + if (ret) + return ret; + chip_id = FIELD_GET(SB2_CHIP_ID_CHIP_ID, val); + + ret = regmap_read(regmap, REG_SB2_CHIP_INFO, &val); + if (ret) + return ret; + chip_rev = FIELD_GET(SB2_CHIP_INFO_REVISE_ID, val); + + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL); + if (!soc_dev_attr) + return -ENOMEM; + + node = of_find_node_by_path("/"); + of_property_read_string(node, "model", &soc_dev_attr->machine); + of_node_put(node); + + s = dhc_soc_by_chip_id(chip_id); + + if (likely(s && s->get_name)) { + soc_dev_attr->soc_id = s->get_name(&pdev->dev, s); + if (IS_ERR(soc_dev_attr->soc_id)) + return PTR_ERR(soc_dev_attr->soc_id); + } else + soc_dev_attr->soc_id = "unknown"; + + soc_dev_attr->revision = dhc_soc_rev(s, chip_rev); + + soc_dev_attr->family = kasprintf(GFP_KERNEL, "Realtek %s", + (s && s->codename) ? s->codename : + ((s && s->family) ? s->family : "Digital Home Center")); + + soc_dev = soc_device_register(soc_dev_attr); + if (IS_ERR(soc_dev)) { + kfree(soc_dev_attr->family); + kfree(soc_dev_attr); + return PTR_ERR(soc_dev); + } + + platform_set_drvdata(pdev, soc_dev); + + pr_info("%s %s (0x%04x) rev %s (0x%04x) detected\n", + soc_dev_attr->family, soc_dev_attr->soc_id, (u32)chip_id, + soc_dev_attr->revision, (u32)chip_rev); + + return 0; +} + +static int dhc_soc_remove(struct platform_device *pdev) +{ + struct soc_device *soc_dev = platform_get_drvdata(pdev); + + soc_device_unregister(soc_dev); + + return 0; +} + +static const struct of_device_id dhc_soc_dt_ids[] = { + { .compatible = "realtek,rtd1195-chip" }, + { } +}; + +static struct platform_driver dhc_soc_driver = { + .probe = dhc_soc_probe, + .remove = dhc_soc_remove, + .driver = { + .name = "dhc-soc", + .of_match_table = dhc_soc_dt_ids, + }, +}; +module_platform_driver(dhc_soc_driver); + +MODULE_DESCRIPTION("Realtek DHC SoC identification driver"); +MODULE_LICENSE("GPL");