From patchwork Thu Mar 28 04:59:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhuohao Lee X-Patchwork-Id: 1067763 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="PnorP7zx"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="LF1mrqe7"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44VCNG4XThz9sPn for ; Thu, 28 Mar 2019 15:59:58 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=NKLLet8oWRX7LKRPOp+ZDqjXADRUoZ4gBMi0SgxljXw=; b=PnorP7zxnbIW8n 6n3LFxrZwg5XsvcI454cxhRNYiRKJwnHKrqP0qfmLbmI/kiwJn3mNoDJGhxuvHvenMKNSr25+2uwU TJWbZU4+bU5zMQSzNZF6DZWp5/m6DZjevxuA93Z77gZBcZHBoDgSh3MOf/QQy0Oq2jCcx4VAr3gqJ AC7Y9gz6naxfqPAn6pIw4bmD1QbYJARC+P9UIQdsWUe+iPlZpnDiyZ65+PsPsdlJPk9+lanmxuQJa 5scdfR6KYSqRm+B+bg4VYVjmmAMgnL/35tCk9f6WeCCIB6+z8neHqNA8+bthmTKgiNaYzqORC5cTY L4ZydHvdEmXw/s9eRrWA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9N8p-00005f-3m; Thu, 28 Mar 2019 04:59:51 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h9N8k-00005H-QG for linux-mtd@lists.infradead.org; Thu, 28 Mar 2019 04:59:48 +0000 Received: by mail-pg1-x541.google.com with SMTP id j26so9029416pgl.5 for ; Wed, 27 Mar 2019 21:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uoJTJgIS3SN73gASZI6+9lIVM2vPmrO7wvZ1LHJGqio=; b=LF1mrqe7gJ/l3Uv1aBjzOX8N8IkFij5ktM+C/CN843MVPQT493f+VT+sB3VMl0WYBh x6AVn7iTVNiVCQ318SeFlaa5Oh4QqqEc3TC/vOqQH0PaLUK29K+gsmVx/S45ZeGnGV3O 8h0vjxGW1Yzuzk96h5tP2JjfFypDZNYyJWezQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uoJTJgIS3SN73gASZI6+9lIVM2vPmrO7wvZ1LHJGqio=; b=tXVuK7qqUeVtGs3PZRKCuAIw6m6j+RT0s3xjfZtYFK6PvqSTHlnTwgANF3iG76wo81 9j0VlBsZfNUhTONd1A38F6pZViW5UMHFLBIa2Wkm/ygzDeXI5Xu+NKRrAPHIVTB+qKAG TrJahOXd75LO3qCfPIy0Fbp3ooOOlBKXggVoMNeNgrwM/7E6ksLoJzSMojiDeipFzHCS udk+jFV+fEjqhCFyYO/R852ErzBLvuO9FDPUwUHb4BdpmzJNWXJF+fLUo/XCOZqnOz5i Ot6qAKeNSnxNs4wHLVS7VncFJiBXdoFXlRYEWzxSCC62Du6V1MXZLy5jDq2onbBtgWvM MCMg== X-Gm-Message-State: APjAAAVUkci885Q89lIVYjtIrcrD0dHlVq2x55uvY7LIvD/Qcib3hRMJ cFgf9q/zeFtmS2aeQksthRL/NI6ry7k= X-Google-Smtp-Source: APXvYqxMTgtBRgapTTkkWRtEm6If4XnlbsryOgZkA/Bp9MwcmsJ2OhIPFH8OHgvX7ydJIfpLuTTw+A== X-Received: by 2002:a63:c204:: with SMTP id b4mr37779763pgd.335.1553749183723; Wed, 27 Mar 2019 21:59:43 -0700 (PDT) Received: from zhuohao-z440.tpe.corp.google.com ([2401:fa00:1:10:e25c:13cd:9607:cc7f]) by smtp.gmail.com with ESMTPSA id y23sm20312665pfn.25.2019.03.27.21.59.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Mar 2019 21:59:43 -0700 (PDT) From: Zhuohao Lee To: linux-mtd@lists.infradead.org Subject: [PATCH v1] mtd: core: add sysfs nodes for querying the flash name and id Date: Thu, 28 Mar 2019 12:59:10 +0800 Message-Id: <20190328045910.98250-1-zhuohao@chromium.org> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190327_215946_905087_FF1E5536 X-CRM114-Status: GOOD ( 14.62 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:541 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: drinkcat@chromium.org, zhuohao@chromium.org, bbrezillon@kernel.org, richard@nod.at, briannorris@chromium.org, marek.vasut@gmail.com, computersforpeace@gmail.com, dwmw2@infradead.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently, we don't have sysfs nodes for querying the underlying flash name and flash id. This information is important especially when we want to know the flash detail of the defective system. In order to support the query, we add two pointers (*flashname, *id) into the mtd_info structure and create two sysfs nodes (flashname, id). This patch is modified based on the SPI-NOR flash system as we only have that system now. But the idea should be applied to the other flash driver like NAND flash. The output of new sysfs nodes on my device are: cat /sys/devices/platform/soc/11010000.spi/spi_master/spi1/spi1.0/mtd/mtd0/flashname w25q64dw cat /sys/devices/platform/soc/11010000.spi/spi_master/spi1/spi1.0/mtd/mtd0/id ef6017 Signed-off-by: Zhuohao Lee --- drivers/mtd/mtdcore.c | 24 ++++++++++++++++++++++++ drivers/mtd/spi-nor/spi-nor.c | 3 +++ include/linux/mtd/mtd.h | 3 +++ 3 files changed, 30 insertions(+) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 3ef01baef9b6..dcbe6719ad67 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -241,6 +241,28 @@ static ssize_t mtd_name_show(struct device *dev, } static DEVICE_ATTR(name, S_IRUGO, mtd_name_show, NULL); +static ssize_t mtd_flashname_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mtd_info *mtd = dev_get_drvdata(dev); + + if (!mtd->flashname) + return 0; + return snprintf(buf, PAGE_SIZE, "%s\n", mtd->flashname); +} +static DEVICE_ATTR(flashname, S_IRUGO, mtd_flashname_show, NULL); + +static ssize_t mtd_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct mtd_info *mtd = dev_get_drvdata(dev); + + if (!mtd->id) + return 0; + return snprintf(buf, PAGE_SIZE, "%*phN\n", mtd->id_size, mtd->id); +} +static DEVICE_ATTR(id, S_IRUGO, mtd_id_show, NULL); + static ssize_t mtd_ecc_strength_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -340,6 +362,8 @@ static struct attribute *mtd_attrs[] = { &dev_attr_oobavail.attr, &dev_attr_numeraseregions.attr, &dev_attr_name.attr, + &dev_attr_flashname.attr, + &dev_attr_id.attr, &dev_attr_ecc_strength.attr, &dev_attr_ecc_step_size.attr, &dev_attr_corrected_bits.attr, diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 6e13bbd1aaa5..0e10858e532c 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -4027,6 +4027,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (!mtd->name) mtd->name = dev_name(dev); + mtd->flashname = info->name; + mtd->id = info->id; + mtd->id_size = info->id_len; mtd->priv = nor; mtd->type = MTD_NORFLASH; mtd->writesize = 1; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 677768b21a1d..0a81569fa4f6 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -210,6 +210,9 @@ struct mtd_info { uint32_t flags; uint32_t orig_flags; /* Flags as before running mtd checks */ uint64_t size; // Total size of the MTD + const char *flashname; /* The underlying flash name */ + const char *id; /* The ID of the flash */ + int id_size; /* Number of bytes of id array */ /* "Major" erase size for the device. Naïve users may take this * to be the only erase size available, or may use the more detailed