From: Chris Ball <cjb@laptop.org>
To: Girish K S <girish.shivananjappa@linaro.org>
Cc: linux-mmc@vger.kernel.org, kgene.kim@samsung.com,
patches@linaro.org, linux-samsung-soc@vger.kernel.org
Subject: Re: [PATCH] mmc: core: eMMC 4.5 Power Class Selection Feature
Date: Wed, 21 Sep 2011 14:06:29 -0400 [thread overview]
Message-ID: <m2hb454voa.fsf@bob.laptop.org> (raw)
In-Reply-To: <1315918652-14340-1-git-send-email-girish.shivananjappa@linaro.org> (Girish K. S.'s message of "Tue, 13 Sep 2011 18:27:32 +0530")
Hi Girish,
On Tue, Sep 13 2011, Girish K S wrote:
> This patch adds the power class selection feature available
> for mmc versions 4.0 and above.
> During the enumeration stage before switching to the lower
> data bus, check if the power class is supported for the
> current bus width. If the power class is available then
> switch to the power class and use the higher data bus. If
> power class is not supported then switch to the lower data
> bus in a worst case.
>
> Signed-off-by: Girish K S <girish.shivananjappa@linaro.org>
> ---
> drivers/mmc/core/mmc.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/mmc/mmc.h | 13 ++++++++
> 2 files changed, 90 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> index 63cc77b..a4004da 100644
> --- a/drivers/mmc/core/mmc.c
> +++ b/drivers/mmc/core/mmc.c
> @@ -536,6 +536,81 @@ static struct device_type mmc_type = {
> };
>
> /*
> + * Select the PowerClass for the current bus width
> + * If power class is defined for 4/8 bit bus in the
> + * extended CSD register, select it by executing the
> + * mmc_switch command.
> + */
> +static int mmc_select_powerclass(struct mmc_card *card, unsigned int bus_width)
> +{
> + u8 *ext_csd;
> + int err;
> + unsigned int pwrclass_val;
> + unsigned int index = 0;
> + struct mmc_host *host = card->host;
> +
> + BUG_ON(!card);
> + BUG_ON(!host);
> +
> + /* Power class selection is supported for versions >= 4.0 */
> + if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
> + return 0;
> + /*Power class values are defined only for 4/8 bit bus*/
Spaces between /* */ and the comment itself, please.
> + if (bus_width == EXT_CSD_BUS_WIDTH_1)
> + return 0;
> +
> + switch ((1 << host->ios.vdd)) {
Extra parens unnecessary.
> + case MMC_VDD_165_195:
> + if (host->ios.clock <= 26000000)
> + index = EXT_CSD_PWR_CL_26_195;
> + else if (host->ios.clock <= 52000000)
> + index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ?
> + EXT_CSD_PWR_CL_52_195 :
> + EXT_CSD_PWR_CL_DDR_52_195;
> + else if (host->ios.clock <= 200000000)
> + index = EXT_CSD_PWR_CL_200_195;
> + break;
> + case MMC_VDD_32_33:
> + case MMC_VDD_33_34:
> + case MMC_VDD_34_35:
> + case MMC_VDD_35_36:
> + if (host->ios.clock <= 26000000)
> + index = EXT_CSD_PWR_CL_26_360;
> + else if (host->ios.clock <= 52000000)
> + index = (bus_width <= EXT_CSD_BUS_WIDTH_8) ?
> + EXT_CSD_PWR_CL_52_360 :
> + EXT_CSD_PWR_CL_DDR_52_360;
> + else if (host->ios.clock <= 200000000)
> + index = EXT_CSD_PWR_CL_200_360;
> + break;
> + default:
> + BUG();
BUG() is a huge deal -- it will take out the entire MMC stack, so it's
not appropriate here. How about just a pr_error() that notes an
unexpected VDD and then returns an error value?
> + break;
> + }
> +
> + err = mmc_get_ext_csd(card, &ext_csd);
> + if (err)
> + goto ret;
> +
> + pwrclass_val = ext_csd[index];
> +
> + if (bus_width & (EXT_CSD_BUS_WIDTH_8 | EXT_CSD_DDR_BUS_WIDTH_8))
> + pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_8BIT_MASK) >>
> + EXT_CSD_PWR_CL_8BIT_SHIFT;
> + else
> + pwrclass_val = (pwrclass_val & EXT_CSD_PWR_CL_4BIT_MASK) >>
> + EXT_CSD_PWR_CL_4BIT_SHIFT;
> +
> + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
> + EXT_CSD_POWER_CLASS,
> + pwrclass_val,
> + 0);
> +ret:
> + mmc_free_ext_csd(ext_csd);
> + return err;
> +}
> +
> +/*
> * Handle the detection and initialisation of a card.
> *
> * In the case of a resume, "oldcard" will contain the card
> @@ -802,6 +877,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
> bus_width = bus_widths[idx];
> if (bus_width == MMC_BUS_WIDTH_1)
> ddr = 0; /* no DDR for 1-bit width */
> + mmc_select_powerclass(card, ext_csd_bits[idx][0]);
Since you're returning a meaningful error value above, we should do
something with it here -- if you don't expect the error cases to be
hit, you could pr_warning() the return value here so that we can
investigate.
Thanks,
- Chris.
--
Chris Ball <cjb@laptop.org> <http://printf.net/>
One Laptop Per Child
next prev parent reply other threads:[~2011-09-21 18:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-13 12:57 [PATCH] mmc: core: eMMC 4.5 Power Class Selection Feature Girish K S
2011-09-21 18:06 ` Chris Ball [this message]
2011-09-22 4:07 ` Girish K S
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=m2hb454voa.fsf@bob.laptop.org \
--to=cjb@laptop.org \
--cc=girish.shivananjappa@linaro.org \
--cc=kgene.kim@samsung.com \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-samsung-soc@vger.kernel.org \
--cc=patches@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