Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp10882lfv; Tue, 12 Apr 2022 15:11:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9LOdXjVe4pW1/kGJPBWcYkhljySmUXgeZmEIu5lR1wi/VW2KuMG/64JF1stTlJ90fh7Oq X-Received: by 2002:a17:902:e882:b0:154:182c:193f with SMTP id w2-20020a170902e88200b00154182c193fmr39215964plg.170.1649801468417; Tue, 12 Apr 2022 15:11:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649801468; cv=none; d=google.com; s=arc-20160816; b=WwHnVM4CnNsvqlMnHR0wMcsi6IA0/zT0Sqji5JYbPpIaGQUWn0FWXKwM9JrVVZNq6L FuS45zGtW7FQd8L23a52nWQgcE0ftzajpeFONnbxTqnhseOs7Sg4FPvk6vCeYj6JUDHG 1InNqyW/aGaDUnp1TGzQ818zzP0QB1gEJZJa9g8/bYuv0J5MhonPJofrCt+rX5bzO85V cfz4fD9U/u3gEiAiG3GTqJtt5VHNW4qwStiqikDzlYHPLDEI1UirTsL9yjm7qUhJKN5x Ws1MTXXWxapVJzm29fU6f/FXBt2XaqJ5HNHjWyXQfNZ0bmiErHiLJjlz/BYJuFh2+aIb Of2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=xDR0Oo93RBMr/a7qSFkHAnxdyg/wff1wMpM/g7CP34w=; b=m2K36gIUCLJr9Li7f+J3QD+Ic6ODc/pMeSCagaGImmWBrgeKLepWq2I2fl02oShKa8 ym/xc24XsF7nqXAILPn4J5GTfYB8cAOEgrwSdLTl1Q4k+cPyIlbuX6c2oVPonDWFBpyw qG+dFoTHqKT+BGgIDtnU3WtXe33W+kP0q8+xD7BUiXfLW8+4a0JqIG0pmZGjlEomVuF0 xVmUGCh+OEdroztaDpxxyiURl/LuH2oUdrBZnuz/XwzMo9KMaBceYE84fURsRldDAPlW SxpXjdkzikiKMrjqOp/9LlxCxLYdKYYnsvwcEsHO3jognWPcaalR0kvgb2Qnq43GeCJ8 28yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gmpvBoMH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q16-20020a170902f79000b00153b2d165cesi11348365pln.470.2022.04.12.15.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 15:11:08 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gmpvBoMH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6CE6B174E9C; Tue, 12 Apr 2022 14:02:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344627AbiDKJnj (ORCPT + 99 others); Mon, 11 Apr 2022 05:43:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344809AbiDKJnY (ORCPT ); Mon, 11 Apr 2022 05:43:24 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40E4C35AA4 for ; Mon, 11 Apr 2022 02:41:10 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id r206-20020a1c44d7000000b0038ccb70e239so4159917wma.3 for ; Mon, 11 Apr 2022 02:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=xDR0Oo93RBMr/a7qSFkHAnxdyg/wff1wMpM/g7CP34w=; b=gmpvBoMH52aIdLBa/PxVc8cIjE+SH82zUdfbrHBrp/oLN6ipQV04xdDZ32gi7TkYij YuqQAXm2crjZ1ntW1FoXCYo/ss0KVodV9aY45i+Ymt3vGcy5lfDqWrZ/fjJvknRx5BT3 aseK8WVQ+0aALq3NkBXUIxyV+3T702Uimjkdso45GbDEC28a65i2SQQlwn9H8Ydst34k rHusuBKSCE9tBxEp5nRB4rjQ5cFVikbzRGIFG1GqrXMXXnr9Pz+vLY2mdnTN7UmxPixy Yqxzl5S/gE+qF4g/AfVcQoTMgPEMD96+0QtbqB97VSjcfd25K0fekERlHB148S20c1iV tHjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=xDR0Oo93RBMr/a7qSFkHAnxdyg/wff1wMpM/g7CP34w=; b=YyoOpdKY588DPpLvIMeWg5iHkrtgFE8V/4h6Nrh03B7tHOrSZXTNjCYssvau40zAth COAi4l9ua6yK4/DvPytED7VU2NsEHo1445KANw5lxuXMK/Wnbm+otpx/gbQsfElaQYMC iTkFGcoic9B7+HSKV8AMtcsKyod1fTsJv2sJVXb4R36oYRo7OrFtfKQqaOzTgMoG1JGX PDt4VHkuLbWMBkDv8kZCH3BtoQHtHrCQfNmPQ8xp7SAcDHhZX2Dtg3t9WVClrz8oG+ES KmFtJltToXmzQogg9XFo5Qee+ZDLcYLnYvXvmp4oT7UtxMa2DemtQg9J2bVQQjG1km/s S5yw== X-Gm-Message-State: AOAM5320ablhncrYP7imxmMhB3oTZxfyEz/NUW9QwXUXtVe6hWCAMv2E UW3jQHs/eM9DrWU+jaBdGw9hIQ== X-Received: by 2002:a1c:7302:0:b0:38c:bb21:faf7 with SMTP id d2-20020a1c7302000000b0038cbb21faf7mr28082521wmb.31.1649670068725; Mon, 11 Apr 2022 02:41:08 -0700 (PDT) Received: from [192.168.86.34] (cpc90716-aztw32-2-0-cust825.18-1.cable.virginm.net. [86.26.103.58]) by smtp.googlemail.com with ESMTPSA id d11-20020a056000186b00b0020799d3d416sm8484092wri.55.2022.04.11.02.41.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Apr 2022 02:41:07 -0700 (PDT) Message-ID: <92e94b98-847d-7d3f-4063-96d2d01eff6e@linaro.org> Date: Mon, 11 Apr 2022 10:41:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v4 3/3] nvmem: Add Apple eFuse driver Content-Language: en-US To: Sven Peter Cc: 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 References: <20220410135414.20606-1-sven@svenpeter.dev> <20220410135414.20606-3-sven@svenpeter.dev> From: Srinivas Kandagatla In-Reply-To: <20220410135414.20606-3-sven@svenpeter.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/04/2022 14:54, 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 Applied all 3, thanks, --srini > --- > 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");