From: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Leilk Liu <leilk.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
Cc: Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
Matthias Brugger
<matthias.bgg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org
Subject: Re: [PATCH v3 3/4] spi: mediatek: Add spi bus for Mediatek MT8173
Date: Fri, 24 Jul 2015 18:49:22 +0100 [thread overview]
Message-ID: <20150724174922.GT11162@sirena.org.uk> (raw)
In-Reply-To: <1437642643-11966-4-git-send-email-leilk.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 2088 bytes --]
On Thu, Jul 23, 2015 at 05:10:42PM +0800, Leilk Liu wrote:
This basically seems fine but there's a couple of issues that should be
relatively easy to fix:
> + mdata->cur_transfer = xfer;
> + mtk_spi_prepare_transfer(master, xfer);
> + mtk_spi_setup_packet(master, xfer);
> +
> + cnt = (xfer->len % 4) ? (xfer->len / 4 + 1) : (xfer->len / 4);
Please write this as an if statement for legibility.
> +static bool mtk_spi_can_dma(struct spi_master *master,
> + struct spi_device *spi,
> + struct spi_transfer *xfer)
> +{
> + struct mtk_spi *mdata = spi_master_get_devdata(master);
> +
> + if (xfer->len > MTK_SPI_MAX_FIFO_SIZE)
> + mdata->use_dma = true;
> + else
> + mdata->use_dma = false;
> +
> + return mdata->use_dma;
> +}
This is broken since can_dma() can be called multiple transfers before
actually doing a transfer (the current implementation loops over all
transfers in a message before starting the message) - you can't store
any local data. The transfer_one() function should do another can_dma()
check to decide if it can DMA, it shouldn't rely on driver global data.
> + if (!mdata->use_dma) {
> + if (trans->rx_buf) {
This should be a variable set when doing the transfer (or perhaps based
on checking spi->cur_xfer with can_dma()).
> + for (i = 0; i < trans->len; i++) {
> + if (i % 4 == 0)
> + reg_val =
> + readl(mdata->base + SPI_RX_DATA_REG);
> + *((u8 *)(trans->rx_buf + i)) =
> + (reg_val >> ((i % 4) * 8)) & 0xff;
This isn't the clearest code ever... a comment would help.
> + if (mdata->tx_sgl && (mdata->tx_sgl_len == 0)) {
> + mdata->tx_sgl = sg_next(mdata->tx_sgl);
> + if (mdata->tx_sgl) {
> + trans->tx_dma = sg_dma_address(mdata->tx_sgl);
> + mdata->tx_sgl_len = sg_dma_len(mdata->tx_sgl);
> + }
> + }
There's a *lot* of code in this interrupt handler, and a lot of it looks
an awful lot like the contents of mtk_spi_dma_transfer() has been
cut'n'pasted in. The shared code should all be factored out into a
function called from both places.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2015-07-24 17:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-23 9:10 [PATCH v3 0/4] Add Mediatek SPI bus driver Leilk Liu
[not found] ` <1437642643-11966-1-git-send-email-leilk.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2015-07-23 9:10 ` [PATCH v3 1/4] spi: support spi without dma channel to use can_dma() Leilk Liu
2015-07-23 9:10 ` [PATCH v3 2/4] dt-bindings: ARM: Mediatek: Document devicetree bindings for spi bus Leilk Liu
2015-07-24 17:34 ` Mark Brown
[not found] ` <20150724173446.GS11162-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-07-27 2:38 ` leilk liu
2015-07-23 9:10 ` [PATCH v3 4/4] arm64: dts: Add spi bus dts Leilk Liu
2015-07-23 9:10 ` [PATCH v3 3/4] spi: mediatek: Add spi bus for Mediatek MT8173 Leilk Liu
[not found] ` <1437642643-11966-4-git-send-email-leilk.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2015-07-24 17:49 ` Mark Brown [this message]
2015-07-27 2:48 ` leilk liu
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=20150724174922.GT11162@sirena.org.uk \
--to=broonie-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=leilk.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=matthias.bgg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.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