mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Masahiro Yamada <yamada.masahiro@socionext.com>,
	linux-mmc@vger.kernel.org
Cc: Piotr Sroka <piotrs@cadence.com>,
	linux-kernel@vger.kernel.org,
	Ulf Hansson <ulf.hansson@linaro.org>
Subject: Re: [PATCH] mmc: sdhci-cadence: use bitfield access macros for cleanup
Date: Thu, 19 Oct 2017 11:37:53 +0300	[thread overview]
Message-ID: <2ed276f9-5869-93ed-766f-a122f4942591@intel.com> (raw)
In-Reply-To: <1507899031-1245-1-git-send-email-yamada.masahiro@socionext.com>

On 13/10/17 15:50, Masahiro Yamada wrote:
> Accessing register fields generally need mask and shift part.
> Defining them separately, like SDHCI_CDNS_HRS06_TUNE_{SHIFT,MASK},
> is tedious.
> 
> Register fields can be always defined by GENMASK (or, BIT if it it
> a single bit).  They are nicely handled by FIELD_* macros.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
> 
>  drivers/mmc/host/sdhci-cadence.c | 28 ++++++++++++++--------------
>  1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci-cadence.c b/drivers/mmc/host/sdhci-cadence.c
> index 56529c3..0f589e2 100644
> --- a/drivers/mmc/host/sdhci-cadence.c
> +++ b/drivers/mmc/host/sdhci-cadence.c
> @@ -13,6 +13,7 @@
>   * GNU General Public License for more details.
>   */
>  
> +#include <linux/bitfield.h>
>  #include <linux/bitops.h>
>  #include <linux/iopoll.h>
>  #include <linux/module.h>
> @@ -27,15 +28,14 @@
>  #define   SDHCI_CDNS_HRS04_ACK			BIT(26)
>  #define   SDHCI_CDNS_HRS04_RD			BIT(25)
>  #define   SDHCI_CDNS_HRS04_WR			BIT(24)
> -#define   SDHCI_CDNS_HRS04_RDATA_SHIFT		16
> -#define   SDHCI_CDNS_HRS04_WDATA_SHIFT		8
> -#define   SDHCI_CDNS_HRS04_ADDR_SHIFT		0
> +#define   SDHCI_CDNS_HRS04_RDATA		GENMASK(23, 16)
> +#define   SDHCI_CDNS_HRS04_WDATA		GENMASK(15, 8)
> +#define   SDHCI_CDNS_HRS04_ADDR			GENMASK(5, 0)
>  
>  #define SDHCI_CDNS_HRS06		0x18		/* eMMC control */
>  #define   SDHCI_CDNS_HRS06_TUNE_UP		BIT(15)
> -#define   SDHCI_CDNS_HRS06_TUNE_SHIFT		8
> -#define   SDHCI_CDNS_HRS06_TUNE_MASK		0x3f
> -#define   SDHCI_CDNS_HRS06_MODE_MASK		0x7
> +#define   SDHCI_CDNS_HRS06_TUNE			GENMASK(13, 8)
> +#define   SDHCI_CDNS_HRS06_MODE			GENMASK(2, 0)
>  #define   SDHCI_CDNS_HRS06_MODE_SD		0x0
>  #define   SDHCI_CDNS_HRS06_MODE_MMC_SDR		0x2
>  #define   SDHCI_CDNS_HRS06_MODE_MMC_DDR		0x3
> @@ -105,8 +105,8 @@ static int sdhci_cdns_write_phy_reg(struct sdhci_cdns_priv *priv,
>  	u32 tmp;
>  	int ret;
>  
> -	tmp = (data << SDHCI_CDNS_HRS04_WDATA_SHIFT) |
> -	      (addr << SDHCI_CDNS_HRS04_ADDR_SHIFT);
> +	tmp = FIELD_PREP(SDHCI_CDNS_HRS04_WDATA, data) |
> +	      FIELD_PREP(SDHCI_CDNS_HRS04_ADDR, addr);
>  	writel(tmp, reg);
>  
>  	tmp |= SDHCI_CDNS_HRS04_WR;
> @@ -189,8 +189,8 @@ static void sdhci_cdns_set_emmc_mode(struct sdhci_cdns_priv *priv, u32 mode)
>  
>  	/* The speed mode for eMMC is selected by HRS06 register */
>  	tmp = readl(priv->hrs_addr + SDHCI_CDNS_HRS06);
> -	tmp &= ~SDHCI_CDNS_HRS06_MODE_MASK;
> -	tmp |= mode;
> +	tmp &= ~SDHCI_CDNS_HRS06_MODE;
> +	tmp |= FIELD_PREP(SDHCI_CDNS_HRS06_MODE, mode);
>  	writel(tmp, priv->hrs_addr + SDHCI_CDNS_HRS06);
>  }
>  
> @@ -199,7 +199,7 @@ static u32 sdhci_cdns_get_emmc_mode(struct sdhci_cdns_priv *priv)
>  	u32 tmp;
>  
>  	tmp = readl(priv->hrs_addr + SDHCI_CDNS_HRS06);
> -	return tmp & SDHCI_CDNS_HRS06_MODE_MASK;
> +	return FIELD_GET(SDHCI_CDNS_HRS06_MODE, tmp);
>  }
>  
>  static void sdhci_cdns_set_uhs_signaling(struct sdhci_host *host,
> @@ -254,12 +254,12 @@ static int sdhci_cdns_set_tune_val(struct sdhci_host *host, unsigned int val)
>  	void __iomem *reg = priv->hrs_addr + SDHCI_CDNS_HRS06;
>  	u32 tmp;
>  
> -	if (WARN_ON(val > SDHCI_CDNS_HRS06_TUNE_MASK))
> +	if (WARN_ON(!FIELD_FIT(SDHCI_CDNS_HRS06_TUNE, val)))
>  		return -EINVAL;
>  
>  	tmp = readl(reg);
> -	tmp &= ~(SDHCI_CDNS_HRS06_TUNE_MASK << SDHCI_CDNS_HRS06_TUNE_SHIFT);
> -	tmp |= val << SDHCI_CDNS_HRS06_TUNE_SHIFT;
> +	tmp &= ~SDHCI_CDNS_HRS06_TUNE;
> +	tmp |= FIELD_PREP(SDHCI_CDNS_HRS06_TUNE, val);
>  	tmp |= SDHCI_CDNS_HRS06_TUNE_UP;
>  	writel(tmp, reg);
>  
> 

  reply	other threads:[~2017-10-19  8:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-13 12:50 Masahiro Yamada
2017-10-19  8:37 ` Adrian Hunter [this message]
2017-10-20 10:02 ` Ulf Hansson

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=2ed276f9-5869-93ed-766f-a122f4942591@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=piotrs@cadence.com \
    --cc=ulf.hansson@linaro.org \
    --cc=yamada.masahiro@socionext.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 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®