All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Masahisa Kojima <masahisa.kojima@linaro.org>
Cc: linux-spi@vger.kernel.org, devicetree@vger.kernel.org,
	geert@linux-m68k.org, tpiepho@impinj.com,
	andy.shevchenko@gmail.com, robh+dt@kernel.org,
	mark.rutland@arm.com, ard.biesheuvel@linaro.org,
	jaswinder.singh@linaro.org, masami.hiramatsu@linaro.org,
	okamoto.satoru@socionext.com, osaki.yoshitoyo@socionext.com
Subject: Re: [PATCH v5 3/3] spi: Add spi driver for Socionext Synquacer platform
Date: Tue, 21 May 2019 19:16:09 +0100	[thread overview]
Message-ID: <20190521181609.GB16633@sirena.org.uk> (raw)
In-Reply-To: <20190521115958.22504-4-masahisa.kojima@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 3623 bytes --]

On Tue, May 21, 2019 at 08:59:58PM +0900, Masahisa Kojima wrote:

> +	switch (sspi->bpw) {
> +	case 8:

> +		{
> +		u8 *buf = sspi->rx_buf;
> +
> +		readsb(sspi->regs + SYNQUACER_HSSPI_REG_RX_FIFO, buf, len);
> +		sspi->rx_buf = buf + len;
> +		break;
> +		}

Please indent these properly.

> +	default:
> +		{
> +		u32 *buf = sspi->rx_buf;
> +
> +		readsl(sspi->regs + SYNQUACER_HSSPI_REG_RX_FIFO, buf, len);
> +		sspi->rx_buf = buf + len;
> +		break;
> +		}

It'd be better to explicitly list the values this works for and return
an error otherwise.

> +	if (sspi->rx_words) {
> +		val = SYNQUACER_HSSPI_RXE_FIFO_MORE_THAN_THRESHOLD |
> +		      SYNQUACER_HSSPI_RXE_SLAVE_RELEASED;
> +		writel_relaxed(val, sspi->regs + SYNQUACER_HSSPI_REG_RXE);
> +		status = wait_for_completion_timeout(&sspi->transfer_done,
> +			msecs_to_jiffies(SYNQUACER_HSSPI_TRANSFER_TMOUT_MSEC));
> +		writel_relaxed(0, sspi->regs + SYNQUACER_HSSPI_REG_RXE);
> +	}
> +
> +	if (xfer->tx_buf) {
> +		val = SYNQUACER_HSSPI_TXE_FIFO_EMPTY;
> +		writel_relaxed(val, sspi->regs + SYNQUACER_HSSPI_REG_TXE);
> +		status = wait_for_completion_timeout(&sspi->transfer_done,
> +			msecs_to_jiffies(SYNQUACER_HSSPI_TRANSFER_TMOUT_MSEC));
> +		writel_relaxed(0, sspi->regs + SYNQUACER_HSSPI_REG_TXE);
> +	}

I guess the TX will complete before the RX usually so I'd kind of expect
the waits to be in the other order?

> +	if (status < 0) {
> +		dev_err(sspi->dev, "failed to transfer\n");
> +		return status;
> +	}

Printing the error code could be helpful for users.

> +static void synquacer_spi_set_cs(struct spi_device *spi, bool enable)
> +{
> +	struct synquacer_spi *sspi = spi_master_get_devdata(spi->master);
> +	u32 val;
> +
> +	val = readl_relaxed(sspi->regs + SYNQUACER_HSSPI_REG_DMSTART);
> +	val &= ~(SYNQUACER_HSSPI_DMPSEL_CS_MASK <<
> +		 SYNQUACER_HSSPI_DMPSEL_CS_SHIFT);
> +	val |= spi->chip_select << SYNQUACER_HSSPI_DMPSEL_CS_SHIFT;
> +
> +	if (enable) {
> +		val |= SYNQUACER_HSSPI_DMSTOP_STOP;
> +		writel_relaxed(val, sspi->regs + SYNQUACER_HSSPI_REG_DMSTART);
> +
> +		if (sspi->rx_buf) {
> +			u32 buf[SYNQUACER_HSSPI_FIFO_DEPTH];
> +
> +			sspi->rx_buf = buf;
> +			sspi->rx_words = SYNQUACER_HSSPI_FIFO_DEPTH;
> +			read_fifo(sspi);
> +		}

This is doing things with the FIFO, that's completely inappropriate for
a set_cs() operation.  The set_cs() operation should set the chip select
and nothing else.

> +static irqreturn_t sq_spi_rx_handler(int irq, void *priv)
> +{
> +	uint32_t val;
> +	struct synquacer_spi *sspi = priv;
> +
> +	val = readl_relaxed(sspi->regs + SYNQUACER_HSSPI_REG_RXF);
> +	if ((val & SYNQUACER_HSSPI_RXF_SLAVE_RELEASED) ||
> +	    (val & SYNQUACER_HSSPI_RXF_FIFO_MORE_THAN_THRESHOLD))
> +		read_fifo(sspi);
> +
> +	if (sspi->rx_words == 0) {
> +		writel_relaxed(0, sspi->regs + SYNQUACER_HSSPI_REG_RXE);
> +		complete(&sspi->transfer_done);
> +	}
> +
> +	return 0;
> +}

0 is not a valid return from an interrupt handler, IRQ_HANDLED or
IRQ_NONE.

> +	ret = devm_request_irq(&pdev->dev, rx_irq, sq_spi_rx_handler,
> +				0, "synquacer-spi-rx", sspi);
> +	ret = devm_request_irq(&pdev->dev, tx_irq, sq_spi_tx_handler,
> +				0, "synquacer-spi-tx", sspi);

The code looked awfully like we depend on having interrupts?  

> +	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_TX_DUAL | SPI_RX_DUAL |
> +			    SPI_TX_QUAD | SPI_RX_QUAD;

I don't see any code in the driver that configures dual or quad mode
support other than setting _PCC_SAFESYNC, I'm not clear how the driver
supports these modes?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2019-05-21 18:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-21 11:59 [PATCH v5 0/3] spi: support for Socionext Synquacer platform Masahisa Kojima
2019-05-21 11:59 ` [PATCH v5 1/3] MAINTAINERS: Add entry for Synquacer SPI driver Masahisa Kojima
2019-05-21 11:59 ` [PATCH v5 2/3] dt-bindings: spi: Add DT bindings for Synquacer Masahisa Kojima
2019-05-21 11:59 ` [PATCH v5 3/3] spi: Add spi driver for Socionext Synquacer platform Masahisa Kojima
2019-05-21 13:55   ` Ard Biesheuvel
2019-05-21 16:27     ` Andy Shevchenko
2019-05-21 16:38   ` Andy Shevchenko
2019-05-27  8:31     ` Masahisa Kojima
2019-05-21 18:16   ` Mark Brown [this message]
2019-05-22  8:27     ` Masahisa Kojima
2019-05-22 11:09       ` Mark Brown
2019-05-23  4:35         ` Masahisa Kojima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190521181609.GB16633@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=geert@linux-m68k.org \
    --cc=jaswinder.singh@linaro.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=masahisa.kojima@linaro.org \
    --cc=masami.hiramatsu@linaro.org \
    --cc=okamoto.satoru@socionext.com \
    --cc=osaki.yoshitoyo@socionext.com \
    --cc=robh+dt@kernel.org \
    --cc=tpiepho@impinj.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.