Skip to content

Commit d323a41

Browse files
mwallePratyush Yadav
authored andcommitted
mtd: spi-nor: remove .setup() callback
With the removal of the Xilinx flashes, there is no more flash driver using that hook. The original intention was to let the driver configure special requirements like page size an opcodes. This is already possible by other means and it is unlikely a flash will overwrite the (more or less complex) setup function. Signed-off-by: Michael Walle <mwalle@kernel.org> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Acked-by: Tudor Ambarus <tudor.ambarus@linaro.org> Signed-off-by: Pratyush Yadav <pratyush@kernel.org> Link: https://lore.kernel.org/r/20240419141249.609534-4-mwalle@kernel.org
1 parent 9539d12 commit d323a41

File tree

2 files changed

+45
-65
lines changed

2 files changed

+45
-65
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,8 +2554,51 @@ static int spi_nor_select_erase(struct spi_nor *nor)
25542554
return 0;
25552555
}
25562556

2557-
static int spi_nor_default_setup(struct spi_nor *nor,
2558-
const struct spi_nor_hwcaps *hwcaps)
2557+
static int spi_nor_set_addr_nbytes(struct spi_nor *nor)
2558+
{
2559+
if (nor->params->addr_nbytes) {
2560+
nor->addr_nbytes = nor->params->addr_nbytes;
2561+
} else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) {
2562+
/*
2563+
* In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
2564+
* in this protocol an odd addr_nbytes cannot be used because
2565+
* then the address phase would only span a cycle and a half.
2566+
* Half a cycle would be left over. We would then have to start
2567+
* the dummy phase in the middle of a cycle and so too the data
2568+
* phase, and we will end the transaction with half a cycle left
2569+
* over.
2570+
*
2571+
* Force all 8D-8D-8D flashes to use an addr_nbytes of 4 to
2572+
* avoid this situation.
2573+
*/
2574+
nor->addr_nbytes = 4;
2575+
} else if (nor->info->addr_nbytes) {
2576+
nor->addr_nbytes = nor->info->addr_nbytes;
2577+
} else {
2578+
nor->addr_nbytes = 3;
2579+
}
2580+
2581+
if (nor->addr_nbytes == 3 && nor->params->size > 0x1000000) {
2582+
/* enable 4-byte addressing if the device exceeds 16MiB */
2583+
nor->addr_nbytes = 4;
2584+
}
2585+
2586+
if (nor->addr_nbytes > SPI_NOR_MAX_ADDR_NBYTES) {
2587+
dev_dbg(nor->dev, "The number of address bytes is too large: %u\n",
2588+
nor->addr_nbytes);
2589+
return -EINVAL;
2590+
}
2591+
2592+
/* Set 4byte opcodes when possible. */
2593+
if (nor->addr_nbytes == 4 && nor->flags & SNOR_F_4B_OPCODES &&
2594+
!(nor->flags & SNOR_F_HAS_4BAIT))
2595+
spi_nor_set_4byte_opcodes(nor);
2596+
2597+
return 0;
2598+
}
2599+
2600+
static int spi_nor_setup(struct spi_nor *nor,
2601+
const struct spi_nor_hwcaps *hwcaps)
25592602
{
25602603
struct spi_nor_flash_parameter *params = nor->params;
25612604
u32 ignored_mask, shared_mask;
@@ -2612,64 +2655,6 @@ static int spi_nor_default_setup(struct spi_nor *nor,
26122655
return err;
26132656
}
26142657

2615-
return 0;
2616-
}
2617-
2618-
static int spi_nor_set_addr_nbytes(struct spi_nor *nor)
2619-
{
2620-
if (nor->params->addr_nbytes) {
2621-
nor->addr_nbytes = nor->params->addr_nbytes;
2622-
} else if (nor->read_proto == SNOR_PROTO_8_8_8_DTR) {
2623-
/*
2624-
* In 8D-8D-8D mode, one byte takes half a cycle to transfer. So
2625-
* in this protocol an odd addr_nbytes cannot be used because
2626-
* then the address phase would only span a cycle and a half.
2627-
* Half a cycle would be left over. We would then have to start
2628-
* the dummy phase in the middle of a cycle and so too the data
2629-
* phase, and we will end the transaction with half a cycle left
2630-
* over.
2631-
*
2632-
* Force all 8D-8D-8D flashes to use an addr_nbytes of 4 to
2633-
* avoid this situation.
2634-
*/
2635-
nor->addr_nbytes = 4;
2636-
} else if (nor->info->addr_nbytes) {
2637-
nor->addr_nbytes = nor->info->addr_nbytes;
2638-
} else {
2639-
nor->addr_nbytes = 3;
2640-
}
2641-
2642-
if (nor->addr_nbytes == 3 && nor->params->size > 0x1000000) {
2643-
/* enable 4-byte addressing if the device exceeds 16MiB */
2644-
nor->addr_nbytes = 4;
2645-
}
2646-
2647-
if (nor->addr_nbytes > SPI_NOR_MAX_ADDR_NBYTES) {
2648-
dev_dbg(nor->dev, "The number of address bytes is too large: %u\n",
2649-
nor->addr_nbytes);
2650-
return -EINVAL;
2651-
}
2652-
2653-
/* Set 4byte opcodes when possible. */
2654-
if (nor->addr_nbytes == 4 && nor->flags & SNOR_F_4B_OPCODES &&
2655-
!(nor->flags & SNOR_F_HAS_4BAIT))
2656-
spi_nor_set_4byte_opcodes(nor);
2657-
2658-
return 0;
2659-
}
2660-
2661-
static int spi_nor_setup(struct spi_nor *nor,
2662-
const struct spi_nor_hwcaps *hwcaps)
2663-
{
2664-
int ret;
2665-
2666-
if (nor->params->setup)
2667-
ret = nor->params->setup(nor, hwcaps);
2668-
else
2669-
ret = spi_nor_default_setup(nor, hwcaps);
2670-
if (ret)
2671-
return ret;
2672-
26732658
return spi_nor_set_addr_nbytes(nor);
26742659
}
26752660

drivers/mtd/spi-nor/core.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,6 @@ struct spi_nor_otp {
366366
* @set_octal_dtr: enables or disables SPI NOR octal DTR mode.
367367
* @quad_enable: enables SPI NOR quad mode.
368368
* @set_4byte_addr_mode: puts the SPI NOR in 4 byte addressing mode.
369-
* @setup: (optional) configures the SPI NOR memory. Useful for
370-
* SPI NOR flashes that have peculiarities to the SPI NOR
371-
* standard e.g. different opcodes, specific address
372-
* calculation, page size, etc.
373369
* @ready: (optional) flashes might use a different mechanism
374370
* than reading the status register to indicate they
375371
* are ready for a new command
@@ -400,7 +396,6 @@ struct spi_nor_flash_parameter {
400396
int (*set_octal_dtr)(struct spi_nor *nor, bool enable);
401397
int (*quad_enable)(struct spi_nor *nor);
402398
int (*set_4byte_addr_mode)(struct spi_nor *nor, bool enable);
403-
int (*setup)(struct spi_nor *nor, const struct spi_nor_hwcaps *hwcaps);
404399
int (*ready)(struct spi_nor *nor);
405400

406401
const struct spi_nor_locking_ops *locking_ops;

0 commit comments

Comments
 (0)