Skip to content

Commit 1018c94

Browse files
Zhuohao Leeambarus
authored andcommitted
mtd: mtdcore: add debugfs nodes for querying the flash name and id
Currently, we don't have vfs 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 mtd_debugfs_populate() to create two debugfs nodes (ie. partname and partid). The upper driver can assign the pointer to partname and partid before calling mtd_device_register(). Signed-off-by: Zhuohao Lee <zhuohao@chromium.org> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
1 parent 7ae2227 commit 1018c94

2 files changed

Lines changed: 80 additions & 9 deletions

File tree

‎drivers/mtd/mtdcore.c‎

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,82 @@ static const struct device_type mtd_devtype = {
335335
.release = mtd_release,
336336
};
337337

338+
static int mtd_partid_show(struct seq_file *s, void *p)
339+
{
340+
struct mtd_info *mtd = s->private;
341+
342+
seq_printf(s, "%s\n", mtd->dbg.partid);
343+
344+
return 0;
345+
}
346+
347+
static int mtd_partid_debugfs_open(struct inode *inode, struct file *file)
348+
{
349+
return single_open(file, mtd_partid_show, inode->i_private);
350+
}
351+
352+
static const struct file_operations mtd_partid_debug_fops = {
353+
.open = mtd_partid_debugfs_open,
354+
.read = seq_read,
355+
.llseek = seq_lseek,
356+
.release = single_release,
357+
};
358+
359+
static int mtd_partname_show(struct seq_file *s, void *p)
360+
{
361+
struct mtd_info *mtd = s->private;
362+
363+
seq_printf(s, "%s\n", mtd->dbg.partname);
364+
365+
return 0;
366+
}
367+
368+
static int mtd_partname_debugfs_open(struct inode *inode, struct file *file)
369+
{
370+
return single_open(file, mtd_partname_show, inode->i_private);
371+
}
372+
373+
static const struct file_operations mtd_partname_debug_fops = {
374+
.open = mtd_partname_debugfs_open,
375+
.read = seq_read,
376+
.llseek = seq_lseek,
377+
.release = single_release,
378+
};
379+
380+
static struct dentry *dfs_dir_mtd;
381+
382+
static void mtd_debugfs_populate(struct mtd_info *mtd)
383+
{
384+
struct device *dev = &mtd->dev;
385+
struct dentry *root, *dent;
386+
387+
if (IS_ERR_OR_NULL(dfs_dir_mtd))
388+
return;
389+
390+
root = debugfs_create_dir(dev_name(dev), dfs_dir_mtd);
391+
if (IS_ERR_OR_NULL(root)) {
392+
dev_dbg(dev, "won't show data in debugfs\n");
393+
return;
394+
}
395+
396+
mtd->dbg.dfs_dir = root;
397+
398+
if (mtd->dbg.partid) {
399+
dent = debugfs_create_file("partid", 0400, root, mtd,
400+
&mtd_partid_debug_fops);
401+
if (IS_ERR_OR_NULL(dent))
402+
dev_err(dev, "can't create debugfs entry for partid\n");
403+
}
404+
405+
if (mtd->dbg.partname) {
406+
dent = debugfs_create_file("partname", 0400, root, mtd,
407+
&mtd_partname_debug_fops);
408+
if (IS_ERR_OR_NULL(dent))
409+
dev_err(dev,
410+
"can't create debugfs entry for partname\n");
411+
}
412+
}
413+
338414
#ifndef CONFIG_MMU
339415
unsigned mtd_mmap_capabilities(struct mtd_info *mtd)
340416
{
@@ -512,8 +588,6 @@ static int mtd_nvmem_add(struct mtd_info *mtd)
512588
return 0;
513589
}
514590

515-
static struct dentry *dfs_dir_mtd;
516-
517591
/**
518592
* add_mtd_device - register an MTD device
519593
* @mtd: pointer to new MTD device info structure
@@ -607,13 +681,7 @@ int add_mtd_device(struct mtd_info *mtd)
607681
if (error)
608682
goto fail_nvmem_add;
609683

610-
if (!IS_ERR_OR_NULL(dfs_dir_mtd)) {
611-
mtd->dbg.dfs_dir = debugfs_create_dir(dev_name(&mtd->dev), dfs_dir_mtd);
612-
if (IS_ERR_OR_NULL(mtd->dbg.dfs_dir)) {
613-
pr_debug("mtd device %s won't show data in debugfs\n",
614-
dev_name(&mtd->dev));
615-
}
616-
}
684+
mtd_debugfs_populate(mtd);
617685

618686
device_create(&mtd_class, mtd->dev.parent, MTD_DEVT(i) + 1, NULL,
619687
"mtd%dro", i);

‎include/linux/mtd/mtd.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ struct module; /* only needed for owner field in mtd_info */
189189
*/
190190
struct mtd_debug_info {
191191
struct dentry *dfs_dir;
192+
193+
const char *partname;
194+
const char *partid;
192195
};
193196

194197
struct mtd_info {

0 commit comments

Comments
 (0)