* [PATCH 1/3] mmc:core: parse voltage from device-tree
@ 2013-07-29 2:56 Haijun Zhang
2013-07-29 2:56 ` [PATCH 2/3] mmc:sdhc: get voltage from sdhc host Haijun Zhang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Haijun Zhang @ 2013-07-29 2:56 UTC (permalink / raw)
To: linux-mmc, linuxppc-dev
Cc: cbouatmailru, cjb, scottwood, AFLEMING, Haijun Zhang,
Haijun Zhang
Add function to support get voltage from device-tree.
If there are voltage-range specified in device-tree node, this function
will parse it and return the avail voltage mask.
Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
---
drivers/mmc/core/core.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/mmc/core.h | 1 +
2 files changed, 49 insertions(+)
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 49a5bca..217cd42 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -27,6 +27,7 @@
#include <linux/fault-inject.h>
#include <linux/random.h>
#include <linux/slab.h>
+#include <linux/of.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
@@ -1196,6 +1197,53 @@ u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max)
}
EXPORT_SYMBOL(mmc_vddrange_to_ocrmask);
+#ifdef CONFIG_OF
+
+/*
+ * mmc_of_parse_voltage - return mask of supported voltages
+ * @host: host whose node should be parsed.
+ *
+ * 1. Return zero: voltage-ranges unspecified in device-tree.
+ * 2. Return negative errno: voltage-range is invalid.
+ * 3. Return ocr_mask: a mask of voltages that parse from device-tree
+ * node can be provided to MMC/SD/SDIO devices.
+ */
+
+u32 mmc_of_parse_voltage(struct mmc_host *host)
+{
+ const u32 *voltage_ranges;
+ int num_ranges, i;
+ struct device_node *np;
+ u32 ocr_mask = 0;
+
+ np = host->parent->of_node;
+ voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges);
+ num_ranges = num_ranges / sizeof(*voltage_ranges) / 2;
+ if (!voltage_ranges || !num_ranges) {
+ dev_info(host->parent, "OF: voltage-ranges unspecified\n");
+ return 0;
+ }
+
+ for (i = 0; i < num_ranges; i++) {
+ const int j = i * 2;
+ u32 mask;
+
+ mask = mmc_vddrange_to_ocrmask(be32_to_cpu(voltage_ranges[j]),
+ be32_to_cpu(voltage_ranges[j + 1]));
+ if (!mask) {
+ dev_err(host->parent,
+ "OF: voltage-range #%d is invalid\n", i);
+ return -EINVAL;
+ }
+ ocr_mask |= mask;
+ }
+
+ return ocr_mask;
+}
+EXPORT_SYMBOL(mmc_of_parse_voltage);
+
+#endif /* CONFIG_OF */
+
#ifdef CONFIG_REGULATOR
/**
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 443243b..107375c 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -209,5 +209,6 @@ static inline void mmc_claim_host(struct mmc_host *host)
}
extern u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);
+extern u32 mmc_of_parse_voltage(struct mmc_host *host);
#endif /* LINUX_MMC_CORE_H */
--
1.8.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/3] mmc:sdhc: get voltage from sdhc host
2013-07-29 2:56 [PATCH 1/3] mmc:core: parse voltage from device-tree Haijun Zhang
@ 2013-07-29 2:56 ` Haijun Zhang
2013-07-29 2:56 ` [PATCH 3/3] mmc:esdhc: add support to get voltage from device-tree Haijun Zhang
2013-07-29 22:07 ` [PATCH 1/3] mmc:core: parse " Scott Wood
2 siblings, 0 replies; 6+ messages in thread
From: Haijun Zhang @ 2013-07-29 2:56 UTC (permalink / raw)
To: linux-mmc, linuxppc-dev
Cc: cbouatmailru, cjb, scottwood, AFLEMING, Haijun Zhang,
Haijun Zhang
We use host->ocr_mask to hold the voltage get from device-tree
node, In case host->ocr_mask was available, we use host->ocr_mask
as the final available voltage can be used by MMC/SD/SDIO card.
Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
---
drivers/mmc/host/sdhci.c | 3 +++
include/linux/mmc/sdhci.h | 1 +
2 files changed, 4 insertions(+)
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index a78bd4f..57541e0 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -3119,6 +3119,9 @@ int sdhci_add_host(struct sdhci_host *host)
SDHCI_MAX_CURRENT_MULTIPLIER;
}
+ if (host->ocr_mask)
+ ocr_avail = host->ocr_mask;
+
mmc->ocr_avail = ocr_avail;
mmc->ocr_avail_sdio = ocr_avail;
if (host->ocr_avail_sdio)
diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
index e3c6a74..3e781b8 100644
--- a/include/linux/mmc/sdhci.h
+++ b/include/linux/mmc/sdhci.h
@@ -171,6 +171,7 @@ struct sdhci_host {
unsigned int ocr_avail_sdio; /* OCR bit masks */
unsigned int ocr_avail_sd;
unsigned int ocr_avail_mmc;
+ u32 ocr_mask; /* available voltages */
wait_queue_head_t buf_ready_int; /* Waitqueue for Buffer Read Ready interrupt */
unsigned int tuning_done; /* Condition flag set when CMD19 succeeds */
--
1.8.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/3] mmc:esdhc: add support to get voltage from device-tree
2013-07-29 2:56 [PATCH 1/3] mmc:core: parse voltage from device-tree Haijun Zhang
2013-07-29 2:56 ` [PATCH 2/3] mmc:sdhc: get voltage from sdhc host Haijun Zhang
@ 2013-07-29 2:56 ` Haijun Zhang
2013-07-29 22:07 ` [PATCH 1/3] mmc:core: parse " Scott Wood
2 siblings, 0 replies; 6+ messages in thread
From: Haijun Zhang @ 2013-07-29 2:56 UTC (permalink / raw)
To: linux-mmc, linuxppc-dev
Cc: cbouatmailru, cjb, scottwood, AFLEMING, Haijun Zhang,
Haijun Zhang
Add suppport to get voltage from device-tree node for esdhc host,
if voltage-ranges was specified in device-tree node we can get
ocr_mask instead of read from host capacity register. If not voltages
still can be get from host capacity register.
Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
---
drivers/mmc/host/sdhci-of-esdhc.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c
index 15039e2..b1a7f54 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -316,6 +316,7 @@ static int sdhci_esdhc_probe(struct platform_device *pdev)
/* call to generic mmc_of_parse to support additional capabilities */
mmc_of_parse(host->mmc);
+ host->ocr_mask = mmc_of_parse_voltage(host->mmc);
ret = sdhci_add_host(host);
if (ret)
--
1.8.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] mmc:core: parse voltage from device-tree
2013-07-29 2:56 [PATCH 1/3] mmc:core: parse voltage from device-tree Haijun Zhang
2013-07-29 2:56 ` [PATCH 2/3] mmc:sdhc: get voltage from sdhc host Haijun Zhang
2013-07-29 2:56 ` [PATCH 3/3] mmc:esdhc: add support to get voltage from device-tree Haijun Zhang
@ 2013-07-29 22:07 ` Scott Wood
2013-07-30 1:34 ` Zhang Haijun
2 siblings, 1 reply; 6+ messages in thread
From: Scott Wood @ 2013-07-29 22:07 UTC (permalink / raw)
Cc: linux-mmc, linuxppc-dev, cbouatmailru, cjb, AFLEMING,
Haijun Zhang
On 07/28/2013 09:56:33 PM, Haijun Zhang wrote:
> Add function to support get voltage from device-tree.
> If there are voltage-range specified in device-tree node, this
> function
> will parse it and return the avail voltage mask.
>
> Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
> ---
> drivers/mmc/core/core.c | 48
> ++++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/mmc/core.h | 1 +
> 2 files changed, 49 insertions(+)
Move the code rather than copying it.
-Scott
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] mmc:core: parse voltage from device-tree
2013-07-29 22:07 ` [PATCH 1/3] mmc:core: parse " Scott Wood
@ 2013-07-30 1:34 ` Zhang Haijun
2013-07-30 19:58 ` Scott Wood
0 siblings, 1 reply; 6+ messages in thread
From: Zhang Haijun @ 2013-07-30 1:34 UTC (permalink / raw)
To: Scott Wood
Cc: Haijun Zhang, linux-mmc, linuxppc-dev, cbouatmailru, cjb,
AFLEMING, Xie Xiaobo-R63061
On 07/30/2013 06:07 AM, Scott Wood wrote:
> On 07/28/2013 09:56:33 PM, Haijun Zhang wrote:
>> Add function to support get voltage from device-tree.
>> If there are voltage-range specified in device-tree node, this function
>> will parse it and return the avail voltage mask.
>>
>> Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
>> ---
>> drivers/mmc/core/core.c | 48
>> ++++++++++++++++++++++++++++++++++++++++++++++++
>> include/linux/mmc/core.h | 1 +
>> 2 files changed, 49 insertions(+)
>
> Move the code rather than copying it.
>
> -Scott
Hi, Scott
You mean?
--
Thanks & Regards
Haijun
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/3] mmc:core: parse voltage from device-tree
2013-07-30 1:34 ` Zhang Haijun
@ 2013-07-30 19:58 ` Scott Wood
0 siblings, 0 replies; 6+ messages in thread
From: Scott Wood @ 2013-07-30 19:58 UTC (permalink / raw)
To: Zhang Haijun
Cc: linux-mmc, AFLEMING, Xie Xiaobo-R63061, cbouatmailru, cjb,
linuxppc-dev, Haijun Zhang
On 07/29/2013 08:34:29 PM, Zhang Haijun wrote:
> On 07/30/2013 06:07 AM, Scott Wood wrote:
>> On 07/28/2013 09:56:33 PM, Haijun Zhang wrote:
>>> Add function to support get voltage from device-tree.
>>> If there are voltage-range specified in device-tree node, this
>>> function
>>> will parse it and return the avail voltage mask.
>>>
>>> Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
>>> ---
>>> drivers/mmc/core/core.c | 48
>>> ++++++++++++++++++++++++++++++++++++++++++++++++
>>> include/linux/mmc/core.h | 1 +
>>> 2 files changed, 49 insertions(+)
>>
>> Move the code rather than copying it.
>>
>> -Scott
> Hi, Scott
>
> You mean?
The point of factoring this out is to avoid duplicating the code. If
you don't remove it from the place you copied it from (and have that
code call here instead), then you're not avoiding the duplication.
-Scott
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-07-30 19:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-29 2:56 [PATCH 1/3] mmc:core: parse voltage from device-tree Haijun Zhang
2013-07-29 2:56 ` [PATCH 2/3] mmc:sdhc: get voltage from sdhc host Haijun Zhang
2013-07-29 2:56 ` [PATCH 3/3] mmc:esdhc: add support to get voltage from device-tree Haijun Zhang
2013-07-29 22:07 ` [PATCH 1/3] mmc:core: parse " Scott Wood
2013-07-30 1:34 ` Zhang Haijun
2013-07-30 19:58 ` Scott Wood
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox