spi: mt65xx: set host->max_speed_hz in probe
Subsystems (2)
PATCH v2 1/1 spi: mt65xx: set host->max_speed_hz in probe
spi-mt65xx leaves host->max_speed_hz unset (0). When a client device omits spi-max-frequency in DT, spi_setup() keeps spi->max_speed_hz == 0, and transfers or spi-mem ops without an explicit speed reach mtk_spi_prepare_transfer() with speed_hz == 0 and mtk_spi_transfer_wait() with mem->spi->max_speed_hz == 0, causing division by zero in both DIV_ROUND_UP(mdata->spi_clk_hz, speed_hz) anddiv_u64(ms, mem->spi->max_speed_hz).
Validate that spi_clk_hz is at least 2 Hz and set host->max_speed_hz to mdata->spi_clk_hz / 2 (the controller's maximum SCK rate at div = 1, sck_time = 1) so the SPI core populates spi->max_speed_hz, xfer->speed_hz, and op->max_freq for all transfer paths.
---
Changes in v2:
- Set host->max_speed_hz = mdata->spi_clk_hz / 2 in mtk_spi_probe() (and reject spi_clk_hz < 2) instead of only guarding speed_hz in mtk_spi_prepare_transfer(), covering mtk_spi_transfer_wait() as well (suggested by Roman Vivchar).
- Move AI coding assistant disclosure below ---.
- Link to v1: https://lore.kernel.org/r/[email protected]
Found and drafted with an AI coding assistant.
drivers/spi/spi-mt65xx.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/spi/spi-mt65xx.c +8 -0
@@ -1285,6 +1285,14 @@ static int mtk_spi_probe(struct platform_device *pdev) } mdata->spi_clk_hz =clk_get_rate (mdata->spi_clk); +if (mdata->spi_clk_hz <2 ) { +clk_disable_unprepare (mdata->spi_clk); +clk_disable_unprepare (mdata->spi_hclk); +return dev_err_probe (dev, -EINVAL ,"invalid spi-clk rate %u\n" , + mdata->spi_clk_hz); + } + + host->max_speed_hz = mdata->spi_clk_hz /2 ;if (mdata->dev_comp->no_need_unprepare) {clk_disable (mdata->spi_clk);
Signature · 1 line
2.54.0 (Apple Git-157)