new file mode 100644
@@ -0,0 +1,26 @@
+Davinci GPIO controller bindings
+
+Required Properties:
+- compatible:"ti,da830-gpio"
+
+- reg: Physical base address of the controller and length of memory mapped
+ region.
+
+- interrupts: The Starting IRQ number for GPIO
+
+- ngpio: The number of GPIO pins supported
+
+- intc_irq_num: The number of IRQs supported by the Interrupt Controller
+
+- gpio_unbanked: The number of GPIOs that have an individual interrupt
+ line to processor.
+
+Example:
+gpio: gpio@1e26000 {
+ compatible = "ti,da830-gpio";
+ reg = <0x226000 0x1000>;
+ interrupts = <42>;
+ ngpio = <144>;
+ intc_irq_num = <101>;
+ gpio_unbanked = <0>;
+};
@@ -19,6 +19,8 @@
#include <linux/irqdomain.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <linux/platform_data/gpio-davinci.h>
#include <mach/gpio-davinci.h>
@@ -133,6 +135,50 @@ static void davinci_gpio_set(struct gpio_chip *chip, unsigned offset,
__raw_writel((1 << offset), value ? ®s->set_data : ®s->clr_data);
}
+static struct davinci_gpio_platform_data *davinci_gpio_set_pdata_of(
+ struct platform_device *pdev)
+{
+ struct device_node *dn = pdev->dev.of_node;
+ struct davinci_gpio_platform_data *pdata;
+ u32 val, ret;
+
+ pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+ if (pdata) {
+ ret = of_property_read_u32(dn, "ngpio", &val);
+ if (ret)
+ goto of_err;
+
+ pdata->ngpio = val;
+
+ ret = of_property_read_u32(dn, "gpio_unbanked", &val);
+ if (ret)
+ goto of_err;
+
+ pdata->gpio_unbanked = val;
+
+ ret = of_property_read_u32(dn, "intc_irq_num", &val);
+ if (ret)
+ goto of_err;
+
+ pdata->intc_irq_num = val;
+ }
+
+ return pdata;
+
+of_err:
+ dev_err(&pdev->dev, "Populating pdata from DT failed: err %d\n", ret);
+ return NULL;
+}
+
+static const struct of_device_id davinci_gpio_ids[] = {
+ {
+ .compatible = "ti,da830-gpio",
+ },
+ { },
+};
+
+MODULE_DEVICE_TABLE(of, davinci_gpio_ids);
+
static int davinci_gpio_probe(struct platform_device *pdev)
{
int i, base;
@@ -142,13 +188,17 @@ static int davinci_gpio_probe(struct platform_device *pdev)
struct davinci_gpio_regs *regs;
struct device *dev = &pdev->dev;
struct resource *res;
+ const struct of_device_id *match =
+ of_match_device(of_match_ptr(davinci_gpio_ids), &pdev->dev);
- pdata = dev->platform_data;
+ pdata = match ? davinci_gpio_set_pdata_of(pdev) : dev->platform_data;
if (!pdata) {
dev_err(dev, "GPIO: No Platform Data Supplied\n");
return -EINVAL;
}
+ dev->platform_data = pdata;
+
/*
* The gpio banks conceptually expose a segmented bitmap,
* and "ngpio" is one more than the largest zero-based
@@ -490,8 +540,9 @@ done:
static struct platform_driver davinci_gpio_driver = {
.probe = davinci_gpio_probe,
.driver = {
- .name = "davinci_gpio",
- .owner = THIS_MODULE,
+ .name = "davinci_gpio",
+ .owner = THIS_MODULE,
+ .of_match_table = of_match_ptr(davinci_gpio_ids),
},
};