Skip to content

Commit ab63e99

Browse files
Tim Kuobroonie
authored andcommitted
spi: mt65xx: add dual and quad mode for standard spi device
Mediatek SPI hardware natively supports dual and quad modes, and these modes are already enabled for SPI flash devices under spi-mem framework in MTK SPI controller spi-mt65xx. However, other SPI devices, such as touch panels, are limited to single mode because spi-mt65xx lacks SPI mode argument parsing from SPI framework for these SPI devices outside spi-mem framework. This patch adds dual and quad mode support for these SPI devices by introducing a new API, mtk_spi_set_nbits, for SPI mode argument parsing. Signed-off-by: Tim Kuo <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent b28a55d commit ab63e99

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

drivers/spi/spi-mt65xx.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,22 @@ static void mtk_spi_setup_packet(struct spi_controller *host)
563563
writel(reg_val, mdata->base + SPI_CFG1_REG);
564564
}
565565

566+
inline u32 mtk_spi_set_nbit(u32 nbit)
567+
{
568+
switch (nbit) {
569+
default:
570+
pr_warn_once("unknown nbit mode %u. Falling back to single mode\n",
571+
nbit);
572+
fallthrough;
573+
case SPI_NBITS_SINGLE:
574+
return 0x0;
575+
case SPI_NBITS_DUAL:
576+
return 0x1;
577+
case SPI_NBITS_QUAD:
578+
return 0x2;
579+
}
580+
}
581+
566582
static void mtk_spi_enable_transfer(struct spi_controller *host)
567583
{
568584
u32 cmd;
@@ -729,10 +745,16 @@ static int mtk_spi_transfer_one(struct spi_controller *host,
729745

730746
/* prepare xfer direction and duplex mode */
731747
if (mdata->dev_comp->ipm_design) {
732-
if (!xfer->tx_buf || !xfer->rx_buf) {
748+
if (xfer->tx_buf && xfer->rx_buf) {
749+
reg_val &= ~SPI_CFG3_IPM_HALF_DUPLEX_EN;
750+
} else if (xfer->tx_buf) {
751+
reg_val |= SPI_CFG3_IPM_HALF_DUPLEX_EN;
752+
reg_val &= ~SPI_CFG3_IPM_HALF_DUPLEX_DIR;
753+
reg_val |= mtk_spi_set_nbit(xfer->tx_nbits);
754+
} else {
733755
reg_val |= SPI_CFG3_IPM_HALF_DUPLEX_EN;
734-
if (xfer->rx_buf)
735-
reg_val |= SPI_CFG3_IPM_HALF_DUPLEX_DIR;
756+
reg_val |= SPI_CFG3_IPM_HALF_DUPLEX_DIR;
757+
reg_val |= mtk_spi_set_nbit(xfer->rx_nbits);
736758
}
737759
writel(reg_val, mdata->base + SPI_CFG3_IPM_REG);
738760
}

0 commit comments

Comments
 (0)