From patchwork Thu Nov 3 21:34:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jonathan_Neusch=C3=A4fer?= X-Patchwork-Id: 15221 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a40e:b0:83:7221:86ba with SMTP id ck14csp1127874dyb; Thu, 3 Nov 2022 14:38:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5vqB7wvLsWeF56qzH+vLCSBHNOPBHmS9WVh6W27hRmTpa3EWPov0o+5266lYekXqD4G9GC X-Received: by 2002:a17:90a:3c8a:b0:213:8043:4b7f with SMTP id g10-20020a17090a3c8a00b0021380434b7fmr41427686pjc.99.1667511490413; Thu, 03 Nov 2022 14:38:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667511490; cv=none; d=google.com; s=arc-20160816; b=Bu1PugHuPmSAzrrjO2JgNVP721a5zj09LHktEQTmeQtNWb7BLepC3rA5MvKQVEqV2V XLIT992TLIi3DXv0tnNhyfIb8tkaI3qWsbw3A8SwhgkfAUR+FlE5/0wPEUY59+0hti4F ln/7zmum4gwJHYiSh8xVlVjTq6v23gPVFMgqec9E+bm4K2JAnoYZNXFFBRtH84/JSfCK hJQshAt3TfZ47+Z4ivpz/pjK4Rz2zJXt++RojTqcuN4j1ZZsWTHFA1cG3Vne+69aZ4H8 aaDcDf0xQucElnvPe4SNbeSbQ8P9SG3kAeA7fPPcljNBvfkr1mULS1t7W8ZN9ZbPmXHT D3cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=v5LJM2ee053CtPpr5M8taFU+gwsWXvsEfJyKRHoba9k=; b=i9TOlpYQvzdXGWYllH4DN+JiLeFdY/J8t1FFOvhsMkiMGyDOciewmvEP2MoVxcPPDl K+sSwW0viIVH9OoclNABNcqBPm8m/hAX+kBoAPvH+Xu1VmoKZ2SAhHvvS+ns46QXI1Pg 6S24iygTRaYQ9zPOZKkGmNHjZo2zVJUH0vL181fbul5yB2e/bC6Bozd7pEOJ+ym3VuIe k5xEaqbA+xEVdSk9U9eHlDCad4LoQyPRIKKoScbW8cTzWiHH0VYuS1NwcTtvh5qBz2qW UrK1KbtkoROyfAO+yBFm6KIqOikDK6H6JwJdEDNJKDO2muLic/F6qyZ+yvqDh1bPmdNQ wPfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=s31663417 header.b=ZtddkZuh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmx.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j190-20020a638bc7000000b004701d95bcf8si2380612pge.564.2022.11.03.14.37.58; Thu, 03 Nov 2022 14:38:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=s31663417 header.b=ZtddkZuh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmx.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231476AbiKCVfY (ORCPT + 99 others); Thu, 3 Nov 2022 17:35:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231688AbiKCVfL (ORCPT ); Thu, 3 Nov 2022 17:35:11 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BE94220E8 for ; Thu, 3 Nov 2022 14:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1667511277; bh=kzvI8y8uyM4os1o1QQC1oIapo3BRq4VS8eS4U1rhvTM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=ZtddkZuh3XHgOl8eSNEbAUrcTmwId+LG15klWehfO/WrvqNzcGNYuxdd4RYAeP6AR /vKBkDajkJXj8BXobe+5IwaRLF9/8gMCZ8ZDT1WsEdGFumuR/JATy/w4KPPoKr37iB xygbQff1BJdmbXhA0Zobt1biFtHk/INF8xs9mK3z3GhyP38RyAQuZZ2AsMX8SHA4r7 wCg5uBCtS+TbyPHonG73e8U0o9iEkiPKSwg3NgX80wJf72jGe2iG2zu1qvDIYP8Q0S JkRUVSUQ0BeqfEnKWytcnMR4ff3PupAVkyd6+G67YHGMSFXVStt06dJyAiw+FZXAwA amOnh5rktfkuw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from probook ([78.34.126.36]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mzyuc-1pCLTm3q0U-00x6sK; Thu, 03 Nov 2022 22:34:37 +0100 From: =?utf-8?q?Jonathan_Neusch=C3=A4fer?= To: openbmc@lists.ozlabs.org, Joel Stanley , Tomer Maimon Cc: =?utf-8?q?Jonathan_Neusch=C3=A4fer?= , Paul Menzel , Arnd Bergmann , Hitomi Hasegawa , Linus Walleij , Conor Dooley , Hector Martin , Robert Jarzmik , Nicolas Ferre , Brian Norris , Sven Peter , linux-kernel@vger.kernel.org Subject: [PATCH v6] soc: nuvoton: Add SoC info driver for WPCM450 Date: Thu, 3 Nov 2022 22:34:15 +0100 Message-Id: <20221103213420.1395507-1-j.neuschaefer@gmx.net> X-Mailer: git-send-email 2.35.1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OvKfAvMgZ/3DZkXRUP5j0xwZL 7ll2nQuKS3Gx56q6WC9R1A6ZihYPoKKA8kC5ObgH97GcBPDnm9JDbFOeZQN8EagmS9nRoK/jB XR5ZSErZnz04HIiqI1lKymGfyH4+5g+d1sv0FrLltuhieLKwBgyMED0+2Ok6YOanLifcTlZxI SKezQw== X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748245018621768045?= X-GMAIL-MSGID: =?utf-8?q?1748512528595767549?= Add a SoC information driver for Nuvoton WPCM450 SoCs. It provides information such as the SoC revision. Usage example: # grep . /sys/devices/soc0/* /sys/devices/soc0/family:Nuvoton NPCM /sys/devices/soc0/revision:A3 /sys/devices/soc0/soc_id:WPCM450 Signed-off-by: Jonathan Neuschäfer Reviewed-by: Joel Stanley Reviewed-by: Paul Menzel --- v6: - Select REGMAP - Rearrange Kconfig structure a bit v5: - Change Kconfig option from bool to tristate v4: - rebase on 5.19-rc1 v3: - Declare revisions array as static - Change get_revision parameter to `unsigned int` - Add Paul's R-b tag - Add usage example - Sort includes v2: - https://lore.kernel.org/lkml/20220409173319.2491196-1-j.neuschaefer@gmx.net/ - Add R-b tag - rebase on 5.18-rc1 v1: - https://lore.kernel.org/lkml/20220129143316.2321460-1-j.neuschaefer@gmx.net/ --- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/nuvoton/Kconfig | 17 +++++ drivers/soc/nuvoton/Makefile | 2 + drivers/soc/nuvoton/wpcm450-soc.c | 109 ++++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 drivers/soc/nuvoton/Kconfig create mode 100644 drivers/soc/nuvoton/Makefile create mode 100644 drivers/soc/nuvoton/wpcm450-soc.c -- 2.35.1 diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index e461c071189b4..f17764a7e5884 100644 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -15,6 +15,7 @@ source "drivers/soc/ixp4xx/Kconfig" source "drivers/soc/litex/Kconfig" source "drivers/soc/mediatek/Kconfig" source "drivers/soc/microchip/Kconfig" +source "drivers/soc/nuvoton/Kconfig" source "drivers/soc/pxa/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index 69ba6508cf2c1..9f92506854852 100644 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -20,6 +20,7 @@ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-$(CONFIG_LITEX_SOC_CONTROLLER) += litex/ obj-y += mediatek/ obj-y += microchip/ +obj-y += nuvoton/ obj-y += pxa/ obj-y += amlogic/ obj-y += qcom/ diff --git a/drivers/soc/nuvoton/Kconfig b/drivers/soc/nuvoton/Kconfig new file mode 100644 index 0000000000000..2167d3d739d84 --- /dev/null +++ b/drivers/soc/nuvoton/Kconfig @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 +menu "Nuvoton SoC drivers" + depends on ARCH_NPCM || COMPILE_TEST + +config WPCM450_SOC + tristate "Nuvoton WPCM450 SoC driver" + default y if ARCH_WPCM450 + select SOC_BUS + select REGMAP + help + Say Y here to compile the SoC information driver for Nuvoton + WPCM450 SoCs. + + This driver provides information such as the SoC model and + revision. + +endmenu diff --git a/drivers/soc/nuvoton/Makefile b/drivers/soc/nuvoton/Makefile new file mode 100644 index 0000000000000..e30317b4e8290 --- /dev/null +++ b/drivers/soc/nuvoton/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_WPCM450_SOC) += wpcm450-soc.o diff --git a/drivers/soc/nuvoton/wpcm450-soc.c b/drivers/soc/nuvoton/wpcm450-soc.c new file mode 100644 index 0000000000000..c5e0d11c383b1 --- /dev/null +++ b/drivers/soc/nuvoton/wpcm450-soc.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Nuvoton WPCM450 SoC Identification + * + * Copyright (C) 2022 Jonathan Neuschäfer + */ + +#include +#include +#include +#include +#include + +#define GCR_PDID 0 +#define PDID_CHIP(x) ((x) & 0x00ffffff) +#define CHIP_WPCM450 0x926450 +#define PDID_REV(x) ((x) >> 24) + +struct revision { + u8 number; + const char *name; +}; + +static const struct revision revisions[] __initconst = { + { 0x00, "Z1" }, + { 0x03, "Z2" }, + { 0x04, "Z21" }, + { 0x08, "A1" }, + { 0x09, "A2" }, + { 0x0a, "A3" }, + {} +}; + +static const char * __init get_revision(unsigned int rev) +{ + int i; + + for (i = 0; revisions[i].name; i++) + if (revisions[i].number == rev) + return revisions[i].name; + return NULL; +} + +static struct soc_device_attribute *wpcm450_attr; +static struct soc_device *wpcm450_soc; + +static int __init wpcm450_soc_init(void) +{ + struct soc_device_attribute *attr; + struct soc_device *soc; + const char *revision; + struct regmap *gcr; + u32 pdid; + int ret; + + if (!of_machine_is_compatible("nuvoton,wpcm450")) + return 0; + + gcr = syscon_regmap_lookup_by_compatible("nuvoton,wpcm450-gcr"); + if (IS_ERR(gcr)) + return PTR_ERR(gcr); + ret = regmap_read(gcr, GCR_PDID, &pdid); + if (ret) + return ret; + + if (PDID_CHIP(pdid) != CHIP_WPCM450) { + pr_warn("Unknown chip ID in GCR.PDID: 0x%06x\n", PDID_CHIP(pdid)); + return -ENODEV; + } + + revision = get_revision(PDID_REV(pdid)); + if (!revision) { + pr_warn("Unknown chip revision in GCR.PDID: 0x%02x\n", PDID_REV(pdid)); + return -ENODEV; + } + + attr = kzalloc(sizeof(*attr), GFP_KERNEL); + if (!attr) + return -ENOMEM; + + attr->family = "Nuvoton NPCM"; + attr->soc_id = "WPCM450"; + attr->revision = revision; + soc = soc_device_register(attr); + if (IS_ERR(soc)) { + kfree(attr); + pr_warn("Could not register SoC device\n"); + return PTR_ERR(soc); + } + + wpcm450_soc = soc; + wpcm450_attr = attr; + return 0; +} +module_init(wpcm450_soc_init); + +static void __exit wpcm450_soc_exit(void) +{ + if (wpcm450_soc) { + soc_device_unregister(wpcm450_soc); + wpcm450_soc = NULL; + kfree(wpcm450_attr); + } +} +module_exit(wpcm450_soc_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Jonathan Neuschäfer"); +MODULE_DESCRIPTION("Nuvoton WPCM450 SoC Identification driver");