spi: npcm-pspi: add full duplex and fix word issue
Subsystems (2)
Tomer Maimon
maintainercover spi: npcm-pspi: add full duplex and fix word issue
This patch set:
1. Add full duplex support - this patch have been upstream to dev-6.1 and removed.
2. Fix transfer bits per word issue.
Tomer Maimon (2):
spi: npcm-pspi: add full duplex support
spi: npcm-pspi: Fix transfer bits per word issue
drivers/spi/spi-npcm-pspi.c | 90 ++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 52 deletions(-)
Signature · 1 line
2.34.1
Tomer Maimon
maintainerPATCH 1/2 spi: npcm-pspi: add full duplex support
The NPCM PSPI handler, on TX-buffer not null, would perform a dummy read but did not save the rx-data, this was valid only for half duplex.
This patch adds full duplex support for NPCM PSPI driver by storing all rx-data when the Rx-buffer is defined also for TX-buffer handling.
--- drivers/spi/spi-npcm-pspi.c | 75 +++++++++++++++---------------------- 1 file changed, 30 insertions(+), 45 deletions(-)
drivers/spi/spi-npcm-pspi.c +30 -45
@@ -195,22 +195,22 @@ static void npcm_pspi_setup_transfer(struct spi_device *spi,static void npcm_pspi_send (struct npcm_pspi *priv) {int wsize; -u16 val; +u16 val =0 ; wsize =min (bytes_per_word (priv->bits_per_word), priv->tx_bytes); priv->tx_bytes -= wsize; -if (!priv->tx_buf) -return ; -switch (wsize) {case 1 : - val = *priv->tx_buf++; +if (priv->tx_buf) + val = *priv->tx_buf++;iowrite8 (val,NPCM_PSPI_DATA + priv->base);break ;case 2 : - val = *priv->tx_buf++; - val = *priv->tx_buf++ | (val <<8 ); +if (priv->tx_buf) { + val = *priv->tx_buf++; + val = *priv->tx_buf++ | (val <<8 ); + }iowrite16 (val,NPCM_PSPI_DATA + priv->base);break ;default :
@@ -222,22 +222,24 @@ static void npcm_pspi_send(struct npcm_pspi *priv)static void npcm_pspi_recv (struct npcm_pspi *priv) {int rsize; -u16 val; +u16 val_16; +u8 val_8; rsize =min (bytes_per_word (priv->bits_per_word), priv->rx_bytes); priv->rx_bytes -= rsize; -if (!priv->rx_buf) -return ; -switch (rsize) {case 1 : - *priv->rx_buf++ =ioread8 (priv->base +NPCM_PSPI_DATA ); + val_8 =ioread8 (priv->base +NPCM_PSPI_DATA ); +if (priv->rx_buf) + *priv->rx_buf++ = val_8;break ;case 2 : - val =ioread16 (priv->base +NPCM_PSPI_DATA ); - *priv->rx_buf++ = (val >>8 ); - *priv->rx_buf++ = val &0xff ; + val_16 =ioread16 (priv->base +NPCM_PSPI_DATA ); +if (priv->rx_buf) { + *priv->rx_buf++ = (val_16 >>8 ); + *priv->rx_buf++ = val_16 &0xff ; + }break ;default :WARN_ON_ONCE (1 );
@@ -296,43 +298,26 @@ static irqreturn_t npcm_pspi_handler(int irq, void *dev_id)struct npcm_pspi *priv = dev_id;u8 stat; - stat =ioread8 (priv->base +NPCM_PSPI_STAT ); -if (!priv->tx_buf && !priv->rx_buf)return IRQ_NONE ; -if (priv->tx_buf) { -if (stat &NPCM_PSPI_STAT_RBF ) { -ioread8 (NPCM_PSPI_DATA + priv->base); -if (priv->tx_bytes ==0 ) { -npcm_pspi_disable (priv); -complete (&priv->xfer_done); -return IRQ_HANDLED ; - } - } - -if ((stat &NPCM_PSPI_STAT_BSY ) ==0 ) -if (priv->tx_bytes) -npcm_pspi_send (priv); +if (priv->tx_bytes ==0 && priv->rx_bytes ==0 ) { +npcm_pspi_disable (priv); +complete (&priv->xfer_done); +return IRQ_HANDLED ; } -if (priv->rx_buf) { -if (stat &NPCM_PSPI_STAT_RBF ) { -if (!priv->rx_bytes) -return IRQ_NONE ; - -npcm_pspi_recv (priv); + stat =ioread8 (priv->base +NPCM_PSPI_STAT ); -if (!priv->rx_bytes) { -npcm_pspi_disable (priv); -complete (&priv->xfer_done); -return IRQ_HANDLED ; - } - } +/* +* first we do the read since if we do the write we previous read might +* be lost (indeed low chances) +*/ +if ((stat &NPCM_PSPI_STAT_RBF ) && priv->rx_bytes) +npcm_pspi_recv (priv); -if (((stat &NPCM_PSPI_STAT_BSY ) ==0 ) && !priv->tx_buf) -iowrite8 (0x0 ,NPCM_PSPI_DATA + priv->base); - } +if (((stat &NPCM_PSPI_STAT_BSY ) ==0 ) && priv->tx_bytes) +npcm_pspi_send (priv);return IRQ_HANDLED ; }
Signature · 1 line
2.34.1
Tomer Maimon
maintainerPATCH 2/2 spi: npcm-pspi: Fix transfer bits per word issue
In reply to Tomer MaimonThis patch fix transfer bits per word issue by avoid polluting SPI transfer data, as it may be reused and alter the transfer length and tx/rx buffer (e.g., tpm-spi).
By default, use an 8-bit data interface mode.
However, change to a 16-bit mode when the transfer length is even.
--- drivers/spi/spi-npcm-pspi.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/spi/spi-npcm-pspi.c +8 -7
@@ -160,6 +160,7 @@ static void npcm_pspi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) {struct npcm_pspi *priv =spi_master_get_devdata (spi->master); +u8 bits_per_word =8 ; priv->tx_buf = t->tx_buf; priv->rx_buf = t->rx_buf;
@@ -172,15 +173,14 @@ static void npcm_pspi_setup_transfer(struct spi_device *spi, }/* -* If transfer is even length, and 8 bits per word transfer, -* then implement 16 bits-per-word transfer. +* If transfer is even length, change to use 16 bits-per-word transfer. */ -if (priv->bits_per_word ==8 && !(t->len &0x1 )) - t->bits_per_word =16 ; +if (!(t->len &0x1 )) + bits_per_word =16 ; -if (!priv->is_save_param || priv->bits_per_word != t->bits_per_word) { -npcm_pspi_set_transfer_size (priv, t->bits_per_word); - priv->bits_per_word = t->bits_per_word; +if (!priv->is_save_param || priv->bits_per_word != bits_per_word) { +npcm_pspi_set_transfer_size (priv, bits_per_word); + priv->bits_per_word = bits_per_word; }if (!priv->is_save_param || priv->speed_hz != t->speed_hz) {
@@ -339,6 +339,7 @@ static int npcm_pspi_probe(struct platform_device *pdev) priv =spi_master_get_devdata (master); priv->master = master; priv->is_save_param = false; + priv->bits_per_word =8 ; priv->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (priv->base)) {
Signature · 1 line
2.34.1
Andrew Jeffery
maintainerQuoted 5 lines · Tomer Maimon
This patch set:
1. Add full duplex support - this patch have been upstream to dev-6.1 and removed.
2. Fix transfer bits per word issue.
Quoted 7 lines
Tomer Maimon (2):
spi: npcm-pspi: add full duplex support
spi: npcm-pspi: Fix transfer bits per word issuedrivers/spi/spi-npcm-pspi.c | 90 ++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 52 deletions(-)
What's the state of this series with respect to upstream? Is this something specific to the openbmc/linux dev-6.6 tree, or is there an upstream equivalent? If the latter, can you please link to the relevant series?
Andrew
Tomer Maimon
maintainerHi Andrew,
Quoted 11 lines · Andrew Jeffery
Quoted 9 lines · Tomer Maimon
This patch set:
1. Add full duplex support - this patch have been upstream to dev-6.1 and removed.
2. Fix transfer bits per word issue.Tomer Maimon (2):
spi: npcm-pspi: add full duplex support
spi: npcm-pspi: Fix transfer bits per word issue
Quoted 8 lines
Quoted 3 lines
drivers/spi/spi-npcm-pspi.c | 90 ++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 52 deletions(-)What's the state of this series with respect to upstream? Is this something specific to the openbmc/linux dev-6.6 tree, or is there an upstream equivalent? If the latter, can you please link to the relevant series?
This patch set hasn't been upstream yet to OpenBMC vanilla and it is not specific to openbmc/linux dev-6.6 tree.
We will do our best to upstream this patch in kernel 6.11 (We already have a lot of patches to handle in the next kernel version :-)). since we need to upgrade the NPCM from dev-6.1 to dev-6.6, we would appreciate it if you could add it now to dev-6.6
Quoted 2 lines
Andrew
Thanks,
Tomer
Andrew Jeffery
maintainerQuoted 23 lines · Tomer Maimon
Hi Andrew,
Quoted 11 lines · Andrew Jeffery
Quoted 9 lines · Tomer Maimon
This patch set:
1. Add full duplex support - this patch have been upstream to dev-6.1 and removed.
2. Fix transfer bits per word issue.Tomer Maimon (2):
spi: npcm-pspi: add full duplex support
spi: npcm-pspi: Fix transfer bits per word issueQuoted 8 lines
Quoted 3 lines
drivers/spi/spi-npcm-pspi.c | 90 ++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 52 deletions(-)What's the state of this series with respect to upstream? Is this something specific to the openbmc/linux dev-6.6 tree, or is there an upstream equivalent? If the latter, can you please link to the relevant series?
Quoted 6 lines
This patch set hasn't been upstream yet to OpenBMC vanilla and it is not specific to openbmc/linux dev-6.6 tree.
We will do our best to upstream this patch in kernel 6.11 (We already have a lot of patches to handle in the next kernel version :-)). since we need to upgrade the NPCM from dev-6.1 to dev-6.6, we would appreciate it if you could add it now to dev-6.6
v6.11-rc1 should be tagged on the weekend. Given that and your intent to start sending the patches during its stabilisation (I'm interpreting your comment above as sending them targeting the v6.12 merge window), I intend to apply this (and the remaining patches I haven't otherwise replied to) once we have links to them on the upstream lists, and tracking them with the usual OpenBMC-Staging-Count tag.
Andrew