RE: [PATCH] mmc: atmel-mci: add pm runtime support

2014-10-29 Thread Yang, Wenyou
Hello Ulf,

Thank you very much for so many comments.

I will do it.

> -Original Message-
> From: Ulf Hansson [mailto:ulf.hans...@linaro.org]
> Sent: Wednesday, October 29, 2014 6:06 PM
> To: Yang, Wenyou
> Cc: Chris Ball; Kevin Hilman; Ferre, Nicolas; Desroches, Ludovic; linux-mmc; 
> linux-
> ker...@vger.kernel.org; linux-arm-ker...@lists.infradead.org
> Subject: Re: [PATCH] mmc: atmel-mci: add pm runtime support
> 
> On 29 October 2014 03:15, Wenyou Yang  wrote:
> 
> Hi Wenyou,
> 
> Could you please provide some more information in the commit message.
> 
> > Signed-off-by: Wenyou Yang 
> > ---
> >  drivers/mmc/host/atmel-mci.c |  116
> > ++
> >  1 file changed, 94 insertions(+), 22 deletions(-)
> >
> > diff --git a/drivers/mmc/host/atmel-mci.c
> > b/drivers/mmc/host/atmel-mci.c index 0b9ddf8..e9d32d0 100644
> > --- a/drivers/mmc/host/atmel-mci.c
> > +++ b/drivers/mmc/host/atmel-mci.c
> > @@ -37,6 +37,8 @@
> >
> >  #include 
> >  #include 
> > +#include 
> > +#include 
> >
> >  #include 
> >  #include 
> > @@ -44,6 +46,8 @@
> >
> >  #include "atmel-mci-regs.h"
> >
> > +#define AUTOSUSPEND_DELAY  50
> > +
> >  #define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE |
> ATMCI_OVRE | ATMCI_UNRE)
> >  #define ATMCI_DMA_THRESHOLD16
> >
> > @@ -386,20 +390,19 @@ static int atmci_regs_show(struct seq_file *s, void 
> > *v)
> > if (!buf)
> > return -ENOMEM;
> >
> > +   pm_runtime_get_sync(>pdev->dev);
> > +
> > /*
> >  * Grab a more or less consistent snapshot. Note that we're
> >  * not disabling interrupts, so IMR and SR may not be
> >  * consistent.
> >  */
> > -   ret = clk_prepare_enable(host->mck);
> > -   if (ret)
> > -   goto out;
> > -
> > spin_lock_bh(>lock);
> > memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE);
> > spin_unlock_bh(>lock);
> >
> > -   clk_disable_unprepare(host->mck);
> > +   pm_runtime_mark_last_busy(>pdev->dev);
> > +   pm_runtime_put_autosuspend(>pdev->dev);
> >
> > seq_printf(s, "MR:\t0x%08x%s%s ",
> > buf[ATMCI_MR / 4], @@ -449,7 +452,6 @@ static
> > int atmci_regs_show(struct seq_file *s, void *v)
> > val & ATMCI_CFG_LSYNC ? " LSYNC" : "");
> > }
> >
> > -out:
> > kfree(buf);
> >
> > return ret;
> > @@ -1252,6 +1254,8 @@ static void atmci_request(struct mmc_host *mmc,
> struct mmc_request *mrq)
> > WARN_ON(slot->mrq);
> > dev_dbg(>pdev->dev, "MRQ: cmd %u\n", mrq->cmd->opcode);
> >
> > +   pm_runtime_get_sync(>pdev->dev);
> > +
> > /*
> >  * We may "know" the card is gone even though there's still an
> >  * electrical connection. If so, we really need to communicate
> > @@ -1281,7 +1285,8 @@ static void atmci_set_ios(struct mmc_host *mmc,
> struct mmc_ios *ios)
> > struct atmel_mci_slot   *slot = mmc_priv(mmc);
> > struct atmel_mci*host = slot->host;
> > unsigned inti;
> > -   boolunprepare_clk;
> > +
> > +   pm_runtime_get_sync(>pdev->dev);
> >
> > slot->sdc_reg &= ~ATMCI_SDCBUS_MASK;
> > switch (ios->bus_width) {
> > @@ -1297,13 +1302,8 @@ static void atmci_set_ios(struct mmc_host *mmc,
> struct mmc_ios *ios)
> > unsigned int clock_min = ~0U;
> > u32 clkdiv;
> >
> > -   clk_prepare(host->mck);
> > -   unprepare_clk = true;
> > -
> > spin_lock_bh(>lock);
> > if (!host->mode_reg) {
> > -   clk_enable(host->mck);
> > -   unprepare_clk = false;
> > atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
> > atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
> > if (host->caps.has_cfg_reg) @@ -1371,8 +1371,6
> > @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
> > } else {
> > bool any_slot_active = false;
> >
> > -   unprepare_clk = false;
> > -

Re: [PATCH] mmc: atmel-mci: add pm runtime support

2014-10-29 Thread Ulf Hansson
On 29 October 2014 03:15, Wenyou Yang  wrote:

Hi Wenyou,

Could you please provide some more information in the commit message.

> Signed-off-by: Wenyou Yang 
> ---
>  drivers/mmc/host/atmel-mci.c |  116 
> ++
>  1 file changed, 94 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
> index 0b9ddf8..e9d32d0 100644
> --- a/drivers/mmc/host/atmel-mci.c
> +++ b/drivers/mmc/host/atmel-mci.c
> @@ -37,6 +37,8 @@
>
>  #include 
>  #include 
> +#include 
> +#include 
>
>  #include 
>  #include 
> @@ -44,6 +46,8 @@
>
>  #include "atmel-mci-regs.h"
>
> +#define AUTOSUSPEND_DELAY  50
> +
>  #define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | 
> ATMCI_UNRE)
>  #define ATMCI_DMA_THRESHOLD16
>
> @@ -386,20 +390,19 @@ static int atmci_regs_show(struct seq_file *s, void *v)
> if (!buf)
> return -ENOMEM;
>
> +   pm_runtime_get_sync(>pdev->dev);
> +
> /*
>  * Grab a more or less consistent snapshot. Note that we're
>  * not disabling interrupts, so IMR and SR may not be
>  * consistent.
>  */
> -   ret = clk_prepare_enable(host->mck);
> -   if (ret)
> -   goto out;
> -
> spin_lock_bh(>lock);
> memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE);
> spin_unlock_bh(>lock);
>
> -   clk_disable_unprepare(host->mck);
> +   pm_runtime_mark_last_busy(>pdev->dev);
> +   pm_runtime_put_autosuspend(>pdev->dev);
>
> seq_printf(s, "MR:\t0x%08x%s%s ",
> buf[ATMCI_MR / 4],
> @@ -449,7 +452,6 @@ static int atmci_regs_show(struct seq_file *s, void *v)
> val & ATMCI_CFG_LSYNC ? " LSYNC" : "");
> }
>
> -out:
> kfree(buf);
>
> return ret;
> @@ -1252,6 +1254,8 @@ static void atmci_request(struct mmc_host *mmc, struct 
> mmc_request *mrq)
> WARN_ON(slot->mrq);
> dev_dbg(>pdev->dev, "MRQ: cmd %u\n", mrq->cmd->opcode);
>
> +   pm_runtime_get_sync(>pdev->dev);
> +
> /*
>  * We may "know" the card is gone even though there's still an
>  * electrical connection. If so, we really need to communicate
> @@ -1281,7 +1285,8 @@ static void atmci_set_ios(struct mmc_host *mmc, struct 
> mmc_ios *ios)
> struct atmel_mci_slot   *slot = mmc_priv(mmc);
> struct atmel_mci*host = slot->host;
> unsigned inti;
> -   boolunprepare_clk;
> +
> +   pm_runtime_get_sync(>pdev->dev);
>
> slot->sdc_reg &= ~ATMCI_SDCBUS_MASK;
> switch (ios->bus_width) {
> @@ -1297,13 +1302,8 @@ static void atmci_set_ios(struct mmc_host *mmc, struct 
> mmc_ios *ios)
> unsigned int clock_min = ~0U;
> u32 clkdiv;
>
> -   clk_prepare(host->mck);
> -   unprepare_clk = true;
> -
> spin_lock_bh(>lock);
> if (!host->mode_reg) {
> -   clk_enable(host->mck);
> -   unprepare_clk = false;
> atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
> atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
> if (host->caps.has_cfg_reg)
> @@ -1371,8 +1371,6 @@ static void atmci_set_ios(struct mmc_host *mmc, struct 
> mmc_ios *ios)
> } else {
> bool any_slot_active = false;
>
> -   unprepare_clk = false;
> -
> spin_lock_bh(>lock);
> slot->clock = 0;
> for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
> @@ -1385,17 +1383,12 @@ static void atmci_set_ios(struct mmc_host *mmc, 
> struct mmc_ios *ios)
> atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS);
> if (host->mode_reg) {
> atmci_readl(host, ATMCI_MR);
> -   clk_disable(host->mck);
> -   unprepare_clk = true;
> }
> host->mode_reg = 0;
> }
> spin_unlock_bh(>lock);
> }
>
> -   if (unprepare_clk)
> -   clk_unprepare(host->mck);
> -
> switch (ios->power_mode) {
> case MMC_POWER_OFF:
> if (!IS_ERR(mmc->supply.vmmc))
> @@ -1421,6 +1414,9 @@ static void atmci_set_ios(struct mmc_host *mmc, struct 
> mmc_ios *ios)
>  */
> break;
> }
> +
> +   pm_runtime_mark_last_busy(>pdev->dev);
> +   pm_runtime_put_autosuspend(>pdev->dev);
>  }
>
>  static int atmci_get_ro(struct mmc_host *mmc)
> @@ -1512,6 +1508,9 @@ static void atmci_request_end(struct atmel_mci *host, 
> struct mmc_request *mrq)
> spin_unlock(>lock);
> mmc_request_done(prev_mmc, mrq);
> spin_lock(>lock);
> +
> +   pm_runtime_mark_last_busy(>pdev->dev);
> +   

Re: [PATCH] mmc: atmel-mci: add pm runtime support

2014-10-29 Thread Ulf Hansson
On 29 October 2014 03:15, Wenyou Yang wenyou.y...@atmel.com wrote:

Hi Wenyou,

Could you please provide some more information in the commit message.

 Signed-off-by: Wenyou Yang wenyou.y...@atmel.com
 ---
  drivers/mmc/host/atmel-mci.c |  116 
 ++
  1 file changed, 94 insertions(+), 22 deletions(-)

 diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
 index 0b9ddf8..e9d32d0 100644
 --- a/drivers/mmc/host/atmel-mci.c
 +++ b/drivers/mmc/host/atmel-mci.c
 @@ -37,6 +37,8 @@

  #include linux/atmel-mci.h
  #include linux/atmel_pdc.h
 +#include linux/pm.h
 +#include linux/pm_runtime.h

  #include asm/cacheflush.h
  #include asm/io.h
 @@ -44,6 +46,8 @@

  #include atmel-mci-regs.h

 +#define AUTOSUSPEND_DELAY  50
 +
  #define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | 
 ATMCI_UNRE)
  #define ATMCI_DMA_THRESHOLD16

 @@ -386,20 +390,19 @@ static int atmci_regs_show(struct seq_file *s, void *v)
 if (!buf)
 return -ENOMEM;

 +   pm_runtime_get_sync(host-pdev-dev);
 +
 /*
  * Grab a more or less consistent snapshot. Note that we're
  * not disabling interrupts, so IMR and SR may not be
  * consistent.
  */
 -   ret = clk_prepare_enable(host-mck);
 -   if (ret)
 -   goto out;
 -
 spin_lock_bh(host-lock);
 memcpy_fromio(buf, host-regs, ATMCI_REGS_SIZE);
 spin_unlock_bh(host-lock);

 -   clk_disable_unprepare(host-mck);
 +   pm_runtime_mark_last_busy(host-pdev-dev);
 +   pm_runtime_put_autosuspend(host-pdev-dev);

 seq_printf(s, MR:\t0x%08x%s%s ,
 buf[ATMCI_MR / 4],
 @@ -449,7 +452,6 @@ static int atmci_regs_show(struct seq_file *s, void *v)
 val  ATMCI_CFG_LSYNC ?  LSYNC : );
 }

 -out:
 kfree(buf);

 return ret;
 @@ -1252,6 +1254,8 @@ static void atmci_request(struct mmc_host *mmc, struct 
 mmc_request *mrq)
 WARN_ON(slot-mrq);
 dev_dbg(host-pdev-dev, MRQ: cmd %u\n, mrq-cmd-opcode);

 +   pm_runtime_get_sync(host-pdev-dev);
 +
 /*
  * We may know the card is gone even though there's still an
  * electrical connection. If so, we really need to communicate
 @@ -1281,7 +1285,8 @@ static void atmci_set_ios(struct mmc_host *mmc, struct 
 mmc_ios *ios)
 struct atmel_mci_slot   *slot = mmc_priv(mmc);
 struct atmel_mci*host = slot-host;
 unsigned inti;
 -   boolunprepare_clk;
 +
 +   pm_runtime_get_sync(host-pdev-dev);

 slot-sdc_reg = ~ATMCI_SDCBUS_MASK;
 switch (ios-bus_width) {
 @@ -1297,13 +1302,8 @@ static void atmci_set_ios(struct mmc_host *mmc, struct 
 mmc_ios *ios)
 unsigned int clock_min = ~0U;
 u32 clkdiv;

 -   clk_prepare(host-mck);
 -   unprepare_clk = true;
 -
 spin_lock_bh(host-lock);
 if (!host-mode_reg) {
 -   clk_enable(host-mck);
 -   unprepare_clk = false;
 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
 if (host-caps.has_cfg_reg)
 @@ -1371,8 +1371,6 @@ static void atmci_set_ios(struct mmc_host *mmc, struct 
 mmc_ios *ios)
 } else {
 bool any_slot_active = false;

 -   unprepare_clk = false;
 -
 spin_lock_bh(host-lock);
 slot-clock = 0;
 for (i = 0; i  ATMCI_MAX_NR_SLOTS; i++) {
 @@ -1385,17 +1383,12 @@ static void atmci_set_ios(struct mmc_host *mmc, 
 struct mmc_ios *ios)
 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS);
 if (host-mode_reg) {
 atmci_readl(host, ATMCI_MR);
 -   clk_disable(host-mck);
 -   unprepare_clk = true;
 }
 host-mode_reg = 0;
 }
 spin_unlock_bh(host-lock);
 }

 -   if (unprepare_clk)
 -   clk_unprepare(host-mck);
 -
 switch (ios-power_mode) {
 case MMC_POWER_OFF:
 if (!IS_ERR(mmc-supply.vmmc))
 @@ -1421,6 +1414,9 @@ static void atmci_set_ios(struct mmc_host *mmc, struct 
 mmc_ios *ios)
  */
 break;
 }
 +
 +   pm_runtime_mark_last_busy(host-pdev-dev);
 +   pm_runtime_put_autosuspend(host-pdev-dev);
  }

  static int atmci_get_ro(struct mmc_host *mmc)
 @@ -1512,6 +1508,9 @@ static void atmci_request_end(struct atmel_mci *host, 
 struct mmc_request *mrq)
 spin_unlock(host-lock);
 mmc_request_done(prev_mmc, mrq);
 spin_lock(host-lock);
 +
 +   pm_runtime_mark_last_busy(host-pdev-dev);
 +   

RE: [PATCH] mmc: atmel-mci: add pm runtime support

2014-10-29 Thread Yang, Wenyou
Hello Ulf,

Thank you very much for so many comments.

I will do it.

 -Original Message-
 From: Ulf Hansson [mailto:ulf.hans...@linaro.org]
 Sent: Wednesday, October 29, 2014 6:06 PM
 To: Yang, Wenyou
 Cc: Chris Ball; Kevin Hilman; Ferre, Nicolas; Desroches, Ludovic; linux-mmc; 
 linux-
 ker...@vger.kernel.org; linux-arm-ker...@lists.infradead.org
 Subject: Re: [PATCH] mmc: atmel-mci: add pm runtime support
 
 On 29 October 2014 03:15, Wenyou Yang wenyou.y...@atmel.com wrote:
 
 Hi Wenyou,
 
 Could you please provide some more information in the commit message.
 
  Signed-off-by: Wenyou Yang wenyou.y...@atmel.com
  ---
   drivers/mmc/host/atmel-mci.c |  116
  ++
   1 file changed, 94 insertions(+), 22 deletions(-)
 
  diff --git a/drivers/mmc/host/atmel-mci.c
  b/drivers/mmc/host/atmel-mci.c index 0b9ddf8..e9d32d0 100644
  --- a/drivers/mmc/host/atmel-mci.c
  +++ b/drivers/mmc/host/atmel-mci.c
  @@ -37,6 +37,8 @@
 
   #include linux/atmel-mci.h
   #include linux/atmel_pdc.h
  +#include linux/pm.h
  +#include linux/pm_runtime.h
 
   #include asm/cacheflush.h
   #include asm/io.h
  @@ -44,6 +46,8 @@
 
   #include atmel-mci-regs.h
 
  +#define AUTOSUSPEND_DELAY  50
  +
   #define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE |
 ATMCI_OVRE | ATMCI_UNRE)
   #define ATMCI_DMA_THRESHOLD16
 
  @@ -386,20 +390,19 @@ static int atmci_regs_show(struct seq_file *s, void 
  *v)
  if (!buf)
  return -ENOMEM;
 
  +   pm_runtime_get_sync(host-pdev-dev);
  +
  /*
   * Grab a more or less consistent snapshot. Note that we're
   * not disabling interrupts, so IMR and SR may not be
   * consistent.
   */
  -   ret = clk_prepare_enable(host-mck);
  -   if (ret)
  -   goto out;
  -
  spin_lock_bh(host-lock);
  memcpy_fromio(buf, host-regs, ATMCI_REGS_SIZE);
  spin_unlock_bh(host-lock);
 
  -   clk_disable_unprepare(host-mck);
  +   pm_runtime_mark_last_busy(host-pdev-dev);
  +   pm_runtime_put_autosuspend(host-pdev-dev);
 
  seq_printf(s, MR:\t0x%08x%s%s ,
  buf[ATMCI_MR / 4], @@ -449,7 +452,6 @@ static
  int atmci_regs_show(struct seq_file *s, void *v)
  val  ATMCI_CFG_LSYNC ?  LSYNC : );
  }
 
  -out:
  kfree(buf);
 
  return ret;
  @@ -1252,6 +1254,8 @@ static void atmci_request(struct mmc_host *mmc,
 struct mmc_request *mrq)
  WARN_ON(slot-mrq);
  dev_dbg(host-pdev-dev, MRQ: cmd %u\n, mrq-cmd-opcode);
 
  +   pm_runtime_get_sync(host-pdev-dev);
  +
  /*
   * We may know the card is gone even though there's still an
   * electrical connection. If so, we really need to communicate
  @@ -1281,7 +1285,8 @@ static void atmci_set_ios(struct mmc_host *mmc,
 struct mmc_ios *ios)
  struct atmel_mci_slot   *slot = mmc_priv(mmc);
  struct atmel_mci*host = slot-host;
  unsigned inti;
  -   boolunprepare_clk;
  +
  +   pm_runtime_get_sync(host-pdev-dev);
 
  slot-sdc_reg = ~ATMCI_SDCBUS_MASK;
  switch (ios-bus_width) {
  @@ -1297,13 +1302,8 @@ static void atmci_set_ios(struct mmc_host *mmc,
 struct mmc_ios *ios)
  unsigned int clock_min = ~0U;
  u32 clkdiv;
 
  -   clk_prepare(host-mck);
  -   unprepare_clk = true;
  -
  spin_lock_bh(host-lock);
  if (!host-mode_reg) {
  -   clk_enable(host-mck);
  -   unprepare_clk = false;
  atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
  atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
  if (host-caps.has_cfg_reg) @@ -1371,8 +1371,6
  @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  } else {
  bool any_slot_active = false;
 
  -   unprepare_clk = false;
  -
  spin_lock_bh(host-lock);
  slot-clock = 0;
  for (i = 0; i  ATMCI_MAX_NR_SLOTS; i++) { @@ -1385,17
  +1383,12 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios
 *ios)
  atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS);
  if (host-mode_reg) {
  atmci_readl(host, ATMCI_MR);
  -   clk_disable(host-mck);
  -   unprepare_clk = true;
  }
  host-mode_reg = 0;
  }
  spin_unlock_bh(host-lock);
  }
 
  -   if (unprepare_clk)
  -   clk_unprepare(host-mck);
  -
  switch (ios-power_mode) {
  case MMC_POWER_OFF:
  if (!IS_ERR(mmc-supply.vmmc)) @@ -1421,6 +1414,9 @@
  static void