| From b242e30661dac5c1c127999600029cd5b3f6b458 Mon Sep 17 00:00:00 2001 |
| From: "SkyLake.Huang" <skylake.huang@mediatek.com> |
| Date: Thu, 23 Jun 2022 18:40:59 +0800 |
| Subject: [PATCH] drivers: mtd: spi-nor: Add calibration support for spi-nor |
| |
| Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com> |
| --- |
| drivers/mtd/spi-nor/spi-nor.c | 17 +++++++++++++++++ |
| 1 file changed, 17 insertions(+) |
| |
| --- a/drivers/mtd/spi-nor/spi-nor.c |
| +++ b/drivers/mtd/spi-nor/spi-nor.c |
| @@ -4897,6 +4897,35 @@ static void spi_nor_debugfs_init(struct |
| info->id_len, info->id); |
| } |
| |
| +static int spi_nor_cal_read(void *priv, u32 *addr, int addrlen, u8 *buf, int readlen) |
| +{ |
| + int ret; |
| + struct spi_nor *nor = (struct spi_nor *)priv; |
| + |
| + nor->reg_proto = SNOR_PROTO_1_1_1; |
| + nor->read_proto = SNOR_PROTO_1_1_1; |
| + nor->read_opcode = SPINOR_OP_READ; |
| + nor->addr_width = 3; |
| + nor->read_dummy = 0; |
| + |
| + return spi_nor_read_raw(nor, *addr, readlen, buf); |
| +} |
| + |
| +static int spi_nor_cal_read_4B(void *priv, u32 *addr, int addrlen, u8 *buf, |
| + int readlen) |
| +{ |
| + int ret; |
| + struct spi_nor *nor = (struct spi_nor *)priv; |
| + |
| + nor->reg_proto = SNOR_PROTO_1_1_1; |
| + nor->read_proto = SNOR_PROTO_1_1_1; |
| + nor->read_opcode = SPINOR_OP_READ_4B; |
| + nor->addr_width = 4; |
| + nor->read_dummy = 0; |
| + |
| + return spi_nor_read_raw(nor, *addr, readlen, buf); |
| +} |
| + |
| static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, |
| const char *name) |
| { |
| @@ -4971,6 +5000,17 @@ int spi_nor_scan(struct spi_nor *nor, co |
| if (!nor->bouncebuf) |
| return -ENOMEM; |
| |
| + if(nor->spimem) { |
| + ret = spi_mem_do_calibration(nor->spimem, |
| + spi_nor_cal_read, nor); |
| + if (ret) { |
| + ret = spi_mem_do_calibration(nor->spimem, |
| + spi_nor_cal_read_4B, nor); |
| + if (ret) |
| + return ret; |
| + } |
| + } |
| + |
| info = spi_nor_get_flash_info(nor, name); |
| if (IS_ERR(info)) |
| return PTR_ERR(info); |