From: Mark Brown <broonie@kernel.org>
To: Harini Katakam <harinik@xilinx.com>
Cc: robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com,
ijc+devicetree@hellion.org.uk, galak@codeaurora.org,
rob@landley.net, grant.likely@linaro.org,
devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org,
michals@xilinx.com
Subject: Re: [PATCH] SPI: Add driver for Cadence SPI controller
Date: Mon, 17 Mar 2014 17:30:17 +0000 [thread overview]
Message-ID: <20140317173017.GW11706@sirena.org.uk> (raw)
In-Reply-To: <1395057936-8643-1-git-send-email-harinik@xilinx.com>
[-- Attachment #1: Type: text/plain, Size: 4822 bytes --]
On Mon, Mar 17, 2014 at 05:35:36PM +0530, Harini Katakam wrote:
> + bits_per_word = transfer ?
> + transfer->bits_per_word : spi->bits_per_word;
This would be a lot more legible without the ternery operator.
> + if (bits_per_word != 8) {
> + dev_err(&spi->dev, "%s, unsupported bits per word %x\n",
> + __func__, spi->bits_per_word);
> + return -EINVAL;
> + }
The core will check this for you.
> +static int cdns_spi_setup(struct spi_device *spi)
> +{
> + if (!spi->max_speed_hz)
> + return -EINVAL;
> +
> + if (!spi->bits_per_word)
> + spi->bits_per_word = 8;
The core does this for you.
> + return cdns_spi_setup_transfer(spi, NULL);
> +}
It's not clear to me why this has been split into a separate function
and the function will write to the hardware which you're not allowed to
do in setup() if it might affect an ongoing transfer.
> + intr_status = cdns_spi_read(xspi->regs + CDNS_SPI_ISR_OFFSET);
> + cdns_spi_write(xspi->regs + CDNS_SPI_ISR_OFFSET, intr_status);
> +
> + if (intr_status & CDNS_SPI_IXR_MODF_MASK) {
> + /* Indicate that transfer is completed, the SPI subsystem will
> + * identify the error as the remaining bytes to be
> + * transferred is non-zero
> + */
> + cdns_spi_write(xspi->regs + CDNS_SPI_IDR_OFFSET,
> + CDNS_SPI_IXR_DEFAULT_MASK);
> + complete(&xspi->done);
> + } else if (intr_status & CDNS_SPI_IXR_TXOW_MASK) {
What happens if both interrupts are flagged at the same time?
> + if (xspi->remaining_bytes) {
> + /* There is more data to send */
> + cdns_spi_fill_tx_fifo(xspi);
> + } else {
> + /* Transfer is completed */
> + cdns_spi_write(xspi->regs + CDNS_SPI_IDR_OFFSET,
> + CDNS_SPI_IXR_DEFAULT_MASK);
> + complete(&xspi->done);
> + }
> + }
I see from further up the file that there are error interrupt states
which might be flagged but these are just being ignored.
> +
> + return IRQ_HANDLED;
This should only be returned if an interrupt was actually handled - if
the line is shared in some system this will break.
> + cdns_spi_write(xspi->regs + CDNS_SPI_IER_OFFSET,
> + CDNS_SPI_IXR_DEFAULT_MASK);
> +
> + ret = wait_for_completion_interruptible_timeout(&xspi->done,
> + CDNS_SPI_TIMEOUT);
> + if (ret < 1) {
If you return a positive value from transfer_one() the core will wait
for you.
> +static int cdns_prepare_transfer_hardware(struct spi_master *master)
> +{
> + struct cdns_spi *xspi = spi_master_get_devdata(master);
> +
> + if (xspi->driver_state != CDNS_SPI_DRIVER_STATE_READY)
> + return -EINVAL;
> +
> + cdns_spi_write(xspi->regs + CDNS_SPI_ER_OFFSET,
> + CDNS_SPI_ER_ENABLE_MASK);
> +
> + return 0;
> +}
You probably want to enable the clocks here (and disable them when
unpreparing too).
> +static int cdns_transfer_one_message(struct spi_master *master,
> + struct spi_message *msg)
> +{
Just implement transfer_one() and provide a set_cs() operation and most
of this code will go away.
> + irq = platform_get_irq(pdev, 0);
> + if (irq < 0) {
> + ret = -ENXIO;
> + dev_err(&pdev->dev, "irq number is negative\n");
> + goto remove_master;
> + }
> +
> + ret = devm_request_irq(&pdev->dev, irq, cdns_spi_irq,
> + 0, pdev->name, xspi);
> + if (ret != 0) {
> + ret = -ENXIO;
> + dev_err(&pdev->dev, "request_irq failed\n");
> + goto remove_master;
> + }
I'd expect to see something that initialises the hardware prior to
requesting the interrupt, you don't know what state the hardware is in
when the driver takes control.
> + init_completion(&xspi->done);
This needs to be done prior to the interrupt as well.
> + ret = of_property_read_u16(pdev->dev.of_node, "num-chip-select",
> + &master->num_chipselect);
> + if (ret < 0) {
> + dev_err(&pdev->dev, "couldn't determine num-chip-select\n");
> + goto clk_dis_all;
> + }
Is there no reasonable default?
> + /* Set to default valid value */
> + xspi->speed_hz = clk_get_rate(xspi->ref_clk) / 4;
The driver should set max_speed_hz as well.
> + dev_info(&pdev->dev, "at 0x%08X mapped to 0x%08X, irq=%d\n",
> + res->start, (u32 __force)xspi->regs, irq);
No need for this, it's just noisy.
> +static int __maybe_unused cdns_spi_suspend(struct device *dev)
> +{
This needs to call spi_master_suspend() as well (and similarly on
resume).
> + cdns_spi_write(xspi->regs + CDNS_SPI_IDR_OFFSET,
> + CDNS_SPI_IXR_DEFAULT_MASK);
> + complete(&xspi->done);
> +
> + ctrl_reg = cdns_spi_read(xspi->regs + CDNS_SPI_CR_OFFSET);
> + ctrl_reg |= CDNS_SPI_CR_SSCTRL_MASK;
> + cdns_spi_write(xspi->regs + CDNS_SPI_CR_OFFSET, ctrl_reg);
Don't do this, the spi_master_suspend() call will quiesce transfers (or
if open coding it should be doing something similar rather than just
breaking any ongoing transfer).
> + clk_disable(xspi->ref_clk);
> + clk_disable(xspi->pclk);
Why not unprepare?
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2014-03-17 17:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-17 12:05 Harini Katakam
2014-03-17 12:47 ` Rob Herring
2014-03-17 13:14 ` Mark Brown
2014-03-17 13:22 ` Michal Simek
2014-03-17 13:30 ` Geert Uytterhoeven
2014-03-17 13:54 ` Harini Katakam
2014-03-17 19:00 ` Rob Herring
2014-03-20 11:23 ` Michal Simek
2014-03-17 14:01 ` Harini Katakam
2014-03-17 17:30 ` Mark Brown [this message]
2014-03-17 17:59 ` Josh Cartwright
2014-03-17 18:14 ` Mark Brown
2014-03-18 5:22 ` Harini Katakam
2014-03-18 11:06 ` Mark Brown
2014-03-18 5:16 ` Harini Katakam
2014-03-18 11:04 ` Mark Brown
2014-03-18 12:13 ` Harini Katakam
2014-03-18 12:33 ` Mark Brown
2014-03-18 14:45 ` Harini Katakam
2014-03-18 15:59 ` Mark Brown
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=20140317173017.GW11706@sirena.org.uk \
--to=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=galak@codeaurora.org \
--cc=grant.likely@linaro.org \
--cc=harinik@xilinx.com \
--cc=ijc+devicetree@hellion.org.uk \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=michals@xilinx.com \
--cc=pawel.moll@arm.com \
--cc=rob@landley.net \
--cc=robh+dt@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®