public inbox for linux-mmc@vger.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Johan Rudholm <johan.rudholm@axis.com>,
	Ulf Hansson <ulf.hansson@linaro.org>
Cc: linux-mmc@vger.kernel.org, "Chris Ball" <chris@printf.net>,
	"Guennadi Liakhovetski" <g.liakhovetski@gmx.de>,
	"David Lanzendörfer" <david.lanzendoerfer@o2s.ch>,
	"Jesper Nilsson" <jespern@axis.com>,
	"Johan Rudholm" <johanru@axis.com>
Subject: Re: [PATCH v2 3/4] mmc: core: turn hw_reset into a bus_ops
Date: Wed, 05 Nov 2014 14:10:15 +0200	[thread overview]
Message-ID: <545A13A7.1040301@intel.com> (raw)
In-Reply-To: <1415113626-30187-4-git-send-email-johanru@axis.com>

On 04/11/14 17:07, Johan Rudholm wrote:
> Move the (e)MMC specific hw_reset code from core.c into mmc.c and call
> it from the new bus_ops member hw_reset. This also lets us add code
> for reseting SD cards as well.
> 
> Signed-off-by: Johan Rudholm <johanru@axis.com>
> ---
>  drivers/mmc/card/mmc_test.c |    3 --
>  drivers/mmc/core/core.c     |   48 ++++++++----------------------------------
>  drivers/mmc/core/core.h     |    4 +++
>  drivers/mmc/core/mmc.c      |   37 +++++++++++++++++++++++++++++++++
>  include/linux/mmc/core.h    |    1 -
>  5 files changed, 50 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
> index 0c0fc52..2cd3385 100644
> --- a/drivers/mmc/card/mmc_test.c
> +++ b/drivers/mmc/card/mmc_test.c
> @@ -2349,9 +2349,6 @@ static int mmc_test_hw_reset(struct mmc_test_card *test)
>  	if (err != -EOPNOTSUPP)
>  		return err;
>  
> -	if (!mmc_can_reset(card))
> -		return RESULT_UNSUP_CARD;
> -

I would like to retain the ability for mmc_test to distinguish
RESULT_UNSUP_CARD from RESULT_UNSUP_HOST

>  	return RESULT_UNSUP_HOST;
>  }
>  
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 2c39d26..b35f205 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -2239,64 +2239,34 @@ static void mmc_hw_reset_for_init(struct mmc_host *host)
>  	mmc_host_clk_release(host);
>  }
>  
> -int mmc_can_reset(struct mmc_card *card)
> -{
> -	u8 rst_n_function;
> -
> -	if (!mmc_card_mmc(card))
> -		return 0;
> -	rst_n_function = card->ext_csd.rst_n_function;
> -	if ((rst_n_function & EXT_CSD_RST_N_EN_MASK) != EXT_CSD_RST_N_ENABLED)
> -		return 0;
> -	return 1;
> -}
> -EXPORT_SYMBOL(mmc_can_reset);
> -
> +/* Reset card in a bus-specific way */
>  static int mmc_do_hw_reset(struct mmc_host *host, int check)
>  {
> -	struct mmc_card *card = host->card;
> -
> -	if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset)
> -		return -EOPNOTSUPP;
> +	int ret;
>  
> -	if (!card)
> +	if (!host->card)
>  		return -EINVAL;
>  
> -	if (!mmc_can_reset(card))
> +	if (!host->bus_ops || !host->bus_ops->hw_reset ||
> +			host->bus_ops->hw_reset(host, MMC_HW_RESET_TEST))
>  		return -EOPNOTSUPP;
>  
> -	mmc_host_clk_hold(host);
> -	mmc_set_clock(host, host->f_init);
> -
> -	host->ops->hw_reset(host);
> -
> -	/* If the reset has happened, then a status command will fail */
> -	if (check) {
> -		u32 status;
> -
> -		if (!mmc_send_status(card, &status)) {
> -			mmc_host_clk_release(host);
> -			return -ENOSYS;
> -		}
> -	}
> -
> -	/* Set initial state and call mmc_set_ios */
> -	mmc_set_initial_state(host);
> +	ret = host->bus_ops->hw_reset(host, check);
>  
> -	mmc_host_clk_release(host);
> +	pr_warn("%s: tried to reset card (%d)\n", mmc_hostname(host), ret);
>  
>  	return host->bus_ops->power_restore(host);
>  }
>  
>  int mmc_hw_reset(struct mmc_host *host)
>  {
> -	return mmc_do_hw_reset(host, 0);
> +	return mmc_do_hw_reset(host, MMC_HW_RESET_RESET);
>  }
>  EXPORT_SYMBOL(mmc_hw_reset);
>  
>  int mmc_hw_reset_check(struct mmc_host *host)
>  {
> -	return mmc_do_hw_reset(host, 1);
> +	return mmc_do_hw_reset(host, MMC_HW_RESET_CHECK);
>  }
>  EXPORT_SYMBOL(mmc_hw_reset_check);
>  
> diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
> index d76597c..918bbe8 100644
> --- a/drivers/mmc/core/core.h
> +++ b/drivers/mmc/core/core.h
> @@ -27,6 +27,10 @@ struct mmc_bus_ops {
>  	int (*power_restore)(struct mmc_host *);
>  	int (*alive)(struct mmc_host *);
>  	int (*shutdown)(struct mmc_host *);
> +	int (*hw_reset)(struct mmc_host *, int);
> +#define MMC_HW_RESET_RESET	0
> +#define MMC_HW_RESET_TEST	1
> +#define MMC_HW_RESET_CHECK	2
>  };
>  
>  void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> index 793c6f7..55e1a97 100644
> --- a/drivers/mmc/core/mmc.c
> +++ b/drivers/mmc/core/mmc.c
> @@ -1773,6 +1773,42 @@ static int mmc_power_restore(struct mmc_host *host)
>  	return ret;
>  }
>  
> +static int mmc_mmc_hw_reset(struct mmc_host *host, int test)
> +{
> +	struct mmc_card *card = host->card;
> +	u8 rst_n_function;
> +
> +	if (!(host->caps & MMC_CAP_HW_RESET) || !host->ops->hw_reset)
> +		return -EOPNOTSUPP;
> +
> +	rst_n_function = card->ext_csd.rst_n_function;
> +	if ((rst_n_function & EXT_CSD_RST_N_EN_MASK) != EXT_CSD_RST_N_ENABLED)
> +		return -EOPNOTSUPP;
> +
> +	if (test == MMC_HW_RESET_TEST)
> +		return 0;
> +
> +	mmc_host_clk_hold(host);
> +	mmc_set_clock(host, host->f_init);
> +
> +	host->ops->hw_reset(host);
> +
> +	if (test == MMC_HW_RESET_CHECK) {
> +		u32 status;
> +
> +		if (!mmc_send_status(card, &status)) {
> +			mmc_host_clk_release(host);
> +			return -ENOSYS;
> +		}
> +	}
> +
> +	mmc_set_initial_state(host);
> +
> +	mmc_host_clk_release(host);
> +
> +	return 0;
> +}
> +
>  static const struct mmc_bus_ops mmc_ops = {
>  	.remove = mmc_remove,
>  	.detect = mmc_detect,
> @@ -1783,6 +1819,7 @@ static const struct mmc_bus_ops mmc_ops = {
>  	.power_restore = mmc_power_restore,
>  	.alive = mmc_alive,
>  	.shutdown = mmc_shutdown,
> +	.hw_reset = mmc_mmc_hw_reset,
>  };
>  
>  /*
> diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
> index f206e29..d7e02a7 100644
> --- a/include/linux/mmc/core.h
> +++ b/include/linux/mmc/core.h
> @@ -182,7 +182,6 @@ extern int mmc_set_blockcount(struct mmc_card *card, unsigned int blockcount,
>  			      bool is_rel_write);
>  extern int mmc_hw_reset(struct mmc_host *host);
>  extern int mmc_hw_reset_check(struct mmc_host *host);
> -extern int mmc_can_reset(struct mmc_card *card);
>  
>  extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
>  extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
> 


  reply	other threads:[~2014-11-05 12:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-04 15:07 [PATCH v2 0/4] mmc: core: hw_reset changes Johan Rudholm
2014-11-04 15:07 ` [PATCH v2 1/4] mmc: core: use mmc_send_status to check hw_reset Johan Rudholm
2014-11-05  9:44   ` Ulf Hansson
2014-11-04 15:07 ` [PATCH v2 2/4] mmc: core: group default initial state Johan Rudholm
2014-11-05 10:13   ` Ulf Hansson
2014-11-05 12:22     ` Johan Rudholm
2014-11-06  9:38       ` Ulf Hansson
2014-11-06 10:43         ` Johan Rudholm
2014-11-04 15:07 ` [PATCH v2 3/4] mmc: core: turn hw_reset into a bus_ops Johan Rudholm
2014-11-05 12:10   ` Adrian Hunter [this message]
2014-11-05 14:40     ` Johan Rudholm
2014-11-04 15:07 ` [PATCH v2 4/4] mmc: sd: add hw_reset callback Johan Rudholm

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=545A13A7.1040301@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=chris@printf.net \
    --cc=david.lanzendoerfer@o2s.ch \
    --cc=g.liakhovetski@gmx.de \
    --cc=jespern@axis.com \
    --cc=johan.rudholm@axis.com \
    --cc=johanru@axis.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.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