b/Documentation/devicetree/bindings/mmc/sdhci-spear.txt
new file mode 100644
@@ -0,0 +1,24 @@
+* SPEAr SDHCI Controller
+
+Required properties:
+- compatible : "st,spear300-sdhci"
+
+Optional Properties:
+- cd-gpios: card detect gpio, with zero flags.
+- power-gpios: specifies the power gpio pin with flags: active low:1, active
+ high:0
+- power-always-enb: power should be on before inserting the card and
so can't be
+ switched off. Only valid when power gpio is supported.
+
+If your board don't support these gpios then don't pass the entry.
+
+Example:
+
+ sdhci@fc000000 {
+ compatible = "st,spear300-sdhci";
+ reg = <0xfc000000 0x1000>;
+
+ power-gpios = <&gpio0 5 0>
+ power-always-enb;
+ cd-gpios = <&gpio0 6 0>
+ };
b/arch/arm/boot/dts/spear300-evb.dts
@@ -80,8 +80,8 @@
};
sdhci@70000000 {
- int-gpio = <&gpio1 0 0>;
- power-gpio = <&gpio1 2 1>;
+ cd-gpios = <&gpio1 0 0>;
+ power-gpios = <&gpio1 2 1>;
status = "okay";
};
b/arch/arm/boot/dts/spear320-evb.dts
@@ -103,8 +103,8 @@
};
sdhci@70000000 {
- power-gpio = <&gpio0 2 1>;
- power_always_enb;
+ power-gpios = <&gpio0 2 1>;
+ power-always-enb;
status = "okay";
};
@@ -20,6 +20,8 @@
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/pm.h>
#include <linux/slab.h>
@@ -68,8 +70,56 @@ static irqreturn_t sdhci_gpio_irq(int irq, void *dev_id)
return IRQ_HANDLED;
}
+#ifdef CONFIG_OF
+static struct sdhci_plat_data * __devinit
+sdhci_probe_config_dt(struct platform_device *pdev)
+{
+ struct device_node *np = pdev->dev.of_node;
+ struct sdhci_plat_data *pdata = NULL;
+ enum of_gpio_flags flags;
+ int pgpio, igpio;
+
+ pgpio = of_get_named_gpio_flags(np, "power-gpios", 0, &flags);
+ if (!gpio_is_valid(pgpio))
+ pgpio = -1;
+
+ igpio = of_get_named_gpio(np, "cd-gpios", 0);
+ if (!gpio_is_valid(igpio))
+ igpio = -1;
+
+ /* If pdata is required */
+ if ((pgpio != -1) || (igpio != -1)) {
+ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata) {
+ dev_err(&pdev->dev, "DT: kzalloc failed\n");
+ return ERR_PTR(-ENOMEM);
+ }
+ }
+
+ /* if power gpio is supported */
+ if (pgpio != -1) {
+ pdata->power_active_high = (flags != OF_GPIO_ACTIVE_LOW);
+
+ if (of_property_read_bool(np, "power-always-enb"))
+ pdata->power_always_enb = true;
+ }
+
+ pdata->card_power_gpio = pgpio;
+ pdata->card_int_gpio = igpio;
+
+ return pdata;
+}
+#else
+static struct sdhci_plat_data * __devinit
+sdhci_probe_config_dt(struct platform_device *pdev)
+{
+ return ERR_PTR(-ENOSYS);
+}
+#endif
+
static int __devinit sdhci_probe(struct platform_device *pdev)
{
+ struct device_node *np = pdev->dev.of_node;
struct sdhci_host *host;
struct resource *iomem;
struct spear_sdhci *sdhci;
@@ -110,8 +160,16 @@ static int __devinit sdhci_probe(struct
platform_device *pdev)
goto put_clk;
}
- /* overwrite platform_data */
- sdhci->data = dev_get_platdata(&pdev->dev);
+ if (np) {
+ sdhci->data = sdhci_probe_config_dt(pdev);
+ if (IS_ERR(sdhci->data)) {
+ dev_err(&pdev->dev, "DT: Failed to get pdata\n");
+ return -ENODEV;
+ }
+ } else {
+ sdhci->data = dev_get_platdata(&pdev->dev);
+ }
+
pdev->dev.platform_data = sdhci;