diff options
Diffstat (limited to 'drivers/nvmem')
| -rw-r--r-- | drivers/nvmem/Kconfig | 9 | ||||
| -rw-r--r-- | drivers/nvmem/Makefile | 2 | ||||
| -rw-r--r-- | drivers/nvmem/imx-ocotp-ele.c | 20 | ||||
| -rw-r--r-- | drivers/nvmem/layouts.c | 2 | ||||
| -rw-r--r-- | drivers/nvmem/layouts/u-boot-env.c | 4 | ||||
| -rw-r--r-- | drivers/nvmem/qnap-mcu-eeprom.c | 111 |
6 files changed, 146 insertions, 2 deletions
diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index e0d88d3199c1..bf47a982cf62 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -285,6 +285,15 @@ config NVMEM_QCOM_SEC_QFPROM This driver can also be built as a module. If so, the module will be called nvmem_sec_qfprom. +config NVMEM_QNAP_MCU_EEPROM + tristate "QNAP MCU EEPROM Support" + depends on MFD_QNAP_MCU + help + Say y here to enable support for accessing the EEPROM attached to + QNAP MCU devices. This EEPROM contains additional runtime device + information, like MAC addresses for ethernet devices that do not + contain their own mac storage. + config NVMEM_RAVE_SP_EEPROM tristate "Rave SP EEPROM Support" depends on RAVE_SP_CORE diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 70a4464dcb1e..7252b8ec88d4 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -56,6 +56,8 @@ obj-$(CONFIG_NVMEM_QCOM_QFPROM) += nvmem_qfprom.o nvmem_qfprom-y := qfprom.o obj-$(CONFIG_NVMEM_QCOM_SEC_QFPROM) += nvmem_sec_qfprom.o nvmem_sec_qfprom-y := sec-qfprom.o +obj-$(CONFIG_NVMEM_QNAP_MCU_EEPROM) += nvmem-qnap-mcu-eeprom.o +nvmem-qnap-mcu-eeprom-y := qnap-mcu-eeprom.o obj-$(CONFIG_NVMEM_RAVE_SP_EEPROM) += nvmem-rave-sp-eeprom.o nvmem-rave-sp-eeprom-y := rave-sp-eeprom.o obj-$(CONFIG_NVMEM_RCAR_EFUSE) += nvmem-rcar-efuse.o diff --git a/drivers/nvmem/imx-ocotp-ele.c b/drivers/nvmem/imx-ocotp-ele.c index 7807ec0e2d18..7cf7e809a8f5 100644 --- a/drivers/nvmem/imx-ocotp-ele.c +++ b/drivers/nvmem/imx-ocotp-ele.c @@ -186,6 +186,25 @@ static const struct ocotp_devtype_data imx93_ocotp_data = { }, }; +static const struct ocotp_devtype_data imx94_ocotp_data = { + .reg_off = 0x8000, + .reg_read = imx_ocotp_reg_read, + .size = 3296, /* 103 Banks */ + .num_entry = 10, + .entry = { + { 0, 1, FUSE_FSB | FUSE_ECC }, + { 7, 1, FUSE_FSB | FUSE_ECC }, + { 9, 3, FUSE_FSB | FUSE_ECC }, + { 12, 24, FUSE_FSB }, + { 36, 2, FUSE_FSB | FUSE_ECC }, + { 38, 14, FUSE_FSB }, + { 59, 1, FUSE_ELE }, + { 525, 2, FUSE_FSB | FUSE_ECC }, + { 528, 7, FUSE_FSB }, + { 536, 280, FUSE_FSB }, + }, +}; + static const struct ocotp_devtype_data imx95_ocotp_data = { .reg_off = 0x8000, .reg_read = imx_ocotp_reg_read, @@ -209,6 +228,7 @@ static const struct ocotp_devtype_data imx95_ocotp_data = { static const struct of_device_id imx_ele_ocotp_dt_ids[] = { { .compatible = "fsl,imx93-ocotp", .data = &imx93_ocotp_data, }, + { .compatible = "fsl,imx94-ocotp", .data = &imx94_ocotp_data, }, { .compatible = "fsl,imx95-ocotp", .data = &imx95_ocotp_data, }, {}, }; diff --git a/drivers/nvmem/layouts.c b/drivers/nvmem/layouts.c index f381ce1e84bd..7ebe53249035 100644 --- a/drivers/nvmem/layouts.c +++ b/drivers/nvmem/layouts.c @@ -51,7 +51,7 @@ static int nvmem_layout_bus_uevent(const struct device *dev, int ret; ret = of_device_uevent_modalias(dev, env); - if (ret != ENODEV) + if (ret != -ENODEV) return ret; return 0; diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c index a27eeb08146f..ab32bf1291af 100644 --- a/drivers/nvmem/layouts/u-boot-env.c +++ b/drivers/nvmem/layouts/u-boot-env.c @@ -99,10 +99,12 @@ int u_boot_env_parse(struct device *dev, struct nvmem_device *nvmem, uint32_t crc32; uint32_t calc; uint8_t *buf; + u32 env_size; int bytes; int err; - dev_size = nvmem_dev_size(nvmem); + dev_size = device_property_read_u32(dev, "env-size", &env_size) ? + nvmem_dev_size(nvmem) : (size_t)env_size; buf = kzalloc(dev_size, GFP_KERNEL); if (!buf) { diff --git a/drivers/nvmem/qnap-mcu-eeprom.c b/drivers/nvmem/qnap-mcu-eeprom.c new file mode 100644 index 000000000000..0b919895b3b2 --- /dev/null +++ b/drivers/nvmem/qnap-mcu-eeprom.c @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * ee1004 - driver for DDR4 SPD EEPROMs + * + * Copyright (C) 2017-2019 Jean Delvare + * + * Based on the at24 driver: + * Copyright (C) 2005-2007 David Brownell + * Copyright (C) 2008 Wolfram Sang, Pengutronix + */ + +#include <linux/mfd/qnap-mcu.h> +#include <linux/module.h> +#include <linux/nvmem-provider.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +/* Determined by trial and error until read anomalies appeared */ +#define QNAP_MCU_EEPROM_SIZE 256 +#define QNAP_MCU_EEPROM_BLOCK_SIZE 32 + +static int qnap_mcu_eeprom_read_block(struct qnap_mcu *mcu, unsigned int offset, + void *val, size_t bytes) +{ + const u8 cmd[] = { 0xf7, 0xa1, offset, bytes }; + u8 *reply; + int ret = 0; + + reply = kzalloc(bytes + sizeof(cmd), GFP_KERNEL); + if (!reply) + return -ENOMEM; + + ret = qnap_mcu_exec(mcu, cmd, sizeof(cmd), reply, bytes + sizeof(cmd)); + if (ret) + goto out; + + /* First bytes must mirror the sent command */ + if (memcmp(cmd, reply, sizeof(cmd))) { + ret = -EIO; + goto out; + } + + memcpy(val, reply + sizeof(cmd), bytes); + +out: + kfree(reply); + return ret; +} + +static int qnap_mcu_eeprom_read(void *priv, unsigned int offset, void *val, size_t bytes) +{ + struct qnap_mcu *mcu = priv; + int pos = 0, ret; + u8 *buf = val; + + if (unlikely(!bytes)) + return 0; + + while (bytes > 0) { + size_t to_read = (bytes > QNAP_MCU_EEPROM_BLOCK_SIZE) ? + QNAP_MCU_EEPROM_BLOCK_SIZE : bytes; + + ret = qnap_mcu_eeprom_read_block(mcu, offset + pos, &buf[pos], to_read); + if (ret < 0) + return ret; + + pos += to_read; + bytes -= to_read; + } + + return 0; +} + +static int qnap_mcu_eeprom_probe(struct platform_device *pdev) +{ + struct qnap_mcu *mcu = dev_get_drvdata(pdev->dev.parent); + struct nvmem_config nvcfg = {}; + struct nvmem_device *ndev; + + nvcfg.dev = &pdev->dev; + nvcfg.of_node = pdev->dev.parent->of_node; + nvcfg.name = dev_name(&pdev->dev); + nvcfg.id = NVMEM_DEVID_NONE; + nvcfg.owner = THIS_MODULE; + nvcfg.type = NVMEM_TYPE_EEPROM; + nvcfg.read_only = true; + nvcfg.root_only = false; + nvcfg.reg_read = qnap_mcu_eeprom_read; + nvcfg.size = QNAP_MCU_EEPROM_SIZE, + nvcfg.word_size = 1, + nvcfg.stride = 1, + nvcfg.priv = mcu, + + ndev = devm_nvmem_register(&pdev->dev, &nvcfg); + if (IS_ERR(ndev)) + return PTR_ERR(ndev); + + return 0; +} + +static struct platform_driver qnap_mcu_eeprom_driver = { + .probe = qnap_mcu_eeprom_probe, + .driver = { + .name = "qnap-mcu-eeprom", + }, +}; +module_platform_driver(qnap_mcu_eeprom_driver); + +MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>"); +MODULE_DESCRIPTION("QNAP MCU EEPROM driver"); +MODULE_LICENSE("GPL"); |
