linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: sdhci: use FIELD_GET/PREP for current capabilities bit masks
@ 2020-05-11  6:28 Masahiro Yamada
  2020-05-15  7:09 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: Masahiro Yamada @ 2020-05-11  6:28 UTC (permalink / raw)
  To: linux-mmc, Ulf Hansson, Adrian Hunter
  Cc: Masahiro Yamada, Fabio Estevam, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo,
	linux-arm-kernel, linux-kernel

Use FIELD_GET and FIELD_PREP to get access to the register fields. Delete
the shift macros and use GENMASK() for the touched macros.

Note that, this has the side-effect of changing the constants to 64-bit on
64-bit platforms.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 drivers/mmc/host/sdhci-esdhc-imx.c |  6 +++---
 drivers/mmc/host/sdhci.c           | 27 ++++++++++++---------------
 drivers/mmc/host/sdhci.h           | 11 ++++-------
 3 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 38cd83118082..9896e03fce71 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -419,9 +419,9 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
 
 	if (unlikely(reg == SDHCI_MAX_CURRENT) && esdhc_is_usdhc(imx_data)) {
 		val = 0;
-		val |= 0xFF << SDHCI_MAX_CURRENT_330_SHIFT;
-		val |= 0xFF << SDHCI_MAX_CURRENT_300_SHIFT;
-		val |= 0xFF << SDHCI_MAX_CURRENT_180_SHIFT;
+		val |= FIELD_PREP(SDHCI_MAX_CURRENT_330_MASK, 0xFF);
+		val |= FIELD_PREP(SDHCI_MAX_CURRENT_300_MASK, 0xFF);
+		val |= FIELD_PREP(SDHCI_MAX_CURRENT_180_MASK, 0xFF);
 	}
 
 	if (unlikely(reg == SDHCI_INT_STATUS)) {
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 344a7e0e33fe..7818e650f974 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -4355,35 +4355,32 @@ int sdhci_setup_host(struct sdhci_host *host)
 
 			curr = min_t(u32, curr, SDHCI_MAX_CURRENT_LIMIT);
 			max_current_caps =
-				(curr << SDHCI_MAX_CURRENT_330_SHIFT) |
-				(curr << SDHCI_MAX_CURRENT_300_SHIFT) |
-				(curr << SDHCI_MAX_CURRENT_180_SHIFT);
+				FIELD_PREP(SDHCI_MAX_CURRENT_330_MASK, curr) |
+				FIELD_PREP(SDHCI_MAX_CURRENT_300_MASK, curr) |
+				FIELD_PREP(SDHCI_MAX_CURRENT_180_MASK, curr);
 		}
 	}
 
 	if (host->caps & SDHCI_CAN_VDD_330) {
 		ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
 
-		mmc->max_current_330 = ((max_current_caps &
-				   SDHCI_MAX_CURRENT_330_MASK) >>
-				   SDHCI_MAX_CURRENT_330_SHIFT) *
-				   SDHCI_MAX_CURRENT_MULTIPLIER;
+		mmc->max_current_330 = FIELD_GET(SDHCI_MAX_CURRENT_330_MASK,
+						 max_current_caps) *
+						SDHCI_MAX_CURRENT_MULTIPLIER;
 	}
 	if (host->caps & SDHCI_CAN_VDD_300) {
 		ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
 
-		mmc->max_current_300 = ((max_current_caps &
-				   SDHCI_MAX_CURRENT_300_MASK) >>
-				   SDHCI_MAX_CURRENT_300_SHIFT) *
-				   SDHCI_MAX_CURRENT_MULTIPLIER;
+		mmc->max_current_300 = FIELD_GET(SDHCI_MAX_CURRENT_300_MASK,
+						 max_current_caps) *
+						SDHCI_MAX_CURRENT_MULTIPLIER;
 	}
 	if (host->caps & SDHCI_CAN_VDD_180) {
 		ocr_avail |= MMC_VDD_165_195;
 
-		mmc->max_current_180 = ((max_current_caps &
-				   SDHCI_MAX_CURRENT_180_MASK) >>
-				   SDHCI_MAX_CURRENT_180_SHIFT) *
-				   SDHCI_MAX_CURRENT_MULTIPLIER;
+		mmc->max_current_180 = FIELD_GET(SDHCI_MAX_CURRENT_180_MASK,
+						 max_current_caps) *
+						SDHCI_MAX_CURRENT_MULTIPLIER;
 	}
 
 	/* If OCR set by host, use it instead. */
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index d7f1441b0fc3..2ff98891bf25 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -233,13 +233,10 @@
 #define  SDHCI_SUPPORT_HS400	0x80000000 /* Non-standard */
 
 #define SDHCI_MAX_CURRENT		0x48
-#define  SDHCI_MAX_CURRENT_LIMIT	0xFF
-#define  SDHCI_MAX_CURRENT_330_MASK	0x0000FF
-#define  SDHCI_MAX_CURRENT_330_SHIFT	0
-#define  SDHCI_MAX_CURRENT_300_MASK	0x00FF00
-#define  SDHCI_MAX_CURRENT_300_SHIFT	8
-#define  SDHCI_MAX_CURRENT_180_MASK	0xFF0000
-#define  SDHCI_MAX_CURRENT_180_SHIFT	16
+#define  SDHCI_MAX_CURRENT_LIMIT	GENMASK(7, 0)
+#define  SDHCI_MAX_CURRENT_330_MASK	GENMASK(7, 0)
+#define  SDHCI_MAX_CURRENT_300_MASK	GENMASK(15, 8)
+#define  SDHCI_MAX_CURRENT_180_MASK	GENMASK(23, 16)
 #define   SDHCI_MAX_CURRENT_MULTIPLIER	4
 
 /* 4C-4F reserved for more max current */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mmc: sdhci: use FIELD_GET/PREP for current capabilities bit masks
  2020-05-11  6:28 [PATCH] mmc: sdhci: use FIELD_GET/PREP for current capabilities bit masks Masahiro Yamada
@ 2020-05-15  7:09 ` Ulf Hansson
  0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2020-05-15  7:09 UTC (permalink / raw)
  To: Masahiro Yamada
  Cc: linux-mmc, Adrian Hunter, Fabio Estevam, NXP Linux Team,
	Pengutronix Kernel Team, Sascha Hauer, Shawn Guo, Linux ARM,
	Linux Kernel Mailing List

On Mon, 11 May 2020 at 08:29, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
>
> Use FIELD_GET and FIELD_PREP to get access to the register fields. Delete
> the shift macros and use GENMASK() for the touched macros.
>
> Note that, this has the side-effect of changing the constants to 64-bit on
> 64-bit platforms.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Applied for next, thanks!

Kind regards
Uffe


> ---
>
>  drivers/mmc/host/sdhci-esdhc-imx.c |  6 +++---
>  drivers/mmc/host/sdhci.c           | 27 ++++++++++++---------------
>  drivers/mmc/host/sdhci.h           | 11 ++++-------
>  3 files changed, 19 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
> index 38cd83118082..9896e03fce71 100644
> --- a/drivers/mmc/host/sdhci-esdhc-imx.c
> +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
> @@ -419,9 +419,9 @@ static u32 esdhc_readl_le(struct sdhci_host *host, int reg)
>
>         if (unlikely(reg == SDHCI_MAX_CURRENT) && esdhc_is_usdhc(imx_data)) {
>                 val = 0;
> -               val |= 0xFF << SDHCI_MAX_CURRENT_330_SHIFT;
> -               val |= 0xFF << SDHCI_MAX_CURRENT_300_SHIFT;
> -               val |= 0xFF << SDHCI_MAX_CURRENT_180_SHIFT;
> +               val |= FIELD_PREP(SDHCI_MAX_CURRENT_330_MASK, 0xFF);
> +               val |= FIELD_PREP(SDHCI_MAX_CURRENT_300_MASK, 0xFF);
> +               val |= FIELD_PREP(SDHCI_MAX_CURRENT_180_MASK, 0xFF);
>         }
>
>         if (unlikely(reg == SDHCI_INT_STATUS)) {
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 344a7e0e33fe..7818e650f974 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -4355,35 +4355,32 @@ int sdhci_setup_host(struct sdhci_host *host)
>
>                         curr = min_t(u32, curr, SDHCI_MAX_CURRENT_LIMIT);
>                         max_current_caps =
> -                               (curr << SDHCI_MAX_CURRENT_330_SHIFT) |
> -                               (curr << SDHCI_MAX_CURRENT_300_SHIFT) |
> -                               (curr << SDHCI_MAX_CURRENT_180_SHIFT);
> +                               FIELD_PREP(SDHCI_MAX_CURRENT_330_MASK, curr) |
> +                               FIELD_PREP(SDHCI_MAX_CURRENT_300_MASK, curr) |
> +                               FIELD_PREP(SDHCI_MAX_CURRENT_180_MASK, curr);
>                 }
>         }
>
>         if (host->caps & SDHCI_CAN_VDD_330) {
>                 ocr_avail |= MMC_VDD_32_33 | MMC_VDD_33_34;
>
> -               mmc->max_current_330 = ((max_current_caps &
> -                                  SDHCI_MAX_CURRENT_330_MASK) >>
> -                                  SDHCI_MAX_CURRENT_330_SHIFT) *
> -                                  SDHCI_MAX_CURRENT_MULTIPLIER;
> +               mmc->max_current_330 = FIELD_GET(SDHCI_MAX_CURRENT_330_MASK,
> +                                                max_current_caps) *
> +                                               SDHCI_MAX_CURRENT_MULTIPLIER;
>         }
>         if (host->caps & SDHCI_CAN_VDD_300) {
>                 ocr_avail |= MMC_VDD_29_30 | MMC_VDD_30_31;
>
> -               mmc->max_current_300 = ((max_current_caps &
> -                                  SDHCI_MAX_CURRENT_300_MASK) >>
> -                                  SDHCI_MAX_CURRENT_300_SHIFT) *
> -                                  SDHCI_MAX_CURRENT_MULTIPLIER;
> +               mmc->max_current_300 = FIELD_GET(SDHCI_MAX_CURRENT_300_MASK,
> +                                                max_current_caps) *
> +                                               SDHCI_MAX_CURRENT_MULTIPLIER;
>         }
>         if (host->caps & SDHCI_CAN_VDD_180) {
>                 ocr_avail |= MMC_VDD_165_195;
>
> -               mmc->max_current_180 = ((max_current_caps &
> -                                  SDHCI_MAX_CURRENT_180_MASK) >>
> -                                  SDHCI_MAX_CURRENT_180_SHIFT) *
> -                                  SDHCI_MAX_CURRENT_MULTIPLIER;
> +               mmc->max_current_180 = FIELD_GET(SDHCI_MAX_CURRENT_180_MASK,
> +                                                max_current_caps) *
> +                                               SDHCI_MAX_CURRENT_MULTIPLIER;
>         }
>
>         /* If OCR set by host, use it instead. */
> diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
> index d7f1441b0fc3..2ff98891bf25 100644
> --- a/drivers/mmc/host/sdhci.h
> +++ b/drivers/mmc/host/sdhci.h
> @@ -233,13 +233,10 @@
>  #define  SDHCI_SUPPORT_HS400   0x80000000 /* Non-standard */
>
>  #define SDHCI_MAX_CURRENT              0x48
> -#define  SDHCI_MAX_CURRENT_LIMIT       0xFF
> -#define  SDHCI_MAX_CURRENT_330_MASK    0x0000FF
> -#define  SDHCI_MAX_CURRENT_330_SHIFT   0
> -#define  SDHCI_MAX_CURRENT_300_MASK    0x00FF00
> -#define  SDHCI_MAX_CURRENT_300_SHIFT   8
> -#define  SDHCI_MAX_CURRENT_180_MASK    0xFF0000
> -#define  SDHCI_MAX_CURRENT_180_SHIFT   16
> +#define  SDHCI_MAX_CURRENT_LIMIT       GENMASK(7, 0)
> +#define  SDHCI_MAX_CURRENT_330_MASK    GENMASK(7, 0)
> +#define  SDHCI_MAX_CURRENT_300_MASK    GENMASK(15, 8)
> +#define  SDHCI_MAX_CURRENT_180_MASK    GENMASK(23, 16)
>  #define   SDHCI_MAX_CURRENT_MULTIPLIER 4
>
>  /* 4C-4F reserved for more max current */
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-15  7:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-11  6:28 [PATCH] mmc: sdhci: use FIELD_GET/PREP for current capabilities bit masks Masahiro Yamada
2020-05-15  7:09 ` Ulf Hansson

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).