Message ID | 20190530152101.176431-2-zhuohao@chromium.org |
---|---|
State | Changes Requested |
Headers | show |
Series | [v4,1/2] mtd: mtdcore: add debugfs nodes for querying the flash name and id | expand |
On Thu, 30 May 2019 23:21:01 +0800 Zhuohao Lee <zhuohao@chromium.org> wrote: > This patch adds spi_nor_debugfs_init() for the debugfs initialization. > With this patch, we can read the partname and partid through the > debugfs. > > The output of new debugfs nodes on my device are: > cat /sys/kernel/debug/mtd/mtd0/partid > spi-nor:ef6017 > cat /sys/kernel/debug/mtd/mtd0/partname > w25q64dw > > Signed-off-by: Zhuohao Lee <zhuohao@chromium.org> > --- > drivers/mtd/spi-nor/spi-nor.c | 13 +++++++++++++ > include/linux/mtd/spi-nor.h | 1 + > 2 files changed, 14 insertions(+) > > diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c > index 6e13bbd1aaa5..c7e57e9a48e5 100644 > --- a/drivers/mtd/spi-nor/spi-nor.c > +++ b/drivers/mtd/spi-nor/spi-nor.c > @@ -3935,6 +3935,17 @@ static void spi_nor_resume(struct mtd_info *mtd) > dev_err(dev, "resume() failed\n"); > } > > +static void spi_nor_debugfs_init(struct spi_nor *nor, > + const struct flash_info *info) > +{ > + struct mtd_info *mtd = &nor->mtd; > + > + mtd->dbg.partname = info->name; > + if (!mtd->dbg.partid) > + mtd->dbg.partid = devm_kasprintf(nor->dev, GFP_KERNEL, "spi-nor:%*phN", > + info->id_len, info->id); nitpick: mtd->dbg.partid = devm_kasprintf(nor->dev, GFP_KERNEL, "spi-nor:%*phN", info->id_len, info->id); to make checkpatch happy. > +} > + > void spi_nor_restore(struct spi_nor *nor) > { > /* restore the addressing mode */ > @@ -4036,6 +4047,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, > mtd->_read = spi_nor_read; > mtd->_resume = spi_nor_resume; > > + spi_nor_debugfs_init(nor, info); > + > /* NOR protection support for STmicro/Micron chips and similar */ > if (JEDEC_MFR(info) == SNOR_MFR_ST || > JEDEC_MFR(info) == SNOR_MFR_MICRON || > diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h > index fa2d89e38e40..4ad8b9117659 100644 > --- a/include/linux/mtd/spi-nor.h > +++ b/include/linux/mtd/spi-nor.h > @@ -386,6 +386,7 @@ struct spi_nor { > u32 flags; > u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE]; > struct spi_nor_erase_map erase_map; > + char *id_string; You never use that field, you can get rid of it. > > int (*prepare)(struct spi_nor *nor, enum spi_nor_ops ops); > void (*unprepare)(struct spi_nor *nor, enum spi_nor_ops ops);
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 6e13bbd1aaa5..c7e57e9a48e5 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -3935,6 +3935,17 @@ static void spi_nor_resume(struct mtd_info *mtd) dev_err(dev, "resume() failed\n"); } +static void spi_nor_debugfs_init(struct spi_nor *nor, + const struct flash_info *info) +{ + struct mtd_info *mtd = &nor->mtd; + + mtd->dbg.partname = info->name; + if (!mtd->dbg.partid) + mtd->dbg.partid = devm_kasprintf(nor->dev, GFP_KERNEL, "spi-nor:%*phN", + info->id_len, info->id); +} + void spi_nor_restore(struct spi_nor *nor) { /* restore the addressing mode */ @@ -4036,6 +4047,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, mtd->_read = spi_nor_read; mtd->_resume = spi_nor_resume; + spi_nor_debugfs_init(nor, info); + /* NOR protection support for STmicro/Micron chips and similar */ if (JEDEC_MFR(info) == SNOR_MFR_ST || JEDEC_MFR(info) == SNOR_MFR_MICRON || diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index fa2d89e38e40..4ad8b9117659 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -386,6 +386,7 @@ struct spi_nor { u32 flags; u8 cmd_buf[SPI_NOR_MAX_CMD_SIZE]; struct spi_nor_erase_map erase_map; + char *id_string; int (*prepare)(struct spi_nor *nor, enum spi_nor_ops ops); void (*unprepare)(struct spi_nor *nor, enum spi_nor_ops ops);
This patch adds spi_nor_debugfs_init() for the debugfs initialization. With this patch, we can read the partname and partid through the debugfs. The output of new debugfs nodes on my device are: cat /sys/kernel/debug/mtd/mtd0/partid spi-nor:ef6017 cat /sys/kernel/debug/mtd/mtd0/partname w25q64dw Signed-off-by: Zhuohao Lee <zhuohao@chromium.org> --- drivers/mtd/spi-nor/spi-nor.c | 13 +++++++++++++ include/linux/mtd/spi-nor.h | 1 + 2 files changed, 14 insertions(+)