From patchwork Sun Apr 10 13:54:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Peter X-Patchwork-Id: 12808157 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7745C433EF for ; Sun, 10 Apr 2022 13:56:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CAjyoopPO/i9aQqVZHuZDe8e1R9JN0iiZo+a/UjSqXg=; b=29fTWm8tarRg8M V6sUN7i9GV2/MUYBfXabVRuaJ8kxwUiIGQOHrCbPG/Gt8sUTrX9AB4lP4Nm3y+VsnTdjYob4PTa7T 5ftYEBKyTNFLFefTz9YZw9zYjzOvklQx9zrlOyd4h7dMGXIorNmD52CF1p9gpIgniLivcwY8HlxAt z2qWjUlHPBGsBjWDZbln2UvC6PPPwOC40w92UxbfaLot5w4C/KYoT+2jfBdW6ymQZvqObnqiOZvVK U5mndkEvFVwDkb2Ewtfxmbwy/CdZZ7cJfqXFhxjX3o/k/9zES8ezpe2fqm+C//XaaFGfV1WuYNYjy Ov13+MoGL75H4dFlr+BA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndY1h-004uJ1-KH; Sun, 10 Apr 2022 13:54:49 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ndY1N-004uCr-42 for linux-arm-kernel@lists.infradead.org; Sun, 10 Apr 2022 13:54:32 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 8345A5C00F9; Sun, 10 Apr 2022 09:54:26 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Sun, 10 Apr 2022 09:54:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=cc:cc:content-transfer-encoding:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; bh=Ra2f5OVvum6qyC ydfuFWdYT4SYyCGdf7Q2RUJs0cQhY=; b=FSdu5GymRcPlnjOkH4jXL+KBZVD9Ot ZkAeLxgjSMlRDTVUVK7o2UKWoySzFROYPDYPb9XGV+pTGeY7CbC2biPO2INsDeIT J/49tu2KfeNnZwzVkPvYJsqZc53FJ7fZiz7+TE5Q96qgEszQkvAuLzRN//0upvUh 2VMumYNdpRJ70gyDc24nJbKZauHKkVGhmvcd1PWbCyZGO4pWCZ1T9G9t/pVLEGzC S0rmJSFRO9nc54+zpKKKBXbNFWM87aRl+qAavUy2MybUdtYY4jRCcghyhFpvugJC Py4nYyIEYnl+29QnyHUw+CGtX7o6uU+6bQoy9vxOmqmCjVkU2ab2NmMg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=Ra2f5O Vvum6qyCydfuFWdYT4SYyCGdf7Q2RUJs0cQhY=; b=nys6of3i69rmu2dpmwQ4eO iqI7CqFlToo0BAcAMluwurS3c4UHgotzxI47SIIw/1BdMNyzGxzInye75pzXXJjU LiZNKxXM+CcGLo5AxT7tUQhIATIVjAT/2di14HT7OUiuNcvsNvMd1ln9PefK8jYy 4+4/N5N6DOyNTGD6WFH9aGuuIeYJPMCjydnBWdj5Tk6a2cWoD3a+pDzVzZbiQ8oT JZfXATF0qMl6qxEUyWnsA5xkSHKUCyjWAQZCrdLOQ8GRNZl8Md0luM5Zm159Q3Tz HU0qXz1HoWbjJwzl/NzQv/fAxBHFcImkETx02OC67fUwxYPhlQOHXCmnRbFzx/JQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudekgedgieejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefuvhgvnhcu rfgvthgvrhcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrfgrthhtvg hrnheptedvkeetleeuffffhfekteetffeggffgveehieelueefvddtueffveevlefhfeej necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshhvvg hnsehsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 10 Apr 2022 09:54:24 -0400 (EDT) From: Sven Peter To: Srinivas Kandagatla Cc: Sven Peter , Rob Herring , Krzysztof Kozlowsk , Joey Gouly , Hector Martin , Alyssa Rosenzweig , Mark Kettenis , linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/3] nvmem: Add Apple eFuse driver Date: Sun, 10 Apr 2022 15:54:14 +0200 Message-Id: <20220410135414.20606-3-sven@svenpeter.dev> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20220410135414.20606-1-sven@svenpeter.dev> References: <20220410135414.20606-1-sven@svenpeter.dev> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220410_065429_332032_EDF9F555 X-CRM114-Status: GOOD ( 20.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Apple SoCs contain eFuses used to store factory-programmed data such as calibration values for the PCIe or the Type-C PHY. They are organized as 32bit values exposed as MMIO. Signed-off-by: Sven Peter --- v3 -> v4: - rebased on 5.18-rc1 and split off MAINTAINER changes as requested by Srinivas Kandagatla v2 -> v3: - removed .owner = THIS_MODULE again since it's already done by the core as pointed out by Krzysztof Kozlowski v1 -> v2: - fixed sparse warning about __iomem by introducing struct apple_efuses_priv as done in other nvmem drivers - make sure the driver actually works as a module by setting .owner to THIS_MODULE and adding MODULE_DEVICE_TABLE pointed out by Joey Gouly drivers/nvmem/Kconfig | 12 ++++++ drivers/nvmem/Makefile | 2 + drivers/nvmem/apple-efuses.c | 80 ++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 drivers/nvmem/apple-efuses.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 555aa77a574d..6283e09cc1e9 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -324,4 +324,16 @@ config NVMEM_SUNPLUS_OCOTP This driver can also be built as a module. If so, the module will be called nvmem-sunplus-ocotp. +config NVMEM_APPLE_EFUSES + tristate "Apple eFuse support" + depends on ARCH_APPLE || COMPILE_TEST + default ARCH_APPLE + help + Say y here to enable support for reading eFuses on Apple SoCs + such as the M1. These are e.g. used to store factory programmed + calibration data required for the PCIe or the USB-C PHY. + + This driver can also be built as a module. If so, the module will + be called nvmem-apple-efuses. + endif diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 891958e29d25..00e136a0a123 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -65,3 +65,5 @@ obj-$(CONFIG_NVMEM_LAYERSCAPE_SFP) += nvmem-layerscape-sfp.o nvmem-layerscape-sfp-y := layerscape-sfp.o obj-$(CONFIG_NVMEM_SUNPLUS_OCOTP) += nvmem_sunplus_ocotp.o nvmem_sunplus_ocotp-y := sunplus-ocotp.o +obj-$(CONFIG_NVMEM_APPLE_EFUSES) += nvmem-apple-efuses.o +nvmem-apple-efuses-y := apple-efuses.o diff --git a/drivers/nvmem/apple-efuses.c b/drivers/nvmem/apple-efuses.c new file mode 100644 index 000000000000..9b7c87102104 --- /dev/null +++ b/drivers/nvmem/apple-efuses.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Apple SoC eFuse driver + * + * Copyright (C) The Asahi Linux Contributors + */ + +#include +#include +#include +#include +#include + +struct apple_efuses_priv { + void __iomem *fuses; +}; + +static int apple_efuses_read(void *context, unsigned int offset, void *val, + size_t bytes) +{ + struct apple_efuses_priv *priv = context; + u32 *dst = val; + + while (bytes >= sizeof(u32)) { + *dst++ = readl_relaxed(priv->fuses + offset); + bytes -= sizeof(u32); + offset += sizeof(u32); + } + + return 0; +} + +static int apple_efuses_probe(struct platform_device *pdev) +{ + struct apple_efuses_priv *priv; + struct resource *res; + struct nvmem_config config = { + .dev = &pdev->dev, + .read_only = true, + .reg_read = apple_efuses_read, + .stride = sizeof(u32), + .word_size = sizeof(u32), + .name = "apple_efuses_nvmem", + .id = NVMEM_DEVID_AUTO, + .root_only = true, + }; + + priv = devm_kzalloc(config.dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + priv->fuses = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(priv->fuses)) + return PTR_ERR(priv->fuses); + + config.priv = priv; + config.size = resource_size(res); + + return PTR_ERR_OR_ZERO(devm_nvmem_register(config.dev, &config)); +} + +static const struct of_device_id apple_efuses_of_match[] = { + { .compatible = "apple,efuses", }, + {} +}; + +MODULE_DEVICE_TABLE(of, apple_efuses_of_match); + +static struct platform_driver apple_efuses_driver = { + .driver = { + .name = "apple_efuses", + .of_match_table = apple_efuses_of_match, + }, + .probe = apple_efuses_probe, +}; + +module_platform_driver(apple_efuses_driver); + +MODULE_AUTHOR("Sven Peter "); +MODULE_LICENSE("GPL");