Skip to content

Commit 1352964

Browse files
miquelraynalbroonie
authored andcommitted
spi: microchip-core-qspi: Support per spi-mem operation frequency switches
Every ->exec_op() call correctly configures the spi bus speed to the maximum allowed frequency for the memory using the constant spi default parameter. Since we can now have per-operation constraints, let's use the value that comes from the spi-mem operation structure instead. In case there is no specific limitation for this operation, the default spi device value will be given anyway. This controller however performed a frequency check, which is also observed during the ->check_op() phase. The per-operation frequency capability is thus advertised to the spi-mem core. Cc: Conor Dooley <[email protected]> Cc: Daire McNamara <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://patch.msgid.link/20241224-winbond-6-11-rc1-quad-support-v2-9-ad218dbc406f@bootlin.com Signed-off-by: Mark Brown <[email protected]>
1 parent 2438db5 commit 1352964

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

drivers/spi/spi-microchip-core-qspi.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ static irqreturn_t mchp_coreqspi_isr(int irq, void *dev_id)
265265
return ret;
266266
}
267267

268-
static int mchp_coreqspi_setup_clock(struct mchp_coreqspi *qspi, struct spi_device *spi)
268+
static int mchp_coreqspi_setup_clock(struct mchp_coreqspi *qspi, struct spi_device *spi,
269+
const struct spi_mem_op *op)
269270
{
270271
unsigned long clk_hz;
271272
u32 control, baud_rate_val = 0;
@@ -274,11 +275,11 @@ static int mchp_coreqspi_setup_clock(struct mchp_coreqspi *qspi, struct spi_devi
274275
if (!clk_hz)
275276
return -EINVAL;
276277

277-
baud_rate_val = DIV_ROUND_UP(clk_hz, 2 * spi->max_speed_hz);
278+
baud_rate_val = DIV_ROUND_UP(clk_hz, 2 * op->max_freq);
278279
if (baud_rate_val > MAX_DIVIDER || baud_rate_val < MIN_DIVIDER) {
279280
dev_err(&spi->dev,
280281
"could not configure the clock for spi clock %d Hz & system clock %ld Hz\n",
281-
spi->max_speed_hz, clk_hz);
282+
op->max_freq, clk_hz);
282283
return -EINVAL;
283284
}
284285

@@ -399,7 +400,7 @@ static int mchp_coreqspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *o
399400
if (err)
400401
goto error;
401402

402-
err = mchp_coreqspi_setup_clock(qspi, mem->spi);
403+
err = mchp_coreqspi_setup_clock(qspi, mem->spi, op);
403404
if (err)
404405
goto error;
405406

@@ -457,6 +458,10 @@ static int mchp_coreqspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *o
457458

458459
static bool mchp_coreqspi_supports_op(struct spi_mem *mem, const struct spi_mem_op *op)
459460
{
461+
struct mchp_coreqspi *qspi = spi_controller_get_devdata(mem->spi->controller);
462+
unsigned long clk_hz;
463+
u32 baud_rate_val;
464+
460465
if (!spi_mem_default_supports_op(mem, op))
461466
return false;
462467

@@ -479,6 +484,14 @@ static bool mchp_coreqspi_supports_op(struct spi_mem *mem, const struct spi_mem_
479484
return false;
480485
}
481486

487+
clk_hz = clk_get_rate(qspi->clk);
488+
if (!clk_hz)
489+
return false;
490+
491+
baud_rate_val = DIV_ROUND_UP(clk_hz, 2 * op->max_freq);
492+
if (baud_rate_val > MAX_DIVIDER || baud_rate_val < MIN_DIVIDER)
493+
return false;
494+
482495
return true;
483496
}
484497

@@ -498,6 +511,10 @@ static const struct spi_controller_mem_ops mchp_coreqspi_mem_ops = {
498511
.exec_op = mchp_coreqspi_exec_op,
499512
};
500513

514+
static const struct spi_controller_mem_caps mchp_coreqspi_mem_caps = {
515+
.per_op_freq = true,
516+
};
517+
501518
static int mchp_coreqspi_probe(struct platform_device *pdev)
502519
{
503520
struct spi_controller *ctlr;
@@ -540,6 +557,7 @@ static int mchp_coreqspi_probe(struct platform_device *pdev)
540557

541558
ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
542559
ctlr->mem_ops = &mchp_coreqspi_mem_ops;
560+
ctlr->mem_caps = &mchp_coreqspi_mem_caps;
543561
ctlr->setup = mchp_coreqspi_setup_op;
544562
ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_RX_DUAL | SPI_RX_QUAD |
545563
SPI_TX_DUAL | SPI_TX_QUAD;

0 commit comments

Comments
 (0)