devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] extcon: gpio: add device tree support for extcon-gpio
@ 2016-05-25 11:35 ` Venkat Reddy Talla
       [not found]   ` <1464176133-10742-1-git-send-email-vreddytalla-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
  2016-05-25 12:32   ` [PATCH v2 1/2] extcon: gpio: add device tree support " Chanwoo Choi
  0 siblings, 2 replies; 4+ messages in thread
From: Venkat Reddy Talla @ 2016-05-25 11:35 UTC (permalink / raw)
  To: MyungJoo Ham, Chanwoo Choi, Rob Herring, Pawel Moll
  Cc: Mark Rutland, Ian Campbell, devicetree, Kumar Gala, linux-kernel,
	Laxman Dewangan, Venkat Reddy Talla

Adding device tree support for extcon-gpio driver.

Signed-off-by: Venkat Reddy Talla <vreddytalla@nvidia.com>

---
changes in v2:
- using gpio flag cell to handle gpio active state
- change dts property name gpio to gpios
- removed prefix for debounce
---
---
 drivers/extcon/extcon-gpio.c       | 80 +++++++++++++++++++++++++++++++++++---
 include/linux/extcon/extcon-gpio.h |  4 +-
 2 files changed, 77 insertions(+), 7 deletions(-)

diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
index d023789..f29032c 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,80 @@ 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;
+	enum of_gpio_flags flags;
+	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_flags(np, "gpios", 0, &flags);
+	if (gpio < 0)
+		return ERR_PTR(gpio);
+
+	pdata->gpio = gpio;
+
+	if (flags & OF_GPIO_ACTIVE_LOW)
+		pdata->gpio_active_low = 1;
+
+	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, "debounce-ms", &pval);
+	if (!ret)
+		pdata->debounce = pval;
+
+	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_id = devm_kzalloc(&pdev->dev,
+			(pdata->extcon_cable_cnt) *
+			sizeof(*pdata->extcon_id), GFP_KERNEL);
+	if (!pdata->extcon_id)
+		return ERR_PTR(-ENOMEM);
+
+	ret = of_property_read_u32_array(np, "extcon-gpio,cable-names",
+			pdata->extcon_id, 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_id)
+		return -EINVAL;
+
 	data->pdata = pdata;
 
 	/* Initialize the gpio */
@@ -113,7 +174,7 @@ 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_id);
 	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..1914894 100644
--- a/include/linux/extcon/extcon-gpio.h
+++ b/include/linux/extcon/extcon-gpio.h
@@ -31,15 +31,17 @@
  *			If false, high state of gpio means active.
  * @debounce:		Debounce time for GPIO IRQ in ms.
  * @irq_flags:		IRQ Flags (e.g., IRQF_TRIGGER_LOW).
+ * extcon_cable_cnt:    External cable count.
  * @check_on_resume:	Boolean describing whether to check the state of gpio
  *			while resuming from sleep.
  */
 struct gpio_extcon_pdata {
-	unsigned int extcon_id;
+	unsigned int *extcon_id;
 	unsigned gpio;
 	bool gpio_active_low;
 	unsigned long debounce;
 	unsigned long irq_flags;
+	int extcon_cable_cnt;
 
 	bool check_on_resume;
 };
-- 
2.1.4

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

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

Adding DT binding doc for extcon gpio device
properties.

Signed-off-by: Venkat Reddy Talla <vreddytalla-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

---
changes in v2:
- added description for extcon-gpio
- using gpio flag cell to handle gpio active state
- change dts property name gpio to gpios
- removed prefix for debounce
- added description for extcon-gpio,cable-names
---
---
 .../devicetree/bindings/extcon/extcon-gpio.txt     | 22 ++++++++++++++++++++++
 1 file changed, 22 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..2302960
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
@@ -0,0 +1,22 @@
+EXTCON FOR GPIO
+
+extcon-gpio responsible to detect external cable state when
+attached or detached.
+
+Required Properties:
+ - compatible : Should be "extcon-gpio";
+
+Optional Properties:
+ - extcon-gpio,name: Name of extcon device.
+ - gpios: gpio number.
+ - extcon-gpio,irq-flags: IRQ flags for gpio.
+ - debounce-ms: Debounce time in ms.
+ - extcon-gpio,cable-names: The unique id of specific external connector
+	defined in include/linux/extcon.h
+
+extcon-gpio {
+	compatible = "extcon-gpio";
+        extcon-gpio,name = "VBUS";
+	gpios = <&gpio 20 0>;
+	extcon-gpio,cable-names = <EXTCON_USB EXTCON_NONE>;
+};
-- 
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

* Re: [PATCH v2 1/2] extcon: gpio: add device tree support for extcon-gpio
  2016-05-25 11:35 ` [PATCH v2 1/2] extcon: gpio: add device tree support for extcon-gpio Venkat Reddy Talla
       [not found]   ` <1464176133-10742-1-git-send-email-vreddytalla-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
@ 2016-05-25 12:32   ` Chanwoo Choi
  1 sibling, 0 replies; 4+ messages in thread
From: Chanwoo Choi @ 2016-05-25 12:32 UTC (permalink / raw)
  To: Venkat Reddy Talla, MyungJoo Ham, Rob Herring, Pawel Moll
  Cc: Mark Rutland, Ian Campbell, devicetree, Kumar Gala, linux-kernel,
	Laxman Dewangan

Hi Venkat,

I'm already working the support the device-tree for extcon-gpio [1].
[1] https://lkml.org/lkml/2015/10/21/8
- [PATCH v3] extcon: gpio: Add the support for Device tree bindings

So, I just apply this patch the temporay extcon-test[2] branch on extcon.git.
[2] https://git.kernel.org/cgit/linux/kernel/git/chanwoo/extcon.git/commit/?h=extcon-test&id=294d13e8d79fb0997e1bb146892cd75ec02221c0

But, Rob Herring gave me the some comment[2]. 
[3] https://lkml.org/lkml/2015/10/21/906
[4] https://lkml.org/lkml/2015/10/26/80

So, if you possible, do you improve the extcon-gpio.c for device-tree using by my patch[1]?
I think that you could improve the extcon-gpio.c driver as comment of Rob Herring.

I'm sorry for late reply.

Thanks,
Chanwoo Choi

On 2016년 05월 25일 20:35, Venkat Reddy Talla wrote:
> Adding device tree support for extcon-gpio driver.
> 
> Signed-off-by: Venkat Reddy Talla <vreddytalla@nvidia.com>
> 
> ---
> changes in v2:
> - using gpio flag cell to handle gpio active state
> - change dts property name gpio to gpios
> - removed prefix for debounce
> ---
> ---
>  drivers/extcon/extcon-gpio.c       | 80 +++++++++++++++++++++++++++++++++++---
>  include/linux/extcon/extcon-gpio.h |  4 +-
>  2 files changed, 77 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c
> index d023789..f29032c 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,80 @@ 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;
> +	enum of_gpio_flags flags;
> +	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_flags(np, "gpios", 0, &flags);
> +	if (gpio < 0)
> +		return ERR_PTR(gpio);
> +
> +	pdata->gpio = gpio;
> +
> +	if (flags & OF_GPIO_ACTIVE_LOW)
> +		pdata->gpio_active_low = 1;
> +
> +	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, "debounce-ms", &pval);
> +	if (!ret)
> +		pdata->debounce = pval;
> +
> +	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_id = devm_kzalloc(&pdev->dev,
> +			(pdata->extcon_cable_cnt) *
> +			sizeof(*pdata->extcon_id), GFP_KERNEL);
> +	if (!pdata->extcon_id)
> +		return ERR_PTR(-ENOMEM);
> +
> +	ret = of_property_read_u32_array(np, "extcon-gpio,cable-names",
> +			pdata->extcon_id, 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_id)
> +		return -EINVAL;
> +
>  	data->pdata = pdata;
>  
>  	/* Initialize the gpio */
> @@ -113,7 +174,7 @@ 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_id);
>  	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..1914894 100644
> --- a/include/linux/extcon/extcon-gpio.h
> +++ b/include/linux/extcon/extcon-gpio.h
> @@ -31,15 +31,17 @@
>   *			If false, high state of gpio means active.
>   * @debounce:		Debounce time for GPIO IRQ in ms.
>   * @irq_flags:		IRQ Flags (e.g., IRQF_TRIGGER_LOW).
> + * extcon_cable_cnt:    External cable count.
>   * @check_on_resume:	Boolean describing whether to check the state of gpio
>   *			while resuming from sleep.
>   */
>  struct gpio_extcon_pdata {
> -	unsigned int extcon_id;
> +	unsigned int *extcon_id;
>  	unsigned gpio;
>  	bool gpio_active_low;
>  	unsigned long debounce;
>  	unsigned long irq_flags;
> +	int extcon_cable_cnt;
>  
>  	bool check_on_resume;
>  };
> 

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

* Re: [PATCH v2 2/2] extcon: gpio: add DT binding doc for extcon-gpio
  2016-05-25 11:35     ` [PATCH v2 2/2] extcon: gpio: add DT binding doc " Venkat Reddy Talla
@ 2016-05-25 12:33       ` Rob Herring
  0 siblings, 0 replies; 4+ messages in thread
From: Rob Herring @ 2016-05-25 12:33 UTC (permalink / raw)
  To: Venkat Reddy Talla
  Cc: MyungJoo Ham, Chanwoo Choi, Pawel Moll, Mark Rutland,
	Ian Campbell, devicetree@vger.kernel.org, Kumar Gala,
	linux-kernel@vger.kernel.org, Laxman Dewangan

On Wed, May 25, 2016 at 6:35 AM, Venkat Reddy Talla <vreddytalla@nvidia.com> wrote:
> Adding DT binding doc for extcon gpio device
> properties.
>
> Signed-off-by: Venkat Reddy Talla <vreddytalla@nvidia.com>
>
> ---
> changes in v2:
> - added description for extcon-gpio
> - using gpio flag cell to handle gpio active state
> - change dts property name gpio to gpios
> - removed prefix for debounce
> - added description for extcon-gpio,cable-names
> ---
> ---
>  .../devicetree/bindings/extcon/extcon-gpio.txt     | 22 ++++++++++++++++++++++
>  1 file changed, 22 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..2302960
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/extcon/extcon-gpio.txt
> @@ -0,0 +1,22 @@
> +EXTCON FOR GPIO
> +
> +extcon-gpio responsible to detect external cable state when
> +attached or detached.
> +
> +Required Properties:
> + - compatible : Should be "extcon-gpio";


> +
> +Optional Properties:
> + - extcon-gpio,name: Name of extcon device.
> + - gpios: gpio number.
> + - extcon-gpio,irq-flags: IRQ flags for gpio.


> + - debounce-ms: Debounce time in ms.
> + - extcon-gpio,cable-names: The unique id of specific external connector
> +       defined in include/linux/extcon.h
> +
> +extcon-gpio {
> +       compatible = "extcon-gpio";
> +        extcon-gpio,name = "VBUS";
> +       gpios = <&gpio 20 0>;
> +       extcon-gpio,cable-names = <EXTCON_USB EXTCON_NONE>;
> +};
> --
> 2.1.4
>

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

end of thread, other threads:[~2016-05-25 12:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20160525113554epcas1p1d75cdfe7b480576e34b222fe6e8339e5@epcas1p1.samsung.com>
2016-05-25 11:35 ` [PATCH v2 1/2] extcon: gpio: add device tree support for extcon-gpio Venkat Reddy Talla
     [not found]   ` <1464176133-10742-1-git-send-email-vreddytalla-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2016-05-25 11:35     ` [PATCH v2 2/2] extcon: gpio: add DT binding doc " Venkat Reddy Talla
2016-05-25 12:33       ` Rob Herring
2016-05-25 12:32   ` [PATCH v2 1/2] extcon: gpio: add device tree support " Chanwoo Choi

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).