[PATCH 1/3] mmc:core: parse voltage from device-tree

Subsystems: multimedia card (mmc), secure digital (sd) and sdio subsystem, the rest

STALE4789d

6 messages, 3 authors, 2013-07-30 · open the first message on its own page

[PATCH 1/3] mmc:core: parse voltage from device-tree

From: Haijun Zhang <hidden>
Date: 2013-07-29 03:49:25

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 <redacted>
---
 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

[PATCH 2/3] mmc:sdhc: get voltage from sdhc host

From: Haijun Zhang <hidden>
Date: 2013-07-29 03:49:10

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 <redacted>
---
 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

[PATCH 3/3] mmc:esdhc: add support to get voltage from device-tree

From: Haijun Zhang <hidden>
Date: 2013-07-29 03:49:53

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 <redacted>
---
 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

Re: [PATCH 1/3] mmc:core: parse voltage from device-tree

From: Scott Wood <hidden>
Date: 2013-07-29 22:07:27

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 =20
function
will parse it and return the avail voltage mask.
=20
Signed-off-by: Haijun Zhang <redacted>
---
 drivers/mmc/core/core.c  | 48 =20
++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mmc/core.h |  1 +
 2 files changed, 49 insertions(+)
Move the code rather than copying it.

-Scott=

Re: [PATCH 1/3] mmc:core: parse voltage from device-tree

From: Zhang Haijun <hidden>
Date: 2013-07-30 01:34:06

On 07/30/2013 06:07 AM, Scott Wood wrote:
On 07/28/2013 09:56:33 PM, Haijun Zhang wrote:
quoted
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 <redacted>
---
 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

Re: [PATCH 1/3] mmc:core: parse voltage from device-tree

From: Scott Wood <hidden>
Date: 2013-07-30 19:59:10

On 07/29/2013 08:34:29 PM, Zhang Haijun wrote:
On 07/30/2013 06:07 AM, Scott Wood wrote:
quoted
On 07/28/2013 09:56:33 PM, Haijun Zhang wrote:
quoted
Add function to support get voltage from device-tree.
If there are voltage-range specified in device-tree node, this =20
function
will parse it and return the avail voltage mask.
=20
Signed-off-by: Haijun Zhang <redacted>
---
 drivers/mmc/core/core.c  | 48 =20
++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mmc/core.h |  1 +
 2 files changed, 49 insertions(+)
=20
Move the code rather than copying it.
=20
-Scott
Hi, Scott
=20
You mean?
The point of factoring this out is to avoid duplicating the code.  If =20
you don't remove it from the place you copied it from (and have that =20
code call here instead), then you're not avoiding the duplication.

-Scott=
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help