linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] mmc:core: parse voltage from device-tree
@ 2013-08-26  1:19 Haijun Zhang
  2013-08-26  1:19 ` [PATCH 2/4] mmc:sdhc: get voltage from sdhc host Haijun Zhang
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Haijun Zhang @ 2013-08-26  1:19 UTC (permalink / raw)
  To: linux-mmc, galak
  Cc: cbouatmailru, cjb, scottwood, X.Xie, 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 available voltage mask.

Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
Acked-by: Anton Vorontsov <anton@enomsg.org>
---
 .../devicetree/bindings/mmc/fsl-esdhc.txt          |  4 ++
 drivers/mmc/core/core.c                            | 44 ++++++++++++++++++++++
 include/linux/mmc/core.h                           |  2 +
 3 files changed, 50 insertions(+)

diff --git a/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt b/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt
index bd9be0b..b7943f3 100644
--- a/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt
+++ b/Documentation/devicetree/bindings/mmc/fsl-esdhc.txt
@@ -19,6 +19,9 @@ Optional properties:
     "bus-width = <1>" property.
   - sdhci,auto-cmd12: specifies that a controller can only handle auto
     CMD12.
+  - voltage-ranges : two cells are required, first cell specifies minimum
+    slot voltage (mV), second cell specifies maximum slot voltage (mV).
+    Several ranges could be specified.
 
 Example:
 
@@ -29,4 +32,5 @@ sdhci@2e000 {
 	interrupt-parent = <&ipic>;
 	/* Filled in by U-Boot */
 	clock-frequency = <0>;
+	voltage-ranges = <3300 3300>;
 };
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 49a5bca..b9b9fb6 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,49 @@ 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
+ * @np: The device node need to be parsed.
+ * @mask: mask of voltages available for MMC/SD/SDIO
+ *
+ * 1. Return zero on success.
+ * 2. Return negative errno: voltage-range is invalid.
+ */
+int mmc_of_parse_voltage(struct device_node *np, u32 *mask)
+{
+	const u32 *voltage_ranges;
+	int num_ranges, i;
+
+	voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges);
+	num_ranges = num_ranges / sizeof(*voltage_ranges) / 2;
+	if (!voltage_ranges || !num_ranges) {
+		pr_info("%s: voltage-ranges unspecified\n", np->full_name);
+		return -EINVAL;
+	}
+
+	for (i = 0; i < num_ranges; i++) {
+		const int j = i * 2;
+		u32 ocr_mask;
+
+		ocr_mask = mmc_vddrange_to_ocrmask(
+				be32_to_cpu(voltage_ranges[j]),
+				be32_to_cpu(voltage_ranges[j + 1]));
+		if (!ocr_mask) {
+			pr_err("%s: voltage-range #%d is invalid\n",
+				np->full_name, i);
+			return -EINVAL;
+		}
+		*mask |= ocr_mask;
+	}
+
+	return 0;
+}
+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..da51bec 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -208,6 +208,8 @@ static inline void mmc_claim_host(struct mmc_host *host)
 	__mmc_claim_host(host, NULL);
 }
 
+struct device_node;
 extern u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);
+extern int mmc_of_parse_voltage(struct device_node *np, u32 *mask);
 
 #endif /* LINUX_MMC_CORE_H */
-- 
1.8.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] mmc:sdhc: get voltage from sdhc host
  2013-08-26  1:19 [PATCH 1/4] mmc:core: parse voltage from device-tree Haijun Zhang
@ 2013-08-26  1:19 ` Haijun Zhang
  2013-08-26  1:19 ` [PATCH 3/4] mmc:esdhc: add support to get voltage from device-tree Haijun Zhang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Haijun Zhang @ 2013-08-26  1:19 UTC (permalink / raw)
  To: linux-mmc, galak
  Cc: cbouatmailru, cjb, scottwood, X.Xie, 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>
Reviewed-by: Anton Vorontsov <anton@enomsg.org>
---
 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/4] mmc:esdhc: add support to get voltage from device-tree
  2013-08-26  1:19 [PATCH 1/4] mmc:core: parse voltage from device-tree Haijun Zhang
  2013-08-26  1:19 ` [PATCH 2/4] mmc:sdhc: get voltage from sdhc host Haijun Zhang
@ 2013-08-26  1:19 ` Haijun Zhang
  2013-08-26  1:19 ` [PATCH 4/4] mmc:of_spi: Update the code of getting voltage-ranges Haijun Zhang
  2013-08-26 16:36 ` [PATCH 1/4] mmc:core: parse voltage from device-tree Chris Ball
  3 siblings, 0 replies; 6+ messages in thread
From: Haijun Zhang @ 2013-08-26  1:19 UTC (permalink / raw)
  To: linux-mmc, galak
  Cc: cbouatmailru, cjb, scottwood, X.Xie, 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>
Acked-by: Anton Vorontsov <anton@enomsg.org>
---
 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..e328252 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);
+	mmc_of_parse_voltage(np, &host->ocr_mask);
 
 	ret = sdhci_add_host(host);
 	if (ret)
-- 
1.8.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] mmc:of_spi: Update the code of getting voltage-ranges
  2013-08-26  1:19 [PATCH 1/4] mmc:core: parse voltage from device-tree Haijun Zhang
  2013-08-26  1:19 ` [PATCH 2/4] mmc:sdhc: get voltage from sdhc host Haijun Zhang
  2013-08-26  1:19 ` [PATCH 3/4] mmc:esdhc: add support to get voltage from device-tree Haijun Zhang
@ 2013-08-26  1:19 ` Haijun Zhang
  2013-08-26 16:36 ` [PATCH 1/4] mmc:core: parse voltage from device-tree Chris Ball
  3 siblings, 0 replies; 6+ messages in thread
From: Haijun Zhang @ 2013-08-26  1:19 UTC (permalink / raw)
  To: linux-mmc, galak
  Cc: cbouatmailru, cjb, scottwood, X.Xie, Haijun Zhang, Haijun Zhang

Using function mmc_of_parse_voltage() to get voltage-ranges.

Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
Acked-by: Anton Vorontsov <anton@enomsg.org>
---
 drivers/mmc/host/of_mmc_spi.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/mmc/host/of_mmc_spi.c b/drivers/mmc/host/of_mmc_spi.c
index d720b5e..fd1928d 100644
--- a/drivers/mmc/host/of_mmc_spi.c
+++ b/drivers/mmc/host/of_mmc_spi.c
@@ -90,8 +90,7 @@ struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi)
 	struct device *dev = &spi->dev;
 	struct device_node *np = dev->of_node;
 	struct of_mmc_spi *oms;
-	const u32 *voltage_ranges;
-	int num_ranges;
+	u32 ocr_mask;
 	int i;
 	int ret = -EINVAL;
 
@@ -102,26 +101,10 @@ struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi)
 	if (!oms)
 		return NULL;
 
-	voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges);
-	num_ranges = num_ranges / sizeof(*voltage_ranges) / 2;
-	if (!voltage_ranges || !num_ranges) {
-		dev_err(dev, "OF: voltage-ranges unspecified\n");
+	if (mmc_of_parse_voltage(np, &ocr_mask))
 		goto err_ocr;
-	}
-
-	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) {
-			ret = -EINVAL;
-			dev_err(dev, "OF: voltage-range #%d is invalid\n", i);
-			goto err_ocr;
-		}
-		oms->pdata.ocr_mask |= mask;
-	}
+	oms->pdata.ocr_mask |= ocr_mask;
 
 	for (i = 0; i < ARRAY_SIZE(oms->gpios); i++) {
 		enum of_gpio_flags gpio_flags;
-- 
1.8.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] mmc:core: parse voltage from device-tree
  2013-08-26  1:19 [PATCH 1/4] mmc:core: parse voltage from device-tree Haijun Zhang
                   ` (2 preceding siblings ...)
  2013-08-26  1:19 ` [PATCH 4/4] mmc:of_spi: Update the code of getting voltage-ranges Haijun Zhang
@ 2013-08-26 16:36 ` Chris Ball
  2013-08-27  0:52   ` Zhang Haijun
  3 siblings, 1 reply; 6+ messages in thread
From: Chris Ball @ 2013-08-26 16:36 UTC (permalink / raw)
  To: Haijun Zhang; +Cc: linux-mmc, galak, cbouatmailru, scottwood, X.Xie

Hi Haijun,

On Sun, Aug 25 2013, 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 available voltage mask.
>
> Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
> Acked-by: Anton Vorontsov <anton@enomsg.org>

Thanks, I've pushed all four patches to mmc-next for 3.12.

- Chris.
-- 
Chris Ball   <cjb@laptop.org>   <http://printf.net/>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/4] mmc:core: parse voltage from device-tree
  2013-08-26 16:36 ` [PATCH 1/4] mmc:core: parse voltage from device-tree Chris Ball
@ 2013-08-27  0:52   ` Zhang Haijun
  0 siblings, 0 replies; 6+ messages in thread
From: Zhang Haijun @ 2013-08-27  0:52 UTC (permalink / raw)
  To: Chris Ball; +Cc: Haijun Zhang, linux-mmc, galak, cbouatmailru, scottwood, X.Xie

On 08/27/2013 12:36 AM, Chris Ball wrote:
> Hi Haijun,
>
> On Sun, Aug 25 2013, 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 available voltage mask.
>>
>> Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
>> Acked-by: Anton Vorontsov <anton@enomsg.org>
>
> Thanks, I've pushed all four patches to mmc-next for 3.12.
>
> - Chris.
>

Thank you very much!

-- 
Thanks & Regards

Haijun


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-08-27  0:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-26  1:19 [PATCH 1/4] mmc:core: parse voltage from device-tree Haijun Zhang
2013-08-26  1:19 ` [PATCH 2/4] mmc:sdhc: get voltage from sdhc host Haijun Zhang
2013-08-26  1:19 ` [PATCH 3/4] mmc:esdhc: add support to get voltage from device-tree Haijun Zhang
2013-08-26  1:19 ` [PATCH 4/4] mmc:of_spi: Update the code of getting voltage-ranges Haijun Zhang
2013-08-26 16:36 ` [PATCH 1/4] mmc:core: parse voltage from device-tree Chris Ball
2013-08-27  0:52   ` Zhang Haijun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).