[U-Boot] [RFC PATCH v2 09/11] sf_mtd: Simply mtd operations

Vignesh R
2018-12-05T08:00:27Z

Hi Boris,

On 04/12/18 6:19 PM, Boris Brezillon wrote:
> On Tue, 4 Dec 2018 17:56:57 +0530
> Vignesh R <vigneshr@ti.com> wrote:
>
>> Now that there is new SPI NOR framework, simplify mtd device
>> registration and read/write/erase operations.
>>
>> Signed-off-by: Vignesh R <vigneshr@ti.com>
>> ---
>> drivers/mtd/spi/sf_internal.h | 2 +-
>> drivers/mtd/spi/sf_mtd.c | 39 ++++++++++++-----------------------
>> drivers/mtd/spi/sf_probe.c | 2 +-
>> 3 files changed, 15 insertions(+), 28 deletions(-)
>>
>> diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
>> index 7e7d400cdbdf..8b445bb0b506 100644
>> --- a/drivers/mtd/spi/sf_internal.h
>> +++ b/drivers/mtd/spi/sf_internal.h
>> @@ -99,6 +99,6 @@ int spi_flash_cmd_get_sw_write_prot(struct spi_flash *flash);
>>
>> #ifdef CONFIG_SPI_FLASH_MTD
>> int spi_flash_mtd_register(struct spi_flash *flash);
>> -void spi_flash_mtd_unregister(void);
>> +void spi_flash_mtd_unregister(struct spi_flash *flash);
>> #endif
>> #endif /* _SF_INTERNAL_H_ */
>> diff --git a/drivers/mtd/spi/sf_mtd.c b/drivers/mtd/spi/sf_mtd.c
>> index 58d7e4439903..9c07ba3cadf7 100644
>> --- a/drivers/mtd/spi/sf_mtd.c
>> +++ b/drivers/mtd/spi/sf_mtd.c
>> @@ -9,17 +9,15 @@
>> #include <linux/mtd/mtd.h>
>> #include <spi_flash.h>
>>
>> -static struct mtd_info sf_mtd_info;
>> static char sf_mtd_name[8];
>>
>> static int spi_flash_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
>> {
>> - struct spi_flash *flash = mtd->priv;
>> int err;
>>
>> instr->state = MTD_ERASING;
>>
>> - err = spi_flash_erase(flash, instr->addr, instr->len);
>> + err = mtd->_erase(mtd, instr);
>
> Please don't dereference mtd hooks directly. I'm pretty sure the
> mtd_erase() overhead is negligible, and if it's not, you can
> implement dummy wrappers for the SPL case to reduce it to zero.
>

I did start with mtd_* APIs here. But, ended up with bunch of patches
just to get MTD configs in shape to satisfy compile time dependencies.
I will send a patch to use mtd_* APIs here once Miquel's MTD config
cleanups are in. Thanks for the review!

--
Regards
Vignesh