Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1749406pxp; Mon, 7 Mar 2022 01:20:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVGoIRRR1w2V1qpVc1vsd+KmKSYekRPXCzX30kWTqfwI0ECTADiRV1qR5Ok02xmajRvcVI X-Received: by 2002:aa7:d1c8:0:b0:415:c61a:8ec8 with SMTP id g8-20020aa7d1c8000000b00415c61a8ec8mr10257146edp.390.1646644829829; Mon, 07 Mar 2022 01:20:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646644829; cv=none; d=google.com; s=arc-20160816; b=tUoNj01WBsP30NRsr1EToSL23mFFeHMzMH+0l+QaB6p6R/5iYQ/OXy4W6PMGuYaS7v L30qookm4eUXbANxmxXIK3R2TlJ0639ma4IMJYHqtPZxch7nGvKhn+6E3l10D4iI07Ml cVoZ1x3xMdL98W80/WXP7lxYTj592pTC0ZTS8osCQcf+lmTbDSRvt45965omdZrTCYRE G08tNvbITXZTXUvCnoAPz9bXsRuvitqTJy7sJMKP3Yr0eqXGrharJeE4CTd3RdMTga+J xcsvOZ5v/Phnc8drq3uu72tS/vLZR8k/BwpzAr37KQEQrhT96t8vpJTh5WqPv6ITxlZI 10HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:dkim-signature:dkim-signature; bh=CuD+6UMoHVIR6oldfnrYz19HAfESfeN1v5yLvdZkpkI=; b=NthRDJvxE/TMl1SyoFIFsaOPVtLCGSLh8iWJLcliKR0rg6P3SzrBVL7W6hbMfdTZt1 kN7Ztg6sMUWFqK3ql/JWdMUh616VXONP6kZubO67/w/vw5dI9QHTy2o6F1OJpGnI+rcA uJ+1J70+bR0h2lGVKQrKRRF9Qqn3mkvuCHuQxROfiL9Q0Xj0104OkSAhkd87Ahk/V8o/ 6xbH087Rs4VDtBI/BDtqOYXdc/QFg+0LOGmo7d7b9InDtKDA1hglWvqgJEtLSYNYYlBU OKQi3B4/1GMBwZON3IljQYWmqu54SIHz5rQgTcJPtGs2V0CF3WOxw2rkJertgjDF85W7 wirg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svenpeter.dev header.s=fm1 header.b=HNlRkQNB; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=GbHVdYZl; 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=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r24-20020a170906549800b006cfcff2e235si7454724ejo.336.2022.03.07.01.20.07; Mon, 07 Mar 2022 01:20:29 -0800 (PST) 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=@svenpeter.dev header.s=fm1 header.b=HNlRkQNB; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=GbHVdYZl; 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=REJECT sp=REJECT dis=NONE) header.from=svenpeter.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235117AbiCGJJn (ORCPT + 99 others); Mon, 7 Mar 2022 04:09:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232755AbiCGJJk (ORCPT ); Mon, 7 Mar 2022 04:09:40 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AF2E60DA2; Mon, 7 Mar 2022 01:08:45 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 3B5FB5C031E; Mon, 7 Mar 2022 04:08:43 -0500 (EST) Received: from imap47 ([10.202.2.97]) by compute2.internal (MEProxy); Mon, 07 Mar 2022 04:08:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svenpeter.dev; h=cc:cc:content-type: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=CuD+6UMoHVIR6oldfnrYz19HAfESfe N1v5yLvdZkpkI=; b=HNlRkQNBATVq9XbYKl09SZsmzqhv+DgzkzTZfACXeadb1r jJp5ggogTaKrs5JuQKLV4+QUqRcScoJlo0nPYYz07y+/khiNQHVC0EUyOVEWOzt0 FX1HspPIUl+5rjAu4hMZsJqsT2uTgQTbcEfdORQd7pqVJPdm6JxF4YDNS8mRktyE TSITmdatD5x1/jhepkiF/WMt80YtiT5URmjape1KP/T5Xen1iHrtc6iujVyg4seS AgkSYfj2I4m3I8isqSUHOs8lBnKnkw529+XdwN6TeojYKkijX/qZHVnAUIggmaAa WUUj0gUNtc/4QA7VnfhLA7bOfh4MWSiiY/FVJIxw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type: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=fm2; bh=CuD+6UMoHVIR6oldf nrYz19HAfESfeN1v5yLvdZkpkI=; b=GbHVdYZl+iMeTFOcCbuo6ObLlJ22l2DtF HxDi+aedjFK4qRHNg+W7RNvauDjN5/uCyEJBsXuQ07CZM/KXpOfpxek/2036uJLM K9Jhf6iG7shFa3WxjfjhAiuzSjN8E4Q/tVLJvSM7VnGp94ebxBu0D65VoE1uF8tm 4R6cLP9xMXYzsTOXe1i0PDDKTCbzM/tw/sGk+Z2b9EHXAHpduoFXmJO8MUkrQxNV VydUNmnjhWPlOuTcXsj+mi8OuqgP+FVqTW5RWe/2DwUiymty06ZK3xZPcMK+EC4y HGZK6V0qPJU37O8GZ97a/e+agEUMo2W1wnAqksAfOCENUkUPOuu9w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddruddufedguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfufhv vghnucfrvghtvghrfdcuoehsvhgvnhesshhvvghnphgvthgvrhdruggvvheqnecuggftrf grthhtvghrnhepgfeigeeiffeuhfettdejgfetjeetfeelfefgfefgvddvtdfghfffudeh vdefkeffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epshhvvghnsehsvhgvnhhpvghtvghrrdguvghv X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id ACC0A2740108; Mon, 7 Mar 2022 04:08:42 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-4778-g14fba9972e-fm-20220217.001-g14fba997 Mime-Version: 1.0 Message-Id: <9f43d5db-1476-4505-a9de-b862fbaf2685@www.fastmail.com> In-Reply-To: References: <20220306121816.70537-1-sven@svenpeter.dev> <20220306121816.70537-2-sven@svenpeter.dev> Date: Mon, 07 Mar 2022 10:08:22 +0100 From: "Sven Peter" To: "Krzysztof Kozlowski" , "Srinivas Kandagatla" Cc: "Rob Herring" , "Joey Gouly" , "Hector Martin" , "Alyssa Rosenzweig" , "Mark Kettenis" , linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] nvmem: Add Apple eFuse driver Content-Type: text/plain X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Sun, Mar 6, 2022, at 13:25, Krzysztof Kozlowski wrote: > On 06/03/2022 13:18, Sven Peter wrote: >> 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 >> --- >> 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 >> >> MAINTAINERS | 1 + >> drivers/nvmem/Kconfig | 12 ++++++ >> drivers/nvmem/Makefile | 2 + >> drivers/nvmem/apple-efuses.c | 82 ++++++++++++++++++++++++++++++++++++ >> 4 files changed, 97 insertions(+) >> create mode 100644 drivers/nvmem/apple-efuses.c >> >> diff --git a/MAINTAINERS b/MAINTAINERS >> index f70d8525cbd4..e3e973a3f651 100644 >> --- a/MAINTAINERS >> +++ b/MAINTAINERS >> @@ -1781,6 +1781,7 @@ F: drivers/i2c/busses/i2c-pasemi-core.c >> F: drivers/i2c/busses/i2c-pasemi-platform.c >> F: drivers/irqchip/irq-apple-aic.c >> F: drivers/mailbox/apple-mailbox.c >> +F: drivers/nvmem/apple-efuses.c >> F: drivers/pinctrl/pinctrl-apple-gpio.c >> F: drivers/soc/apple/* >> F: drivers/watchdog/apple_wdt.c >> diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig >> index da414617a54d..bba29d1aec96 100644 >> --- a/drivers/nvmem/Kconfig >> +++ b/drivers/nvmem/Kconfig >> @@ -300,4 +300,16 @@ config NVMEM_BRCM_NVRAM >> This driver provides support for Broadcom's NVRAM that can be accessed >> using I/O mapping. >> >> +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 dcbbde35b6a8..1a8e54691d3e 100644 >> --- a/drivers/nvmem/Makefile >> +++ b/drivers/nvmem/Makefile >> @@ -61,3 +61,5 @@ obj-$(CONFIG_NVMEM_RMEM) += nvmem-rmem.o >> nvmem-rmem-y := rmem.o >> obj-$(CONFIG_NVMEM_BRCM_NVRAM) += nvmem_brcm_nvram.o >> nvmem_brcm_nvram-y := brcm_nvram.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..dd5576ec5408 >> --- /dev/null >> +++ b/drivers/nvmem/apple-efuses.c >> @@ -0,0 +1,82 @@ >> +// 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, >> + .owner = THIS_MODULE, >> + .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, >> + .owner = THIS_MODULE, > > You wrote it also in changelog, but why do you need it? Doesn't core set > it? Coccinelle should complain about this as well. > yeah, you're right. I shouldn't have just blindly followed what Hector and Joey had to do for another subsystem to make reference counting work there. I just checked again and it's neither required here not in struct nvmem_config because module_platform_driver -> platform_driver_register -> __platform_driver_register will set it in struct platform_driver and the nvmem core will take it from there and set it inside nvmem_config. thanks, Sven