]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nvmem: an8855: Add support for Airoha AN8855 Switch EFUSE
authorChristian Marangi <ansuelsmth@gmail.com>
Fri, 12 Sep 2025 13:14:15 +0000 (14:14 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 12 Sep 2025 13:49:03 +0000 (15:49 +0200)
Add support for Airoha AN8855 Switch EFUSE. These EFUSE might be used
for calibration data for the internal switch PHYs.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
Link: https://lore.kernel.org/r/20250912131415.303407-6-srini@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/nvmem/Kconfig
drivers/nvmem/Makefile
drivers/nvmem/an8855-efuse.c [new file with mode: 0644]

index f3b8ffa77528032d452820ef4441cf6cda85dbf5..e0d88d3199c11a3b71cc274b2114e9554ac486fc 100644 (file)
@@ -28,6 +28,17 @@ source "drivers/nvmem/layouts/Kconfig"
 
 # Devices
 
+config NVMEM_AN8855_EFUSE
+       tristate "Airoha AN8855 eFuse support"
+       depends on MFD_AIROHA_AN8855 || COMPILE_TEST
+       help
+         Say y here to enable support for reading eFuses on Airoha AN8855
+         Switch. These are e.g. used to store factory programmed
+         calibration data required for the PHY.
+
+         This driver can also be built as a module. If so, the module will
+         be called nvmem-an8855-efuse.
+
 config NVMEM_APPLE_EFUSES
        tristate "Apple eFuse support"
        depends on ARCH_APPLE || COMPILE_TEST
index 5634945f81969ecedee0dc029ba1cf3fadc5b5e1..70a4464dcb1e25cf9116280a32f4a0f4f9941a75 100644 (file)
@@ -10,6 +10,8 @@ nvmem_layouts-y                       := layouts.o
 obj-y                          += layouts/
 
 # Devices
+obj-$(CONFIG_NVMEM_AN8855_EFUSE)       += nvmem-an8855-efuse.o
+nvmem-an8855-efuse-y                   := an8855-efuse.o
 obj-$(CONFIG_NVMEM_APPLE_EFUSES)       += nvmem-apple-efuses.o
 nvmem-apple-efuses-y                   := apple-efuses.o
 obj-$(CONFIG_NVMEM_APPLE_SPMI)         += apple_nvmem_spmi.o
diff --git a/drivers/nvmem/an8855-efuse.c b/drivers/nvmem/an8855-efuse.c
new file mode 100644 (file)
index 0000000..d1afde6
--- /dev/null
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ *  Airoha AN8855 Switch EFUSE Driver
+ */
+
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/nvmem-provider.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+
+#define AN8855_EFUSE_CELL              50
+
+#define AN8855_EFUSE_DATA0             0x1000a500
+#define   AN8855_EFUSE_R50O            GENMASK(30, 24)
+
+static int an8855_efuse_read(void *context, unsigned int offset,
+                            void *val, size_t bytes)
+{
+       struct regmap *regmap = context;
+
+       return regmap_bulk_read(regmap, AN8855_EFUSE_DATA0 + offset,
+                               val, bytes / sizeof(u32));
+}
+
+static int an8855_efuse_probe(struct platform_device *pdev)
+{
+       struct nvmem_config an8855_nvmem_config = {
+               .name = "an8855-efuse",
+               .size = AN8855_EFUSE_CELL * sizeof(u32),
+               .stride = sizeof(u32),
+               .word_size = sizeof(u32),
+               .reg_read = an8855_efuse_read,
+       };
+       struct device *dev = &pdev->dev;
+       struct nvmem_device *nvmem;
+       struct regmap *regmap;
+
+       /* Assign NVMEM priv to MFD regmap */
+       regmap = dev_get_regmap(dev->parent, NULL);
+       if (!regmap)
+               return -ENOENT;
+
+       an8855_nvmem_config.priv = regmap;
+       an8855_nvmem_config.dev = dev;
+       nvmem = devm_nvmem_register(dev, &an8855_nvmem_config);
+
+       return PTR_ERR_OR_ZERO(nvmem);
+}
+
+static const struct of_device_id an8855_efuse_of_match[] = {
+       { .compatible = "airoha,an8855-efuse", },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, an8855_efuse_of_match);
+
+static struct platform_driver an8855_efuse_driver = {
+       .probe = an8855_efuse_probe,
+       .driver = {
+               .name = "an8855-efuse",
+               .of_match_table = an8855_efuse_of_match,
+       },
+};
+module_platform_driver(an8855_efuse_driver);
+
+MODULE_AUTHOR("Christian Marangi <ansuelsmth@gmail.com>");
+MODULE_DESCRIPTION("Driver for AN8855 Switch EFUSE");
+MODULE_LICENSE("GPL");