mtd: spi-nor: manufacturers: Use spi_nor_read_id() core method
authorTudor Ambarus <tudor.ambarus@microchip.com>
Wed, 20 Apr 2022 10:34:21 +0000 (13:34 +0300)
committerPratyush Yadav <p.yadav@ti.com>
Wed, 27 Apr 2022 09:27:35 +0000 (14:57 +0530)
Use spi_nor_read_id() core method to avoid duplication of code. Now the ID
is read on the full SPI_NOR_MAX_ID_LEN instead of
round_up(nor->info->id_len, 2), but it doesn't harm to read more ID bytes,
so the change comes with no secondary effects. dev_dbg messages in case
spi_nor_read_id() fails, will be added in a further patch after we split
the octal DTR enable/disable methods.

Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Reviewed-by: Pratyush Yadav <p.yadav@ti.com>
Reviewed-by: Michael Walle <michael@walle.cc>
Link: https://lore.kernel.org/r/20220420103427.47867-6-tudor.ambarus@microchip.com
drivers/mtd/spi-nor/micron-st.c
drivers/mtd/spi-nor/spansion.c

index 8a20475ce77a1693f865b53a0067199ebafa9ba9..41b87868ecf9d6638f35ea322272bb6a735cf438 100644 (file)
@@ -91,17 +91,10 @@ static int micron_st_nor_octal_dtr_enable(struct spi_nor *nor, bool enable)
                return ret;
 
        /* Read flash ID to make sure the switch was successful. */
-       op = (struct spi_mem_op)
-               SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 1),
-                          SPI_MEM_OP_NO_ADDR,
-                          SPI_MEM_OP_DUMMY(enable ? 8 : 0, 1),
-                          SPI_MEM_OP_DATA_IN(round_up(nor->info->id_len, 2),
-                                             buf, 1));
-
        if (enable)
-               spi_nor_spimem_setup_op(nor, &op, SNOR_PROTO_8_8_8_DTR);
-
-       ret = spi_mem_exec_op(nor->spimem, &op);
+               ret = spi_nor_read_id(nor, 0, 8, buf, SNOR_PROTO_8_8_8_DTR);
+       else
+               ret = spi_nor_read_id(nor, 0, 0, buf, SNOR_PROTO_1_1_1);
        if (ret)
                return ret;
 
index f24e546e04a550e8e586e5afcf6eb1edc5b120dc..c5988312cc91dc0dc17243a44a47faa95edab251 100644 (file)
@@ -98,17 +98,10 @@ static int cypress_nor_octal_dtr_enable(struct spi_nor *nor, bool enable)
                return ret;
 
        /* Read flash ID to make sure the switch was successful. */
-       op = (struct spi_mem_op)
-               SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 1),
-                          SPI_MEM_OP_ADDR(enable ? 4 : 0, 0, 1),
-                          SPI_MEM_OP_DUMMY(enable ? 3 : 0, 1),
-                          SPI_MEM_OP_DATA_IN(round_up(nor->info->id_len, 2),
-                                             buf, 1));
-
        if (enable)
-               spi_nor_spimem_setup_op(nor, &op, SNOR_PROTO_8_8_8_DTR);
-
-       ret = spi_mem_exec_op(nor->spimem, &op);
+               ret = spi_nor_read_id(nor, 4, 3, buf, SNOR_PROTO_8_8_8_DTR);
+       else
+               ret = spi_nor_read_id(nor, 0, 0, buf, SNOR_PROTO_1_1_1);
        if (ret)
                return ret;