From nobody Wed Dec 17 16:22:19 2025 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D452227FB34 for ; Mon, 3 Nov 2025 23:29:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.11.138.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762212598; cv=none; b=TSoutNOAVGvzkXypfaIKuRcmZMRHv9tdDP0h7eoJox9sJj6LmZclOHjfBOqOoSLtFop1A6V5rxK9NVIpybSWZxzLoakH2jejWmywYTYGFGgyF0cCjyJH5tQLtAOub8O7Lfzf/OU0w5Xw38xkFLC0dEFo4KA7RT4jy7lMvc8EPXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762212598; c=relaxed/simple; bh=vXGcGn58vWdXedDJLRaiFyhiM6JKzmGMNBIqv3t86wQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lv32FfgX1Lf7SNgoT54wIuah75PEdr4R3ipDmp2bfkY4y4Ul3XHssLtPiI/thRzMzKOOYZnaAx1aF0YS83FD/WqoLt6Nw7tQkmhIdjPqkxwv07iRzk21H+mrbBi2HMPOHbI+yUKqujYsa8wuWYcvItpbdq06aaMlJTyu4DeYbxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sntech.de; spf=pass smtp.mailfrom=sntech.de; dkim=pass (2048-bit key) header.d=sntech.de header.i=@sntech.de header.b=xDnFextq; arc=none smtp.client-ip=185.11.138.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sntech.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sntech.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sntech.de header.i=@sntech.de header.b="xDnFextq" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sntech.de; s=gloria202408; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type; bh=11i3Z5YPaobAbC+fYmMd/zEgSFa2BqMyQg1J80qqwww=; b=xDnFextqlA9oycxDGWTG084N73 CDEDcpmEp4Jn0RLOfSp1AY8BEAOQyryJ26Qym5+AmM0nZsuohgwvkrRYtKrf3BYwwEiDi9BLsj7rt lRUFywZb3YoXjNuiLYQhMuyb+ur5Ae7oIw5BxiNXqlFyfyxMhK5GnLp8biGFwNOf6bTkbNckuHwE9 Yv3fJs2wXWZqSlpdBmMUz1kTZAnO4cKXybiDQaW27cf/L8Y3ey3eiVPws8VbrQ7R35mOGU65GXsoD AjgR8VHzkPtiRPIVEbtE5RWTd01tz4Bmrr9KPdId4PNl///j5H+AxMSmJtLB4qzrPGo/ggzjhJZR+ TgVFTccw==; Received: from i53875a3a.versanet.de ([83.135.90.58] helo=phil.fritz.box) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vG3zh-0007mj-Cy; Tue, 04 Nov 2025 00:29:49 +0100 From: Heiko Stuebner To: lee@kernel.org, srini@kernel.org Cc: heiko@sntech.de, linux-kernel@vger.kernel.org Subject: [PATCH v4 1/2] nvmem: Add driver for the eeprom in qnap-mcu controllers Date: Tue, 4 Nov 2025 00:29:41 +0100 Message-ID: <20251103232942.410386-2-heiko@sntech.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20251103232942.410386-1-heiko@sntech.de> References: <20251103232942.410386-1-heiko@sntech.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Srinivas Kandagatla --- drivers/nvmem/Kconfig | 9 +++ drivers/nvmem/Makefile | 2 + drivers/nvmem/qnap-mcu-eeprom.c | 111 ++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 drivers/nvmem/qnap-mcu-eeprom.c 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 wil= l be called nvmem_sec_qfprom. =20 +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) +=3D nvmem_qfprom.o nvmem_qfprom-y :=3D qfprom.o obj-$(CONFIG_NVMEM_QCOM_SEC_QFPROM) +=3D nvmem_sec_qfprom.o nvmem_sec_qfprom-y :=3D sec-qfprom.o +obj-$(CONFIG_NVMEM_QNAP_MCU_EEPROM) +=3D nvmem-qnap-mcu-eeprom.o +nvmem-qnap-mcu-eeprom-y :=3D qnap-mcu-eeprom.o obj-$(CONFIG_NVMEM_RAVE_SP_EEPROM) +=3D nvmem-rave-sp-eeprom.o nvmem-rave-sp-eeprom-y :=3D rave-sp-eeprom.o obj-$(CONFIG_NVMEM_RCAR_EFUSE) +=3D nvmem-rcar-efuse.o diff --git a/drivers/nvmem/qnap-mcu-eeprom.c b/drivers/nvmem/qnap-mcu-eepro= m.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 +#include +#include +#include +#include + +/* 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 o= ffset, + void *val, size_t bytes) +{ + const u8 cmd[] =3D { 0xf7, 0xa1, offset, bytes }; + u8 *reply; + int ret =3D 0; + + reply =3D kzalloc(bytes + sizeof(cmd), GFP_KERNEL); + if (!reply) + return -ENOMEM; + + ret =3D 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 =3D -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 =3D priv; + int pos =3D 0, ret; + u8 *buf =3D val; + + if (unlikely(!bytes)) + return 0; + + while (bytes > 0) { + size_t to_read =3D (bytes > QNAP_MCU_EEPROM_BLOCK_SIZE) ? + QNAP_MCU_EEPROM_BLOCK_SIZE : bytes; + + ret =3D qnap_mcu_eeprom_read_block(mcu, offset + pos, &buf[pos], to_read= ); + if (ret < 0) + return ret; + + pos +=3D to_read; + bytes -=3D to_read; + } + + return 0; +} + +static int qnap_mcu_eeprom_probe(struct platform_device *pdev) +{ + struct qnap_mcu *mcu =3D dev_get_drvdata(pdev->dev.parent); + struct nvmem_config nvcfg =3D {}; + struct nvmem_device *ndev; + + nvcfg.dev =3D &pdev->dev; + nvcfg.of_node =3D pdev->dev.parent->of_node; + nvcfg.name =3D dev_name(&pdev->dev); + nvcfg.id =3D NVMEM_DEVID_NONE; + nvcfg.owner =3D THIS_MODULE; + nvcfg.type =3D NVMEM_TYPE_EEPROM; + nvcfg.read_only =3D true; + nvcfg.root_only =3D false; + nvcfg.reg_read =3D qnap_mcu_eeprom_read; + nvcfg.size =3D QNAP_MCU_EEPROM_SIZE, + nvcfg.word_size =3D 1, + nvcfg.stride =3D 1, + nvcfg.priv =3D mcu, + + ndev =3D devm_nvmem_register(&pdev->dev, &nvcfg); + if (IS_ERR(ndev)) + return PTR_ERR(ndev); + + return 0; +} + +static struct platform_driver qnap_mcu_eeprom_driver =3D { + .probe =3D qnap_mcu_eeprom_probe, + .driver =3D { + .name =3D "qnap-mcu-eeprom", + }, +}; +module_platform_driver(qnap_mcu_eeprom_driver); + +MODULE_AUTHOR("Heiko Stuebner "); +MODULE_DESCRIPTION("QNAP MCU EEPROM driver"); +MODULE_LICENSE("GPL"); --=20 2.47.2 From nobody Wed Dec 17 16:22:19 2025 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45DF82C11CB for ; Mon, 3 Nov 2025 23:29:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.11.138.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762212599; cv=none; b=EWhXRNoDCo1xXeSUOpkNim7lMVUKlA9MEYB84RXgey/DrA9i9gno81cSVb+Jr0nuO+D/Ziu6mwpg69bpzQpXTaW1VG9hGDAxVVXaEhhkVwe4WvC94oG55cl4k/ildKk8kyb2XHZw3lIYtL+X/R4bkTtvxcMXeXFA+McOTTGRJbE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762212599; c=relaxed/simple; bh=7e8bhWKRVDtf8aKVV0+AAUPqW42KeeIQqV6I3K53e8k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oGhbL6ycpn4RV63tvQyhu6YMbDCzFUk1TU/mQrYOQjoMlQmeD7iYkMIDjlK8fMnQp1MApyfb1Dkof2YfEFdbgjVEpI5cDRONpfpzs0MMksDG2OW5GEsF4BGQyWw0puTiJz7FfbK2fLyZJYR//FgwYGBf5701lAkQOJywKk6araA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sntech.de; spf=pass smtp.mailfrom=sntech.de; dkim=pass (2048-bit key) header.d=sntech.de header.i=@sntech.de header.b=N8yOZ+gE; arc=none smtp.client-ip=185.11.138.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sntech.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sntech.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sntech.de header.i=@sntech.de header.b="N8yOZ+gE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sntech.de; s=gloria202408; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type; bh=FXGH735qWrvmiJLs+utyhLgjj/KKbRgYW73cH1TeOdo=; b=N8yOZ+gEf7cJJZR0XT8ItYqhqZ GGmifbmfrUBIDXEzpF1QxYFRcJCYmsClkJf2dOwptR/n2HG0Ank36miWFj5dePaUVedpCHcDpLgay gjtpS6ZSOuTN4DmGACPifmcFYG1aAJKV2Q8VGx55L5tn/4Ofe3GNVHPV9Tlm6eT0b4sC69+3dDpZM xtSevcVsl0knc1XGNT3dYD0ZE9wwAJP/Os3km2Tt1prfqFmlB4D+WLescGIkAfnhT5UZZJc5YuRbf 09sDdw+BkD1bmKiOCpGZI7XJmXpxVtTmDj9KoJy9CG757zr7cpuTTUEsOVFpRYYsNsOa5FWwC+Wmb jnW2pbdA==; Received: from i53875a3a.versanet.de ([83.135.90.58] helo=phil.fritz.box) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1vG3zh-0007mj-KX; Tue, 04 Nov 2025 00:29:49 +0100 From: Heiko Stuebner To: lee@kernel.org, srini@kernel.org Cc: heiko@sntech.de, linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] mfd: qnap-mcu: Hook up the eeprom sub-device Date: Tue, 4 Nov 2025 00:29:42 +0100 Message-ID: <20251103232942.410386-3-heiko@sntech.de> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20251103232942.410386-1-heiko@sntech.de> References: <20251103232942.410386-1-heiko@sntech.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the qnap-mcu-eeprom platform-driver as sub-device for the MCU. Signed-off-by: Heiko Stuebner --- drivers/mfd/qnap-mcu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mfd/qnap-mcu.c b/drivers/mfd/qnap-mcu.c index 4ec1f4cf902f..2be429a50611 100644 --- a/drivers/mfd/qnap-mcu.c +++ b/drivers/mfd/qnap-mcu.c @@ -264,6 +264,7 @@ static const struct qnap_mcu_variant qnap_ts433_mcu =3D= { }; =20 static struct mfd_cell qnap_mcu_cells[] =3D { + { .name =3D "qnap-mcu-eeprom", }, { .name =3D "qnap-mcu-input", }, { .name =3D "qnap-mcu-leds", }, { .name =3D "qnap-mcu-hwmon", } --=20 2.47.2