linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: zhangfei gao <zhangfei.gao@gmail.com>
To: Arindam Nath <arindam.nath@amd.com>
Cc: cjb@laptop.org, prakity@marvell.com, subhashj@codeaurora.org,
	linux-mmc@vger.kernel.org, henry.su@amd.com, aaron.lu@amd.com,
	anath.amd@gmail.com
Subject: Re: [PATCH v2 09/12] mmc: sd: add support for tuning during uhs initialization
Date: Tue, 15 Mar 2011 06:32:18 -0400	[thread overview]
Message-ID: <AANLkTinzMXwJD0TyMBFbitE6PoNMZLmjn_tXmP=hZuY-@mail.gmail.com> (raw)
In-Reply-To: <1299238369-1768-10-git-send-email-arindam.nath@amd.com>

On Fri, Mar 4, 2011 at 6:32 AM, Arindam Nath <arindam.nath@amd.com> wrote:
> Host Controller needs tuning during initialization to operate SDR50
> and SDR104 UHS-I cards. Whether SDR50 mode actually needs tuning is
> indicated by bit 45 of the Host Controller Capabilities register.
> A new command CMD19 has been defined in the Physical Layer spec
> v3.01 to request the card to send tuning pattern.
>
> We enable Buffer Read Ready interrupt at the very begining of tuning
> procedure, because that is the only interrupt generated by the Host
> Controller during tuning. The tuning block is sent by the card to the
> Host Controller using DAT lines, so we set Data Present Select (bit 5)
> in the Command register. The Host Controller is responsible for doing
> the verfication of tuning block sent by the card at the hardware level.
> After sending CMD19, we wait for Buffer Read Ready interrupt. In case
> we don't receive an interrupt after the specified timeout value, we
> fall back on fixed sampling clock by setting Execute Tuning (bit 6)
> and Sampling Clock Seletc (bit 7) of Host Control2 register to 0.
> Before exiting the tuning procedure, we disable Buffer Read Ready
> interrupt.
>
> Signed-off-by: Arindam Nath <arindam.nath@amd.com>
> ---
>  drivers/mmc/core/sd.c     |    4 +
>  drivers/mmc/host/sdhci.c  |  137 ++++++++++++++++++++++++++++++++++++++++++++-
>  drivers/mmc/host/sdhci.h  |    3 +
>  include/linux/mmc/host.h  |    1 +
>  include/linux/mmc/mmc.h   |    1 +
>  include/linux/mmc/sdhci.h |    4 +
>  6 files changed, 149 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
> index be01397..1e2d157 100644
> --- a/drivers/mmc/core/sd.c
> +++ b/drivers/mmc/core/sd.c
> @@ -637,6 +637,10 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
>        /* Set current limit for the card */
>        err = sd_set_current_limit(card, status);
>
> +       /* SPI mode doesn't define CMD19 */
> +       if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning)
> +               card->host->ops->execute_tuning(card->host);
> +
>  out:
>        kfree(status);
>
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 245cc39..8f4f102 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -39,6 +39,8 @@
>  #define SDHCI_USE_LEDS_CLASS
>  #endif
>
> +#define MAX_TUNING_LOOP 40
> +
>  static unsigned int debug_quirks = 0;
>
>  static void sdhci_prepare_data(struct sdhci_host *, struct mmc_data *);
> @@ -985,7 +987,9 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
>                flags |= SDHCI_CMD_CRC;
>        if (cmd->flags & MMC_RSP_OPCODE)
>                flags |= SDHCI_CMD_INDEX;
> -       if (cmd->data)
> +
> +       /* CMD19 is special in that the Data Present Select should be set */
> +       if (cmd->data || (cmd->opcode == MMC_SEND_TUNING_BLOCK))
>                flags |= SDHCI_CMD_DATA;
>
>        sdhci_writew(host, SDHCI_MAKE_CMD(cmd->opcode, flags), SDHCI_COMMAND);
> @@ -1485,6 +1489,119 @@ static int sdhci_get_max_current_180(struct mmc_host *mmc)
>        return max_current_180;
>  }
>
> +static void sdhci_execute_tuning(struct mmc_host *mmc)
> +{
> +       struct sdhci_host *host;
> +       u16 ctrl;
> +       int tuning_loop_counter = MAX_TUNING_LOOP;
> +       unsigned long flags;
> +       unsigned long timeout;
> +
> +       host = mmc_priv(mmc);
> +
> +       spin_lock_irqsave(&host->lock, flags);
> +
> +       ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
> +
> +       /*
> +        * Host Controller needs tuning only in case of SDR104 mode
> +        * and for SDR50 mode when Use Tuning for SDR50 is set in
> +        * Capabilities register.
> +        */
> +       if ((ctrl & SDHCI_CTRL_UHS_SDR104) ||
> +           ((ctrl & SDHCI_CTRL_UHS_SDR50) &&
> +           (host->flags & SDHCI_SDR50_NEEDS_TUNING)))
> +               ctrl |= SDHCI_CTRL_EXEC_TUNING;
> +       else {
> +               spin_unlock_irqrestore(&host->lock, flags);
> +               return;
> +       }
> +
> +       sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
> +
> +       /*
> +        * As per the Host Controller spec v3.00, tuning command
> +        * generates Buffer Read Ready interrupt, so enable that.
> +        */
> +       sdhci_unmask_irqs(host, SDHCI_INT_DATA_AVAIL);
> +
> +       /*
> +        * Issue CMD19 repeatedly till Execute Tuning is set to 0 or the number
> +        * of loops reaches 40 times or a timeout of 150ms occurs.
> +        */
> +       timeout = 150;
> +       do {
> +               struct mmc_command cmd;
> +               struct mmc_request mrq;
> +
> +               if (!tuning_loop_counter && !timeout)
> +                       break;
> +
> +               memset(&cmd, 0, sizeof(struct mmc_command));
> +               cmd.opcode = MMC_SEND_TUNING_BLOCK;
> +               cmd.arg = 0;
> +               cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
> +
> +               memset(&cmd.resp, 0, sizeof(cmd.resp));
> +               cmd.retries = 0;
> +
> +               cmd.data = NULL;
> +               cmd.error = 0;
> +
> +               memset(&mrq, 0, sizeof(struct mmc_request));
> +               mrq.cmd = &cmd;
> +               host->mrq = &mrq;

Tune may fail since SDHCI_TRNS_DMA is set in SDHCI_TRANSFER_MODE,
SDHCI_TRNS_DMA required to be cleared before send_command, such as
sdhci_writew(host, 0x12, SDHCI_TRANSFER_MODE);

> +               sdhci_send_command(host, &cmd);
> +
> +               host->cmd = NULL;
> +               host->mrq = NULL;
> +
> +               spin_unlock_irqrestore(&host->lock, flags);
> +
> +               /* Wait for Buffer Read Ready interrupt */
> +               wait_event_interruptible_timeout(host->buf_ready_int,
> +                                       (host->tuning_done == 1),
> +                                       msecs_to_jiffies(50));
> +               spin_lock_irqsave(&host->lock, flags);
> +
> +               if (!host->tuning_done) {
> +                       printk(KERN_INFO DRIVER_NAME ": Tuning procedure"
> +                               " failed, falling back to fixed sampling"
> +                               " clock\n");
> +                       ctrl &= ~SDHCI_CTRL_TUNED_CLK;
> +                       ctrl &= ~SDHCI_CTRL_EXEC_TUNING;
> +                       sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
> +
> +                       goto out;
> +               }
> +
> +               host->tuning_done = 0;
> +
> +               ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
> +               tuning_loop_counter--;
> +               timeout--;
> +               mdelay(1);
> +       } while (ctrl & SDHCI_CTRL_EXEC_TUNING);
> +
> +       /*
> +        * The Host Driver has exhausted the maximum number of loops allowed,
> +        * so use fixed sampling frequency.
> +        */
> +       if (!tuning_loop_counter || !timeout) {
> +               ctrl &= ~SDHCI_CTRL_TUNED_CLK;
> +               sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
> +       } else {
> +               if (!(ctrl & SDHCI_CTRL_TUNED_CLK))
> +                       printk(KERN_INFO DRIVER_NAME ": Tuning procedure"
> +                               " failed, falling back to fixed sampling"
> +                               " clock\n");
> +       }
> +
> +out:
> +       sdhci_mask_irqs(host, SDHCI_INT_DATA_AVAIL);
> +       spin_unlock_irqrestore(&host->lock, flags);
> +}
> +
>  static const struct mmc_host_ops sdhci_ops = {
>        .request        = sdhci_request,
>        .set_ios        = sdhci_set_ios,
> @@ -1492,6 +1609,7 @@ static const struct mmc_host_ops sdhci_ops = {
>        .enable_sdio_irq = sdhci_enable_sdio_irq,
>        .start_signal_voltage_switch    = sdhci_start_signal_voltage_switch,
>        .get_max_current_180            = sdhci_get_max_current_180,
> +       .execute_tuning                 = sdhci_execute_tuning,
>  };
>
>  /*****************************************************************************\
> @@ -1703,6 +1821,16 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
>  {
>        BUG_ON(intmask == 0);
>
> +       /* CMD19 generates _only_ Buffer Read Ready interrupt */
> +       if (intmask & SDHCI_INT_DATA_AVAIL) {
> +               if (SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
> +                               == MMC_SEND_TUNING_BLOCK) {
> +                       host->tuning_done = 1;
> +                       wake_up(&host->buf_ready_int);
> +                       return;
> +               }
> +       }
> +
>        if (!host->data) {
>                /*
>                 * The "data complete" interrupt is also used to
> @@ -2126,6 +2254,10 @@ int sdhci_add_host(struct sdhci_host *host)
>        if (caps[1] & SDHCI_SUPPORT_DDR50)
>                mmc->caps |= MMC_CAP_UHS_DDR50;
>
> +       /* Does the host needs tuning for SDR50? */
> +       if (caps[1] & SDHCI_USE_SDR50_TUNING)
> +               host->flags |= SDHCI_SDR50_NEEDS_TUNING;
> +
>        /* Driver Type(s) (A, C, D) supported by the host */
>        if (caps[1] & SDHCI_DRIVER_TYPE_A)
>                mmc->caps |= MMC_CAP_DRIVER_TYPE_A;
> @@ -2269,6 +2401,9 @@ int sdhci_add_host(struct sdhci_host *host)
>
>        setup_timer(&host->timer, sdhci_timeout_timer, (unsigned long)host);
>
> +       if (host->version >= SDHCI_SPEC_300)
> +               init_waitqueue_head(&host->buf_ready_int);
> +
>        ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
>                mmc_hostname(mmc), host);
>        if (ret)
> diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
> index 5bf244d..4746879 100644
> --- a/drivers/mmc/host/sdhci.h
> +++ b/drivers/mmc/host/sdhci.h
> @@ -160,6 +160,8 @@
>  #define  SDHCI_CTRL_DRV_TYPE_A         0x0010
>  #define  SDHCI_CTRL_DRV_TYPE_C         0x0020
>  #define  SDHCI_CTRL_DRV_TYPE_D         0x0030
> +#define  SDHCI_CTRL_EXEC_TUNING                0x0040
> +#define  SDHCI_CTRL_TUNED_CLK          0x0080
>  #define  SDHCI_CTRL_PRESET_VAL_ENABLE  0x8000
>
>  #define SDHCI_CAPABILITIES     0x40
> @@ -187,6 +189,7 @@
>  #define  SDHCI_DRIVER_TYPE_A   0x00000010
>  #define  SDHCI_DRIVER_TYPE_C   0x00000020
>  #define  SDHCI_DRIVER_TYPE_D   0x00000040
> +#define  SDHCI_USE_SDR50_TUNING        0x00002000
>
>  #define SDHCI_CAPABILITIES_1   0x44
>
> diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
> index e84cd05..651e40b 100644
> --- a/include/linux/mmc/host.h
> +++ b/include/linux/mmc/host.h
> @@ -129,6 +129,7 @@ struct mmc_host_ops {
>
>        int     (*start_signal_voltage_switch)(struct mmc_host *host);
>        int     (*get_max_current_180)(struct mmc_host *mmc);
> +       void    (*execute_tuning)(struct mmc_host *host);
>  };
>
>  struct mmc_card;
> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
> index 612301f..9194f9e 100644
> --- a/include/linux/mmc/mmc.h
> +++ b/include/linux/mmc/mmc.h
> @@ -50,6 +50,7 @@
>  #define MMC_SET_BLOCKLEN         16   /* ac   [31:0] block len   R1  */
>  #define MMC_READ_SINGLE_BLOCK    17   /* adtc [31:0] data addr   R1  */
>  #define MMC_READ_MULTIPLE_BLOCK  18   /* adtc [31:0] data addr   R1  */
> +#define MMC_SEND_TUNING_BLOCK    19   /* adtc                    R1  */
>
>   /* class 3 */
>  #define MMC_WRITE_DAT_UNTIL_STOP 20   /* adtc [31:0] data addr   R1  */
> diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
> index 282d158..5203b97 100644
> --- a/include/linux/mmc/sdhci.h
> +++ b/include/linux/mmc/sdhci.h
> @@ -109,6 +109,7 @@ struct sdhci_host {
>  #define SDHCI_USE_ADMA         (1<<1)  /* Host is ADMA capable */
>  #define SDHCI_REQ_USE_DMA      (1<<2)  /* Use DMA for this req. */
>  #define SDHCI_DEVICE_DEAD      (1<<3)  /* Device unresponsive */
> +#define SDHCI_SDR50_NEEDS_TUNING (1<<4)        /* SDR50 needs tuning */
>
>        unsigned int version;   /* SDHCI spec. version */
>
> @@ -147,6 +148,9 @@ struct sdhci_host {
>
>        struct mmc_command      *saved_abort_cmd; /* Abort command saved for data error recovery */
>
> +       wait_queue_head_t       buf_ready_int;  /* Waitqueue for Buffer Read Ready interrupt */
> +       unsigned int            tuning_done;    /* Condition flag set when CMD19 succeeds */
> +
>        unsigned long private[0] ____cacheline_aligned;
>  };
>  #endif /* __SDHCI_H */
> --
> 1.7.1
>
>

  parent reply	other threads:[~2011-03-15 10:32 UTC|newest]

Thread overview: 125+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-04 11:32 [PATCH v2 00/12] add support for host controller v3.00 Arindam Nath
2011-03-04 11:32 ` [PATCH v2 01/12] mmc: sdhci: add support for auto CMD23 Arindam Nath
2011-03-09 12:22   ` subhashj
2011-03-09 12:55     ` Nath, Arindam
2011-03-15 11:23   ` Subhash Jadavani
2011-03-15 11:35     ` Nath, Arindam
2011-03-15 11:52       ` Subhash Jadavani
2011-03-16  6:07         ` Nath, Arindam
2011-03-04 11:32 ` [PATCH v2 02/12] mmc: sd: add support for signal voltage switch procedure Arindam Nath
2011-03-04 11:47   ` Wolfram Sang
2011-03-04 11:52     ` Nath, Arindam
2011-03-09 10:44   ` subhashj
2011-03-10  6:30     ` subhashj
2011-03-10  8:05       ` Nath, Arindam
2011-03-09 12:45   ` zhangfei gao
2011-03-10  8:11     ` Nath, Arindam
2011-03-15 10:18   ` Subhash Jadavani
2011-03-15 10:32     ` Nath, Arindam
2011-03-15 11:18       ` Subhash Jadavani
2011-03-15 11:28         ` Nath, Arindam
2011-03-15 11:58           ` Subhash Jadavani
2011-03-16  3:03             ` zhangfei gao
2011-03-16  6:30               ` Nath, Arindam
2011-03-16 10:44                 ` zhangfei gao
2011-03-16 10:48                   ` Nath, Arindam
2011-03-16 21:39   ` Philip Rakity
2011-03-17  4:18     ` Nath, Arindam
2011-03-24 10:52   ` zhangfei gao
2011-03-24 10:59     ` Nath, Arindam
2011-03-04 11:32 ` [PATCH v2 03/12] mmc: sd: query function modes for uhs cards Arindam Nath
2011-03-09 14:08   ` subhashj
2011-03-09 14:31     ` Nath, Arindam
2011-03-09 18:04       ` subhashj
2011-03-09 18:16         ` Nath, Arindam
2011-03-04 11:32 ` [PATCH v2 04/12] mmc: sd: add support for driver type selection Arindam Nath
2011-03-09  5:33   ` Philip Rakity
2011-03-09  8:11     ` Nath, Arindam
2011-03-10  6:57   ` subhashj
2011-03-10  8:31     ` Nath, Arindam
2011-03-10 10:28       ` subhashj
2011-03-10 10:44         ` Nath, Arindam
2011-03-10 11:25           ` subhashj
2011-03-10 11:34             ` Nath, Arindam
2011-03-04 11:32 ` [PATCH v2 05/12] mmc: sdhci: reset sdclk before setting high speed enable Arindam Nath
2011-03-05  4:57   ` Philip Rakity
2011-03-05  5:07     ` Nath, Arindam
2011-03-04 11:32 ` [PATCH v2 06/12] mmc: sd: add support for uhs bus speed mode selection Arindam Nath
2011-03-10  8:00   ` subhashj
2011-03-10  8:36     ` Nath, Arindam
2011-03-10 10:07       ` subhashj
2011-03-10 10:15         ` Nath, Arindam
2011-03-21  6:42   ` Subhash Jadavani
2011-03-23  6:04     ` Nath, Arindam
2011-03-23  6:14       ` Subhash Jadavani
2011-03-23  6:17         ` Nath, Arindam
2011-03-23  6:26           ` Subhash Jadavani
2011-03-23  6:35             ` Nath, Arindam
2011-03-23  7:23               ` Subhash Jadavani
2011-03-23 14:02                 ` Nath, Arindam
2011-03-24  7:25                   ` Subhash Jadavani
2011-03-24  8:42                     ` Nath, Arindam
2011-03-04 11:32 ` [PATCH v2 07/12] mmc: sd: set current limit for uhs cards Arindam Nath
2011-03-09 21:41   ` Philip Rakity
2011-03-10  3:12     ` Nath, Arindam
2011-03-10  8:16   ` subhashj
2011-03-10  8:43     ` Nath, Arindam
2011-03-10  9:45       ` subhashj
2011-03-16 14:26   ` Philip Rakity
2011-03-16 14:32     ` Nath, Arindam
2011-03-16 14:51       ` Philip Rakity
2011-03-16 15:00         ` Nath, Arindam
2011-03-16 15:18           ` Philip Rakity
2011-03-16 15:24             ` Nath, Arindam
2011-03-16 15:31               ` Philip Rakity
2011-03-16 15:33                 ` Nath, Arindam
2011-03-16 15:34                   ` Philip Rakity
2011-03-21  7:43   ` Subhash Jadavani
2011-03-21  7:54     ` Nath, Arindam
2011-03-04 11:32 ` [PATCH v2 08/12] mmc: sd: report correct speed and capacity of " Arindam Nath
2011-03-10 11:48   ` subhashj
2011-03-10 13:28     ` Nath, Arindam
2011-03-10 13:41       ` subhashj
2011-03-04 11:32 ` [PATCH v2 09/12] mmc: sd: add support for tuning during uhs initialization Arindam Nath
2011-03-04 18:27   ` Philip Rakity
2011-03-04 18:48     ` Nath, Arindam
2011-03-04 18:34   ` Philip Rakity
2011-03-04 18:54     ` Nath, Arindam
2011-03-15 10:32   ` zhangfei gao [this message]
2011-03-15 10:43     ` Nath, Arindam
2011-03-16  2:51       ` zhangfei gao
2011-03-16  6:20         ` Nath, Arindam
2011-03-16 10:18           ` zhangfei gao
2011-03-21  9:43   ` Subhash Jadavani
2011-03-21  9:50     ` Nath, Arindam
2011-03-23  6:58       ` Subhash Jadavani
2011-03-21 10:58   ` Subhash Jadavani
2011-03-21 11:07     ` Nath, Arindam
2011-03-23  6:08       ` Subhash Jadavani
2011-03-23  6:14         ` Nath, Arindam
2011-03-23  6:19           ` Subhash Jadavani
2011-03-23  6:22             ` Nath, Arindam
2011-03-23  6:34               ` Subhash Jadavani
2011-03-23  6:41                 ` Nath, Arindam
2011-03-23  6:45                   ` Subhash Jadavani
2011-03-23  6:48                     ` Nath, Arindam
2011-03-04 11:32 ` [PATCH v2 10/12] mmc: sdhci: enable preset value after " Arindam Nath
2011-03-10 13:23   ` subhashj
2011-03-10 13:30     ` Nath, Arindam
2011-03-10 13:45       ` subhashj
2011-03-10 13:49         ` Nath, Arindam
2011-03-10 14:03           ` subhashj
2011-03-10 14:07             ` Nath, Arindam
2011-03-10 14:12               ` subhashj
2011-03-10 14:15                 ` Nath, Arindam
2011-03-10 14:19                   ` subhashj
2011-03-10 14:24                     ` Nath, Arindam
2011-03-04 11:32 ` [PATCH v2 11/12] mmc: sdhci: add support for programmable clock mode Arindam Nath
2011-03-04 11:32 ` [PATCH v2 12/12] mmc: sdhci: add support for retuning mode 1 Arindam Nath
2011-03-10 13:57   ` subhashj
2011-03-10 14:00     ` Nath, Arindam
2011-03-04 15:16 ` [PATCH v2 00/12] add support for host controller v3.00 Chris Ball
2011-03-04 15:55   ` Nath, Arindam
2011-03-11 13:13 ` subhashj
2011-03-11 15:29   ` Nath, Arindam
2011-03-11 16:06     ` Chris Ball

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='AANLkTinzMXwJD0TyMBFbitE6PoNMZLmjn_tXmP=hZuY-@mail.gmail.com' \
    --to=zhangfei.gao@gmail.com \
    --cc=aaron.lu@amd.com \
    --cc=anath.amd@gmail.com \
    --cc=arindam.nath@amd.com \
    --cc=cjb@laptop.org \
    --cc=henry.su@amd.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=prakity@marvell.com \
    --cc=subhashj@codeaurora.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).