diff mbox

[2/2] extcon: gpio: Add dt support for the driver.

Message ID 1402977500-19987-3-git-send-email-george.cherian@ti.com
State Superseded, archived
Headers show

Commit Message

George Cherian June 17, 2014, 3:58 a.m. UTC
Add device tree support to extcon-gpio driver.
Add devicetree binding documentation

Signed-off-by: George Cherian <george.cherian@ti.com>
---
 .../devicetree/bindings/extcon/extcon-gpio.txt     | 34 ++++++++++++++++++++++
 drivers/extcon/extcon-gpio.c                       | 29 ++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt

Comments

Mark Rutland June 17, 2014, 3:57 p.m. UTC | #1
On Tue, Jun 17, 2014 at 04:58:20AM +0100, George Cherian wrote:
> Add device tree support to extcon-gpio driver.
> Add devicetree binding documentation
> 
> Signed-off-by: George Cherian <george.cherian@ti.com>
> ---
>  .../devicetree/bindings/extcon/extcon-gpio.txt     | 34 ++++++++++++++++++++++
>  drivers/extcon/extcon-gpio.c                       | 29 ++++++++++++++++++
>  2 files changed, 63 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> 
> diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> new file mode 100644
> index 0000000..80b791b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> @@ -0,0 +1,34 @@
> +GPIO based EXTCON
> +
> +EXTCON GPIO
> +-----------
> +
> +Required Properties:
> + - compatible: should be:
> +   * "ti,extcon-gpio"
> + - gpios: specifies the gpio pin used.
> + - debounce: Debounce time for GPIO IRQ in ms
> + - irq-flags: IRQ flag to be used ( eg: IRQ_TYPE_EDGE_FALLING)

This looks distinctly odd. Why do you need this here?

> +Optional Properties:
> + - gpio-active-low: Property describing whether gpio active state is 1 or 0
> +		    If defined , low state of gpio means active.

Surely this is defined in the gpio flags?

> + - check-on-resume: Property describing whether to check the gpio state
> +		    while resuming from SLEEP.

Does this need to be in DT? Surely we could jsut always check this?

> + - state-on: print_state is overriden with state_on string if provided.
> +	     If NULL, default method of extcon class is used.
> + - state_off: print_state is overriden with state_off string  if provided.
> +	      If NUll, default method of extcon class is used.

This means nothing from a HW perspective. This describes linux internal
details.

[...]

> +		of_property_read_u32(np, "debounce", (u32 *)&pdata->debounce);
> +		of_property_read_u32(np, "irq-flags", (u32 *)&pdata->irq_flags);

If you need theses casts, the code is broken.

These functions can only read into a u32. If you pass a smaller type
you'll trash aribtrary memory locations, and if you pass a larger type
this is broken for BE.

Mark.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
George Cherian June 19, 2014, 3:30 a.m. UTC | #2
On 6/17/2014 9:27 PM, Mark Rutland wrote:
> On Tue, Jun 17, 2014 at 04:58:20AM +0100, George Cherian wrote:
>> Add device tree support to extcon-gpio driver.
>> Add devicetree binding documentation
>>
>> Signed-off-by: George Cherian <george.cherian@ti.com>
>> ---
>>   .../devicetree/bindings/extcon/extcon-gpio.txt     | 34 ++++++++++++++++++++++
>>   drivers/extcon/extcon-gpio.c                       | 29 ++++++++++++++++++
>>   2 files changed, 63 insertions(+)
>>   create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt
>>
>> diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
>> new file mode 100644
>> index 0000000..80b791b
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
>> @@ -0,0 +1,34 @@
>> +GPIO based EXTCON
>> +
>> +EXTCON GPIO
>> +-----------
>> +
>> +Required Properties:
>> + - compatible: should be:
>> +   * "ti,extcon-gpio"
>> + - gpios: specifies the gpio pin used.
>> + - debounce: Debounce time for GPIO IRQ in ms
>> + - irq-flags: IRQ flag to be used ( eg: IRQ_TYPE_EDGE_FALLING)
> This looks distinctly odd. Why do you need this here?
The driver takes this as part of platform data. It never continues 
operation if
an invalid irq-flag is supplied. Also these can be used for different SoC's
whose GPIO's might support IRQ_TYPE_EDGE_FALLING/RISING.
Now since this is based on gpio we cant up front give a seperate
"interrupts = " property, since we dont know the gpio-pin irq number.

Chanwoo any comments?
>
>> +Optional Properties:
>> + - gpio-active-low: Property describing whether gpio active state is 1 or 0
>> +		    If defined , low state of gpio means active.
> Surely this is defined in the gpio flags?

Yes, I will make necessary changes.
>
>> + - check-on-resume: Property describing whether to check the gpio state
>> +		    while resuming from SLEEP.
> Does this need to be in DT? Surely we could jsut always check this?
okay. For my use-case I dont need this.
Chanwoo, any comments?
>> + - state-on: print_state is overriden with state_on string if provided.
>> +	     If NULL, default method of extcon class is used.
>> + - state_off: print_state is overriden with state_off string  if provided.
>> +	      If NUll, default method of extcon class is used.
> This means nothing from a HW perspective. This describes linux internal
> details.
You mean to say this should not be part of dt?

> [...]
>
>> +		of_property_read_u32(np, "debounce", (u32 *)&pdata->debounce);
>> +		of_property_read_u32(np, "irq-flags", (u32 *)&pdata->irq_flags);
> If you need theses casts, the code is broken.
I dont need this, will remove in v2.
>
> These functions can only read into a u32. If you pass a smaller type
> you'll trash aribtrary memory locations, and if you pass a larger type
> this is broken for BE.
true.
> Mark.
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/extcon/extcon-gpio.txt b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
new file mode 100644
index 0000000..80b791b
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
@@ -0,0 +1,34 @@ 
+GPIO based EXTCON
+
+EXTCON GPIO
+-----------
+
+Required Properties:
+ - compatible: should be:
+   * "ti,extcon-gpio"
+ - gpios: specifies the gpio pin used.
+ - debounce: Debounce time for GPIO IRQ in ms
+ - irq-flags: IRQ flag to be used ( eg: IRQ_TYPE_EDGE_FALLING)
+
+Optional Properties:
+ - gpio-active-low: Property describing whether gpio active state is 1 or 0
+		    If defined , low state of gpio means active.
+ - check-on-resume: Property describing whether to check the gpio state
+		    while resuming from SLEEP.
+ - state-on: print_state is overriden with state_on string if provided.
+	     If NULL, default method of extcon class is used.
+ - state_off: print_state is overriden with state_off string  if provided.
+	      If NUll, default method of extcon class is used.
+
+Eg:
+
+        extcon1: am43_usbid_extcon1 {
+                compatible = "ti,extcon-gpio";
+                gpios = <&gpio3 12 GPIO_ACTIVE_HIGH>;
+                gpio-active-low;
+                debounce = <20>;
+                irq-flags = <IRQ_TYPE_EDGE_FALLING>;
+                state-on = "USB ID FLOAT";
+                state-off = "USB ID GND";
+
+        };
diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index 6c268b4..14d999d 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -27,6 +27,7 @@ 
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
@@ -83,12 +84,34 @@  static ssize_t extcon_gpio_print_state(struct extcon_dev *edev, char *buf)
 
 static int gpio_extcon_probe(struct platform_device *pdev)
 {
+	struct device_node *np = pdev->dev.of_node;
 	struct gpio_extcon_platform_data *pdata = dev_get_platdata(&pdev->dev);
 	struct gpio_extcon_data *extcon_data;
 	int ret;
 
+	if (np) {
+		pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+		if (!pdata)
+			return -ENOMEM;
+
+		pdata->gpio = of_get_gpio(np, 0);
+		if (!gpio_is_valid(pdata->gpio))
+			return -EPROBE_DEFER;
+
+		pdata->name = np->name;
+		pdata->gpio_active_low = of_property_read_bool(np,
+						"gpio-active-low");
+		pdata->check_on_resume = of_property_read_bool(np,
+						"check-on-resume");
+		of_property_read_u32(np, "debounce", (u32 *)&pdata->debounce);
+		of_property_read_u32(np, "irq-flags", (u32 *)&pdata->irq_flags);
+		of_property_read_string(np, "state-on", &pdata->state_on);
+		of_property_read_string(np, "state-off", &pdata->state_off);
+	}
+
 	if (!pdata)
 		return -EBUSY;
+
 	if (!pdata->irq_flags) {
 		dev_err(&pdev->dev, "IRQ flag is not specified.\n");
 		return -EINVAL;
@@ -177,6 +200,11 @@  static int gpio_extcon_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops, NULL, gpio_extcon_resume);
 
+static struct of_device_id of_extcon_gpio_match_tbl[] = {
+	{ .compatible = "ti,extcon-gpio", },
+	{ /* end */ }
+};
+
 static struct platform_driver gpio_extcon_driver = {
 	.probe		= gpio_extcon_probe,
 	.remove		= gpio_extcon_remove,
@@ -184,6 +212,7 @@  static struct platform_driver gpio_extcon_driver = {
 		.name	= "extcon-gpio",
 		.owner	= THIS_MODULE,
 		.pm	= &gpio_extcon_pm_ops,
+		.of_match_table = of_extcon_gpio_match_tbl,
 	},
 };