2022-02-27 12:00:02

by Sven Peter

[permalink] [raw]
Subject: [PATCH 1/2] dt-bindings: nvmem: Add apple,efuses

Apple SoCs come with eFuses used to store factory-programmed data
such as calibration settings for the PCIe and Type-C PHY.

Signed-off-by: Sven Peter <[email protected]>
---
.../bindings/nvmem/apple,efuses.yaml | 50 +++++++++++++++++++
MAINTAINERS | 1 +
2 files changed, 51 insertions(+)
create mode 100644 Documentation/devicetree/bindings/nvmem/apple,efuses.yaml

diff --git a/Documentation/devicetree/bindings/nvmem/apple,efuses.yaml b/Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
new file mode 100644
index 000000000000..a735d54856ae
--- /dev/null
+++ b/Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
@@ -0,0 +1,50 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/nvmem/apple,efuses.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Apple SoC eFuse-based NVMEM
+
+description: |
+ Apple SoCs such as the M1 contain factory-programmed eFuses used to e.g. store
+ calibration data for the PCIe and the Type-C PHY or unique chip identifiers such
+ as the ECID.
+
+maintainers:
+ - Sven Peter <[email protected]>
+
+allOf:
+ - $ref: "nvmem.yaml#"
+
+properties:
+ compatible:
+ items:
+ - enum:
+ - apple,t8103-efuses
+ - apple,t6000-efuses
+ - const: apple,efuses
+
+ reg:
+ maxItems: 1
+
+required:
+ - compatible
+ - reg
+
+unevaluatedProperties: false
+
+examples:
+ - |
+ efuse@3d2bc000 {
+ compatible = "apple,t8103-efuses", "apple,efuses";
+ reg = <0x3d2bc000 0x1000>;
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ ecid: efuse@500 {
+ reg = <0x500 0x8>;
+ };
+ };
+
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 2524b75763cd..1bc57af09c80 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1771,6 +1771,7 @@ F: Documentation/devicetree/bindings/arm/apple/*
F: Documentation/devicetree/bindings/i2c/apple,i2c.yaml
F: Documentation/devicetree/bindings/interrupt-controller/apple,aic.yaml
F: Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml
+F: Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
F: Documentation/devicetree/bindings/pci/apple,pcie.yaml
F: Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
F: Documentation/devicetree/bindings/power/apple*
--
2.25.1


2022-02-27 12:08:36

by Sven Peter

[permalink] [raw]
Subject: [PATCH 2/2] nvmem: Add Apple eFuse driver

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 <[email protected]>
---
MAINTAINERS | 1 +
drivers/nvmem/Kconfig | 12 +++++++
drivers/nvmem/Makefile | 2 ++
drivers/nvmem/apple-efuses.c | 67 ++++++++++++++++++++++++++++++++++++
4 files changed, 82 insertions(+)
create mode 100644 drivers/nvmem/apple-efuses.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 1bc57af09c80..031198aec108 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..ef6a13c8a4d6 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 enabled 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..925fc0033b83
--- /dev/null
+++ b/drivers/nvmem/apple-efuses.c
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Apple SoC eFuse driver
+ *
+ * Copyright (C) The Asahi Linux Contributors
+ */
+
+#include <linux/io.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/platform_device.h>
+
+static int apple_efuses_read(void *context, unsigned int offset, void *val,
+ size_t bytes)
+{
+ void __iomem *fuses = context;
+ u32 *dst = val;
+
+ while (bytes >= sizeof(u32)) {
+ *dst++ = readl_relaxed(fuses + offset);
+ bytes -= sizeof(u32);
+ offset += sizeof(u32);
+ }
+
+ return 0;
+}
+
+static int apple_efuses_probe(struct platform_device *pdev)
+{
+ 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,
+ };
+
+ config.priv = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
+ if (IS_ERR(config.priv))
+ return PTR_ERR(config.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", },
+ {}
+};
+
+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 <[email protected]>");
+MODULE_LICENSE("GPL");
--
2.25.1

2022-03-03 15:54:27

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 2/2] nvmem: Add Apple eFuse driver

Hi Sven,

I love your patch! Perhaps something to improve:

[auto build test WARNING on soc/for-next]
[also build test WARNING on linus/master v5.17-rc6]
[cannot apply to robh/for-next next-20220303]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Sven-Peter/dt-bindings-nvmem-Add-apple-efuses/20220227-195847
base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
config: ia64-randconfig-s031-20220302 (https://download.01.org/0day-ci/archive/20220303/[email protected]/config)
compiler: ia64-linux-gcc (GCC) 11.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.4-dirty
# https://github.com/0day-ci/linux/commit/e47f957c24fcbc9f99a972b1b7c802eec04ed40a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Sven-Peter/dt-bindings-nvmem-Add-apple-efuses/20220227-195847
git checkout e47f957c24fcbc9f99a972b1b7c802eec04ed40a
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=ia64 SHELL=/bin/bash drivers/nvmem/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>


sparse warnings: (new ones prefixed by >>)
>> drivers/nvmem/apple-efuses.c:17:31: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected void [noderef] __iomem *fuses @@ got void *context @@
drivers/nvmem/apple-efuses.c:17:31: sparse: expected void [noderef] __iomem *fuses
drivers/nvmem/apple-efuses.c:17:31: sparse: got void *context
>> drivers/nvmem/apple-efuses.c:42:21: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected void *priv @@ got void [noderef] __iomem * @@
drivers/nvmem/apple-efuses.c:42:21: sparse: expected void *priv
drivers/nvmem/apple-efuses.c:42:21: sparse: got void [noderef] __iomem *
drivers/nvmem/apple-efuses.c: note: in included file (through arch/ia64/include/asm/io.h, include/linux/io.h):
include/asm-generic/io.h:267:16: sparse: sparse: cast to restricted __le32

vim +17 drivers/nvmem/apple-efuses.c

13
14 static int apple_efuses_read(void *context, unsigned int offset, void *val,
15 size_t bytes)
16 {
> 17 void __iomem *fuses = context;
18 u32 *dst = val;
19
20 while (bytes >= sizeof(u32)) {
21 *dst++ = readl_relaxed(fuses + offset);
22 bytes -= sizeof(u32);
23 offset += sizeof(u32);
24 }
25
26 return 0;
27 }
28
29 static int apple_efuses_probe(struct platform_device *pdev)
30 {
31 struct resource *res;
32 struct nvmem_config config = {
33 .dev = &pdev->dev,
34 .read_only = true,
35 .reg_read = apple_efuses_read,
36 .stride = sizeof(u32),
37 .word_size = sizeof(u32),
38 .name = "apple_efuses_nvmem",
39 .id = NVMEM_DEVID_AUTO,
40 };
41
> 42 config.priv = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
43 if (IS_ERR(config.priv))
44 return PTR_ERR(config.priv);
45
46 config.size = resource_size(res);
47
48 return PTR_ERR_OR_ZERO(devm_nvmem_register(config.dev, &config));
49 }
50

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

2022-03-04 16:04:14

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH 1/2] dt-bindings: nvmem: Add apple,efuses

On 27/02/2022 12:57, Sven Peter wrote:
> Apple SoCs come with eFuses used to store factory-programmed data
> such as calibration settings for the PCIe and Type-C PHY.
>
> Signed-off-by: Sven Peter <[email protected]>
> ---
> .../bindings/nvmem/apple,efuses.yaml | 50 +++++++++++++++++++
> MAINTAINERS | 1 +
> 2 files changed, 51 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
>
> diff --git a/Documentation/devicetree/bindings/nvmem/apple,efuses.yaml b/Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
> new file mode 100644
> index 000000000000..a735d54856ae
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
> @@ -0,0 +1,50 @@
> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/nvmem/apple,efuses.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Apple SoC eFuse-based NVMEM
> +
> +description: |
> + Apple SoCs such as the M1 contain factory-programmed eFuses used to e.g. store
> + calibration data for the PCIe and the Type-C PHY or unique chip identifiers such
> + as the ECID.
> +
> +maintainers:
> + - Sven Peter <[email protected]>
> +
> +allOf:
> + - $ref: "nvmem.yaml#"
> +
> +properties:
> + compatible:
> + items:
> + - enum:
> + - apple,t8103-efuses
> + - apple,t6000-efuses
> + - const: apple,efuses
> +
> + reg:
> + maxItems: 1
> +
> +required:
> + - compatible
> + - reg
> +
> +unevaluatedProperties: false
> +
> +examples:
> + - |
> + efuse@3d2bc000 {
> + compatible = "apple,t8103-efuses", "apple,efuses";
> + reg = <0x3d2bc000 0x1000>;
> + #address-cells = <1>;
> + #size-cells = <1>;
> +
> + ecid: efuse@500 {
> + reg = <0x500 0x8>;

Mismatched indentation. Rest looks good.

Best regards,
Krzysztof

2022-03-05 17:25:45

by Sven Peter

[permalink] [raw]
Subject: Re: [PATCH 1/2] dt-bindings: nvmem: Add apple,efuses



On Thu, Mar 3, 2022, at 19:00, Krzysztof Kozlowski wrote:
> On 27/02/2022 12:57, Sven Peter wrote:
>> Apple SoCs come with eFuses used to store factory-programmed data
>> such as calibration settings for the PCIe and Type-C PHY.
>>
>> Signed-off-by: Sven Peter <[email protected]>
>> ---
>> .../bindings/nvmem/apple,efuses.yaml | 50 +++++++++++++++++++
>> MAINTAINERS | 1 +
>> 2 files changed, 51 insertions(+)
>> create mode 100644 Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
>>
>> diff --git a/Documentation/devicetree/bindings/nvmem/apple,efuses.yaml b/Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
>> new file mode 100644
>> index 000000000000..a735d54856ae
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/nvmem/apple,efuses.yaml
>> @@ -0,0 +1,50 @@
>> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
>> +%YAML 1.2
>> +---
>> +$id: http://devicetree.org/schemas/nvmem/apple,efuses.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: Apple SoC eFuse-based NVMEM
>> +
>> +description: |
>> + Apple SoCs such as the M1 contain factory-programmed eFuses used to e.g. store
>> + calibration data for the PCIe and the Type-C PHY or unique chip identifiers such
>> + as the ECID.
>> +
>> +maintainers:
>> + - Sven Peter <[email protected]>
>> +
>> +allOf:
>> + - $ref: "nvmem.yaml#"
>> +
>> +properties:
>> + compatible:
>> + items:
>> + - enum:
>> + - apple,t8103-efuses
>> + - apple,t6000-efuses
>> + - const: apple,efuses
>> +
>> + reg:
>> + maxItems: 1
>> +
>> +required:
>> + - compatible
>> + - reg
>> +
>> +unevaluatedProperties: false
>> +
>> +examples:
>> + - |
>> + efuse@3d2bc000 {
>> + compatible = "apple,t8103-efuses", "apple,efuses";
>> + reg = <0x3d2bc000 0x1000>;
>> + #address-cells = <1>;
>> + #size-cells = <1>;
>> +
>> + ecid: efuse@500 {
>> + reg = <0x500 0x8>;
>
> Mismatched indentation. Rest looks good.

Good catch, thanks! Will fix it for v2.


Best,


Sven