From: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
To: Feng Tang <feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
alek.du-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
alan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org
Subject: Re: [PATCH v2 3/4] spi/dw_spi: change poll mode transfer from byte ops to batch ops
Date: Wed, 30 Mar 2011 21:32:39 -0600 [thread overview]
Message-ID: <20110331033239.GE19333@ponder.secretlab.ca> (raw)
In-Reply-To: <1301497795-6924-4-git-send-email-feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
On Wed, Mar 30, 2011 at 11:09:54PM +0800, Feng Tang wrote:
> From: Alek Du <alek.du-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>
> Current poll transfer will read/write one word, then wait till the
> hw is non-busy, it's not efficient. This patch will try to read/write
> as many words as permitted by hardware FIFO depth.
>
> Signed-off-by: Alek Du <alek.du-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> Signed-off-by: Feng Tang <feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Applied, thanks.
g.
> ---
> drivers/spi/dw_spi.c | 71 +++++++++++++++++++++++++++++++++----------------
> 1 files changed, 48 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/spi/dw_spi.c b/drivers/spi/dw_spi.c
> index d3aaf8d..7a2a722 100644
> --- a/drivers/spi/dw_spi.c
> +++ b/drivers/spi/dw_spi.c
> @@ -160,6 +160,37 @@ static inline void mrst_spi_debugfs_remove(struct dw_spi *dws)
> }
> #endif /* CONFIG_DEBUG_FS */
>
> +/* Return the max entries we can fill into tx fifo */
> +static inline u32 tx_max(struct dw_spi *dws)
> +{
> + u32 tx_left, tx_room, rxtx_gap;
> +
> + tx_left = (dws->tx_end - dws->tx) / dws->n_bytes;
> + tx_room = dws->fifo_len - dw_readw(dws, txflr);
> +
> + /*
> + * Another concern is about the tx/rx mismatch, we
> + * though to use (dws->fifo_len - rxflr - txflr) as
> + * one maximum value for tx, but it doesn't cover the
> + * data which is out of tx/rx fifo and inside the
> + * shift registers. So a control from sw point of
> + * view is taken.
> + */
> + rxtx_gap = ((dws->rx_end - dws->rx) - (dws->tx_end - dws->tx))
> + / dws->n_bytes;
> +
> + return min3(tx_left, tx_room, (u32) (dws->fifo_len - rxtx_gap));
> +}
> +
> +/* Return the max entries we should read out of rx fifo */
> +static inline u32 rx_max(struct dw_spi *dws)
> +{
> + u32 rx_left = (dws->rx_end - dws->rx) / dws->n_bytes;
> +
> + return min(rx_left, (u32)dw_readw(dws, rxflr));
> +}
> +
> +
> static void wait_till_not_busy(struct dw_spi *dws)
> {
> unsigned long end = jiffies + 1 + usecs_to_jiffies(5000);
> @@ -175,33 +206,30 @@ static void wait_till_not_busy(struct dw_spi *dws)
>
> static int dw_writer(struct dw_spi *dws)
> {
> + u32 max = tx_max(dws);
> u16 txw = 0;
>
> - if (!(dw_readw(dws, sr) & SR_TF_NOT_FULL)
> - || (dws->tx == dws->tx_end))
> - return 0;
> -
> - /* Set the tx word if the transfer's original "tx" is not null */
> - if (dws->tx_end - dws->len) {
> - if (dws->n_bytes == 1)
> - txw = *(u8 *)(dws->tx);
> - else
> - txw = *(u16 *)(dws->tx);
> + while (max--) {
> + /* Set the tx word if the transfer's original "tx" is not null */
> + if (dws->tx_end - dws->len) {
> + if (dws->n_bytes == 1)
> + txw = *(u8 *)(dws->tx);
> + else
> + txw = *(u16 *)(dws->tx);
> + }
> + dw_writew(dws, dr, txw);
> + dws->tx += dws->n_bytes;
> }
>
> - dw_writew(dws, dr, txw);
> - dws->tx += dws->n_bytes;
> -
> - wait_till_not_busy(dws);
> return 1;
> }
>
> static int dw_reader(struct dw_spi *dws)
> {
> + u32 max = rx_max(dws);
> u16 rxw;
>
> - while ((dw_readw(dws, sr) & SR_RF_NOT_EMPT)
> - && (dws->rx < dws->rx_end)) {
> + while (max--) {
> rxw = dw_readw(dws, dr);
> /* Care rx only if the transfer's original "rx" is not null */
> if (dws->rx_end - dws->len) {
> @@ -213,7 +241,6 @@ static int dw_reader(struct dw_spi *dws)
> dws->rx += dws->n_bytes;
> }
>
> - wait_till_not_busy(dws);
> return dws->rx == dws->rx_end;
> }
>
> @@ -368,13 +395,11 @@ static irqreturn_t dw_spi_irq(int irq, void *dev_id)
> /* Must be called inside pump_transfers() */
> static void poll_transfer(struct dw_spi *dws)
> {
> - while (dw_writer(dws))
> + do {
> + dw_writer(dws);
> dw_reader(dws);
> - /*
> - * There is a possibility that the last word of a transaction
> - * will be lost if data is not ready. Re-read to solve this issue.
> - */
> - dw_reader(dws);
> + cpu_relax();
> + } while (dws->rx_end > dws->rx);
>
> dw_spi_xfer_done(dws);
> }
> --
> 1.7.0.4
>
------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself;
WebMatrix provides all the features you need to develop and
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
next prev parent reply other threads:[~2011-03-31 3:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-30 15:09 [PATCH v2 0/4] patch serie for dw_spi driver Feng Tang
[not found] ` <1301497795-6924-1-git-send-email-feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2011-03-30 15:09 ` [PATCH v2 1/4] spi/dw_spi: unify the low level read/write routines Feng Tang
[not found] ` <1301497795-6924-2-git-send-email-feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2011-03-31 3:32 ` Grant Likely
2011-03-30 15:09 ` [PATCH v2 2/4] spi/dw_spi: remove the un-necessary flush() Feng Tang
[not found] ` <1301497795-6924-3-git-send-email-feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2011-03-31 3:32 ` Grant Likely
2011-03-30 15:09 ` [PATCH v2 3/4] spi/dw_spi: change poll mode transfer from byte ops to batch ops Feng Tang
[not found] ` <1301497795-6924-4-git-send-email-feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2011-03-31 3:32 ` Grant Likely [this message]
2011-03-31 9:54 ` Alan Cox
[not found] ` <20110331105448.0f6d0bd4-Z/y2cZnRghHXmaaqVzeoHQ@public.gmane.org>
2011-03-31 12:54 ` Du, Alek
2011-03-31 13:13 ` Grant Likely
2011-04-25 7:46 ` Feng Tang
2011-04-25 8:54 ` Du, Alek
2011-03-30 15:09 ` [PATCH v2 4/4] spi/dw_spi: improve the interrupt mode with the " Feng Tang
[not found] ` <1301497795-6924-5-git-send-email-feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2011-03-31 3:32 ` Grant Likely
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=20110331033239.GE19333@ponder.secretlab.ca \
--to=grant.likely-s3s/wqlpoipyb63q8fvjnq@public.gmane.org \
--cc=alan-VuQAYsv1563Yd54FQh9/CA@public.gmane.org \
--cc=alek.du-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
--cc=feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@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;
as well as URLs for NNTP newsgroup(s).