From patchwork Mon Jul 1 13:53:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 13718173 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 24E21C30653 for ; Mon, 1 Jul 2024 13:56:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RzH6RKhqG7asGToyqbDIc0Ta9xHkhu3O+xKJKjCA3DE=; b=yJZRS9HvZpHphZ81humNvR3z34 hA5vS3y84ZCalhL0mv0YqyOv/BJuJg+pQaN63/HdI7tUjt35EofRyQM/6YmQpJciPzTVpcZEx/Pxr aRK3x2nUyCO0hbOCbpfCmOL0Dy6SzHPtVQpw2YCqx9ykJhgyamlEBc8jb9JBDvh7ycUPnN9B4PNmo PtMLHqHkzlQ1uf2dfxcEr73yoMrk18wZtDBcOWZY26D44+kjFDp1rTB5KvYcGhBUIHs1pBeYPbYKc iwZTw7turpucNkXKiBmrKrV/B5HIvFk8UxAGtFTt1X+C+8jjAtCv5z4o7nQWfT1rH+ZK2ECdhRvG0 HSU5ZjWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOHWE-00000003bi0-13Xa; Mon, 01 Jul 2024 13:56:34 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOHUl-00000003ati-0zBX for linux-arm-kernel@bombadil.infradead.org; Mon, 01 Jul 2024 13:55:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=RzH6RKhqG7asGToyqbDIc0Ta9xHkhu3O+xKJKjCA3DE=; b=lb7dDR4OMzjVRMb6hEYWFRc8EM lIXe1HteG5yGVckBN3bieP/YI87dXkxYrM/3mw4mKN3R53ThDW0ZI6t3TF4cxd2VQZ/zVb3jQuhgt YRdiOXonDgu3+ulwRl/6sIs2v+39HagIztDb3wfhiNKc3raf/rzyOUwjFBwVnMNJ0MIa4fgNVxsud N+kp5ZJTQVLCQWuUjqM6a1gYxuXu/iRtIAJBcJ0p3YmtGkfx+heD2c1pLHZAzcBuJf1XhOS1u2dw1 G806pmjQHnmIaIHl7FS1JL1upgbaUzBOSocm4HxwOFKV3fIFe8KOZAi1eC29Q/ydQluCNnpOFX9fg FdRZ9iQA==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sOHUg-00000009fWm-1LRh for linux-arm-kernel@lists.infradead.org; Mon, 01 Jul 2024 13:55:01 +0000 Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1sOHTX-0001LY-Aa; Mon, 01 Jul 2024 15:53:47 +0200 From: Marco Felsch Date: Mon, 01 Jul 2024 15:53:42 +0200 Subject: [PATCH 3/9] mtd: add support to handle EEPROM devices MIME-Version: 1.0 Message-Id: <20240701-b4-v6-10-topic-usbc-tcpci-v1-3-3fd5f4a193cc@pengutronix.de> References: <20240701-b4-v6-10-topic-usbc-tcpci-v1-0-3fd5f4a193cc@pengutronix.de> In-Reply-To: <20240701-b4-v6-10-topic-usbc-tcpci-v1-0-3fd5f4a193cc@pengutronix.de> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Arnd Bergmann , Greg Kroah-Hartman , Bartosz Golaszewski , Russell King , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Vladimir Zapolskiy , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Tony Lindgren , Geert Uytterhoeven , Magnus Damm , Dinh Nguyen , Thierry Reding , Jonathan Hunter , =?utf-8?q?Jonathan_Neusch=C3=A4fer?= , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Naveen N. Rao" , Thomas Bogendoerfer , Huacai Chen , WANG Xuerui Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, imx@lists.linux.dev, linux-omap@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-tegra@vger.kernel.org, openbmc@lists.ozlabs.org, linuxppc-dev@lists.ozlabs.org, linux-mips@vger.kernel.org, loongarch@lists.linux.dev, Marco Felsch X-Mailer: b4 0.15-dev X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240701_145459_011540_8150C6F7 X-CRM114-Status: GOOD ( 23.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org At the moment EEPROMs are covered by misc/driver/eeprom/* drivers. This commit prepares the MTD framework to handle EEPROM devices within the MTD layer. To keep the backward compatibility with the current misc drivers the master device must be exposed always. Furthermore the NVMEM device parent must be set to the I2C device instead of the MTD device and the name must be either the I2C device name or the name specified via the label. Signed-off-by: Marco Felsch --- drivers/mtd/mtdcore.c | 32 +++++++++++++++++++++++++++++++- include/uapi/mtd/mtd-abi.h | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index dcd97e59425e..e2a996ccd17e 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -149,6 +149,9 @@ static ssize_t mtd_type_show(struct device *dev, case MTD_ROM: type = "rom"; break; + case MTD_EEPROM: + type = "eeprom"; + break; case MTD_NORFLASH: type = "nor"; break; @@ -578,6 +581,33 @@ static int mtd_nvmem_add(struct mtd_info *mtd) config.ignore_wp = true; config.priv = mtd; + switch (mtd->type) { + case MTD_EEPROM: + config.type = NVMEM_TYPE_EEPROM; + /* + * The master device must be backward compatible with the + * predecessor (misc/eeprom/at24.c) driver. Therefore we need to + * adapt the naming scheme. + * + * Initialize config.id to NVMEM_DEVID_AUTO even if the + * mtd->name is provided via an label as some platform can have + * multiple eeproms with same label and we can not register each + * of those with same label. Failing to register those eeproms + * trigger cascade failure on such platform. + */ + if (mtd_is_master(mtd)) { + config.id = NVMEM_DEVID_AUTO; + config.compat = true; + config.name = mtd->name; + config.dev = mtd->dev.parent; + config.base_dev = mtd->dev.parent; + } + break; + default: + config.type = NVMEM_TYPE_UNKNOWN; + break; + } + mtd->nvmem = nvmem_register(&config); if (IS_ERR(mtd->nvmem)) { /* Just ignore if there is no NVMEM support in the kernel */ @@ -1076,7 +1106,7 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types, if (ret) goto out; - if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER)) { + if (IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER) || mtd->type == MTD_EEPROM) { ret = add_mtd_device(mtd); if (ret) goto out; diff --git a/include/uapi/mtd/mtd-abi.h b/include/uapi/mtd/mtd-abi.h index 714d55b49d2a..59bf43d58ddb 100644 --- a/include/uapi/mtd/mtd-abi.h +++ b/include/uapi/mtd/mtd-abi.h @@ -146,6 +146,7 @@ struct mtd_read_req { #define MTD_DATAFLASH 6 #define MTD_UBIVOLUME 7 #define MTD_MLCNANDFLASH 8 /* MLC NAND (including TLC) */ +#define MTD_EEPROM 9 #define MTD_WRITEABLE 0x400 /* Device is writeable */ #define MTD_BIT_WRITEABLE 0x800 /* Single bits can be flipped */ @@ -159,6 +160,7 @@ struct mtd_read_req { #define MTD_CAP_NORFLASH (MTD_WRITEABLE | MTD_BIT_WRITEABLE) #define MTD_CAP_NANDFLASH (MTD_WRITEABLE) #define MTD_CAP_NVRAM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE) +#define MTD_CAP_EEPROM (MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE) /* Obsolete ECC byte placement modes (used with obsolete MEMGETOOBSEL) */ #define MTD_NANDECC_OFF 0 /* Switch off ECC (Not recommended) */