linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3 V3] mmc:core: parse voltage from device-tree
@ 2013-08-09  3:11 Haijun Zhang
  2013-08-09  3:11 ` [PATCH V2] mmc:of_spi: Update the code of getting voltage-ranges Haijun Zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Haijun Zhang @ 2013-08-09  3:11 UTC (permalink / raw)
  To: linux-mmc
  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 available voltage mask.

Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
---
changes for V3:
	- Correct the type of return value.
changes for v2:
	- Update the parameters of function

 drivers/mmc/core/core.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mmc/core.h |  2 ++
 2 files changed, 47 insertions(+)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 49a5bca..1b13c37 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1196,6 +1196,51 @@ 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.
+ *
+ * 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 that can be provided to MMC/SD/SDIO devices.
+ */
+int mmc_of_parse_voltage(struct device_node *np)
+{
+	const u32 *voltage_ranges;
+	int num_ranges, i;
+	int ocr_mask;
+
+	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 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) {
+			pr_err("%s: voltage-range #%d is invalid\n",
+				np->full_name, 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..117f719 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -10,6 +10,7 @@
 
 #include <linux/interrupt.h>
 #include <linux/completion.h>
+#include <linux/of.h>
 
 struct request;
 struct mmc_data;
@@ -209,5 +210,6 @@ static inline void mmc_claim_host(struct mmc_host *host)
 }
 
 extern u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);
+extern int mmc_of_parse_voltage(struct device_node *np);
 
 #endif /* LINUX_MMC_CORE_H */
-- 
1.8.0



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

* [PATCH V2] mmc:of_spi: Update the code of getting voltage-ranges
  2013-08-09  3:11 [PATCH 1/3 V3] mmc:core: parse voltage from device-tree Haijun Zhang
@ 2013-08-09  3:11 ` Haijun Zhang
  2013-08-09  3:11 ` [PATCH 2/3 V2] mmc:sdhc: get voltage from sdhc host Haijun Zhang
  2013-08-09 22:42 ` [PATCH 1/3 V3] mmc:core: parse voltage from device-tree Anton Vorontsov
  2 siblings, 0 replies; 4+ messages in thread
From: Haijun Zhang @ 2013-08-09  3:11 UTC (permalink / raw)
  To: linux-mmc
  Cc: cbouatmailru, cjb, scottwood, AFLEMING, Haijun Zhang,
	Haijun Zhang

Using function mmc_of_parse_voltage() to get voltage-ranges.

Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com>
---
changes for V2:
	- changed the type of ocr_mask

 drivers/mmc/host/of_mmc_spi.c | 22 ++++------------------
 1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/drivers/mmc/host/of_mmc_spi.c b/drivers/mmc/host/of_mmc_spi.c
index d720b5e..635b895 100644
--- a/drivers/mmc/host/of_mmc_spi.c
+++ b/drivers/mmc/host/of_mmc_spi.c
@@ -92,6 +92,7 @@ struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi)
 	struct of_mmc_spi *oms;
 	const u32 *voltage_ranges;
 	int num_ranges;
+	int ocr_mask;
 	int i;
 	int ret = -EINVAL;
 
@@ -102,26 +103,11 @@ 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");
+	ocr_mask = mmc_of_parse_voltage(np);
+	if (ocr_mask <= 0)
 		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] 4+ messages in thread

* [PATCH 2/3 V2] mmc:sdhc: get voltage from sdhc host
  2013-08-09  3:11 [PATCH 1/3 V3] mmc:core: parse voltage from device-tree Haijun Zhang
  2013-08-09  3:11 ` [PATCH V2] mmc:of_spi: Update the code of getting voltage-ranges Haijun Zhang
@ 2013-08-09  3:11 ` Haijun Zhang
  2013-08-09 22:42 ` [PATCH 1/3 V3] mmc:core: parse voltage from device-tree Anton Vorontsov
  2 siblings, 0 replies; 4+ messages in thread
From: Haijun Zhang @ 2013-08-09  3:11 UTC (permalink / raw)
  To: linux-mmc
  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>
---
changes for v2:
	- Change the type of the value

 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..cf20ee6 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 > 0)
+		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..f9f5008 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;
+	int 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] 4+ messages in thread

* Re: [PATCH 1/3 V3] mmc:core: parse voltage from device-tree
  2013-08-09  3:11 [PATCH 1/3 V3] mmc:core: parse voltage from device-tree Haijun Zhang
  2013-08-09  3:11 ` [PATCH V2] mmc:of_spi: Update the code of getting voltage-ranges Haijun Zhang
  2013-08-09  3:11 ` [PATCH 2/3 V2] mmc:sdhc: get voltage from sdhc host Haijun Zhang
@ 2013-08-09 22:42 ` Anton Vorontsov
  2 siblings, 0 replies; 4+ messages in thread
From: Anton Vorontsov @ 2013-08-09 22:42 UTC (permalink / raw)
  To: Haijun Zhang; +Cc: linux-mmc, cjb, scottwood, AFLEMING

On Fri, Aug 09, 2013 at 11:11:01AM +0800, 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>
> ---
> changes for V3:
> 	- Correct the type of return value.
> changes for v2:
> 	- Update the parameters of function
> 
>  drivers/mmc/core/core.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/mmc/core.h |  2 ++
>  2 files changed, 47 insertions(+)
> 
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 49a5bca..1b13c37 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -1196,6 +1196,51 @@ 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.
> + *
> + * 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 that can be provided to MMC/SD/SDIO devices.
> + */
> +int mmc_of_parse_voltage(struct device_node *np)
> +{
> +	const u32 *voltage_ranges;
> +	int num_ranges, i;
> +	int ocr_mask;
> +
> +	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 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) {
> +			pr_err("%s: voltage-range #%d is invalid\n",
> +				np->full_name, i);
> +			return -EINVAL;
> +		}
> +		ocr_mask |= mask;
> +	}
> +
> +	return ocr_mask;

Are you sure that (u32)(-EINVAL) is not a valid ocr_mask? In any case,
please don't do these kind of hacks... don't return mask and a errors
together.

> +}
> +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..117f719 100644
> --- a/include/linux/mmc/core.h
> +++ b/include/linux/mmc/core.h
> @@ -10,6 +10,7 @@
>  
>  #include <linux/interrupt.h>
>  #include <linux/completion.h>
> +#include <linux/of.h>
>  
>  struct request;
>  struct mmc_data;
> @@ -209,5 +210,6 @@ static inline void mmc_claim_host(struct mmc_host *host)
>  }
>  
>  extern u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);
> +extern int mmc_of_parse_voltage(struct device_node *np);

You don't really need to include the whole linux/of.h, forward-declaration
of 'struct device_node;' is enough here.

Thanks,

Anton

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

end of thread, other threads:[~2013-08-09 22:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-09  3:11 [PATCH 1/3 V3] mmc:core: parse voltage from device-tree Haijun Zhang
2013-08-09  3:11 ` [PATCH V2] mmc:of_spi: Update the code of getting voltage-ranges Haijun Zhang
2013-08-09  3:11 ` [PATCH 2/3 V2] mmc:sdhc: get voltage from sdhc host Haijun Zhang
2013-08-09 22:42 ` [PATCH 1/3 V3] mmc:core: parse voltage from device-tree Anton Vorontsov

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).