diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c index c1f766cb225a..527165ccc839 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c @@ -7,6 +7,7 @@ */ #include #include +#include #include #include #include @@ -732,6 +733,31 @@ static int common_nfc_set_geometry(struct gpmi_nand_data *this) return err; } +#ifdef CONFIG_DEBUG_FS +static void bch_remove_debugfs(void *data) +{ + struct gpmi_nand_data *this = data; + + debugfs_remove_recursive(this->dbg_root); + this->dbg_root = NULL; +} + +static void bch_create_debugfs(struct gpmi_nand_data *this) +{ + struct bch_geometry *bch_geo = &this->bch_geometry; + + this->dbg_root = debugfs_create_dir("gpmi-nand", NULL); + this->dbg_bch_geo.data = (void *)bch_geo; + this->dbg_bch_geo.size = sizeof(struct bch_geometry); + this->raw_mode = true; + debugfs_create_blob("bch_geometry", 0444, this->dbg_root, &this->dbg_bch_geo); + debugfs_create_bool("raw_mode", 0444, this->dbg_root, &this->raw_mode); + devm_add_action_or_reset(this->dev, bch_remove_debugfs, this); +} +#else +static void bch_create_debugfs(struct gpmi_nand_data *this) {} +#endif /* CONFIG_DEBUG_FS */ + /* Configures the geometry for BCH. */ static int bch_set_geometry(struct gpmi_nand_data *this) { @@ -2282,6 +2308,9 @@ static int gpmi_init_last(struct gpmi_nand_data *this) if (ret) return ret; + /* save BCH geometry to debugfs if CONFIG_DEBUG_FS is enabled */ + bch_create_debugfs(this); + /* Init the nand_ecc_ctrl{} */ ecc->read_page = gpmi_ecc_read_page; ecc->write_page = gpmi_ecc_write_page; diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h index 3e9bc985e44a..80c32efbaef8 100644 --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.h @@ -161,6 +161,12 @@ struct gpmi_nand_data { #define DMA_CHANS 8 struct dma_chan *dma_chans[DMA_CHANS]; struct completion dma_done; + +#ifdef CONFIG_DEBUG_FS + struct dentry *dbg_root; + struct debugfs_blob_wrapper dbg_bch_geo; + bool raw_mode; +#endif }; /* BCH : Status Block Completion Codes */