Skip to content

Commit e4feefa

Browse files
clegofficbroonie
authored andcommitted
spi: stm32: Add SPI_READY mode to spi controller
The spi ready functionality is supported by our peripheral in host and target modes on STM32MP2x SoCs. Update our spi controller driver to allow devices to use this functionality. Signed-off-by: Clément Le Goffic <clement.legoffic@foss.st.com> Link: https://patch.msgid.link/20250616-spi-upstream-v1-1-7e8593f3f75d@foss.st.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 86731a2 commit e4feefa

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

drivers/spi/spi-stm32.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@
154154
/* STM32H7_SPI_I2SCFGR bit fields */
155155
#define STM32H7_SPI_I2SCFGR_I2SMOD BIT(0)
156156

157+
/* STM32MP25_SPICFG2 bit fields */
158+
#define STM32MP25_SPI_CFG2_RDIOM BIT(13)
159+
157160
/* STM32MP25 SPI registers bit fields */
158161
#define STM32MP25_SPI_HWCFGR1 0x3F0
159162

@@ -222,6 +225,7 @@ struct stm32_spi_reg {
222225
* @rx: SPI RX data register
223226
* @tx: SPI TX data register
224227
* @fullcfg: SPI full or limited feature set register
228+
* @rdy_en: SPI ready feature register
225229
*/
226230
struct stm32_spi_regspec {
227231
const struct stm32_spi_reg en;
@@ -235,6 +239,7 @@ struct stm32_spi_regspec {
235239
const struct stm32_spi_reg rx;
236240
const struct stm32_spi_reg tx;
237241
const struct stm32_spi_reg fullcfg;
242+
const struct stm32_spi_reg rdy_en;
238243
};
239244

240245
struct stm32_spi;
@@ -415,6 +420,8 @@ static const struct stm32_spi_regspec stm32mp25_spi_regspec = {
415420
.tx = { STM32H7_SPI_TXDR },
416421

417422
.fullcfg = { STM32MP25_SPI_HWCFGR1, STM32MP25_SPI_HWCFGR1_FULLCFG },
423+
424+
.rdy_en = { STM32H7_SPI_CFG2, STM32MP25_SPI_CFG2_RDIOM },
418425
};
419426

420427
static inline void stm32_spi_set_bits(struct stm32_spi *spi,
@@ -1172,15 +1179,21 @@ static int stm32_spi_prepare_msg(struct spi_controller *ctrl,
11721179
else
11731180
clrb |= spi->cfg->regs->cs_high.mask;
11741181

1175-
dev_dbg(spi->dev, "cpol=%d cpha=%d lsb_first=%d cs_high=%d\n",
1182+
if (spi_dev->mode & SPI_READY)
1183+
setb |= spi->cfg->regs->rdy_en.mask;
1184+
else
1185+
clrb |= spi->cfg->regs->rdy_en.mask;
1186+
1187+
dev_dbg(spi->dev, "cpol=%d cpha=%d lsb_first=%d cs_high=%d rdy=%d\n",
11761188
!!(spi_dev->mode & SPI_CPOL),
11771189
!!(spi_dev->mode & SPI_CPHA),
11781190
!!(spi_dev->mode & SPI_LSB_FIRST),
1179-
!!(spi_dev->mode & SPI_CS_HIGH));
1191+
!!(spi_dev->mode & SPI_CS_HIGH),
1192+
!!(spi_dev->mode & SPI_READY));
11801193

11811194
spin_lock_irqsave(&spi->lock, flags);
11821195

1183-
/* CPOL, CPHA and LSB FIRST bits have common register */
1196+
/* CPOL, CPHA, LSB FIRST, CS_HIGH and RDY_EN bits have common register */
11841197
if (clrb || setb)
11851198
writel_relaxed(
11861199
(readl_relaxed(spi->base + spi->cfg->regs->cpol.reg) &
@@ -1768,6 +1781,13 @@ static int stm32_spi_transfer_one_setup(struct stm32_spi *spi,
17681781
spi->cur_bpw = transfer->bits_per_word;
17691782
spi->cfg->set_bpw(spi);
17701783

1784+
if (spi_dev->mode & SPI_READY && spi->cur_bpw < 8) {
1785+
writel_relaxed(readl_relaxed(spi->base + spi->cfg->regs->rdy_en.reg) &
1786+
~spi->cfg->regs->rdy_en.mask,
1787+
spi->base + spi->cfg->regs->rdy_en.reg);
1788+
dev_dbg(spi->dev, "RDY logic disabled as bits per word < 8\n");
1789+
}
1790+
17711791
/* Update spi->cur_speed with real clock speed */
17721792
if (STM32_SPI_HOST_MODE(spi)) {
17731793
mbr = stm32_spi_prepare_mbr(spi, transfer->speed_hz,
@@ -2179,7 +2199,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
21792199
ctrl->auto_runtime_pm = true;
21802200
ctrl->bus_num = pdev->id;
21812201
ctrl->mode_bits = SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST |
2182-
SPI_3WIRE;
2202+
SPI_3WIRE | SPI_READY;
21832203
ctrl->bits_per_word_mask = spi->cfg->get_bpw_mask(spi);
21842204
ctrl->max_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_min;
21852205
ctrl->min_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_max;

0 commit comments

Comments
 (0)