Message ID | 1374479636-9254-2-git-send-email-Haijun.Zhang@freescale.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
On 07/22/2013 02:53:56 AM, Haijun Zhang wrote: > Add voltage-range support in esdhc of T4, So we can choose > to read voltages from dts file as one optional. > If we can get a valid voltage-range from device node, we use > this voltage as the final voltage support. Else we still read > from capacity or from other provider. > > Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com> > Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com> > --- > drivers/mmc/host/sdhci-of-esdhc.c | 31 > +++++++++++++++++++++++++++++++ > drivers/mmc/host/sdhci.c | 3 +++ > include/linux/mmc/sdhci.h | 1 + > 3 files changed, 35 insertions(+) > > diff --git a/drivers/mmc/host/sdhci-of-esdhc.c > b/drivers/mmc/host/sdhci-of-esdhc.c > index 15039e2..8b4b27a 100644 > --- a/drivers/mmc/host/sdhci-of-esdhc.c > +++ b/drivers/mmc/host/sdhci-of-esdhc.c > @@ -262,6 +262,35 @@ static int esdhc_pltfm_bus_width(struct > sdhci_host *host, int width) > return 0; > } > > +static void esdhc_get_voltage(struct sdhci_host *host, > + struct platform_device *pdev) > +{ > + const u32 *voltage_ranges; > + int num_ranges, i; > + struct device_node *np; > + np = pdev->dev.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(&pdev->dev, "OF: voltage-ranges > unspecified\n"); > + return; > + } > + > + 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_info(&pdev->dev, > + "OF: false voltage-ranges specified\n"); > + return; > + } > + host->ocr_mask |= mask; > + } > +} Don't duplicate this code. Move it somewhere common and share it. Why did you remove the range index from the error string, and why did you change it from dev_err to dev_info? -Scott
On 07/22/2013 09:38:33 PM, Zhang Haijun-B42677 wrote: > > -----Original Message----- > > From: Wood Scott-B07421 > > Sent: Tuesday, July 23, 2013 1:41 AM > > To: Zhang Haijun-B42677 > > Cc: linux-mmc@vger.kernel.org; linuxppc-dev@lists.ozlabs.org; > > cbouatmailru@gmail.com; cjb@laptop.org; Fleming Andy-AFLEMING; Zhang > > Haijun-B42677; Zhang Haijun-B42677 > > Subject: Re: [PATCH 2/2] mmc: esdhc: get voltage from dts file > > > > On 07/22/2013 02:53:56 AM, Haijun Zhang wrote: > > > Add voltage-range support in esdhc of T4, So we can choose to read > > > voltages from dts file as one optional. > > > If we can get a valid voltage-range from device node, we use this > > > voltage as the final voltage support. Else we still read from > capacity > > > or from other provider. > > > > > > Signed-off-by: Haijun Zhang <haijun.zhang@freescale.com> > > > Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com> > > > --- > > > drivers/mmc/host/sdhci-of-esdhc.c | 31 > > > +++++++++++++++++++++++++++++++ > > > drivers/mmc/host/sdhci.c | 3 +++ > > > include/linux/mmc/sdhci.h | 1 + > > > 3 files changed, 35 insertions(+) > > > > > > diff --git a/drivers/mmc/host/sdhci-of-esdhc.c > > > b/drivers/mmc/host/sdhci-of-esdhc.c > > > index 15039e2..8b4b27a 100644 > > > --- a/drivers/mmc/host/sdhci-of-esdhc.c > > > +++ b/drivers/mmc/host/sdhci-of-esdhc.c > > > @@ -262,6 +262,35 @@ static int esdhc_pltfm_bus_width(struct > > > sdhci_host *host, int width) > > > return 0; > > > } > > > > > > +static void esdhc_get_voltage(struct sdhci_host *host, > > > + struct platform_device *pdev) > > > +{ > > > + const u32 *voltage_ranges; > > > + int num_ranges, i; > > > + struct device_node *np; > > > + np = pdev->dev.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(&pdev->dev, "OF: voltage-ranges > > > unspecified\n"); > > > + return; > > > + } > > > + > > > + 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_info(&pdev->dev, > > > + "OF: false voltage-ranges specified\n"); > > > + return; > > > + } > > > + host->ocr_mask |= mask; > > > + } > > > +} > > > > Don't duplicate this code. Move it somewhere common and share it. > [Haijun Wrote:] So, move it drivers/mmc/host/sdhci-pltfm.c and share > it as > Sdhc_get_voltage()....? I'll let the MMC maintainer say what the appropriate place would be... Don't capitalize the function name, though. :-) -Scott
On Mon, Jul 22, 2013 at 09:41:34PM -0500, Scott Wood wrote: [...] > >> > +static void esdhc_get_voltage(struct sdhci_host *host, > >> > + struct platform_device *pdev) > >> > +{ .... > >> > +} > >> > >> Don't duplicate this code. Move it somewhere common and share it. > >[Haijun Wrote:] So, move it drivers/mmc/host/sdhci-pltfm.c and > >share it as > >Sdhc_get_voltage()....? > > I'll let the MMC maintainer say what the appropriate place would > be... Don't capitalize the function name, though. :-) Somewhere in drivers/mmc/core/core.c, near mmc_vddrange_to_ocrmask() would be most appropriate, IMO. #ifdef CONFIG_OF would be needed, though. Thanks, Anton
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c index 15039e2..8b4b27a 100644 --- a/drivers/mmc/host/sdhci-of-esdhc.c +++ b/drivers/mmc/host/sdhci-of-esdhc.c @@ -262,6 +262,35 @@ static int esdhc_pltfm_bus_width(struct sdhci_host *host, int width) return 0; } +static void esdhc_get_voltage(struct sdhci_host *host, + struct platform_device *pdev) +{ + const u32 *voltage_ranges; + int num_ranges, i; + struct device_node *np; + np = pdev->dev.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(&pdev->dev, "OF: voltage-ranges unspecified\n"); + return; + } + + 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_info(&pdev->dev, + "OF: false voltage-ranges specified\n"); + return; + } + host->ocr_mask |= mask; + } +} + static const struct sdhci_ops sdhci_esdhc_ops = { .read_l = esdhc_readl, .read_w = esdhc_readw, @@ -317,6 +346,8 @@ static int sdhci_esdhc_probe(struct platform_device *pdev) /* call to generic mmc_of_parse to support additional capabilities */ mmc_of_parse(host->mmc); + esdhc_get_voltage(host, pdev); + ret = sdhci_add_host(host); if (ret) sdhci_pltfm_free(pdev); 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 */