devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] extcon: gpio: add device tree support for extcon-gpio
@ 2016-05-03  5:49 Venkat Reddy Talla
  2016-05-03  5:49 ` [PATCH 2/2] extcon: gpio: add DT binding doc " Venkat Reddy Talla
  0 siblings, 1 reply; 4+ messages in thread
From: Venkat Reddy Talla @ 2016-05-03  5:49 UTC (permalink / raw)
  To: MyungJoo Ham, Chanwoo Choi, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Laxman Dewangan,
	Venkat Reddy Talla

Adding device tree support for extcon-gpio driver.

Signed-off-by: Venkat Reddy Talla <vreddytalla-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
---
 drivers/extcon/extcon-gpio.c       | 80 +++++++++++++++++++++++++++++++++++---
 include/linux/extcon/extcon-gpio.h |  2 +
 2 files changed, 76 insertions(+), 6 deletions(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index d023789..b7fae7e 100644
--- a/drivers/extcon/extcon-gpio.c
+++ b/drivers/extcon/extcon-gpio.c
@@ -28,6 +28,8 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 
 struct gpio_extcon_data {
 	struct extcon_dev *edev;
@@ -90,21 +92,79 @@ static int gpio_extcon_init(struct device *dev, struct gpio_extcon_data *data)
 	return 0;
 }
 
+static struct gpio_extcon_pdata *gpio_extcon_of_pdata(
+		struct platform_device *pdev)
+{
+	struct gpio_extcon_pdata *pdata;
+	struct device_node *np = pdev->dev.of_node;
+	int gpio;
+	u32 pval;
+	int ret;
+
+	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	gpio = of_get_named_gpio(np, "gpio", 0);
+	if (gpio < 0)
+		return ERR_PTR(gpio);
+
+	pdata->gpio = gpio;
+
+	ret = of_property_read_u32(np, "extcon-gpio,irq-flags", &pval);
+	if (!ret)
+		pdata->irq_flags = pval;
+	else
+		pdata->irq_flags = IRQF_TRIGGER_RISING |
+						IRQF_TRIGGER_FALLING;
+
+	ret = of_property_read_u32(np, "extcon-gpio,debounce", &pval);
+	if (!ret)
+		pdata->debounce = pval;
+
+	pdata->gpio_active_low = of_property_read_bool(np,
+				"extcon-gpio,connection-state-low");
+
+	pdata->extcon_cable_cnt = of_property_count_u32_elems(np,
+						"extcon-gpio,cable-names");
+	if (pdata->extcon_cable_cnt <= 0) {
+		dev_err(&pdev->dev, "not found out cable names\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	pdata->extcon_cable_names = devm_kzalloc(&pdev->dev,
+			(pdata->extcon_cable_cnt) *
+			sizeof(*pdata->extcon_cable_names), GFP_KERNEL);
+	if (!pdata->extcon_cable_names)
+		return ERR_PTR(-ENOMEM);
+
+	ret = of_property_read_u32_array(np, "extcon-gpio,cable-names",
+			pdata->extcon_cable_names, pdata->extcon_cable_cnt);
+	if (ret)
+		return ERR_PTR(-EINVAL);
+
+	return pdata;
+}
+
 static int gpio_extcon_probe(struct platform_device *pdev)
 {
 	struct gpio_extcon_pdata *pdata = dev_get_platdata(&pdev->dev);
 	struct gpio_extcon_data *data;
 	int ret;
 
-	if (!pdata)
-		return -EBUSY;
-	if (!pdata->irq_flags || pdata->extcon_id > EXTCON_NONE)
-		return -EINVAL;
-
 	data = devm_kzalloc(&pdev->dev, sizeof(struct gpio_extcon_data),
 				   GFP_KERNEL);
 	if (!data)
 		return -ENOMEM;
+
+	if (!pdata && pdev->dev.of_node)
+		pdata = gpio_extcon_of_pdata(pdev);
+
+	if (IS_ERR(pdata))
+		return PTR_ERR(pdata);
+	if (!pdata->irq_flags || !pdata->extcon_cable_names)
+		return -EINVAL;
+
 	data->pdata = pdata;
 
 	/* Initialize the gpio */
@@ -113,7 +173,8 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 		return ret;
 
 	/* Allocate the memory of extcon devie and register extcon device */
-	data->edev = devm_extcon_dev_allocate(&pdev->dev, &pdata->extcon_id);
+	data->edev = devm_extcon_dev_allocate(&pdev->dev,
+				pdata->extcon_cable_names);
 	if (IS_ERR(data->edev)) {
 		dev_err(&pdev->dev, "failed to allocate extcon device\n");
 		return -ENOMEM;
@@ -167,12 +228,19 @@ static int gpio_extcon_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops, NULL, gpio_extcon_resume);
 
+static const struct of_device_id of_extcon_gpio_tbl[] = {
+	{ .compatible = "extcon-gpio", },
+	{ /* end */ }
+};
+MODULE_DEVICE_TABLE(of, of_extcon_gpio_tbl);
+
 static struct platform_driver gpio_extcon_driver = {
 	.probe		= gpio_extcon_probe,
 	.remove		= gpio_extcon_remove,
 	.driver		= {
 		.name	= "extcon-gpio",
 		.pm	= &gpio_extcon_pm_ops,
+		.of_match_table = of_extcon_gpio_tbl,
 	},
 };
 
diff --git a/include/linux/extcon/extcon-gpio.h b/include/linux/extcon/extcon-gpio.h
index 7cacafb..c27df9b 100644
--- a/include/linux/extcon/extcon-gpio.h
+++ b/include/linux/extcon/extcon-gpio.h
@@ -36,6 +36,8 @@
  */
 struct gpio_extcon_pdata {
 	unsigned int extcon_id;
+	unsigned int *extcon_cable_names;
+	int extcon_cable_cnt;
 	unsigned gpio;
 	bool gpio_active_low;
 	unsigned long debounce;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] extcon: gpio: add DT binding doc for extcon-gpio
  2016-05-03  5:49 [PATCH 1/2] extcon: gpio: add device tree support for extcon-gpio Venkat Reddy Talla
@ 2016-05-03  5:49 ` Venkat Reddy Talla
       [not found]   ` <1462254591-8907-2-git-send-email-vreddytalla-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Venkat Reddy Talla @ 2016-05-03  5:49 UTC (permalink / raw)
  To: MyungJoo Ham, Chanwoo Choi, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala
  Cc: linux-kernel, devicetree, Laxman Dewangan, Venkat Reddy Talla

Addiing DT binding doc for the extcon gpios properties.

Signed-off-by: Venkat Reddy Talla <vreddytalla@nvidia.com>
---
 .../devicetree/bindings/extcon/extcon-gpio.txt        | 19 +++++++++++++++++++
 1 file changed, 19 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..4a49c23
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
@@ -0,0 +1,19 @@
+EXTCON FOR GPIO
+
+Required Properties:
+ - compatible : Should be "extcon-gpio";
+
+Optional Properties:
+ - extcon-gpio,name: Name of extcon device.
+ - gpio: gpio number.
+ - extcon-gpio,irq-flags: IRQ flags for GPIO.
+ - extcon-gpio,debounce: Debounce time in ms.
+ - extcon-gpio,connection-state-low: boolean, Connection state with
+                gpio state. True if gpio low means connected.
+
+extcon-gpio {
+	compatible = "extcon-gpio";
+        extcon-gpio,name = "VBUS";
+	gpio = <&gpio 20 0>;
+	extcon-gpio,cable-names = <EXTCON_USB EXTCON_NONE>;
+};
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] extcon: gpio: add DT binding doc for extcon-gpio
       [not found]   ` <1462254591-8907-2-git-send-email-vreddytalla-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2016-05-04 13:30     ` Rob Herring
  2016-05-17 11:27       ` Venkat Reddy Talla
  0 siblings, 1 reply; 4+ messages in thread
From: Rob Herring @ 2016-05-04 13:30 UTC (permalink / raw)
  To: Venkat Reddy Talla
  Cc: MyungJoo Ham, Chanwoo Choi, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, Laxman Dewangan

On Tue, May 03, 2016 at 11:19:51AM +0530, Venkat Reddy Talla wrote:
> Addiing DT binding doc for the extcon gpios properties.
> 
> Signed-off-by: Venkat Reddy Talla <vreddytalla-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> ---
>  .../devicetree/bindings/extcon/extcon-gpio.txt        | 19 +++++++++++++++++++
>  1 file changed, 19 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..4a49c23
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> @@ -0,0 +1,19 @@
> +EXTCON FOR GPIO

This needs a better description of what this is and what h/w this 
applies to.

> +
> +Required Properties:
> + - compatible : Should be "extcon-gpio";
> +
> +Optional Properties:
> + - extcon-gpio,name: Name of extcon device.
> + - gpio: gpio number.

Should be 'gpios'.

> + - extcon-gpio,irq-flags: IRQ flags for GPIO.

If this is an interrupt, then you should be using the interrupts 
property.

> + - extcon-gpio,debounce: Debounce time in ms.

extcon-gpio is not a vendor prefix, so drop it.

Add unit suffix (-ms).

> + - extcon-gpio,connection-state-low: boolean, Connection state with
> +                gpio state. True if gpio low means connected.

The active state should be in the GPIO flags cell.

> +
> +extcon-gpio {
> +	compatible = "extcon-gpio";
> +        extcon-gpio,name = "VBUS";

How is VBus a gpio?

> +	gpio = <&gpio 20 0>;
> +	extcon-gpio,cable-names = <EXTCON_USB EXTCON_NONE>;

Not documented.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH 2/2] extcon: gpio: add DT binding doc for extcon-gpio
  2016-05-04 13:30     ` Rob Herring
@ 2016-05-17 11:27       ` Venkat Reddy Talla
  0 siblings, 0 replies; 4+ messages in thread
From: Venkat Reddy Talla @ 2016-05-17 11:27 UTC (permalink / raw)
  To: Rob Herring
  Cc: MyungJoo Ham, Chanwoo Choi, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Laxman Dewangan

Thanks for review, please find my inline reply.

> -----Original Message-----
> From: Rob Herring [mailto:robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org]
> Sent: Wednesday, May 04, 2016 7:01 PM
> To: Venkat Reddy Talla
> Cc: MyungJoo Ham; Chanwoo Choi; Pawel Moll; Mark Rutland; Ian Campbell;
> Kumar Gala; linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org;
> Laxman Dewangan
> Subject: Re: [PATCH 2/2] extcon: gpio: add DT binding doc for extcon-gpio
> 
> On Tue, May 03, 2016 at 11:19:51AM +0530, Venkat Reddy Talla wrote:
> > Addiing DT binding doc for the extcon gpios properties.
> >
> > Signed-off-by: Venkat Reddy Talla <vreddytalla-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> > ---
> >  .../devicetree/bindings/extcon/extcon-gpio.txt        | 19
> +++++++++++++++++++
> >  1 file changed, 19 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..4a49c23
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> > @@ -0,0 +1,19 @@
> > +EXTCON FOR GPIO
> 
> This needs a better description of what this is and what h/w this applies to.
> 
I will take care in my next patch.

> > +
> > +Required Properties:
> > + - compatible : Should be "extcon-gpio";
> > +
> > +Optional Properties:
> > + - extcon-gpio,name: Name of extcon device.
> > + - gpio: gpio number.
> 
> Should be 'gpios'.
> 
OK, I will take care in my next patch.

> > + - extcon-gpio,irq-flags: IRQ flags for GPIO.
> 
> If this is an interrupt, then you should be using the interrupts property.
> 
Need to provide GPIO number instead of interrupt from DTS to read GPIO value when external connected attached/detached and also driver supports platform data with passing GPIO number.
So need to pass irq-flags using separate dts property or need to hardcode in driver.

> > + - extcon-gpio,debounce: Debounce time in ms.
> 
> extcon-gpio is not a vendor prefix, so drop it.
> 
> Add unit suffix (-ms).
> 
OK, I will take care in my next patch.

> > + - extcon-gpio,connection-state-low: boolean, Connection state with
> > +                gpio state. True if gpio low means connected.
> 
> The active state should be in the GPIO flags cell.
> 
OK, I will take care in my next patch.
> > +
> > +extcon-gpio {
> > +	compatible = "extcon-gpio";
> > +        extcon-gpio,name = "VBUS";
> 
> How is VBus a gpio?
> 
Here VBUS is not gpio number, VBUS is extcon device name, extcon gpio is used to detect VBUS.

> > +	gpio = <&gpio 20 0>;
> > +	extcon-gpio,cable-names = <EXTCON_USB EXTCON_NONE>;
> 
> Not documented.
> 
> Rob
OK, I will take care in my next patch.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-05-17 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-03  5:49 [PATCH 1/2] extcon: gpio: add device tree support for extcon-gpio Venkat Reddy Talla
2016-05-03  5:49 ` [PATCH 2/2] extcon: gpio: add DT binding doc " Venkat Reddy Talla
     [not found]   ` <1462254591-8907-2-git-send-email-vreddytalla-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-05-04 13:30     ` Rob Herring
2016-05-17 11:27       ` Venkat Reddy Talla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).