Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1658269rdb; Sun, 19 Nov 2023 05:27:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsisvcwrODHovTKKVZCjUYM0lwvufB1Ce5P6baLpu0zRNWhduLth5Uf3mou7+Mn9DPk+IH X-Received: by 2002:a17:902:d389:b0:1cc:2f90:6291 with SMTP id e9-20020a170902d38900b001cc2f906291mr5290573pld.54.1700400425487; Sun, 19 Nov 2023 05:27:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700400425; cv=none; d=google.com; s=arc-20160816; b=AafPJ3PyKAMGHCDpNFmMBkNEWpJe4N8aqEqdWHn3Trwn5HUHcQVFsy1r8MRs8kpHxF ywpJG92Hot7m3n8xO8yXzc2IzgpIvdeJJAWiS2/b/Tua5EluSb3W0sP8Tr9Ta+DjvZ1w ypnLOCKUOpHN8nMzjzIVHI8tihPtlLNQV/SLRTcft+MuV2Etv7Er6Y5iCYcr7gplkGXY tgXDiMg/rVyEhEP/jS3+bb3q2PJ2njI15zyyhDhkYtWIrlFZyy9frOGm96mOWT6EGm8g NVQp2vXP0F2UTmcHM+hNSXPCx332jw+KPDaUkxaqbEnTfXRic0xTSvJyni1urH6HkVkO VX1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SZd4IRfLpSa8hoG/U23WMQ9clOZkCDCszxuVLz+2Ghs=; fh=QOXzc0jzHScFsS/HivTQq27dVg7pcIBOIWuB/9pJlTU=; b=ujM+iAsBeuGMNhxEJZ25nvWcwCW7TmUoHSq/K0bjgrTdugcOSioq7UAxCaajmoyqfT CqbLi94B9HsR8496mAOI9KdjOdKp48IeOTsurkUxihaYyWauI2WP28LO9ZxBRlyGpnzw VPbe2Z6YTAv+kWzHLjjrd3ex6r+v0tPZfGYAQFaI4UgcjvN6rfBvldHavrFSrfH5f3Ff lhPYjoF0v4SNf9pbiiIYEci5jYRdo8ACEFAPg83mrBtulm2MOp9km63SBaUBfzTx6LsZ y5KjAJUIQlL3KQFoU+aUoGT5sgFBqRo8obxJxQM+GBiZAwtG5c5vNbXhisj7VzlIaqC5 YKJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oLTZp+OH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id b38-20020a630c26000000b005b01279150fsi6112878pgl.528.2023.11.19.05.27.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 05:27:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oLTZp+OH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 6A2E38082B9C; Sun, 19 Nov 2023 05:26:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231324AbjKSN0H (ORCPT + 99 others); Sun, 19 Nov 2023 08:26:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231298AbjKSN0D (ORCPT ); Sun, 19 Nov 2023 08:26:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F075C2 for ; Sun, 19 Nov 2023 05:26:00 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBB94C433C7; Sun, 19 Nov 2023 13:25:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700400359; bh=gn56HK2d1OyTTEnjGs+yYxtFyImiBagPEv90zBmniFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oLTZp+OHJtnhUROcIaDB4jhD9RrNHCEhHnfAWQQxyYURjFadduuvoaO3BWrfdFnjY 1/fiM4Y3bPBexCvrmCyJ5wg56/23OwBF46k27Q9R0mS0xCMcmqgSiULEWr+8pPJjrq GrUz5kAVVgQKIQzhb/cUzAeZbOEFZqjmI/AkR0i/zCPlVEOx7q8fJVkjwnIId4vBtx H1Bwz7LR097OfmJCam7jext9XkfuSwMkPSWcadp6eSK/V1zp3tuXbtQdOlNQGIvBbb n4fjHW5bQAAtnkzJNjLNK6zIA7MCcsRKrz6P7KljeyrNy13f6bdbYT+26R47W1y4wl 6Z/2Kl35JMTUg== From: Jisheng Zhang To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Chao Wei , Chen Wang Subject: [PATCH 2/2] nvmem: Add Sophgo eFuse driver Date: Sun, 19 Nov 2023 21:13:32 +0800 Message-Id: <20231119131332.999-3-jszhang@kernel.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20231119131332.999-1-jszhang@kernel.org> References: <20231119131332.999-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 19 Nov 2023 05:26:40 -0800 (PST) Sophgo SoCs such as CV1800B contain eFuses used to store factory-programmed data such as calibration values for the built-in ethernet PHY. As for CV1800B, HW automatically loads the eFuse content into CONTENT base registers which are organized as 32bit values exposed as MMIO. Currently, add read support for the eFuse. This is a preparation step for supporting the built-in ethernet phy. Signed-off-by: Jisheng Zhang --- drivers/nvmem/Kconfig | 13 +++++ drivers/nvmem/Makefile | 2 + drivers/nvmem/sophgo-efuse.c | 97 ++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 drivers/nvmem/sophgo-efuse.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 5bc9c4874fe3..f2de7338c6e9 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -298,6 +298,19 @@ config NVMEM_SNVS_LPGPR This driver can also be built as a module. If so, the module will be called nvmem-snvs-lpgpr. +config NVMEM_SOPHGO_EFUSE + tristate "Sophgo eFuse support" + depends on ARCH_SOPHGO || COMPILE_TEST + default ARCH_SOPHGO + help + Say y here to enable support for reading eFuses on Sophgo SoCs + such as the CV1800B. These are e.g. used to store factory programmed + calibration data required for the builtin ethernet PHY. + + This driver can also be built as a module. If so, the module will + be called nvmem-sophgo-efuse. + + config NVMEM_SPMI_SDAM tristate "SPMI SDAM Support" depends on SPMI diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 423baf089515..f3602bb16efc 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -60,6 +60,8 @@ obj-$(CONFIG_NVMEM_SC27XX_EFUSE) += nvmem-sc27xx-efuse.o nvmem-sc27xx-efuse-y := sc27xx-efuse.o obj-$(CONFIG_NVMEM_SNVS_LPGPR) += nvmem_snvs_lpgpr.o nvmem_snvs_lpgpr-y := snvs_lpgpr.o +obj-$(CONFIG_NVMEM_SOPHGO_EFUSE) += nvmem-sophgo-efuse.o +nvmem-sophgo-efuse-y := sophgo-efuse.o obj-$(CONFIG_NVMEM_SPMI_SDAM) += nvmem_qcom-spmi-sdam.o nvmem_qcom-spmi-sdam-y += qcom-spmi-sdam.o obj-$(CONFIG_NVMEM_SPRD_EFUSE) += nvmem_sprd_efuse.o diff --git a/drivers/nvmem/sophgo-efuse.c b/drivers/nvmem/sophgo-efuse.c new file mode 100644 index 000000000000..3b4eb4d097e3 --- /dev/null +++ b/drivers/nvmem/sophgo-efuse.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Sophgo SoC eFuse driver + * + * Copyright (C) 2023 Jisheng Zhang + */ + +#include +#include +#include +#include +#include +#include + +#define CV1800B_EFUSE_CONTENT_BASE 0x100 +#define CV1800B_EFUSE_CONTENT_SIZE 0x100 + +struct sophgo_efuses_priv { + void __iomem *base; + struct clk *clk; +}; + +static int sophgo_efuses_read(void *context, unsigned int offset, void *val, + size_t bytes) +{ + struct sophgo_efuses_priv *priv = context; + u32 *dst = val; + int ret; + + ret = clk_prepare_enable(priv->clk); + if (ret < 0) + return ret; + + while (bytes >= sizeof(u32)) { + *dst++ = readl_relaxed(priv->base + CV1800B_EFUSE_CONTENT_BASE + offset); + bytes -= sizeof(u32); + offset += sizeof(u32); + } + + clk_disable_unprepare(priv->clk); + + return 0; +} + +static int sophgo_efuses_probe(struct platform_device *pdev) +{ + struct sophgo_efuses_priv *priv; + struct resource *res; + struct nvmem_config config = { + .dev = &pdev->dev, + .add_legacy_fixed_of_cells = true, + .read_only = true, + .reg_read = sophgo_efuses_read, + .stride = sizeof(u32), + .word_size = sizeof(u32), + .name = "sophgo_efuse_nvmem", + .id = NVMEM_DEVID_AUTO, + .root_only = true, + }; + + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(priv->base)) + return PTR_ERR(priv->base); + + priv->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(priv->clk)) + return PTR_ERR(priv->clk); + + config.priv = priv; + config.size = CV1800B_EFUSE_CONTENT_SIZE; + + return PTR_ERR_OR_ZERO(devm_nvmem_register(config.dev, &config)); +} + +static const struct of_device_id sophgo_efuses_of_match[] = { + { .compatible = "sophgo,cv1800b-efuse", }, + {} +}; + +MODULE_DEVICE_TABLE(of, sophgo_efuses_of_match); + +static struct platform_driver sophgo_efuses_driver = { + .driver = { + .name = "sophgo_efuse", + .of_match_table = sophgo_efuses_of_match, + }, + .probe = sophgo_efuses_probe, +}; + +module_platform_driver(sophgo_efuses_driver); + +MODULE_AUTHOR("Jisheng Zhang "); +MODULE_LICENSE("GPL"); -- 2.42.0