Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

nvmem: Add driver for the eeprom in qnap-mcu controllers

The qnap-mcu also has an eeprom connected to it, that contains some
specific product-information like the mac addresses for the network
interfaces.

Add a nvmem driver for it.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Srinivas Kandagatla <srini@kernel.org>
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
Link: https://patch.msgid.link/20251114110636.143268-4-srini@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Heiko Stuebner and committed by
Greg Kroah-Hartman
2f9fae50 47b7ea65

+122
+9
drivers/nvmem/Kconfig
··· 285 285 This driver can also be built as a module. If so, the module will be called 286 286 nvmem_sec_qfprom. 287 287 288 + config NVMEM_QNAP_MCU_EEPROM 289 + tristate "QNAP MCU EEPROM Support" 290 + depends on MFD_QNAP_MCU 291 + help 292 + Say y here to enable support for accessing the EEPROM attached to 293 + QNAP MCU devices. This EEPROM contains additional runtime device 294 + information, like MAC addresses for ethernet devices that do not 295 + contain their own mac storage. 296 + 288 297 config NVMEM_RAVE_SP_EEPROM 289 298 tristate "Rave SP EEPROM Support" 290 299 depends on RAVE_SP_CORE
+2
drivers/nvmem/Makefile
··· 56 56 nvmem_qfprom-y := qfprom.o 57 57 obj-$(CONFIG_NVMEM_QCOM_SEC_QFPROM) += nvmem_sec_qfprom.o 58 58 nvmem_sec_qfprom-y := sec-qfprom.o 59 + obj-$(CONFIG_NVMEM_QNAP_MCU_EEPROM) += nvmem-qnap-mcu-eeprom.o 60 + nvmem-qnap-mcu-eeprom-y := qnap-mcu-eeprom.o 59 61 obj-$(CONFIG_NVMEM_RAVE_SP_EEPROM) += nvmem-rave-sp-eeprom.o 60 62 nvmem-rave-sp-eeprom-y := rave-sp-eeprom.o 61 63 obj-$(CONFIG_NVMEM_RCAR_EFUSE) += nvmem-rcar-efuse.o
+111
drivers/nvmem/qnap-mcu-eeprom.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * ee1004 - driver for DDR4 SPD EEPROMs 4 + * 5 + * Copyright (C) 2017-2019 Jean Delvare 6 + * 7 + * Based on the at24 driver: 8 + * Copyright (C) 2005-2007 David Brownell 9 + * Copyright (C) 2008 Wolfram Sang, Pengutronix 10 + */ 11 + 12 + #include <linux/mfd/qnap-mcu.h> 13 + #include <linux/module.h> 14 + #include <linux/nvmem-provider.h> 15 + #include <linux/platform_device.h> 16 + #include <linux/slab.h> 17 + 18 + /* Determined by trial and error until read anomalies appeared */ 19 + #define QNAP_MCU_EEPROM_SIZE 256 20 + #define QNAP_MCU_EEPROM_BLOCK_SIZE 32 21 + 22 + static int qnap_mcu_eeprom_read_block(struct qnap_mcu *mcu, unsigned int offset, 23 + void *val, size_t bytes) 24 + { 25 + const u8 cmd[] = { 0xf7, 0xa1, offset, bytes }; 26 + u8 *reply; 27 + int ret = 0; 28 + 29 + reply = kzalloc(bytes + sizeof(cmd), GFP_KERNEL); 30 + if (!reply) 31 + return -ENOMEM; 32 + 33 + ret = qnap_mcu_exec(mcu, cmd, sizeof(cmd), reply, bytes + sizeof(cmd)); 34 + if (ret) 35 + goto out; 36 + 37 + /* First bytes must mirror the sent command */ 38 + if (memcmp(cmd, reply, sizeof(cmd))) { 39 + ret = -EIO; 40 + goto out; 41 + } 42 + 43 + memcpy(val, reply + sizeof(cmd), bytes); 44 + 45 + out: 46 + kfree(reply); 47 + return ret; 48 + } 49 + 50 + static int qnap_mcu_eeprom_read(void *priv, unsigned int offset, void *val, size_t bytes) 51 + { 52 + struct qnap_mcu *mcu = priv; 53 + int pos = 0, ret; 54 + u8 *buf = val; 55 + 56 + if (unlikely(!bytes)) 57 + return 0; 58 + 59 + while (bytes > 0) { 60 + size_t to_read = (bytes > QNAP_MCU_EEPROM_BLOCK_SIZE) ? 61 + QNAP_MCU_EEPROM_BLOCK_SIZE : bytes; 62 + 63 + ret = qnap_mcu_eeprom_read_block(mcu, offset + pos, &buf[pos], to_read); 64 + if (ret < 0) 65 + return ret; 66 + 67 + pos += to_read; 68 + bytes -= to_read; 69 + } 70 + 71 + return 0; 72 + } 73 + 74 + static int qnap_mcu_eeprom_probe(struct platform_device *pdev) 75 + { 76 + struct qnap_mcu *mcu = dev_get_drvdata(pdev->dev.parent); 77 + struct nvmem_config nvcfg = {}; 78 + struct nvmem_device *ndev; 79 + 80 + nvcfg.dev = &pdev->dev; 81 + nvcfg.of_node = pdev->dev.parent->of_node; 82 + nvcfg.name = dev_name(&pdev->dev); 83 + nvcfg.id = NVMEM_DEVID_NONE; 84 + nvcfg.owner = THIS_MODULE; 85 + nvcfg.type = NVMEM_TYPE_EEPROM; 86 + nvcfg.read_only = true; 87 + nvcfg.root_only = false; 88 + nvcfg.reg_read = qnap_mcu_eeprom_read; 89 + nvcfg.size = QNAP_MCU_EEPROM_SIZE, 90 + nvcfg.word_size = 1, 91 + nvcfg.stride = 1, 92 + nvcfg.priv = mcu, 93 + 94 + ndev = devm_nvmem_register(&pdev->dev, &nvcfg); 95 + if (IS_ERR(ndev)) 96 + return PTR_ERR(ndev); 97 + 98 + return 0; 99 + } 100 + 101 + static struct platform_driver qnap_mcu_eeprom_driver = { 102 + .probe = qnap_mcu_eeprom_probe, 103 + .driver = { 104 + .name = "qnap-mcu-eeprom", 105 + }, 106 + }; 107 + module_platform_driver(qnap_mcu_eeprom_driver); 108 + 109 + MODULE_AUTHOR("Heiko Stuebner <heiko@sntech.de>"); 110 + MODULE_DESCRIPTION("QNAP MCU EEPROM driver"); 111 + MODULE_LICENSE("GPL");