Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1534130pxy; Thu, 29 Apr 2021 08:59:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUC/Eic5oS6SQKi0dfUIUlS7+35XkxYkDPbcmT5DGrCHC3kG6VBz0NnZ7lxdpWg9Obimyb X-Received: by 2002:a63:4d24:: with SMTP id a36mr400091pgb.64.1619711954047; Thu, 29 Apr 2021 08:59:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619711954; cv=none; d=google.com; s=arc-20160816; b=HmTVO92PMk+0gdzaYYxE2CgeSw4wuiCXdPi0xT7f9V00hF/JssVKABUfoqZ2sjdCZn EnIsjrwNXo71H6FGg97JqZgt35XlaaTNq5iOIavcewN+vRPaO+u6FiMPIDY/zEv4dD0B YKZRsEW3QhvhmMdNc7KaviRagHfOIhhFWqM05ElqNt0UXpHGE71Og5q45VFcd30tU4wF S6tRgVXlVVlodl9l/ZOxwoSPh+IIsz+W/KxCvTv1WOIrVvYmqjoax/CRiButVMcbE/+/ HXtVOSsjEpzbXo1siAQWf2xzUj7cfcCFO30y/VzOgV88cfKjtQlvlKJOhf2tP8A6qlWY kHyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=exHt7jGjL5ivMzMAGm04Xavf1GZfyAPchfYVuiKjf8w=; b=Vvny5aogC5LievAbwpm2rImL9dCs8SzSi+d1KGRvVcYor+KY0PTPp6mb47KbHfzjcH SEHG9qxkz2Ecp8lLGoYUk7F+zDTF6awnrChLvKy7n/SBKXmo9binuxZYTaWFqA0N6fEt XmCOx7WpHRqfnnmBT1E1CyHh2L2iY/ANU5uphYaYAhosU4GOHTZJQnjmJ1X4l/utU/ud cbgiNk6aleD/so+0xjaSJj51Xec+pJ9WVM4Ncn8MFNunogQ2I0c1q46zTqg2eAO7ITZy rqpZXV2z4RLokmtMl9WBQo/9I+ZwoxZ//fUY6kJPqTDOIoQ8r2xSkRxR+B2F3JLyVU5S JPhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=dHbfL81z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v11si139035plp.409.2021.04.29.08.58.50; Thu, 29 Apr 2021 08:59:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=dHbfL81z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240773AbhD2P6V (ORCPT + 99 others); Thu, 29 Apr 2021 11:58:21 -0400 Received: from ssl.serverraum.org ([176.9.125.105]:43675 "EHLO ssl.serverraum.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233132AbhD2P6S (ORCPT ); Thu, 29 Apr 2021 11:58:18 -0400 Received: from mwalle01.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:fa59:71ff:fe9b:b851]) (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 2F22B22234; Thu, 29 Apr 2021 17:57:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1619711849; 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=exHt7jGjL5ivMzMAGm04Xavf1GZfyAPchfYVuiKjf8w=; b=dHbfL81zqkW46HjcWv78rLQ3dhoHkDsS0Ik55w2HaOqHvZR6N/lFvU9kHLWdyU86+dLWpm R2tERNiOyT3sAcLm89/k9XEQO0pUnhy3uv70z+ZkyTqRsn94/X/1YQ29ivSqYHl08P5QOn MwJnnvV7QZekLdDjaGuGLoGxDbFBw6k= From: Michael Walle To: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Cc: Tudor Ambarus , Pratyush Yadav , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Alexander Williams , Yicong Yang , Heiko Thiery , Michael Walle Subject: [PATCH v3 2/2] mtd: spi-nor: add initial sysfs support Date: Thu, 29 Apr 2021 17:57:13 +0200 Message-Id: <20210429155713.28808-3-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210429155713.28808-1-michael@walle.cc> References: <20210429155713.28808-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support to show the manufacturer, the partname and JEDEC identifier as well as to dump the SFDP table. Not all flashes list their SFDP table contents in their datasheet. So having that is useful. It might also be helpful in bug reports from users. Signed-off-by: Michael Walle --- Pratyush, Heiko, I've dropped your Acked and Tested-by because there were some changes. .../ABI/testing/sysfs-bus-spi-devices-spi-nor | 31 +++++++ drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 2 + drivers/mtd/spi-nor/sysfs.c | 92 +++++++++++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor create mode 100644 drivers/mtd/spi-nor/sysfs.c diff --git a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file mode 100644 index 000000000000..4c88307759e2 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor @@ -0,0 +1,31 @@ +What: /sys/bus/spi/devices/.../jedec_id +Date: April 2021 +KernelVersion: 5.14 +Contact: linux-mtd@lists.infradead.org +Description: (RO) The JEDEC ID of the SPI NOR flash as reported by the + flash device. + + +What: /sys/bus/spi/devices/.../manufacturer +Date: April 2021 +KernelVersion: 5.14 +Contact: linux-mtd@lists.infradead.org +Description: (RO) Manufacturer of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../partname +Date: April 2021 +KernelVersion: 5.14 +Contact: linux-mtd@lists.infradead.org +Description: (RO) Part name of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../sfdp +Date: April 2021 +KernelVersion: 5.14 +Contact: linux-mtd@lists.infradead.org +Description: (RO) This attribute is only present if the SPI NOR flash + device supports the "Read SFDP" command (5Ah). + + If present, it contains the complete SFDP (serial flash + discoverable parameters) binary data of the flash. diff --git a/drivers/mtd/spi-nor/Makefile b/drivers/mtd/spi-nor/Makefile index 136f245c91dc..6b904e439372 100644 --- a/drivers/mtd/spi-nor/Makefile +++ b/drivers/mtd/spi-nor/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -spi-nor-objs := core.o sfdp.o swp.o otp.o +spi-nor-objs := core.o sfdp.o swp.o otp.o sysfs.o spi-nor-objs += atmel.o spi-nor-objs += catalyst.o spi-nor-objs += eon.o diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 20c7ee604731..57d8a4dae5fd 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -3349,6 +3349,7 @@ static struct spi_mem_driver spi_nor_driver = { .driver = { .name = "spi-nor", .of_match_table = spi_nor_of_table, + .dev_groups = spi_nor_sysfs_groups, }, .id_table = spi_nor_dev_ids, }, diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h index 92ee2f6551b3..b988e5e64b2d 100644 --- a/drivers/mtd/spi-nor/core.h +++ b/drivers/mtd/spi-nor/core.h @@ -489,6 +489,8 @@ extern const struct spi_nor_manufacturer spi_nor_winbond; extern const struct spi_nor_manufacturer spi_nor_xilinx; extern const struct spi_nor_manufacturer spi_nor_xmc; +extern const struct attribute_group *spi_nor_sysfs_groups[]; + void spi_nor_spimem_setup_op(const struct spi_nor *nor, struct spi_mem_op *op, const enum spi_nor_protocol proto); diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c new file mode 100644 index 000000000000..8f1aad4061cd --- /dev/null +++ b/drivers/mtd/spi-nor/sysfs.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include + +#include "core.h" + +static ssize_t manufacturer_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct spi_device *spi = to_spi_device(dev); + struct spi_mem *spimem = spi_get_drvdata(spi); + struct spi_nor *nor = spi_mem_get_drvdata(spimem); + + return sysfs_emit(buf, "%s\n", nor->manufacturer->name); +} +static DEVICE_ATTR_RO(manufacturer); + +static ssize_t partname_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct spi_device *spi = to_spi_device(dev); + struct spi_mem *spimem = spi_get_drvdata(spi); + struct spi_nor *nor = spi_mem_get_drvdata(spimem); + + return sysfs_emit(buf, "%s\n", nor->info->name); +} +static DEVICE_ATTR_RO(partname); + +static ssize_t jedec_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct spi_device *spi = to_spi_device(dev); + struct spi_mem *spimem = spi_get_drvdata(spi); + struct spi_nor *nor = spi_mem_get_drvdata(spimem); + + return sysfs_emit(buf, "%*phN\n", nor->info->id_len, nor->info->id); +} +static DEVICE_ATTR_RO(jedec_id); + +static struct attribute *spi_nor_sysfs_entries[] = { + &dev_attr_manufacturer.attr, + &dev_attr_partname.attr, + &dev_attr_jedec_id.attr, + NULL +}; + +static ssize_t sfdp_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, char *buf, + loff_t off, size_t count) +{ + struct spi_device *spi = to_spi_device(kobj_to_dev(kobj)); + struct spi_mem *spimem = spi_get_drvdata(spi); + struct spi_nor *nor = spi_mem_get_drvdata(spimem); + struct sfdp *sfdp = nor->sfdp; + size_t sfdp_size = sfdp->num_dwords * sizeof(*sfdp->dwords); + + return memory_read_from_buffer(buf, count, &off, nor->sfdp->dwords, + sfdp_size); +} +static BIN_ATTR_RO(sfdp, 0); + +static struct bin_attribute *spi_nor_sysfs_bin_entries[] = { + &bin_attr_sfdp, + NULL +}; + +static umode_t spi_nor_sysfs_is_bin_visible(struct kobject *kobj, + struct bin_attribute *attr, int n) +{ + struct spi_device *spi = to_spi_device(kobj_to_dev(kobj)); + struct spi_mem *spimem = spi_get_drvdata(spi); + struct spi_nor *nor = spi_mem_get_drvdata(spimem); + + if (attr == &bin_attr_sfdp && nor->sfdp) + return 0444; + + return 0; +} + +static const struct attribute_group spi_nor_sysfs_group = { + .is_bin_visible = spi_nor_sysfs_is_bin_visible, + .attrs = spi_nor_sysfs_entries, + .bin_attrs = spi_nor_sysfs_bin_entries, +}; + +const struct attribute_group *spi_nor_sysfs_groups[] = { + &spi_nor_sysfs_group, + NULL +}; -- 2.20.1