mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/4] mci: sdhci: provide sdhci_readx_poll_timeout helpers
Date: Mon, 20 Apr 2020 08:22:32 +0200	[thread overview]
Message-ID: <20200420062232.GB1694@pengutronix.de> (raw)
In-Reply-To: <20200415092916.21285-1-a.fatoum@pengutronix.de>

On Wed, Apr 15, 2020 at 11:29:13AM +0200, Ahmad Fatoum wrote:
> The sdhci_readN accessors don't lend themselves for clean use with
> readx_poll_timeout because they accept two arguments. Add
> a sdhci-specific helper, so the sdhci drivers can cut down on the
> timeout loop boilerplate.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/mci/sdhci.h | 51 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 51 insertions(+)
> 
> diff --git a/drivers/mci/sdhci.h b/drivers/mci/sdhci.h
> index a307dc97cd9a..7ac32f1541b8 100644
> --- a/drivers/mci/sdhci.h
> +++ b/drivers/mci/sdhci.h
> @@ -1,6 +1,8 @@
>  #ifndef __MCI_SDHCI_H
>  #define __MCI_SDHCI_H
>  
> +#include <pbl.h>
> +
>  #define SDHCI_DMA_ADDRESS					0x00
>  #define SDHCI_BLOCK_SIZE__BLOCK_COUNT				0x04
>  #define SDHCI_BLOCK_SIZE					0x04
> @@ -144,4 +146,53 @@ void sdhci_set_cmd_xfer_mode(struct sdhci *host, struct mci_cmd *cmd,
>  			     u32 *xfer);
>  int sdhci_transfer_data(struct sdhci *sdhci, struct mci_data *data);
>  
> +/**
> + * sdhci_readx_poll_timeout -	Periodically poll an sdhci register until
> + *				a condition is met or a timeout occurs
> + * @bits: access width
> + * @sdhci: sdhci instance
> + * @reg: Register to poll
> + * @val: Variable to read the value into
> + * @cond: Break condition (usually involving @val)
> + * @timeout_us: Timeout in us, 0 means never timeout
> + *
> + * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
> + * case, the last read value at @reg is stored in @val.
> + *
> + * When available, you'll probably want to use one of the specialized
> + * macros defined below rather than this macro directly.
> + *
> + * We do not have timing functions in the PBL, so ignore the timeout value and
> + * loop infinitely here.
> + *
> + * Based on readx_poll_timeout from <linux/iopoll.h>
> + */
> +#define sdhci_readx_poll_timeout(bits, sdhci, reg, val, cond, timeout_us)	\
> +({ \
> +	uint64_t start; \
> +	if (!IN_PBL && timeout_us) \
> +		start = get_time_ns(); \
> +	for (;;) { \
> +		(val) = sdhci_read##bits(sdhci, reg); \
> +		if (cond) \
> +			break; \
> +		if (!IN_PBL && timeout_us && \
> +		    is_timeout(start, ((timeout_us) * USECOND))) { \
> +			(val) = sdhci_read##bits(sdhci, reg); \
> +			break; \
> +		} \
> +	} \
> +	(cond) ? 0 : -ETIMEDOUT; \
> +})

Is this really an improvement? How many variants of these helpers will we get?

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2020-04-20  6:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-15  9:29 Ahmad Fatoum
2020-04-15  9:29 ` [PATCH 2/4] mci: sdhci: implement sdhci_reset() Ahmad Fatoum
2020-04-15  9:29 ` [PATCH 3/4] ARM: at91: dts: specify aliases for sdmmc nodes Ahmad Fatoum
2020-04-15  9:29 ` [PATCH 4/4] mci: sdhci: add Atmel SDHCI (sama5d2, sam9x60) support Ahmad Fatoum
2020-04-20  6:22 ` Sascha Hauer [this message]
2020-04-20  6:25   ` [PATCH 1/4] mci: sdhci: provide sdhci_readx_poll_timeout helpers Ahmad Fatoum
2020-04-22  5:51     ` Sascha Hauer
2020-04-22  5:49 ` [PATCH 1/2] iopoll: Introduce read_poll_timeout Sascha Hauer
2020-04-22  5:49   ` [PATCH 2/2] mci: sdhci: provide sdhci_readx_poll_timeout helpers Sascha Hauer

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=20200420062232.GB1694@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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