Hi all,
Here are the bindings, again. Still RFC.
This patch series depends on:
http://lkml.org/lkml/2008/10/16/250
http://lkml.org/lkml/2008/10/24/416
+ of_gpio_flags enum (Trent Piepho will post an updated patch soon,
I believe).
Pierre, the approach is somewhat similar to this one:
http://lkml.org/lkml/2008/5/26/135
Posted few months ago.
I know you don't like it, but I ask you to reconsider it. The
I2C and SPI cases are similar, and recently we tried to write
bindings for some I2C GPIO controllers.
There we've learned that we:
1. Don't like the bus notifiers approach b/c we can't place the OF
code into the module.
http://lkml.org/lkml/2008/10/21/425
Hacks are possible, but they're are ugly.
2. Don't want to write new drivers to solely handle the platform
data:
http://lkml.org/lkml/2008/10/28/257
http://lkml.org/lkml/2008/10/28/268
And personally I don't want to do refactoring for every driver that
we'd want to use with the OpenFirmware...
If I understood correctly, for GPIO controllers David agreed that
we can live with the platform data accessors, at least for now:
http://lkml.org/lkml/2008/10/23/24
And when/if we'll find something better I'll be the first who
will offer help to convert the bindings code to this "something
better".
Thanks,
--
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
The bindings describes a case where MMC/SD/SDIO slot directly connected
to a SPI bus. Such setups are widely used on embedded PowerPC boards.
The patch also adds the mmc-spi-slot entry to the OpenFirmware modalias
table.
Signed-off-by: Anton Vorontsov <[email protected]>
---
.../powerpc/dts-bindings/mmc-spi-slot.txt | 23 ++++++++++++++++++++
drivers/of/base.c | 1 +
2 files changed, 24 insertions(+), 0 deletions(-)
create mode 100644 Documentation/powerpc/dts-bindings/mmc-spi-slot.txt
diff --git a/Documentation/powerpc/dts-bindings/mmc-spi-slot.txt b/Documentation/powerpc/dts-bindings/mmc-spi-slot.txt
new file mode 100644
index 0000000..c39ac28
--- /dev/null
+++ b/Documentation/powerpc/dts-bindings/mmc-spi-slot.txt
@@ -0,0 +1,23 @@
+MMC/SD/SDIO slot directly connected to a SPI bus
+
+Required properties:
+- compatible : should be "mmc-spi-slot".
+- reg : should specify SPI address (chip-select number).
+- spi-max-frequency : maximum frequency for this device (Hz).
+- 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.
+- gpios : (optional) may specify GPIOs in this order: Card-Detect GPIO,
+ Write-Protect GPIO.
+
+Example:
+
+ mmc-slot@0 {
+ compatible = "fsl,mpc8323rdb-mmc-slot",
+ "mmc-spi-slot";
+ reg = <0>;
+ gpios = <&qe_pio_d 14 1
+ &qe_pio_d 15 0>;
+ voltage-ranges = <3300 3300>;
+ spi-max-frequency = <50000000>;
+ };
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 7c79e94..c6797ca 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -411,6 +411,7 @@ struct of_modalias_table {
};
static struct of_modalias_table of_modalias_table[] = {
{ "fsl,mcu-mpc8349emitx", "mcu-mpc8349emitx" },
+ { "mmc-spi-slot", "mmc_spi" },
};
/**
--
1.5.6.3
This function sets the OCR mask bits according to provided voltage
ranges. Will be used by the mmc_spi OpenFirmware bindings.
Signed-off-by: Anton Vorontsov <[email protected]>
---
drivers/mmc/core/core.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++
include/linux/mmc/core.h | 3 ++
2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 044d84e..d4afae8 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -20,6 +20,7 @@
#include <linux/err.h>
#include <linux/leds.h>
#include <linux/scatterlist.h>
+#include <linux/log2.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
@@ -444,6 +445,60 @@ void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
mmc_set_ios(host);
}
+static int mmc_vdd_to_ocrbit(int vdd)
+{
+ int bit;
+ const int max_bit = ilog2(MMC_VDD_35_36);
+
+ if (vdd < 1650 || vdd > 3600)
+ return -EINVAL;
+
+ if (vdd >= 1650 && vdd <= 1950)
+ return ilog2(MMC_VDD_165_195);
+
+ /* base 2000 mV, step 100 mV, bit's base 8 */
+ bit = (vdd - 2000) / 100 + 8;
+ if (bit > max_bit)
+ return max_bit;
+ return bit;
+}
+
+/**
+ * mmc_vddrange_to_ocrmask - Convert a voltage range to the OCR mask
+ * @vdd_min: minimum voltage value (mV)
+ * @vdd_max: maximum voltage value (mV)
+ * @mask: pointer to the mask
+ *
+ * This function sets the OCR mask bits according to the provided @vdd_min
+ * and @vdd_max values.
+ *
+ * NOTE: You _must_ set the mask value to 0 before calling this function the
+ * first time. This is done so that you can call this function several
+ * times to set OCR mask for discontinuous voltage ranges.
+ *
+ * The function returns 0 on success and a negative errno value when
+ * a conversion is not possible.
+ */
+int mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max, unsigned int *mask)
+{
+ if (vdd_max < vdd_min)
+ return -EINVAL;
+
+ vdd_max = mmc_vdd_to_ocrbit(vdd_max);
+ if (vdd_max < 0)
+ return -EINVAL;
+
+ vdd_min = mmc_vdd_to_ocrbit(vdd_min);
+ if (vdd_min < 0)
+ return -EINVAL;
+
+ /* fill the mask, from max bit to min bit */
+ while (vdd_max >= vdd_min)
+ *mask |= 1 << vdd_max--;
+ return 0;
+}
+EXPORT_SYMBOL(mmc_vddrange_to_ocrmask);
+
/*
* Mask off any voltages we don't support and select
* the lowest voltage
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 143cebf..3b139b0 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -151,4 +151,7 @@ static inline void mmc_claim_host(struct mmc_host *host)
__mmc_claim_host(host, NULL);
}
+extern int mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max,
+ unsigned int *mask);
+
#endif
--
1.5.6.3
The support is implemented via platform data accessors, new module
(of_mmc_spi) will be created automatically when the driver compiles
on OpenFirmware platforms. Link-time dependency will load the module
automatically.
Signed-off-by: Anton Vorontsov <[email protected]>
---
drivers/mmc/host/Makefile | 3 +
drivers/mmc/host/mmc_spi.c | 4 +-
drivers/mmc/host/of_mmc_spi.c | 147 +++++++++++++++++++++++++++++++++++++++++
include/linux/spi/mmc_spi.h | 8 ++
4 files changed, 161 insertions(+), 1 deletions(-)
create mode 100644 drivers/mmc/host/of_mmc_spi.c
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index c794cc5..f485328 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -19,6 +19,9 @@ obj-$(CONFIG_MMC_AT91) += at91_mci.o
obj-$(CONFIG_MMC_ATMELMCI) += atmel-mci.o
obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
obj-$(CONFIG_MMC_SPI) += mmc_spi.o
+ifeq ($(CONFIG_OF),y)
+obj-$(CONFIG_MMC_SPI) += of_mmc_spi.o
+endif
obj-$(CONFIG_MMC_S3C) += s3cmci.o
obj-$(CONFIG_MMC_SDRICOH_CS) += sdricoh_cs.o
obj-$(CONFIG_MMC_TMIO) += tmio_mmc.o
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 07faf54..416a0e3 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1285,7 +1285,7 @@ static int mmc_spi_probe(struct spi_device *spi)
/* Platform data is used to hook up things like card sensing
* and power switching gpios.
*/
- host->pdata = spi->dev.platform_data;
+ host->pdata = mmc_spi_get_pdata(spi);
if (host->pdata)
mmc->ocr_avail = host->pdata->ocr_mask;
if (!mmc->ocr_avail) {
@@ -1368,6 +1368,7 @@ fail_glue_init:
fail_nobuf1:
mmc_free_host(mmc);
+ mmc_spi_put_pdata(spi);
dev_set_drvdata(&spi->dev, NULL);
nomem:
@@ -1402,6 +1403,7 @@ static int __devexit mmc_spi_remove(struct spi_device *spi)
spi->max_speed_hz = mmc->f_max;
mmc_free_host(mmc);
+ mmc_spi_put_pdata(spi);
dev_set_drvdata(&spi->dev, NULL);
}
return 0;
diff --git a/drivers/mmc/host/of_mmc_spi.c b/drivers/mmc/host/of_mmc_spi.c
new file mode 100644
index 0000000..b5e5555
--- /dev/null
+++ b/drivers/mmc/host/of_mmc_spi.c
@@ -0,0 +1,147 @@
+/*
+ * OpenFirmware bindings for the MMC-over-SPI driver
+ *
+ * Copyright (c) MontaVista Software, Inc. 2008.
+ *
+ * Author: Anton Vorontsov <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/gpio.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/mmc_spi.h>
+#include <linux/mmc/core.h>
+#include <linux/mmc/host.h>
+
+enum {
+ CD_GPIO = 0,
+ WP_GPIO,
+ NUM_GPIOS,
+};
+
+struct of_mmc_spi {
+ int gpios[NUM_GPIOS];
+ bool alow_gpios[NUM_GPIOS];
+ struct mmc_spi_platform_data pdata;
+};
+
+static struct of_mmc_spi *to_of_mmc_spi(struct device *dev)
+{
+ return container_of(dev->platform_data, struct of_mmc_spi, pdata);
+}
+
+static int of_mmc_spi_read_gpio(struct device *dev, int gpio_num)
+{
+ struct of_mmc_spi *oms = to_of_mmc_spi(dev);
+ const bool active_low = oms->alow_gpios[gpio_num];
+ const bool value = gpio_get_value(oms->gpios[gpio_num]);
+
+ return active_low ^ value;
+}
+
+static int of_mmc_spi_get_cd(struct device *dev)
+{
+ return of_mmc_spi_read_gpio(dev, CD_GPIO);
+}
+
+static int of_mmc_spi_get_ro(struct device *dev)
+{
+ return of_mmc_spi_read_gpio(dev, WP_GPIO);
+}
+
+struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi)
+{
+ struct device *dev = &spi->dev;
+ struct device_node *np = dev_archdata_get_node(&dev->archdata);
+ struct of_mmc_spi *oms;
+ const u32 *voltage_ranges;
+ int num_ranges;
+ int i;
+ int ret = -EINVAL;
+
+ if (dev->platform_data || !np)
+ return dev->platform_data;
+
+ oms = kzalloc(sizeof(*oms), GFP_KERNEL);
+ 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");
+ goto err_ocr;
+ }
+
+ for (i = 0; i < num_ranges; i++) {
+ const int j = i * 2;
+
+ ret = mmc_vddrange_to_ocrmask(voltage_ranges[j],
+ voltage_ranges[j + 1],
+ &oms->pdata.ocr_mask);
+ if (ret) {
+ dev_err(dev, "OF: voltage-range #%d is invalid\n", i);
+ goto err_ocr;
+ }
+ }
+
+ for (i = 0; i < ARRAY_SIZE(oms->gpios); i++) {
+ enum of_gpio_flags gpio_flags;
+
+ oms->gpios[i] = of_get_gpio(np, i, &gpio_flags);
+ if (!gpio_is_valid(oms->gpios[i]))
+ continue;
+
+ ret = gpio_request(oms->gpios[i], dev->bus_id);
+ if (ret < 0) {
+ oms->gpios[i] = -EINVAL;
+ continue;
+ }
+
+ if (gpio_flags & OF_GPIO_ACTIVE_LOW)
+ oms->alow_gpios[i] = true;
+ }
+
+ if (gpio_is_valid(oms->gpios[CD_GPIO]))
+ oms->pdata.get_cd = of_mmc_spi_get_cd;
+ if (gpio_is_valid(oms->gpios[CD_GPIO]))
+ oms->pdata.get_ro = of_mmc_spi_get_ro;
+
+ /* We don't support interrupts yet, let's poll. */
+ oms->pdata.caps |= MMC_CAP_NEEDS_POLL;
+
+ dev->platform_data = &oms->pdata;
+ return dev->platform_data;
+err_ocr:
+ kfree(oms);
+ return NULL;
+}
+EXPORT_SYMBOL(mmc_spi_get_pdata);
+
+void mmc_spi_put_pdata(struct spi_device *spi)
+{
+ struct device *dev = &spi->dev;
+ struct device_node *np = dev_archdata_get_node(&dev->archdata);
+ struct of_mmc_spi *oms = to_of_mmc_spi(dev);
+ int i;
+
+ if (!dev->platform_data || !np)
+ return;
+
+ for (i = 0; i < ARRAY_SIZE(oms->gpios); i++) {
+ if (gpio_is_valid(oms->gpios[i]))
+ gpio_free(oms->gpios[i]);
+ }
+ kfree(oms);
+ dev->platform_data = NULL;
+}
+EXPORT_SYMBOL(mmc_spi_put_pdata);
diff --git a/include/linux/spi/mmc_spi.h b/include/linux/spi/mmc_spi.h
index a3626ae..87ee555 100644
--- a/include/linux/spi/mmc_spi.h
+++ b/include/linux/spi/mmc_spi.h
@@ -41,4 +41,12 @@ struct mmc_spi_platform_data {
void (*setpower)(struct device *, unsigned int maskval);
};
+#ifdef CONFIG_OF
+extern struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi);
+extern void mmc_spi_put_pdata(struct spi_device *spi);
+#else
+#define mmc_spi_get_pdata(spi) ((spi)->dev.platform_data)
+#define mmc_spi_put_pdata(spi)
+#endif /* CONFIG_OF */
+
#endif /* __LINUX_SPI_MMC_SPI_H */
--
1.5.6.3
On Thu, Oct 30, 2008 at 1:56 PM, Anton Vorontsov
<[email protected]> wrote:
> The bindings describes a case where MMC/SD/SDIO slot directly connected
> to a SPI bus. Such setups are widely used on embedded PowerPC boards.
>
> The patch also adds the mmc-spi-slot entry to the OpenFirmware modalias
> table.
>
> Signed-off-by: Anton Vorontsov <[email protected]>
Mostly looks good to me. A few comments below.
> ---
> .../powerpc/dts-bindings/mmc-spi-slot.txt | 23 ++++++++++++++++++++
> drivers/of/base.c | 1 +
> 2 files changed, 24 insertions(+), 0 deletions(-)
> create mode 100644 Documentation/powerpc/dts-bindings/mmc-spi-slot.txt
>
> diff --git a/Documentation/powerpc/dts-bindings/mmc-spi-slot.txt b/Documentation/powerpc/dts-bindings/mmc-spi-slot.txt
> new file mode 100644
> index 0000000..c39ac28
> --- /dev/null
> +++ b/Documentation/powerpc/dts-bindings/mmc-spi-slot.txt
> @@ -0,0 +1,23 @@
> +MMC/SD/SDIO slot directly connected to a SPI bus
> +
> +Required properties:
> +- compatible : should be "mmc-spi-slot".
> +- reg : should specify SPI address (chip-select number).
> +- spi-max-frequency : maximum frequency for this device (Hz).
> +- 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.
> +- gpios : (optional) may specify GPIOs in this order: Card-Detect GPIO,
> + Write-Protect GPIO.
I wonder if we're following the example of irq mappings too closely
for the gpios property. I like the layout of the property
(<controller> <specifier>), but I think the 'gpios' name is getting
too overloaded. In this case a single property 'gpios' is being used
to encode 2 unrelated bits of information; the write protect pin and
the card detect pins.
In this particular case I think it is better to use 2 properties in
this case; something like 'spi-writeprotect-gpio' and
'spi-carddetect-gpio' using the same specifier format. Doing so adds
a bit more clarity to the purpose of the properties.
I my mind I differentiate this from other examples (for instance a
series of CS pins) based on how closely related the pin functions are.
So I would say for the following examples...
1) GPIO data bus (SPI, MDIO and I2C are great examples); all pins must
be present - single gpio property
2) This MMC case (pins are optional and unrelated); separate gpio properties
3) LCD with backlight and contrast control pins; one gpio property for
backlight pins, one for constrast pins.
Thoughts?
> +
> +Example:
> +
> + mmc-slot@0 {
> + compatible = "fsl,mpc8323rdb-mmc-slot",
> + "mmc-spi-slot";
> + reg = <0>;
> + gpios = <&qe_pio_d 14 1
> + &qe_pio_d 15 0>;
> + voltage-ranges = <3300 3300>;
> + spi-max-frequency = <50000000>;
> + };
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 7c79e94..c6797ca 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -411,6 +411,7 @@ struct of_modalias_table {
> };
> static struct of_modalias_table of_modalias_table[] = {
> { "fsl,mcu-mpc8349emitx", "mcu-mpc8349emitx" },
> + { "mmc-spi-slot", "mmc_spi" },
> };
>
> /**
> --
> 1.5.6.3
>
>
--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
On Thu, Oct 30, 2008 at 02:37:31PM -0600, Grant Likely wrote:
[...]
> > +- gpios : (optional) may specify GPIOs in this order: Card-Detect GPIO,
> > + Write-Protect GPIO.
>
> I wonder if we're following the example of irq mappings too closely
> for the gpios property. I like the layout of the property
> (<controller> <specifier>), but I think the 'gpios' name is getting
> too overloaded. In this case a single property 'gpios' is being used
> to encode 2 unrelated bits of information; the write protect pin and
> the card detect pins.
>
> In this particular case I think it is better to use 2 properties in
> this case; something like 'spi-writeprotect-gpio' and
> 'spi-carddetect-gpio' using the same specifier format. Doing so adds
> a bit more clarity to the purpose of the properties.
>
> I my mind I differentiate this from other examples (for instance a
> series of CS pins) based on how closely related the pin functions are.
> So I would say for the following examples...
> 1) GPIO data bus (SPI, MDIO and I2C are great examples); all pins must
> be present - single gpio property
> 2) This MMC case (pins are optional and unrelated); separate gpio properties
> 3) LCD with backlight and contrast control pins; one gpio property for
> backlight pins, one for constrast pins.
>
> Thoughts?
It's pretty trivial to implement (of_get_named_gpio() -- could be just
factored out of of_get_gpio()).
Though,
1. The idea is quite extreme. It needs discussion, and furthermore,
we need to define when do we use gpios = <> and when something-gpio =
<>; We need to be consistent, and to be consistent, the rules should
be clear and written.
2. We should think about it very very carefully. Do we want to lose the
track of gpios? For example, there are quite defined rules when (and
in what properties) you may encounter memory addresses, when and
where you can encounter interrupt specifiers. We do the same for
gpios, and so far it works great. We need to think about any possible
drawbacks of the scheme you purpose (we would never know where to
expect gpios - it isn't a problem per se, but maybe it could lead
to some problem in future? I don't know.)
Quite honestly I don't like the idea... maybe I just used to
interrupts = <>, reg = <>, ranges = <>, interrupt-map = <> and so
forth, and now my subconsciousness tells me "it's wrong to do
something-interrupt = <> stuff." ;-)
Anyway, your proposal is forward and backward compatible with the
existing scheme, and can even coexist. Thus I'd prefer to stay with
the today's gpios = <>. We can always start use the new scheme when
it will be thought out enough.
Thanks,
p.s. I'd prefer a new thread for this discussion, somewhere
in [email protected], so that it won't relate to this
particular patch.
--
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
On Fri, Oct 31, 2008 at 02:02:53AM +0300, Anton Vorontsov wrote:
[...]
> It's pretty trivial to implement (of_get_named_gpio() -- could be just
> factored out of of_get_gpio()).
>
> Though,
>
> 1. The idea is quite extreme. It needs discussion, and furthermore,
> we need to define when do we use gpios = <> and when something-gpio =
> <>; We need to be consistent, and to be consistent, the rules should
> be clear and written.
>
> 2. We should think about it very very carefully. Do we want to lose the
> track of gpios? For example, there are quite defined rules when (and
> in what properties) you may encounter memory addresses, when and
> where you can encounter interrupt specifiers. We do the same for
> gpios, and so far it works great. We need to think about any possible
> drawbacks of the scheme you purpose (we would never know where to
> expect gpios - it isn't a problem per se, but maybe it could lead
> to some problem in future? I don't know.)
>
> Quite honestly I don't like the idea... maybe I just used to
> interrupts = <>, reg = <>, ranges = <>, interrupt-map = <> and so
> forth, and now my subconsciousness tells me "it's wrong to do
> something-interrupt = <> stuff." ;-)
Btw, not that I hate this new scheme, sometimes the scheme is even
inevitable. For example when we have gpios with two or more ellipsis:
gpios = <... ...>.
But this should be a separate discussion, really.
--
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
On Fri, Oct 31, 2008 at 02:02:53AM +0300, Anton Vorontsov wrote:
> On Thu, Oct 30, 2008 at 02:37:31PM -0600, Grant Likely wrote:
> [...]
> > > +- gpios : (optional) may specify GPIOs in this order: Card-Detect GPIO,
> > > + Write-Protect GPIO.
> >
> > I wonder if we're following the example of irq mappings too closely
> > for the gpios property. I like the layout of the property
> > (<controller> <specifier>), but I think the 'gpios' name is getting
> > too overloaded. In this case a single property 'gpios' is being used
> > to encode 2 unrelated bits of information; the write protect pin and
> > the card detect pins.
> >
> > In this particular case I think it is better to use 2 properties in
> > this case; something like 'spi-writeprotect-gpio' and
> > 'spi-carddetect-gpio' using the same specifier format. Doing so adds
> > a bit more clarity to the purpose of the properties.
> >
> > I my mind I differentiate this from other examples (for instance a
> > series of CS pins) based on how closely related the pin functions are.
> > So I would say for the following examples...
> > 1) GPIO data bus (SPI, MDIO and I2C are great examples); all pins must
> > be present - single gpio property
> > 2) This MMC case (pins are optional and unrelated); separate gpio properties
> > 3) LCD with backlight and contrast control pins; one gpio property for
> > backlight pins, one for constrast pins.
> >
> > Thoughts?
>
> It's pretty trivial to implement (of_get_named_gpio() -- could be just
> factored out of of_get_gpio()).
>
> Though,
>
> 1. The idea is quite extreme. It needs discussion, and furthermore,
> we need to define when do we use gpios = <> and when something-gpio =
> <>; We need to be consistent, and to be consistent, the rules should
> be clear and written.
>
> 2. We should think about it very very carefully. Do we want to lose the
> track of gpios? For example, there are quite defined rules when (and
> in what properties) you may encounter memory addresses, when and
> where you can encounter interrupt specifiers. We do the same for
> gpios, and so far it works great. We need to think about any possible
> drawbacks of the scheme you purpose (we would never know where to
> expect gpios - it isn't a problem per se, but maybe it could lead
> to some problem in future? I don't know.)
>
> Quite honestly I don't like the idea... maybe I just used to
> interrupts = <>, reg = <>, ranges = <>, interrupt-map = <> and so
> forth, and now my subconsciousness tells me "it's wrong to do
> something-interrupt = <> stuff." ;-)
Fwiw, I agree. The current scheme works, adding new places to look
for gpio specifiers will just complexify things. Long lists of gpios
may be somewhat awkward to work with, but I don't think it's
sufficiently bad to warrant another scheme.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
On Thu, 30 Oct 2008 22:55:46 +0300
Anton Vorontsov <[email protected]> wrote:
>
> Pierre, the approach is somewhat similar to this one:
> http://lkml.org/lkml/2008/5/26/135
> Posted few months ago.
>
> I know you don't like it, but I ask you to reconsider it. The
> I2C and SPI cases are similar, and recently we tried to write
> bindings for some I2C GPIO controllers.
>
This new version is a bit better in that you've generalised thing more.
I'd still prefer if we can have an interface where the driver doesn't
have to know that it is on an ACPI/OF/EFI/whatnot host, but I can live
with this model for now.
Rgds
--
-- Pierre Ossman
Linux kernel, MMC maintainer http://www.kernel.org
rdesktop, core developer http://www.rdesktop.org
WARNING: This correspondence is being monitored by the
Swedish government. Make sure your server uses encryption
for SMTP traffic and consider using PGP for end-to-end
encryption.
On Thu, 30 Oct 2008 22:56:32 +0300
Anton Vorontsov <[email protected]> wrote:
> +/**
> + * mmc_vddrange_to_ocrmask - Convert a voltage range to the OCR mask
> + * @vdd_min: minimum voltage value (mV)
> + * @vdd_max: maximum voltage value (mV)
> + * @mask: pointer to the mask
> + *
Why the pointer? Why not let the caller handle the aggregation? That
would be a lot safer.
> + /* fill the mask, from max bit to min bit */
> + while (vdd_max >= vdd_min)
> + *mask |= 1 << vdd_max--;
> + return 0;
Many cards get a bit uppity with a single bit set. If possible, try to
make this function set two bits when the voltage is right on the
boundary (e.g. 3.3V).
Rgds
--
-- Pierre Ossman
Linux kernel, MMC maintainer http://www.kernel.org
rdesktop, core developer http://www.rdesktop.org
WARNING: This correspondence is being monitored by the
Swedish government. Make sure your server uses encryption
for SMTP traffic and consider using PGP for end-to-end
encryption.
This function sets the OCR mask bits according to provided voltage
ranges. Will be used by the mmc_spi OpenFirmware bindings.
Signed-off-by: Anton Vorontsov <[email protected]>
---
Hi Pierre,
Sorry for the delay.
On Sat, Nov 08, 2008 at 09:55:37PM +0100, Pierre Ossman wrote:
> On Thu, 30 Oct 2008 22:56:32 +0300
> Anton Vorontsov <[email protected]> wrote:
>
> > +/**
> > + * mmc_vddrange_to_ocrmask - Convert a voltage range to the OCR mask
> > + * @vdd_min: minimum voltage value (mV)
> > + * @vdd_max: maximum voltage value (mV)
> > + * @mask: pointer to the mask
> > + *
>
> Why the pointer? Why not let the caller handle the aggregation? That
> would be a lot safer.
Yeah, makes sense. Now the function returns OCR mask, or 0 on error.
> > + /* fill the mask, from max bit to min bit */
> > + while (vdd_max >= vdd_min)
> > + *mask |= 1 << vdd_max--;
> > + return 0;
>
> Many cards get a bit uppity with a single bit set. If possible, try to
> make this function set two bits when the voltage is right on the
> boundary (e.g. 3.3V).
Something like this patch (the boundary cases are documented now)?
p.s. If the patch is OK I'll respin the whole patchset.
drivers/mmc/core/core.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++
include/linux/mmc/core.h | 2 +
2 files changed, 77 insertions(+), 0 deletions(-)
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 044d84e..1673765 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -20,6 +20,7 @@
#include <linux/err.h>
#include <linux/leds.h>
#include <linux/scatterlist.h>
+#include <linux/log2.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
@@ -444,6 +445,80 @@ void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
mmc_set_ios(host);
}
+/**
+ * mmc_vdd_to_ocrbitnum - Convert a voltage to the OCR bit number
+ * @vdd: voltage (mV)
+ * @low_bits: prefer low bits in boundary cases
+ *
+ * This function returns the OCR bit number according to the provided @vdd
+ * value. If conversion is not possible a negative errno value returned.
+ *
+ * Depending on the @low_bits flag the function prefers low or high OCR bits
+ * on boundary voltages. For example,
+ * with @low_bits = true, 3300 mV translates to ilog2(MMC_VDD_32_33);
+ * with @low_bits = false, 3300 mV translates to ilog2(MMC_VDD_33_34);
+ *
+ * Any value in the [1951:1999] range translates to the ilog2(MMC_VDD_20_21).
+ */
+static int mmc_vdd_to_ocrbitnum(int vdd, bool low_bits)
+{
+ const int max_bit = ilog2(MMC_VDD_35_36);
+ int bit;
+
+ if (vdd < 1650 || vdd > 3600)
+ return -EINVAL;
+
+ if (vdd >= 1650 && vdd <= 1950)
+ return ilog2(MMC_VDD_165_195);
+
+ if (low_bits)
+ vdd -= 1;
+
+ /* Base 2000 mV, step 100 mV, bit's base 8. */
+ bit = (vdd - 2000) / 100 + 8;
+ if (bit > max_bit)
+ return max_bit;
+ return bit;
+}
+
+/**
+ * mmc_vddrange_to_ocrmask - Convert a voltage range to the OCR mask
+ * @vdd_min: minimum voltage value (mV)
+ * @vdd_max: maximum voltage value (mV)
+ *
+ * This function returns the OCR mask bits according to the provided @vdd_min
+ * and @vdd_max values. If conversion is not possible the function returns 0.
+ *
+ * Notes wrt boundary cases:
+ * This function sets the OCR bits for all boundary voltages, for example
+ * [3300:3400] range is translated to MMC_VDD_32_33 | MMC_VDD_33_34 |
+ * MMC_VDD_34_35 mask.
+ */
+u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max)
+{
+ u32 mask = 0;
+
+ if (vdd_max < vdd_min)
+ return 0;
+
+ /* Prefer high bits for the boundary vdd_max values. */
+ vdd_max = mmc_vdd_to_ocrbitnum(vdd_max, false);
+ if (vdd_max < 0)
+ return 0;
+
+ /* Prefer low bits for the boundary vdd_min values. */
+ vdd_min = mmc_vdd_to_ocrbitnum(vdd_min, true);
+ if (vdd_min < 0)
+ return 0;
+
+ /* Fill the mask, from max bit to min bit. */
+ while (vdd_max >= vdd_min)
+ mask |= 1 << vdd_max--;
+
+ return mask;
+}
+EXPORT_SYMBOL(mmc_vddrange_to_ocrmask);
+
/*
* Mask off any voltages we don't support and select
* the lowest voltage
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 143cebf..7ac8b50 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -151,4 +151,6 @@ static inline void mmc_claim_host(struct mmc_host *host)
__mmc_claim_host(host, NULL);
}
+extern u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max);
+
#endif
--
1.5.6.5
On Wed, 26 Nov 2008 22:54:17 +0300
Anton Vorontsov <[email protected]> wrote:
> This function sets the OCR mask bits according to provided voltage
> ranges. Will be used by the mmc_spi OpenFirmware bindings.
>
> Signed-off-by: Anton Vorontsov <[email protected]>
> ---
>
> Hi Pierre,
>
> Sorry for the delay.
>
This looks perfect. Just tell me when you want me to queue it up.
Rgds
--
-- Pierre Ossman
Linux kernel, MMC maintainer http://www.kernel.org
rdesktop, core developer http://www.rdesktop.org
WARNING: This correspondence is being monitored by the
Swedish government. Make sure your server uses encryption
for SMTP traffic and consider using PGP for end-to-end
encryption.
On Sun, Nov 30, 2008 at 09:06:48PM +0100, Pierre Ossman wrote:
> On Wed, 26 Nov 2008 22:54:17 +0300
> Anton Vorontsov <[email protected]> wrote:
>
> > This function sets the OCR mask bits according to provided voltage
> > ranges. Will be used by the mmc_spi OpenFirmware bindings.
> >
> > Signed-off-by: Anton Vorontsov <[email protected]>
> > ---
> >
> > Hi Pierre,
> >
> > Sorry for the delay.
> >
>
> This looks perfect. Just tell me when you want me to queue it up.
I plan resend the series (OF MMC SPI) some time between 2.6.28-rc0
and -rc1, that is, when all needed powerpc patches will be merged
into the Linus' tree.
Though, the $subject patch could be merged anytime as it doesn't
depend on anything else. So, if you'll merge it earlier, that will
make things a bit easier: -1 patch to resend. ;-)
Thanks,
--
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
On Mon, 1 Dec 2008 14:53:20 +0300
Anton Vorontsov <[email protected]> wrote:
>
> Though, the $subject patch could be merged anytime as it doesn't
> depend on anything else. So, if you'll merge it earlier, that will
> make things a bit easier: -1 patch to resend. ;-)
>
Queued up. Will be sent once the merge window opens up.
Rgds
--
-- Pierre Ossman
Linux kernel, MMC maintainer http://www.kernel.org
rdesktop, core developer http://www.rdesktop.org
WARNING: This correspondence is being monitored by the
Swedish government. Make sure your server uses encryption
for SMTP traffic and consider using PGP for end-to-end
encryption.