From nobody Fri May 8 01:40:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 880A9C43217 for ; Fri, 13 May 2022 13:39:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359698AbiEMNiG (ORCPT ); Fri, 13 May 2022 09:38:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381348AbiEMNfc (ORCPT ); Fri, 13 May 2022 09:35:32 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D194F5FCF for ; Fri, 13 May 2022 06:35:29 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id DFE65221D4; Fri, 13 May 2022 15:35:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1652448928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9ZoXseUxXDuBhnUU+CGsQXKX/xQuLPABnNgtpp1mC+U=; b=YQJ0xJ6ilUYAf2PtdFVg0FFO7xDDVImh8oloeDySiX/UTZmczh09vDOmjmGjqNbBy1W72O +xVqWrrrnVPOkQkd4SEjgEoE21WbuM4NfMKz+eueT95K9CghOTvA9jClPAsWO0H5K8rNqX MSzsMTjNPw/UxRUrSGu7Qj8oob+aiQI= From: Michael Walle To: Tudor Ambarus , Pratyush Yadav , Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH 1/6] mtd: spi-nor: hide jedec_id sysfs attribute if not present Date: Fri, 13 May 2022 15:35:15 +0200 Message-Id: <20220513133520.3945820-2-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220513133520.3945820-1-michael@walle.cc> References: <20220513133520.3945820-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some non-jedec compliant flashes (like the Everspin flashes) don't have an ID at all. Hide the attribute in this case. Fixes: 36ac02286265 ("mtd: spi-nor: add initial sysfs support") Signed-off-by: Michael Walle Reviewed-by: Takahiro Kuwano --- .../ABI/testing/sysfs-bus-spi-devices-spi-nor | 3 +++ drivers/mtd/spi-nor/sysfs.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor b/Docu= mentation/ABI/testing/sysfs-bus-spi-devices-spi-nor index d76cd3946434..e9ef69aef20b 100644 --- a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor +++ b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor @@ -5,6 +5,9 @@ Contact: linux-mtd@lists.infradead.org Description: (RO) The JEDEC ID of the SPI NOR flash as reported by the flash device. =20 + The attribute is not present if the flash doesn't support + the "Read JEDEC ID" command (9Fh). This is the case for + non-JEDEC compliant flashes. =20 What: /sys/bus/spi/devices/.../spi-nor/manufacturer Date: April 2021 diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c index 9aec9d8a98ad..4c3b351aef24 100644 --- a/drivers/mtd/spi-nor/sysfs.c +++ b/drivers/mtd/spi-nor/sysfs.c @@ -67,6 +67,19 @@ static struct bin_attribute *spi_nor_sysfs_bin_entries[]= =3D { NULL }; =20 +static umode_t spi_nor_sysfs_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + struct spi_device *spi =3D to_spi_device(kobj_to_dev(kobj)); + struct spi_mem *spimem =3D spi_get_drvdata(spi); + struct spi_nor *nor =3D spi_mem_get_drvdata(spimem); + + if (attr =3D=3D &dev_attr_jedec_id.attr && !nor->info->id_len) + return 0; + + return 0444; +} + static umode_t spi_nor_sysfs_is_bin_visible(struct kobject *kobj, struct bin_attribute *attr, int n) { @@ -82,6 +95,7 @@ static umode_t spi_nor_sysfs_is_bin_visible(struct kobjec= t *kobj, =20 static const struct attribute_group spi_nor_sysfs_group =3D { .name =3D "spi-nor", + .is_visible =3D spi_nor_sysfs_is_visible, .is_bin_visible =3D spi_nor_sysfs_is_bin_visible, .attrs =3D spi_nor_sysfs_entries, .bin_attrs =3D spi_nor_sysfs_bin_entries, --=20 2.30.2 From nobody Fri May 8 01:40:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92EC6C433F5 for ; Fri, 13 May 2022 13:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355744AbiEMNiI (ORCPT ); Fri, 13 May 2022 09:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381350AbiEMNfc (ORCPT ); Fri, 13 May 2022 09:35:32 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4753A614D for ; Fri, 13 May 2022 06:35:30 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 62C1822249; Fri, 13 May 2022 15:35:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1652448928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MRhm9+AKqiCcFzEMtgbAPpFPGlNCeXLEsZ2HWJ7ms0c=; b=ZhTR67jMRyktCADJBzMCgBxZXj5Y48+NC4yRJ2e+cLkHVKej8MxqnREkz56Kx/05gT3slt shj3wLY+wp3CwbGtPvULuvDRGPXlnntCSem8E5uTc/o/w2jVA4DScBmhSui79amE1ZeOHH nqyem7xqbK3UCQ9qct/bCAF0zhKN3cQ= From: Michael Walle To: Tudor Ambarus , Pratyush Yadav , Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH 2/6] mtd: spi-nor: sysfs: hide manufacturer if it is not set Date: Fri, 13 May 2022 15:35:16 +0200 Message-Id: <20220513133520.3945820-3-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220513133520.3945820-1-michael@walle.cc> References: <20220513133520.3945820-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The manufacturer may be optional when pure SFDP flashes are supported. Hide the sysfs property if no manufacturer is set. Signed-off-by: Michael Walle Reviewed-by: Takahiro Kuwano --- Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor | 3 +++ drivers/mtd/spi-nor/sysfs.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor b/Docu= mentation/ABI/testing/sysfs-bus-spi-devices-spi-nor index e9ef69aef20b..c800621eff95 100644 --- a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor +++ b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor @@ -15,6 +15,9 @@ KernelVersion: 5.14 Contact: linux-mtd@lists.infradead.org Description: (RO) Manufacturer of the SPI NOR flash. =20 + The attribute is not present if the flash device isn't + known to the kernel and is only probed by its SFDP + tables. =20 What: /sys/bus/spi/devices/.../spi-nor/partname Date: April 2021 diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c index 4c3b351aef24..20563c1926f4 100644 --- a/drivers/mtd/spi-nor/sysfs.c +++ b/drivers/mtd/spi-nor/sysfs.c @@ -74,6 +74,8 @@ static umode_t spi_nor_sysfs_is_visible(struct kobject *k= obj, struct spi_mem *spimem =3D spi_get_drvdata(spi); struct spi_nor *nor =3D spi_mem_get_drvdata(spimem); =20 + if (attr =3D=3D &dev_attr_manufacturer.attr && !nor->manufacturer) + return 0; if (attr =3D=3D &dev_attr_jedec_id.attr && !nor->info->id_len) return 0; =20 --=20 2.30.2 From nobody Fri May 8 01:40:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77D7FC43219 for ; Fri, 13 May 2022 13:39:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381553AbiEMNiC (ORCPT ); Fri, 13 May 2022 09:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381352AbiEMNfd (ORCPT ); Fri, 13 May 2022 09:35:33 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D92C615F for ; Fri, 13 May 2022 06:35:30 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id ABD222224D; Fri, 13 May 2022 15:35:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1652448928; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xavI/gAisc47AB04Lxd4coGNq76/GR9N74Rm+AMG6uI=; b=kV8Y0Jw3EDQL4i0NJHEfAhJ6F0g6bKhBayKgmBQbhkRYWqUV4GlnZm/c8aLAPLdcgiqASR jB9UiWS2jzfGWRVwAQbsciLbjfFAWZDf3zNygvuEogdP7bBYgQR2ZGhJwDOvhfRGQjEWQn Bxjdq579wN/jjTOL8dfZlo92oVv+MAg= From: Michael Walle To: Tudor Ambarus , Pratyush Yadav , Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH 3/6] mtd: spi-nor: remember full JEDEC flash ID Date: Fri, 13 May 2022 15:35:17 +0200 Message-Id: <20220513133520.3945820-4-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220513133520.3945820-1-michael@walle.cc> References: <20220513133520.3945820-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" At the moment, we print the JEDEC ID that is stored in our database. The generic flash support won't have such an entry in our database. To find out the JEDEC ID later we will have to cache it. There is also another advantage: If the flash is found in the database, the ID could be truncated because the ID of the entry is used which can be shorter. Some flashes still holds valuable information in the bytes after the JEDEC ID and come in handy during debugging of when coping with INFO6() entries. These are not accessible for now. Save a copy of the ID bytes after reading and display it via debugfs. Signed-off-by: Michael Walle Reviewed-by: Takahiro Kuwano --- drivers/mtd/spi-nor/core.c | 5 +++++ drivers/mtd/spi-nor/debugfs.c | 2 +- include/linux/mtd/spi-nor.h | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index ce5d69317d46..65cd8e668579 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -1664,6 +1664,11 @@ static const struct flash_info *spi_nor_detect(struc= t spi_nor *nor) return ERR_PTR(ret); } =20 + /* Cache the complete flash ID. */ + nor->id =3D devm_kmemdup(nor->dev, id, SPI_NOR_MAX_ID_LEN, GFP_KERNEL); + if (!nor->id) + return ERR_PTR(-ENOMEM); + info =3D spi_nor_match_id(nor, id); if (!info) { dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n", diff --git a/drivers/mtd/spi-nor/debugfs.c b/drivers/mtd/spi-nor/debugfs.c index eaf84f7a0676..23d51e7ba0a7 100644 --- a/drivers/mtd/spi-nor/debugfs.c +++ b/drivers/mtd/spi-nor/debugfs.c @@ -81,7 +81,7 @@ static int spi_nor_params_show(struct seq_file *s, void *= data) int i; =20 seq_printf(s, "name\t\t%s\n", info->name); - seq_printf(s, "id\t\t%*ph\n", info->id_len, info->id); + seq_printf(s, "id\t\t%*ph\n", SPI_NOR_MAX_ID_LEN, nor->id); string_get_size(params->size, 1, STRING_UNITS_2, buf, sizeof(buf)); seq_printf(s, "size\t\t%s\n", buf); seq_printf(s, "write size\t%u\n", params->writesize); diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 1ede4c89805a..4dd6cd7389ca 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -349,6 +349,8 @@ struct spi_nor_flash_parameter; * @bouncebuf: bounce buffer used when the buffer passed by the MTD * layer is not DMA-able * @bouncebuf_size: size of the bounce buffer + * @id: The flash's ID bytes. Always contains + * SPI_NOR_MAX_ID_LEN bytes. * @info: SPI NOR part JEDEC MFR ID and other info * @manufacturer: SPI NOR manufacturer * @addr_width: number of address bytes @@ -379,6 +381,7 @@ struct spi_nor { struct spi_mem *spimem; u8 *bouncebuf; size_t bouncebuf_size; + u8 *id; const struct flash_info *info; const struct spi_nor_manufacturer *manufacturer; u8 addr_width; --=20 2.30.2 From nobody Fri May 8 01:40:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55F97C4332F for ; Fri, 13 May 2022 13:39:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381543AbiEMNh6 (ORCPT ); Fri, 13 May 2022 09:37:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381353AbiEMNfd (ORCPT ); Fri, 13 May 2022 09:35:33 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D954662CB for ; Fri, 13 May 2022 06:35:30 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 1B5322224E; Fri, 13 May 2022 15:35:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1652448929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lh+U1nOda0NfWwmDOTPUquxb7TCGhj6x58ZzYRjPX6s=; b=pVZMQFzcRU2XQkzbBw/yFO4g/TsrQlIiyZqHFvWyN2BqYIFDIlaTr9gs3/u1OANW56hJO/ WojOnHdh5g7uhlcv9d3Xo82vkmNsHiKWlrEd0pwBc8KDuaSEXlLMBfwDoJ4IKo0JYJ1K5x uwu7/caqzng7tXPCASG4krs2f+q6Hks= From: Michael Walle To: Tudor Ambarus , Pratyush Yadav , Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH 4/6] mtd: spi-nor: move function declaration out of sfdp.h Date: Fri, 13 May 2022 15:35:18 +0200 Message-Id: <20220513133520.3945820-5-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220513133520.3945820-1-michael@walle.cc> References: <20220513133520.3945820-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" sfdp.h should only contain constants related to the JEDEC SFDP specification(s). Signed-off-by: Michael Walle Reviewed-by: Takahiro Kuwano --- drivers/mtd/spi-nor/core.h | 2 ++ drivers/mtd/spi-nor/sfdp.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 61886868cd02..3a19b8092ab8 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -694,6 +694,8 @@ int spi_nor_controller_ops_read_reg(struct spi_nor *nor= , u8 opcode, int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode, const u8 *buf, size_t len); =20 +int spi_nor_parse_sfdp(struct spi_nor *nor); + static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd) { return container_of(mtd, struct spi_nor, mtd); diff --git a/drivers/mtd/spi-nor/sfdp.h b/drivers/mtd/spi-nor/sfdp.h index bbf80d2990ab..c1969f0a2f46 100644 --- a/drivers/mtd/spi-nor/sfdp.h +++ b/drivers/mtd/spi-nor/sfdp.h @@ -107,6 +107,4 @@ struct sfdp_parameter_header { u8 id_msb; }; =20 -int spi_nor_parse_sfdp(struct spi_nor *nor); - #endif /* __LINUX_MTD_SFDP_H */ --=20 2.30.2 From nobody Fri May 8 01:40:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97162C4167B for ; Fri, 13 May 2022 13:39:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381592AbiEMNiN (ORCPT ); Fri, 13 May 2022 09:38:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381355AbiEMNff (ORCPT ); Fri, 13 May 2022 09:35:35 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA4EE63A6 for ; Fri, 13 May 2022 06:35:33 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 672202224F; Fri, 13 May 2022 15:35:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1652448929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LJSt6IT3ECdLzAVmB/COzMrm9/Mol0eBhyUGK0zCRhc=; b=lVVp1YCd4TNs7AOsWX50tJLf4Fe/V+31U8QWT4eM33NZIvm8U2aoEGWZnFh0mWl6x36RoL RXFsr/GhNPSShK1g/EwEdHNbjeU/jG15FulAojMh52qz6xadEiMIScEESlW8TERlPGT/4/ hLqzVn/UCeNA6Gf5hQgmEtbZxjCmcyE= From: Michael Walle To: Tudor Ambarus , Pratyush Yadav , Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH 5/6] mtd: spi-nor: add generic flash driver Date: Fri, 13 May 2022 15:35:19 +0200 Message-Id: <20220513133520.3945820-6-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220513133520.3945820-1-michael@walle.cc> References: <20220513133520.3945820-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Our SFDP is parsing is everything we need to support all basic operations of a flash device. If the flash isn't found in our in-kernel flash database, gracefully fall back to a driver described solely by its SFDP tables. It is still recommended to add the flash to the in-kernel database. First, we get a proper partname and secondly, for all features not described by the SFDP like OTP we need the entry anyway. Signed-off-by: Michael Walle Reported-by: kernel test robot Reviewed-by: Takahiro Kuwano --- drivers/mtd/spi-nor/core.c | 13 +++++++++++++ drivers/mtd/spi-nor/core.h | 1 + drivers/mtd/spi-nor/sfdp.c | 27 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 65cd8e668579..ee193a61310a 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -1632,6 +1632,11 @@ static const struct spi_nor_manufacturer *manufactur= ers[] =3D { &spi_nor_xmc, }; =20 +static const struct flash_info spi_nor_generic_flash =3D { + .name =3D "spi-nor-generic", + .parse_sfdp =3D true, +}; + static const struct flash_info *spi_nor_match_id(struct spi_nor *nor, const u8 *id) { @@ -1670,6 +1675,14 @@ static const struct flash_info *spi_nor_detect(struc= t spi_nor *nor) return ERR_PTR(-ENOMEM); =20 info =3D spi_nor_match_id(nor, id); + + /* Fallback to a generic flash described only by its SFDP data. */ + if (!info) { + ret =3D spi_nor_check_sfdp_signature(nor); + if (!ret) + info =3D &spi_nor_generic_flash; + } + if (!info) { dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n", SPI_NOR_MAX_ID_LEN, id); diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 3a19b8092ab8..aa9f218245a5 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -694,6 +694,7 @@ int spi_nor_controller_ops_read_reg(struct spi_nor *nor= , u8 opcode, int spi_nor_controller_ops_write_reg(struct spi_nor *nor, u8 opcode, const u8 *buf, size_t len); =20 +int spi_nor_check_sfdp_signature(struct spi_nor *nor); int spi_nor_parse_sfdp(struct spi_nor *nor); =20 static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd) diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c index a5211543d30d..9bdb3d5dc7e8 100644 --- a/drivers/mtd/spi-nor/sfdp.c +++ b/drivers/mtd/spi-nor/sfdp.c @@ -1247,6 +1247,33 @@ static void spi_nor_post_sfdp_fixups(struct spi_nor = *nor) nor->info->fixups->post_sfdp(nor); } =20 +/** + * spi_nor_check_sfdp_header() - check for a valid SFDP header + * @nor: pointer to a 'struct spi_nor' + * + * Used to detect if the flash supports the RDSFDP command as well as the + * presence of a valid SFDP table. + * + * Return: 0 on success, -errno otherwise. + */ +int spi_nor_check_sfdp_signature(struct spi_nor *nor) +{ + u32 signature; + int err; + + /* Get the SFDP header. */ + err =3D spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(signature), + &signature); + if (err < 0) + return err; + + /* Check the SFDP signature. */ + if (le32_to_cpu(signature) !=3D SFDP_SIGNATURE) + return -EINVAL; + + return 0; +} + /** * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters. * @nor: pointer to a 'struct spi_nor' --=20 2.30.2 From nobody Fri May 8 01:40:18 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5DF5C43217 for ; Fri, 13 May 2022 13:38:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381603AbiEMNiS (ORCPT ); Fri, 13 May 2022 09:38:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381356AbiEMNff (ORCPT ); Fri, 13 May 2022 09:35:35 -0400 Received: from ssl.serverraum.org (ssl.serverraum.org [176.9.125.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA67263B8 for ; Fri, 13 May 2022 06:35:33 -0700 (PDT) Received: from mwalle01.kontron.local. (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id AD66022253; Fri, 13 May 2022 15:35:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1652448929; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7SVQYJZn3MFW22DboTz0AGRIBdFV6caUuIlQOpfVNEM=; b=OqgVcIKS9cWpiQSb6R55BgLtStx6Yx9vXWnqlEsYfTEm5DYWcLaRCzLRvv6cTYbrhFCvng hy7n5II+ilnbm8VrXTtcrzWBghu5e5J3dj/HsoXNSZVFJhDTZlnjfSjjnU8vQyHb86QlCg HlOfx8oSH8wmt9CvAPSNdXx5046yqXw= From: Michael Walle To: Tudor Ambarus , Pratyush Yadav , Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH 6/6] mtd: spi-nor: sysfs: print JEDEC ID for generic flash driver Date: Fri, 13 May 2022 15:35:20 +0200 Message-Id: <20220513133520.3945820-7-michael@walle.cc> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220513133520.3945820-1-michael@walle.cc> References: <20220513133520.3945820-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We don't have a database entry for the generic SPI-NOR flash driver and thus we don't have a JEDEC ID to print. Print the (cached) JEDEC ID instead. Signed-off-by: Michael Walle Reviewed-by: Takahiro Kuwano --- drivers/mtd/spi-nor/sysfs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c index 20563c1926f4..c09bb832b3b9 100644 --- a/drivers/mtd/spi-nor/sysfs.c +++ b/drivers/mtd/spi-nor/sysfs.c @@ -35,8 +35,10 @@ static ssize_t jedec_id_show(struct device *dev, struct spi_device *spi =3D to_spi_device(dev); struct spi_mem *spimem =3D spi_get_drvdata(spi); struct spi_nor *nor =3D spi_mem_get_drvdata(spimem); + const u8 *id =3D nor->info->id_len ? nor->info->id : nor->id; + u8 id_len =3D nor->info->id_len ?: SPI_NOR_MAX_ID_LEN; =20 - return sysfs_emit(buf, "%*phN\n", nor->info->id_len, nor->info->id); + return sysfs_emit(buf, "%*phN\n", id_len, id); } static DEVICE_ATTR_RO(jedec_id); =20 @@ -76,7 +78,7 @@ static umode_t spi_nor_sysfs_is_visible(struct kobject *k= obj, =20 if (attr =3D=3D &dev_attr_manufacturer.attr && !nor->manufacturer) return 0; - if (attr =3D=3D &dev_attr_jedec_id.attr && !nor->info->id_len) + if (attr =3D=3D &dev_attr_jedec_id.attr && !nor->info->id_len && !nor->id) return 0; =20 return 0444; --=20 2.30.2