linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mmc: sdhci-acpi: AMDI0040: Allow changing HS200/HS400 driver strength
@ 2020-10-27  8:46 Victor Ding
  2020-10-27 13:01 ` Adrian Hunter
  2020-10-27 13:41 ` Ulf Hansson
  0 siblings, 2 replies; 4+ messages in thread
From: Victor Ding @ 2020-10-27  8:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ulf Hansson, Adrian Hunter, Raul E Rangel, Victor Ding, linux-mmc

From: Raul E Rangel <rrangel@chromium.org>

This change will allow platform designers better control over signal
integrity by allowing them to tune the HS200 and HS400 driver strengths.

The driver strength was previously hard coded to A to solve boot
problems with certain platforms. This driver strength does not
universally apply to all platforms so we need a knob to adjust it.

All older platforms currently have the SDR104 preset hard coded to A in
the firmware. This means that switching from the hard coded value in
the kernel to reading the SDR104 preset is a no-op for these platforms.
Newer platforms will have properly set presets. So this change will
support both new and old platforms.

Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Signed-off-by: Victor Ding <victording@google.com>

---

Changes in v2:
By Victor Ding <victording@google.com>
 - Rebased the patch by using FIELD_GET for preset value bit masks.
 - (No functional changes).

The original patch was developed by Raul E Rangel.
https://patchwork.kernel.org/project/linux-mmc/patch/20200928154718.2.Ic6b6031366f090393d00a53fd69e1ada31ceb29e@changeid/

 drivers/mmc/host/sdhci-acpi.c | 39 ++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
index 54205e3be9e8..225cb34cf1b9 100644
--- a/drivers/mmc/host/sdhci-acpi.c
+++ b/drivers/mmc/host/sdhci-acpi.c
@@ -5,6 +5,7 @@
  * Copyright (c) 2012, Intel Corporation.
  */
 
+#include <linux/bitfield.h>
 #include <linux/init.h>
 #include <linux/export.h>
 #include <linux/module.h>
@@ -545,10 +546,42 @@ struct amd_sdhci_host {
 
 static int amd_select_drive_strength(struct mmc_card *card,
 				     unsigned int max_dtr, int host_drv,
-				     int card_drv, int *drv_type)
+				     int card_drv, int *host_driver_strength)
 {
-	*drv_type = MMC_SET_DRIVER_TYPE_A;
-	return MMC_SET_DRIVER_TYPE_A;
+	struct sdhci_host *host = mmc_priv(card->host);
+	u16 preset, preset_driver_strength;
+
+	/*
+	 * This method is only called by mmc_select_hs200 so we only need to
+	 * read from the HS200 (SDR104) preset register.
+	 *
+	 * Firmware that has "invalid/default" presets return a driver strength
+	 * of A. This matches the previously hard coded value.
+	 */
+	preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR104);
+	preset_driver_strength = FIELD_GET(SDHCI_PRESET_DRV_MASK, preset);
+
+	/*
+	 * We want the controller driver strength to match the card's driver
+	 * strength so they have similar rise/fall times.
+	 *
+	 * The controller driver strength set by this method is sticky for all
+	 * timings after this method is called. This unfortunately means that
+	 * while HS400 tuning is in progress we end up with mismatched driver
+	 * strengths between the controller and the card. HS400 tuning requires
+	 * switching from HS400->DDR52->HS->HS200->HS400. So the driver mismatch
+	 * happens while in DDR52 and HS modes. This has not been observed to
+	 * cause problems. Enabling presets would fix this issue.
+	 */
+	*host_driver_strength = preset_driver_strength;
+
+	/*
+	 * The resulting card driver strength is only set when switching the
+	 * card's timing to HS200 or HS400. The card will use the default driver
+	 * strength (B) for any other mode.
+	 */
+	return preset_driver_strength;
+
 }
 
 static void sdhci_acpi_amd_hs400_dll(struct sdhci_host *host, bool enable)
-- 
2.29.0.rc2.309.g374f81d7ae-goog


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

* Re: [PATCH v2] mmc: sdhci-acpi: AMDI0040: Allow changing HS200/HS400 driver strength
  2020-10-27  8:46 [PATCH v2] mmc: sdhci-acpi: AMDI0040: Allow changing HS200/HS400 driver strength Victor Ding
@ 2020-10-27 13:01 ` Adrian Hunter
  2020-10-27 13:41 ` Ulf Hansson
  1 sibling, 0 replies; 4+ messages in thread
From: Adrian Hunter @ 2020-10-27 13:01 UTC (permalink / raw)
  To: Victor Ding, linux-kernel; +Cc: Ulf Hansson, Raul E Rangel, linux-mmc

On 27/10/20 10:46 am, Victor Ding wrote:
> From: Raul E Rangel <rrangel@chromium.org>
> 
> This change will allow platform designers better control over signal
> integrity by allowing them to tune the HS200 and HS400 driver strengths.
> 
> The driver strength was previously hard coded to A to solve boot
> problems with certain platforms. This driver strength does not
> universally apply to all platforms so we need a knob to adjust it.
> 
> All older platforms currently have the SDR104 preset hard coded to A in
> the firmware. This means that switching from the hard coded value in
> the kernel to reading the SDR104 preset is a no-op for these platforms.
> Newer platforms will have properly set presets. So this change will
> support both new and old platforms.
> 
> Signed-off-by: Raul E Rangel <rrangel@chromium.org>
> Signed-off-by: Victor Ding <victording@google.com>

Apart from unnecessary blank line after "return preset_driver_strength;"

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

> 
> ---
> 
> Changes in v2:
> By Victor Ding <victording@google.com>
>  - Rebased the patch by using FIELD_GET for preset value bit masks.
>  - (No functional changes).
> 
> The original patch was developed by Raul E Rangel.
> https://patchwork.kernel.org/project/linux-mmc/patch/20200928154718.2.Ic6b6031366f090393d00a53fd69e1ada31ceb29e@changeid/
> 
>  drivers/mmc/host/sdhci-acpi.c | 39 ++++++++++++++++++++++++++++++++---
>  1 file changed, 36 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
> index 54205e3be9e8..225cb34cf1b9 100644
> --- a/drivers/mmc/host/sdhci-acpi.c
> +++ b/drivers/mmc/host/sdhci-acpi.c
> @@ -5,6 +5,7 @@
>   * Copyright (c) 2012, Intel Corporation.
>   */
>  
> +#include <linux/bitfield.h>
>  #include <linux/init.h>
>  #include <linux/export.h>
>  #include <linux/module.h>
> @@ -545,10 +546,42 @@ struct amd_sdhci_host {
>  
>  static int amd_select_drive_strength(struct mmc_card *card,
>  				     unsigned int max_dtr, int host_drv,
> -				     int card_drv, int *drv_type)
> +				     int card_drv, int *host_driver_strength)
>  {
> -	*drv_type = MMC_SET_DRIVER_TYPE_A;
> -	return MMC_SET_DRIVER_TYPE_A;
> +	struct sdhci_host *host = mmc_priv(card->host);
> +	u16 preset, preset_driver_strength;
> +
> +	/*
> +	 * This method is only called by mmc_select_hs200 so we only need to
> +	 * read from the HS200 (SDR104) preset register.
> +	 *
> +	 * Firmware that has "invalid/default" presets return a driver strength
> +	 * of A. This matches the previously hard coded value.
> +	 */
> +	preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR104);
> +	preset_driver_strength = FIELD_GET(SDHCI_PRESET_DRV_MASK, preset);
> +
> +	/*
> +	 * We want the controller driver strength to match the card's driver
> +	 * strength so they have similar rise/fall times.
> +	 *
> +	 * The controller driver strength set by this method is sticky for all
> +	 * timings after this method is called. This unfortunately means that
> +	 * while HS400 tuning is in progress we end up with mismatched driver
> +	 * strengths between the controller and the card. HS400 tuning requires
> +	 * switching from HS400->DDR52->HS->HS200->HS400. So the driver mismatch
> +	 * happens while in DDR52 and HS modes. This has not been observed to
> +	 * cause problems. Enabling presets would fix this issue.
> +	 */
> +	*host_driver_strength = preset_driver_strength;
> +
> +	/*
> +	 * The resulting card driver strength is only set when switching the
> +	 * card's timing to HS200 or HS400. The card will use the default driver
> +	 * strength (B) for any other mode.
> +	 */
> +	return preset_driver_strength;
> +

Unnecessary blank line.

>  }
>  
>  static void sdhci_acpi_amd_hs400_dll(struct sdhci_host *host, bool enable)
> 


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

* Re: [PATCH v2] mmc: sdhci-acpi: AMDI0040: Allow changing HS200/HS400 driver strength
  2020-10-27  8:46 [PATCH v2] mmc: sdhci-acpi: AMDI0040: Allow changing HS200/HS400 driver strength Victor Ding
  2020-10-27 13:01 ` Adrian Hunter
@ 2020-10-27 13:41 ` Ulf Hansson
  2020-12-02 16:00   ` Raul Rangel
  1 sibling, 1 reply; 4+ messages in thread
From: Ulf Hansson @ 2020-10-27 13:41 UTC (permalink / raw)
  To: Victor Ding
  Cc: Linux Kernel Mailing List, Adrian Hunter, Raul E Rangel, linux-mmc

On Tue, 27 Oct 2020 at 09:46, Victor Ding <victording@google.com> wrote:
>
> From: Raul E Rangel <rrangel@chromium.org>
>
> This change will allow platform designers better control over signal
> integrity by allowing them to tune the HS200 and HS400 driver strengths.
>
> The driver strength was previously hard coded to A to solve boot
> problems with certain platforms. This driver strength does not
> universally apply to all platforms so we need a knob to adjust it.
>
> All older platforms currently have the SDR104 preset hard coded to A in
> the firmware. This means that switching from the hard coded value in
> the kernel to reading the SDR104 preset is a no-op for these platforms.
> Newer platforms will have properly set presets. So this change will
> support both new and old platforms.
>
> Signed-off-by: Raul E Rangel <rrangel@chromium.org>
> Signed-off-by: Victor Ding <victording@google.com>

Applied for next, thanks!

Note that I amended the patch to fix the white-space issue, as pointed
out by Adrian.

Kind regards
Uffe


>
> ---
>
> Changes in v2:
> By Victor Ding <victording@google.com>
>  - Rebased the patch by using FIELD_GET for preset value bit masks.
>  - (No functional changes).
>
> The original patch was developed by Raul E Rangel.
> https://patchwork.kernel.org/project/linux-mmc/patch/20200928154718.2.Ic6b6031366f090393d00a53fd69e1ada31ceb29e@changeid/
>
>  drivers/mmc/host/sdhci-acpi.c | 39 ++++++++++++++++++++++++++++++++---
>  1 file changed, 36 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
> index 54205e3be9e8..225cb34cf1b9 100644
> --- a/drivers/mmc/host/sdhci-acpi.c
> +++ b/drivers/mmc/host/sdhci-acpi.c
> @@ -5,6 +5,7 @@
>   * Copyright (c) 2012, Intel Corporation.
>   */
>
> +#include <linux/bitfield.h>
>  #include <linux/init.h>
>  #include <linux/export.h>
>  #include <linux/module.h>
> @@ -545,10 +546,42 @@ struct amd_sdhci_host {
>
>  static int amd_select_drive_strength(struct mmc_card *card,
>                                      unsigned int max_dtr, int host_drv,
> -                                    int card_drv, int *drv_type)
> +                                    int card_drv, int *host_driver_strength)
>  {
> -       *drv_type = MMC_SET_DRIVER_TYPE_A;
> -       return MMC_SET_DRIVER_TYPE_A;
> +       struct sdhci_host *host = mmc_priv(card->host);
> +       u16 preset, preset_driver_strength;
> +
> +       /*
> +        * This method is only called by mmc_select_hs200 so we only need to
> +        * read from the HS200 (SDR104) preset register.
> +        *
> +        * Firmware that has "invalid/default" presets return a driver strength
> +        * of A. This matches the previously hard coded value.
> +        */
> +       preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR104);
> +       preset_driver_strength = FIELD_GET(SDHCI_PRESET_DRV_MASK, preset);
> +
> +       /*
> +        * We want the controller driver strength to match the card's driver
> +        * strength so they have similar rise/fall times.
> +        *
> +        * The controller driver strength set by this method is sticky for all
> +        * timings after this method is called. This unfortunately means that
> +        * while HS400 tuning is in progress we end up with mismatched driver
> +        * strengths between the controller and the card. HS400 tuning requires
> +        * switching from HS400->DDR52->HS->HS200->HS400. So the driver mismatch
> +        * happens while in DDR52 and HS modes. This has not been observed to
> +        * cause problems. Enabling presets would fix this issue.
> +        */
> +       *host_driver_strength = preset_driver_strength;
> +
> +       /*
> +        * The resulting card driver strength is only set when switching the
> +        * card's timing to HS200 or HS400. The card will use the default driver
> +        * strength (B) for any other mode.
> +        */
> +       return preset_driver_strength;
> +
>  }
>
>  static void sdhci_acpi_amd_hs400_dll(struct sdhci_host *host, bool enable)
> --
> 2.29.0.rc2.309.g374f81d7ae-goog
>

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

* Re: [PATCH v2] mmc: sdhci-acpi: AMDI0040: Allow changing HS200/HS400 driver strength
  2020-10-27 13:41 ` Ulf Hansson
@ 2020-12-02 16:00   ` Raul Rangel
  0 siblings, 0 replies; 4+ messages in thread
From: Raul Rangel @ 2020-12-02 16:00 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Victor Ding, Linux Kernel Mailing List, Adrian Hunter, linux-mmc

Thanks Victor and Ulf!

On Tue, Oct 27, 2020 at 7:42 AM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Tue, 27 Oct 2020 at 09:46, Victor Ding <victording@google.com> wrote:
> >
> > From: Raul E Rangel <rrangel@chromium.org>
> >
> > This change will allow platform designers better control over signal
> > integrity by allowing them to tune the HS200 and HS400 driver strengths.
> >
> > The driver strength was previously hard coded to A to solve boot
> > problems with certain platforms. This driver strength does not
> > universally apply to all platforms so we need a knob to adjust it.
> >
> > All older platforms currently have the SDR104 preset hard coded to A in
> > the firmware. This means that switching from the hard coded value in
> > the kernel to reading the SDR104 preset is a no-op for these platforms.
> > Newer platforms will have properly set presets. So this change will
> > support both new and old platforms.
> >
> > Signed-off-by: Raul E Rangel <rrangel@chromium.org>
> > Signed-off-by: Victor Ding <victording@google.com>
>
> Applied for next, thanks!
>
> Note that I amended the patch to fix the white-space issue, as pointed
> out by Adrian.
>
> Kind regards
> Uffe
>
>
> >
> > ---
> >
> > Changes in v2:
> > By Victor Ding <victording@google.com>
> >  - Rebased the patch by using FIELD_GET for preset value bit masks.
> >  - (No functional changes).
> >
> > The original patch was developed by Raul E Rangel.
> > https://patchwork.kernel.org/project/linux-mmc/patch/20200928154718.2.Ic6b6031366f090393d00a53fd69e1ada31ceb29e@changeid/
> >
> >  drivers/mmc/host/sdhci-acpi.c | 39 ++++++++++++++++++++++++++++++++---
> >  1 file changed, 36 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
> > index 54205e3be9e8..225cb34cf1b9 100644
> > --- a/drivers/mmc/host/sdhci-acpi.c
> > +++ b/drivers/mmc/host/sdhci-acpi.c
> > @@ -5,6 +5,7 @@
> >   * Copyright (c) 2012, Intel Corporation.
> >   */
> >
> > +#include <linux/bitfield.h>
> >  #include <linux/init.h>
> >  #include <linux/export.h>
> >  #include <linux/module.h>
> > @@ -545,10 +546,42 @@ struct amd_sdhci_host {
> >
> >  static int amd_select_drive_strength(struct mmc_card *card,
> >                                      unsigned int max_dtr, int host_drv,
> > -                                    int card_drv, int *drv_type)
> > +                                    int card_drv, int *host_driver_strength)
> >  {
> > -       *drv_type = MMC_SET_DRIVER_TYPE_A;
> > -       return MMC_SET_DRIVER_TYPE_A;
> > +       struct sdhci_host *host = mmc_priv(card->host);
> > +       u16 preset, preset_driver_strength;
> > +
> > +       /*
> > +        * This method is only called by mmc_select_hs200 so we only need to
> > +        * read from the HS200 (SDR104) preset register.
> > +        *
> > +        * Firmware that has "invalid/default" presets return a driver strength
> > +        * of A. This matches the previously hard coded value.
> > +        */
> > +       preset = sdhci_readw(host, SDHCI_PRESET_FOR_SDR104);
> > +       preset_driver_strength = FIELD_GET(SDHCI_PRESET_DRV_MASK, preset);
> > +
> > +       /*
> > +        * We want the controller driver strength to match the card's driver
> > +        * strength so they have similar rise/fall times.
> > +        *
> > +        * The controller driver strength set by this method is sticky for all
> > +        * timings after this method is called. This unfortunately means that
> > +        * while HS400 tuning is in progress we end up with mismatched driver
> > +        * strengths between the controller and the card. HS400 tuning requires
> > +        * switching from HS400->DDR52->HS->HS200->HS400. So the driver mismatch
> > +        * happens while in DDR52 and HS modes. This has not been observed to
> > +        * cause problems. Enabling presets would fix this issue.
> > +        */
> > +       *host_driver_strength = preset_driver_strength;
> > +
> > +       /*
> > +        * The resulting card driver strength is only set when switching the
> > +        * card's timing to HS200 or HS400. The card will use the default driver
> > +        * strength (B) for any other mode.
> > +        */
> > +       return preset_driver_strength;
> > +
> >  }
> >
> >  static void sdhci_acpi_amd_hs400_dll(struct sdhci_host *host, bool enable)
> > --
> > 2.29.0.rc2.309.g374f81d7ae-goog
> >

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

end of thread, other threads:[~2020-12-02 16:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27  8:46 [PATCH v2] mmc: sdhci-acpi: AMDI0040: Allow changing HS200/HS400 driver strength Victor Ding
2020-10-27 13:01 ` Adrian Hunter
2020-10-27 13:41 ` Ulf Hansson
2020-12-02 16:00   ` Raul Rangel

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