Skip to contentSkip to conversation

extcon: gpio: Add the support for Device tree bindings

PATCH In review Venkat Reddy Talla 5 participants 15 messages May 26, 2016 – Jun 7, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 extcon: gpio: Add the support for Device tree bindings

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id' and 'gpios' property.

For example:

	usb_cable: extcon-gpio-0 {
		compatible = "extcon-gpio";
		extcon-id = <EXTCON_USB>;
		gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
	}
	ta_cable: extcon-gpio-1 {
		compatible = "extcon-gpio";
		extcon-id = <EXTCON_CHG_USB_DCP>;
		gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
		debounce-ms = <50>;	/* 50 millisecond */
		wakeup-source;
	}
	&dwc3_usb {
		extcon = <&usb_cable>;
	};
	&charger {
		extcon = <&ta_cable>;
	};

---
changes from v3:
- add description for wakeup-source in documentation
- change dts property extcon-gpio name to gpios
- use of_get_named_gpio_flags to get gpio number and flags Changes from v2:
- Add the more description for 'extcon-id' property in documentation Changes from v1:
- Create the include/dt-bindings/extcon/extcon.h including the identification of external connector. These definitions are used in dts file.
- Fix error if CONFIG_OF is disabled.
- Add signed-off tag by Myungjoo Ham
---

---
 .../devicetree/bindings/extcon/extcon-gpio.txt     |  48 +++++++++
 drivers/extcon/extcon-gpio.c                       | 109 +++++++++++++++++----
 include/dt-bindings/extcon/extcon.h                |  47 +++++++++
 include/linux/extcon/extcon-gpio.h                 |   8 +-
 4 files changed, 189 insertions(+), 23 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt
 create mode 100644 include/dt-bindings/extcon/extcon.h
Documentation/devicetree/bindings/extcon/extcon-gpio.txt new file +48 -0
new file mode 100644
index 0000000..81f7932
@@ -0,0 +1,48 @@
+GPIO Extcon device
+
+This is a virtual device used to generate the specific cable states from the
+GPIO pin.
+
+Required properties:
+- compatible: Must be "extcon-gpio".
+- extcon-id: The extcon support the various type of external connector to check
+  whether connector is attached or detached. The each external connector has
+  the unique number to identify it. So this property includes the unique number
+  which indicates the specific external connector. When external connector is
+  attached or detached, GPIO pin detect the changed state. See include/
+  dt-bindings/extcon/extcon.h which defines the unique number for supported
+  external connector from extcon framework.
+- gpios: GPIO pin to detect the external connector. See gpio binding.
+
+Optional properties:
+- debounce-ms: the debounce dealy for GPIO pin in millisecond.
+- wakeup-source: Boolean, extcon can wake-up the system from suspend.
+  if gpio provided in extcon-gpio DT node is registered as interrupt,
+  then extcon can wake-up the system from suspend if wakeup-source property
+  is available in DT node, if gpio registered as interrupt but wakeup-source
+  is not available in DT node, then system wake-up due to extcon events
+  not supported.
+
+Example: Examples of extcon-gpio node as listed below:
+
+	usb_cable: extcon-gpio-0 {
+		compatible = "extcon-gpio";
+		extcon-id = <EXTCON_USB>;
+		extcon-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+	}
+
+	ta_cable: extcon-gpio-1 {
+		compatible = "extcon-gpio";
+		extcon-id = <EXTCON_CHG_USB_DCP>;
+		extcon-gpio = <&gpio3 2 GPIO_ACTIVE_LOW>;
+		debounce-ms = <50>;	/* 50 millisecond */
+		wakeup-source;
+	}
+
+	&dwc3_usb {
+		extcon = <&usb_cable>;
+	};
+
+	&charger {
+		extcon = <&ta_cable>;
+	};
drivers/extcon/extcon-gpio.c +90 -19

192 lines not on this page · raw message

include/dt-bindings/extcon/extcon.h new file +47 -0

47 lines not on this page · raw message

include/linux/extcon/extcon-gpio.h +4 -4
index 7cacafb..f7e7673 100644
@@ -1,8 +1,8 @@
 /*
  * Single-state GPIO extcon driver based on extcon class
  *
- * Copyright (C) 2012 Samsung Electronics
- * Author: MyungJoo Ham <[email protected]>
+ * Copyright (C) 2016 Chanwoo Choi <[email protected]>, Samsung Electronics
+ * Copyright (C) 2012 MyungJoo Ham <[email protected]>, Samsung Electronics
  *
  * based on switch class driver
  * Copyright (C) 2008 Google, Inc.
@@ -35,10 +35,10 @@
  *			while resuming from sleep.
  */
 struct gpio_extcon_pdata {
-	unsigned int extcon_id;
+	u32 extcon_id;
 	unsigned gpio;
 	bool gpio_active_low;
-	unsigned long debounce;
+	u32 debounce;
 	unsigned long irq_flags;
 
 	bool check_on_resume;
Signature · 1 line
2.1.4
#1 lore raw

Hi Venkat,

There is some miscommunication. On previous my reply, I don't mean that the author of the patch[1] is changed from me to you.

I'd like you to remain the original author(me) for the patch[1] without changing the author.
[1] https://lkml.org/lkml/2015/10/21/8
- [PATCH v3] extcon: gpio: Add the support for Device tree bindings

You can use the patch[1] as based patch and you can add new feature on base patch[1]. Also, If you ok, you can modify the extccon-gpio.c driver as Rob comment[2].

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

Thanks,
Chanwoo Choi

Quoted 395 lines · Venkat Reddy Talla

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id' and 'gpios' property.

For example:

        usb_cable: extcon-gpio-0 {
                compatible = "extcon-gpio";
                extcon-id = <EXTCON_USB>;
                gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
        }
        ta_cable: extcon-gpio-1 {
                compatible = "extcon-gpio";
                extcon-id = <EXTCON_CHG_USB_DCP>;
                gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
                debounce-ms = <50>;     /* 50 millisecond */
                wakeup-source;
        }
        &dwc3_usb {
                extcon = <&usb_cable>;
        };
        &charger {
                extcon = <&ta_cable>;
        };

---
changes from v3:
- add description for wakeup-source in documentation
- change dts property extcon-gpio name to gpios
- use of_get_named_gpio_flags to get gpio number and flags Changes from v2:
- Add the more description for 'extcon-id' property in documentation Changes from v1:
- Create the include/dt-bindings/extcon/extcon.h including the identification of external connector. These definitions are used in dts file.
- Fix error if CONFIG_OF is disabled.
- Add signed-off tag by Myungjoo Ham
---

---
 .../devicetree/bindings/extcon/extcon-gpio.txt     |  48 +++++++++
 drivers/extcon/extcon-gpio.c                       | 109 +++++++++++++++++----
 include/dt-bindings/extcon/extcon.h                |  47 +++++++++
 include/linux/extcon/extcon-gpio.h                 |   8 +-
 4 files changed, 189 insertions(+), 23 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt
 create mode 100644 include/dt-bindings/extcon/extcon.h
Documentation/devicetree/bindings/extcon/extcon-gpio.txt new file +48 -0
new file mode 100644
index 0000000..81f7932
@@ -0,0 +1,48 @@
+GPIO Extcon device
+
+This is a virtual device used to generate the specific cable states from the
+GPIO pin.
+
+Required properties:
+- compatible: Must be "extcon-gpio".
+- extcon-id: The extcon support the various type of external connector to check
+  whether connector is attached or detached. The each external connector has
+  the unique number to identify it. So this property includes the unique number
+  which indicates the specific external connector. When external connector is
+  attached or detached, GPIO pin detect the changed state. See include/
+  dt-bindings/extcon/extcon.h which defines the unique number for supported
+  external connector from extcon framework.
+- gpios: GPIO pin to detect the external connector. See gpio binding.
+
+Optional properties:
+- debounce-ms: the debounce dealy for GPIO pin in millisecond.
+- wakeup-source: Boolean, extcon can wake-up the system from suspend.
+  if gpio provided in extcon-gpio DT node is registered as interrupt,
+  then extcon can wake-up the system from suspend if wakeup-source property
+  is available in DT node, if gpio registered as interrupt but wakeup-source
+  is not available in DT node, then system wake-up due to extcon events
+  not supported.
+
+Example: Examples of extcon-gpio node as listed below:
+
+       usb_cable: extcon-gpio-0 {
+               compatible = "extcon-gpio";
+               extcon-id = <EXTCON_USB>;
+               extcon-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+       }
+
+       ta_cable: extcon-gpio-1 {
+               compatible = "extcon-gpio";
+               extcon-id = <EXTCON_CHG_USB_DCP>;
+               extcon-gpio = <&gpio3 2 GPIO_ACTIVE_LOW>;
+               debounce-ms = <50>;     /* 50 millisecond */
+               wakeup-source;
+       }
+
+       &dwc3_usb {
+               extcon = <&usb_cable>;
+       };
+
+       &charger {
+               extcon = <&ta_cable>;
+       };
drivers/extcon/extcon-gpio.c +90 -19
index d023789..592f395 100644
@@ -1,11 +1,9 @@
 /*
  * extcon_gpio.c - Single-state GPIO extcon driver based on extcon class
  *
- * Copyright (C) 2008 Google, Inc.
- * Author: Mike Lockwood <[email protected]>
- *
- * Modified by MyungJoo Ham <[email protected]> to support extcon
- * (originally switch class is supported)
+ * Copyright (C) 2016 Chanwoo Choi <[email protected]>, Samsung Electronics
+ * Copyright (C) 2012 MyungJoo Ham <[email protected]>, Samsung Electronics
+ * Copyright (C) 2008 Mike Lockwood <[email protected]>, Google, Inc.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
@@ -25,13 +23,17 @@
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
 
 struct gpio_extcon_data {
        struct extcon_dev *edev;
        int irq;
+       bool irq_wakeup;
        struct delayed_work work;
        unsigned long debounce_jiffies;
 
@@ -49,7 +51,7 @@ static void gpio_extcon_work(struct work_struct *work)
        state = gpiod_get_value_cansleep(data->id_gpiod);
        if (data->pdata->gpio_active_low)
                state = !state;
-       extcon_set_state(data->edev, state);
+       extcon_set_cable_state_(data->edev, data->pdata->extcon_id, state);
 }
 
 static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
@@ -61,6 +63,42 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
+static int gpio_extcon_parse_of(struct platform_device *pdev,
+                               struct gpio_extcon_data *data)
+{
+       struct gpio_extcon_pdata *pdata;
+       struct device_node *np = pdev->dev.of_node;
+       enum of_gpio_flags flags;
+       int ret;
+
+       pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+       if (!pdata)
+               return -ENOMEM;
+
+       ret = device_property_read_u32(&pdev->dev, "extcon-id",
+                                        &pdata->extcon_id);
+       if (ret < 0)
+               return -EINVAL;
+
+       pdata->gpio = of_get_named_gpio_flags(np, "gpios", 0, &flags);
+       if (pdata->gpio < 0)
+               return -EINVAL;
+
+       if (flags & OF_GPIO_ACTIVE_LOW)
+               pdata->gpio_active_low = true;
+
+       data->irq_wakeup = device_property_read_bool(&pdev->dev,
+                                               "wakeup-source");
+
+       device_property_read_u32(&pdev->dev, "debounce-ms", &pdata->debounce);
+
+       pdata->irq_flags = (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
+                               | IRQF_ONESHOT);
+
+       data->pdata = pdata;
+       return 0;
+}
+
 static int gpio_extcon_init(struct device *dev, struct gpio_extcon_data *data)
 {
        struct gpio_extcon_pdata *pdata = data->pdata;
@@ -96,16 +134,20 @@ static int gpio_extcon_probe(struct platform_device *pdev)
        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);
+       data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
        if (!data)
                return -ENOMEM;
-       data->pdata = pdata;
+
+       if (!pdata) {
+               ret = gpio_extcon_parse_of(pdev, data);
+               if (ret < 0)
+                       return ret;
+       } else {
+               data->pdata = pdata;
+       }
+
+       if (!data->pdata->irq_flags || data->pdata->extcon_id == EXTCON_NONE)
+               return -EINVAL;
 
        /* Initialize the gpio */
        ret = gpio_extcon_init(&pdev->dev, data);
@@ -113,7 +155,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,
+                                               &data->pdata->extcon_id);
        if (IS_ERR(data->edev)) {
                dev_err(&pdev->dev, "failed to allocate extcon device\n");
                return -ENOMEM;
@@ -130,7 +173,8 @@ static int gpio_extcon_probe(struct platform_device *pdev)
         * is attached or detached.
         */
        ret = devm_request_any_context_irq(&pdev->dev, data->irq,
-                                       gpio_irq_handler, pdata->irq_flags,
+                                       gpio_irq_handler,
+                                       data->pdata->irq_flags,
                                        pdev->name, data);
        if (ret < 0)
                return ret;
@@ -139,6 +183,8 @@ static int gpio_extcon_probe(struct platform_device *pdev)
        /* Perform initial detection */
        gpio_extcon_work(&data->work.work);
 
+       if (data->irq_wakeup)
+               device_init_wakeup(&pdev->dev, data->irq_wakeup);
        return 0;
 }
 
@@ -152,11 +198,23 @@ static int gpio_extcon_remove(struct platform_device *pdev)
 }
 
 #ifdef CONFIG_PM_SLEEP
+static int gpio_extcon_suspend(struct device *dev)
+{
+       struct gpio_extcon_data *data = dev_get_drvdata(dev);
+
+       if (data->irq_wakeup)
+               enable_irq_wake(data->irq);
+
+       return 0;
+}
+
 static int gpio_extcon_resume(struct device *dev)
 {
-       struct gpio_extcon_data *data;
+       struct gpio_extcon_data *data = dev_get_drvdata(dev);
+
+       if (data->irq_wakeup)
+               disable_irq_wake(data->irq);
 
-       data = dev_get_drvdata(dev);
        if (data->pdata->check_on_resume)
                queue_delayed_work(system_power_efficient_wq,
                        &data->work, data->debounce_jiffies);
@@ -165,7 +223,18 @@ static int gpio_extcon_resume(struct device *dev)
 }
 #endif
 
-static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops, NULL, gpio_extcon_resume);
+#if defined(CONFIG_OF)
+static const struct of_device_id gpio_extcon_of_match[] = {
+       { .compatible = "extcon-gpio", },
+       { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, gpio_extcon_of_match);
+#else
+#define gpio_extcon_of_match   NULL
+#endif
+
+static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops,
+                       gpio_extcon_suspend, gpio_extcon_resume);
 
 static struct platform_driver gpio_extcon_driver = {
        .probe          = gpio_extcon_probe,
@@ -173,11 +242,13 @@ static struct platform_driver gpio_extcon_driver = {
        .driver         = {
                .name   = "extcon-gpio",
                .pm     = &gpio_extcon_pm_ops,
+               .of_match_table = gpio_extcon_of_match,
        },
 };
 
 module_platform_driver(gpio_extcon_driver);
 
+MODULE_AUTHOR("Chanwoo Choi <[email protected]>");
 MODULE_AUTHOR("Mike Lockwood <[email protected]>");
 MODULE_DESCRIPTION("GPIO extcon driver");
 MODULE_LICENSE("GPL");
include/dt-bindings/extcon/extcon.h new file +47 -0
new file mode 100644
index 0000000..dbba588
@@ -0,0 +1,47 @@
+/*
+ * This header provides constants for most extcon bindings.
+ *
+ * Most extcon bindings include the unique identification format.
+ * In most cases, the unique id format uses the standard values/macro
+ * defined in this header.
+ */
+
+#ifndef _DT_BINDINGS_EXTCON_EXTCON_H
+#define _DT_BINDINGS_EXTCON_EXTCON_H
+
+/* USB external connector */
+#define EXTCON_USB             1
+#define EXTCON_USB_HOST                2
+
+/* Charging external connector */
+#define EXTCON_CHG_USB_SDP     5       /* Standard Downstream Port */
+#define EXTCON_CHG_USB_DCP     6       /* Dedicated Charging Port */
+#define EXTCON_CHG_USB_CDP     7       /* Charging Downstream Port */
+#define EXTCON_CHG_USB_ACA     8       /* Accessory Charger Adapter */
+#define EXTCON_CHG_USB_FAST    9
+#define EXTCON_CHG_USB_SLOW    10
+
+/* Jack external connector */
+#define EXTCON_JACK_MICROPHONE 20
+#define EXTCON_JACK_HEADPHONE  21
+#define EXTCON_JACK_LINE_IN    22
+#define EXTCON_JACK_LINE_OUT   23
+#define EXTCON_JACK_VIDEO_IN   24
+#define EXTCON_JACK_VIDEO_OUT  25
+#define EXTCON_JACK_SPDIF_IN   26      /* Sony Philips Digital InterFace */
+#define EXTCON_JACK_SPDIF_OUT  27
+
+/* Display external connector */
+#define EXTCON_DISP_HDMI       40      /* High-Definition Multimedia Interface */
+#define EXTCON_DISP_MHL                41      /* Mobile High-Definition Link */
+#define EXTCON_DISP_DVI                42      /* Digital Visual Interface */
+#define EXTCON_DISP_VGA                43      /* Video Graphics Array */
+
+/* Miscellaneous external connector */
+#define EXTCON_DOCK            60
+#define EXTCON_JIG             61
+#define EXTCON_MECHANICAL      62
+
+#define EXTCON_NUM             63
+
+#endif /* _DT_BINDINGS_EXTCON_EXTCON_H */
include/linux/extcon/extcon-gpio.h +4 -5
index 7cacafb..f7e7673 100644
@@ -1,8 +1,8 @@
 /*
  * Single-state GPIO extcon driver based on extcon class
  *
- * Copyright (C) 2012 Samsung Electronics
- * Author: MyungJoo Ham <[email protected]>
+ * Copyright (C) 2016 Chanwoo Choi <[email protected]>, Samsung Electronics
+ * Copyright (C) 2012 MyungJoo Ham <[email protected]>, Samsung Electronics
  *
  * based on switch class driver
  * Copyright (C) 2008 Google, Inc.
@@ -35,10 +35,10 @@
  *                     while resuming from sleep.
  */
 struct gpio_extcon_pdata {
-       unsigned int extcon_id;
+       u32 extcon_id;
        unsigned gpio;
        bool gpio_active_low;
-       unsigned long debounce;
+       u32 debounce;
        unsigned long irq_flags;
 
        bool check_on_resume;
--

2.1.4

#2 lore raw

Hi Choi,

Sorry for changing author, will update author field with your name.

Regarding Rob Herring comments, You had already replied.

I felt separate compatible for each external connector is not required,
as client driver can detect the type of external cable(sdp,dcp, microphone) on receiving notification from extcon provider, I have also added more description for wakeup-source.

Do you see any other changes required on top of v4 patch?

Regards,
Venkat

Quoted 456 lines

-----Original Message-----
From: Chanwoo Choi [mailto:[email protected]]
Sent: Thursday, May 26, 2016 6:52 PM
To: Venkat Reddy Talla
Cc: MyungJoo Ham; Rob Herring; Pawel Moll; Mark Rutland; Ian Campbell; devicetree; Kumar Gala; linux-kernel; Laxman Dewangan
Subject: Re: [PATCH v4] extcon: gpio: Add the support for Device tree bindings

Hi Venkat,

There is some miscommunication. On previous my reply, I don't mean that the author of the patch[1] is changed from me to you.

I'd like you to remain the original author(me) for the patch[1] without changing the author.
[1] https://lkml.org/lkml/2015/10/21/8
- [PATCH v3] extcon: gpio: Add the support for Device tree bindings

You can use the patch[1] as based patch and you can add new feature on base patch[1]. Also, If you ok, you can modify the extccon-gpio.c driver as Rob comment[2].

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

Thanks,
Chanwoo Choi

Quoted 72 lines · Venkat Reddy Talla

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id' and 'gpios' property.

For example:

        usb_cable: extcon-gpio-0 {
                compatible = "extcon-gpio";
                extcon-id = <EXTCON_USB>;
                gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
        }
        ta_cable: extcon-gpio-1 {
                compatible = "extcon-gpio";
                extcon-id = <EXTCON_CHG_USB_DCP>;
                gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
                debounce-ms = <50>;     /* 50 millisecond */
                wakeup-source;
        }
        &dwc3_usb {
                extcon = <&usb_cable>;
        };
        &charger {
                extcon = <&ta_cable>;
        };

---
changes from v3:
- add description for wakeup-source in documentation
- change dts property extcon-gpio name to gpios
- use of_get_named_gpio_flags to get gpio number and flags Changes from v2:
- Add the more description for 'extcon-id' property in documentation Changes from v1:
- Create the include/dt-bindings/extcon/extcon.h including the identification of external connector. These definitions are used in dts file.
- Fix error if CONFIG_OF is disabled.
- Add signed-off tag by Myungjoo Ham
---

---
 .../devicetree/bindings/extcon/extcon-gpio.txt     |  48 +++++++++
 drivers/extcon/extcon-gpio.c                       | 109 +++++++++++++++++----
 include/dt-bindings/extcon/extcon.h                |  47 +++++++++
 include/linux/extcon/extcon-gpio.h                 |   8 +-
 4 files changed, 189 insertions(+), 23 deletions(-)  create mode
100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt
 create mode 100644 include/dt-bindings/extcon/extcon.h
Documentation/devicetree/bindings/extcon/extcon-gpio.txt new file +15 -0
new file mode 100644
index 0000000..81f7932
@@ -0,0 +1,48 @@
+GPIO Extcon device
+
+This is a virtual device used to generate the specific cable states
+from the GPIO pin.
+
+Required properties:
+- compatible: Must be "extcon-gpio".
+- extcon-id: The extcon support the various type of external
+connector to check
+  whether connector is attached or detached. The each external
+connector has
+  the unique number to identify it. So this property includes the
+unique number
+  which indicates the specific external connector. When external
+connector is

Documentation/devicetree/bindings/extcon/extcon-gpio.txt line 25

Quoted 10 lines
Documentation/devicetree/bindings/extcon/extcon-gpio.txt new file +10 -0
+  attached or detached, GPIO pin detect the changed state. See
+include/
+  dt-bindings/extcon/extcon.h which defines the unique number for
+supported
+  external connector from extcon framework.
+- gpios: GPIO pin to detect the external connector. See gpio binding.
+
+Optional properties:
+- debounce-ms: the debounce dealy for GPIO pin in millisecond.
+- wakeup-source: Boolean, extcon can wake-up the system from

suspend.

Quoted 37 lines
Documentation/devicetree/bindings/extcon/extcon-gpio.txt new file +32 -0
+  if gpio provided in extcon-gpio DT node is registered as interrupt,
+  then extcon can wake-up the system from suspend if wakeup-source
+property
+  is available in DT node, if gpio registered as interrupt but
+wakeup-source
+  is not available in DT node, then system wake-up due to extcon
+events
+  not supported.
+
+Example: Examples of extcon-gpio node as listed below:
+
+       usb_cable: extcon-gpio-0 {
+               compatible = "extcon-gpio";
+               extcon-id = <EXTCON_USB>;
+               extcon-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+       }
+
+       ta_cable: extcon-gpio-1 {
+               compatible = "extcon-gpio";
+               extcon-id = <EXTCON_CHG_USB_DCP>;
+               extcon-gpio = <&gpio3 2 GPIO_ACTIVE_LOW>;
+               debounce-ms = <50>;     /* 50 millisecond */
+               wakeup-source;
+       }
+
+       &dwc3_usb {
+               extcon = <&usb_cable>;
+       };
+
+       &charger {
+               extcon = <&ta_cable>;
+       };
(quoted diff) +0 -0

b/drivers/extcon/extcon-gpio.c index d023789..592f395 100644

drivers/extcon/extcon-gpio.c line 7

Quoted 7 lines
drivers/extcon/extcon-gpio.c +0 -4
@@ -1,11 +1,9 @@
 /*
  * extcon_gpio.c - Single-state GPIO extcon driver based on extcon class
  *
- * Copyright (C) 2008 Google, Inc.
- * Author: Mike Lockwood <[email protected]>
- *
- * Modified by MyungJoo Ham <[email protected]> to

support

Quoted 3 lines

extcon
- * (originally switch class is supported)
+ * Copyright (C) 2016 Chanwoo Choi <[email protected]>,

Samsung

Quoted 4 lines

+ Electronics
+ * Copyright (C) 2012 MyungJoo Ham <[email protected]>,
+ Samsung Electronics
+ * Copyright (C) 2008 Mike Lockwood <[email protected]>, Google,

Inc.

drivers/extcon/extcon-gpio.c static void gpio_extcon_work(struct work_struct

Quoted 20 lines

*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation,
and @@ -25,13 +23,17 @@ #include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/module.h>

drivers/extcon/extcon-gpio.c +4 -0
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
 
 struct gpio_extcon_data {
        struct extcon_dev *edev;
        int irq;
+       bool irq_wakeup;
        struct delayed_work work;
        unsigned long debounce_jiffies;
@@ -49,7 +51,7 @@ static void gpio_extcon_work(struct work_struct

*work)

Quoted 67 lines
drivers/extcon/extcon-gpio.c +39 -1
        state = gpiod_get_value_cansleep(data->id_gpiod);
        if (data->pdata->gpio_active_low)
                state = !state;
-       extcon_set_state(data->edev, state);
+       extcon_set_cable_state_(data->edev, data->pdata->extcon_id,
+ state);
 }
 
 static irqreturn_t gpio_irq_handler(int irq, void *dev_id) @@ -61,6
+63,42 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
+static int gpio_extcon_parse_of(struct platform_device *pdev,
+                               struct gpio_extcon_data *data) {
+       struct gpio_extcon_pdata *pdata;
+       struct device_node *np = pdev->dev.of_node;
+       enum of_gpio_flags flags;
+       int ret;
+
+       pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+       if (!pdata)
+               return -ENOMEM;
+
+       ret = device_property_read_u32(&pdev->dev, "extcon-id",
+                                        &pdata->extcon_id);
+       if (ret < 0)
+               return -EINVAL;
+
+       pdata->gpio = of_get_named_gpio_flags(np, "gpios", 0, &flags);
+       if (pdata->gpio < 0)
+               return -EINVAL;
+
+       if (flags & OF_GPIO_ACTIVE_LOW)
+               pdata->gpio_active_low = true;
+
+       data->irq_wakeup = device_property_read_bool(&pdev->dev,
+                                               "wakeup-source");
+
+       device_property_read_u32(&pdev->dev, "debounce-ms",
+ &pdata->debounce);
+
+       pdata->irq_flags = (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
+                               | IRQF_ONESHOT);
+
+       data->pdata = pdata;
+       return 0;
+}
+
 static int gpio_extcon_init(struct device *dev, struct
gpio_extcon_data *data)  {
        struct gpio_extcon_pdata *pdata = data->pdata; @@ -96,16
+134,20 @@ static int gpio_extcon_probe(struct platform_device *pdev)
        struct gpio_extcon_data *data;
        int ret;
drivers/extcon/extcon-gpio.c +1 -8
-       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);
+       data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
        if (!data)
                return -ENOMEM;
-       data->pdata = pdata;

drivers/extcon/extcon-gpio.c static int gpio_extcon_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/extcon/extcon-gpio.c +10 -0
+
+       if (!pdata) {
+               ret = gpio_extcon_parse_of(pdev, data);
+               if (ret < 0)
+                       return ret;
+       } else {
+               data->pdata = pdata;
+       }
+
+       if (!data->pdata->irq_flags || data->pdata->extcon_id ==

EXTCON_NONE)

drivers/extcon/extcon-gpio.c static int gpio_extcon_probe(struct

Quoted 17 lines

+ return -EINVAL;

        /* Initialize the gpio */
        ret = gpio_extcon_init(&pdev->dev, data); @@ -113,7 +155,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);

drivers/extcon/extcon-gpio.c +3 -0
+       data->edev = devm_extcon_dev_allocate(&pdev->dev,
+
+ &data->pdata->extcon_id);
        if (IS_ERR(data->edev)) {
                dev_err(&pdev->dev, "failed to allocate extcon device\n");
                return -ENOMEM;
@@ -130,7 +173,8 @@ static int gpio_extcon_probe(struct

platform_device *pdev)

drivers/extcon/extcon-gpio.c static int gpio_extcon_probe(struct

Quoted 10 lines
drivers/extcon/extcon-gpio.c +2 -1
         * is attached or detached.
         */
        ret = devm_request_any_context_irq(&pdev->dev, data->irq,
-                                       gpio_irq_handler, pdata->irq_flags,
+                                       gpio_irq_handler,
+                                       data->pdata->irq_flags,
                                        pdev->name, data);
        if (ret < 0)
                return ret;
@@ -139,6 +183,8 @@ static int gpio_extcon_probe(struct

platform_device *pdev)

drivers/extcon/extcon-gpio.c static struct platform_driver gpio_extcon_driver =

Quoted 52 lines
drivers/extcon/extcon-gpio.c +15 -3
        /* Perform initial detection */
        gpio_extcon_work(&data->work.work);
 
+       if (data->irq_wakeup)
+               device_init_wakeup(&pdev->dev, data->irq_wakeup);
        return 0;
 }
 
@@ -152,11 +198,23 @@ static int gpio_extcon_remove(struct
 platform_device *pdev)  }
 
 #ifdef CONFIG_PM_SLEEP
+static int gpio_extcon_suspend(struct device *dev) {
+       struct gpio_extcon_data *data = dev_get_drvdata(dev);
+
+       if (data->irq_wakeup)
+               enable_irq_wake(data->irq);
+
+       return 0;
+}
+
 static int gpio_extcon_resume(struct device *dev)  {
-       struct gpio_extcon_data *data;
+       struct gpio_extcon_data *data = dev_get_drvdata(dev);
+
+       if (data->irq_wakeup)
+               disable_irq_wake(data->irq);
 
-       data = dev_get_drvdata(dev);
        if (data->pdata->check_on_resume)
                queue_delayed_work(system_power_efficient_wq,
                        &data->work, data->debounce_jiffies); @@
-165,7 +223,18 @@ static int gpio_extcon_resume(struct device *dev)  }

#endif

-static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops, NULL, gpio_extcon_resume);

drivers/extcon/extcon-gpio.c +11 -0
+#if defined(CONFIG_OF)
+static const struct of_device_id gpio_extcon_of_match[] = {
+       { .compatible = "extcon-gpio", },
+       { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, gpio_extcon_of_match); #else
+#define gpio_extcon_of_match   NULL
+#endif
+
+static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops,
+                       gpio_extcon_suspend, gpio_extcon_resume);
 
 static struct platform_driver gpio_extcon_driver = {
        .probe          = gpio_extcon_probe,
@@ -173,11 +242,13 @@ static struct platform_driver gpio_extcon_driver =

{

drivers/extcon/extcon-gpio.c static struct platform_driver gpio_extcon_driver = {

Quoted 12 lines
drivers/extcon/extcon-gpio.c +2 -0
        .driver         = {
                .name   = "extcon-gpio",
                .pm     = &gpio_extcon_pm_ops,
+               .of_match_table = gpio_extcon_of_match,
        },
 };
 
 module_platform_driver(gpio_extcon_driver);
 
+MODULE_AUTHOR("Chanwoo Choi <[email protected]>");
 MODULE_AUTHOR("Mike Lockwood <[email protected]>");
 MODULE_DESCRIPTION("GPIO extcon driver");  MODULE_LICENSE("GPL");

diff

Quoted 28 lines
drivers/extcon/extcon-gpio.c +0 -1
--git a/include/dt-bindings/extcon/extcon.h

b/include/dt-bindings/extcon/extcon.h
new file mode 100644
index 0000000..dbba588

include/dt-bindings/extcon/extcon.h new file +21 -0
@@ -0,0 +1,47 @@
+/*
+ * This header provides constants for most extcon bindings.
+ *
+ * Most extcon bindings include the unique identification format.
+ * In most cases, the unique id format uses the standard values/macro
+ * defined in this header.
+ */
+
+#ifndef _DT_BINDINGS_EXTCON_EXTCON_H
+#define _DT_BINDINGS_EXTCON_EXTCON_H
+
+/* USB external connector */
+#define EXTCON_USB             1
+#define EXTCON_USB_HOST                2
+
+/* Charging external connector */
+#define EXTCON_CHG_USB_SDP     5       /* Standard Downstream Port */
+#define EXTCON_CHG_USB_DCP     6       /* Dedicated Charging Port */
+#define EXTCON_CHG_USB_CDP     7       /* Charging Downstream Port */
+#define EXTCON_CHG_USB_ACA     8       /* Accessory Charger Adapter */
+#define EXTCON_CHG_USB_FAST    9

include/dt-bindings/extcon/extcon.h line 31

Quoted 10 lines
include/dt-bindings/extcon/extcon.h new file +10 -0
+#define EXTCON_CHG_USB_SLOW    10
+
+/* Jack external connector */
+#define EXTCON_JACK_MICROPHONE 20
+#define EXTCON_JACK_HEADPHONE  21
+#define EXTCON_JACK_LINE_IN    22
+#define EXTCON_JACK_LINE_OUT   23
+#define EXTCON_JACK_VIDEO_IN   24
+#define EXTCON_JACK_VIDEO_OUT  25
+#define EXTCON_JACK_SPDIF_IN   26      /* Sony Philips Digital InterFace

*/

include/dt-bindings/extcon/extcon.h

Quoted 4 lines
include/dt-bindings/extcon/extcon.h new file +4 -0
+#define EXTCON_JACK_SPDIF_OUT  27
+
+/* Display external connector */
+#define EXTCON_DISP_HDMI       40      /* High-Definition Multimedia

Interface */

include/dt-bindings/extcon/extcon.h line 36

Quoted 1 line
include/dt-bindings/extcon/extcon.h new file +1 -0
+#define EXTCON_DISP_MHL                41      /* Mobile High-Definition Link

*/

Quoted 17 lines
include/dt-bindings/extcon/extcon.h new file +11 -0
+#define EXTCON_DISP_DVI                42      /* Digital Visual Interface */
+#define EXTCON_DISP_VGA                43      /* Video Graphics Array */
+
+/* Miscellaneous external connector */
+#define EXTCON_DOCK            60
+#define EXTCON_JIG             61
+#define EXTCON_MECHANICAL      62
+
+#define EXTCON_NUM             63
+
+#endif /* _DT_BINDINGS_EXTCON_EXTCON_H */
include/linux/extcon/extcon-gpio.h +0 -0
index 7cacafb..f7e7673 100644

include/linux/extcon/extcon-gpio.h line 4

Quoted 6 lines
include/linux/extcon/extcon-gpio.h +1 -2
@@ -1,8 +1,8 @@
 /*
  * Single-state GPIO extcon driver based on extcon class
  *
- * Copyright (C) 2012 Samsung Electronics
- * Author: MyungJoo Ham <[email protected]>
+ * Copyright (C) 2016 Chanwoo Choi <[email protected]>,

Samsung

Quoted 22 lines
include/linux/extcon/extcon-gpio.h +5 -3
+ Electronics
+ * Copyright (C) 2012 MyungJoo Ham <[email protected]>,
+ Samsung Electronics
  *
  * based on switch class driver
  * Copyright (C) 2008 Google, Inc.
@@ -35,10 +35,10 @@
  *                     while resuming from sleep.
  */
 struct gpio_extcon_pdata {
-       unsigned int extcon_id;
+       u32 extcon_id;
        unsigned gpio;
        bool gpio_active_low;
-       unsigned long debounce;
+       u32 debounce;
        unsigned long irq_flags;
 
        bool check_on_resume;
--

2.1.4

maintainer
#3 lore raw

Hi Venkat,

Quoted 5 lines · Venkat Reddy Talla

Hi Choi,

Sorry for changing author, will update author field with your name.

Regarding Rob Herring comments, You had already replied.

Rob gave some comment which the compatible string of extcon-gpio.c should include the type of external connector. I replied about it [1].
[1] https://lkml.org/lkml/2016/5/31/109

Quoted 3 lines

I felt separate compatible for each external connector is not required,
as client driver can detect the type of external cable(sdp,dcp, microphone) on receiving notification from extcon provider,

You're right about the operation point of view.
But, As Rob gave some comment, The device-tree should include the device information instead of driver information. The 'extcon-gpio' compatible mean the only driver without h/w information.

I think that there is more discussion how to decide the compatible name of extcon-gpio.c driver.

Quoted 1 line

I have also added more description for wakeup-source.

OK.

Quoted 2 lines

Do you see any other changes required on top of v4 patch?

Regards,
Chanwoo Choi

Quoted 460 lines

Regards,
Venkat

Quoted 456 lines

-----Original Message-----
From: Chanwoo Choi [mailto:[email protected]]
Sent: Thursday, May 26, 2016 6:52 PM
To: Venkat Reddy Talla
Cc: MyungJoo Ham; Rob Herring; Pawel Moll; Mark Rutland; Ian Campbell; devicetree; Kumar Gala; linux-kernel; Laxman Dewangan
Subject: Re: [PATCH v4] extcon: gpio: Add the support for Device tree bindings

Hi Venkat,

There is some miscommunication. On previous my reply, I don't mean that the author of the patch[1] is changed from me to you.

I'd like you to remain the original author(me) for the patch[1] without changing the author.
[1] https://lkml.org/lkml/2015/10/21/8
- [PATCH v3] extcon: gpio: Add the support for Device tree bindings

You can use the patch[1] as based patch and you can add new feature on base patch[1]. Also, If you ok, you can modify the extccon-gpio.c driver as Rob comment[2].

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

Thanks,
Chanwoo Choi

Quoted 72 lines · Venkat Reddy Talla

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id' and 'gpios' property.

For example:

        usb_cable: extcon-gpio-0 {
                compatible = "extcon-gpio";
                extcon-id = <EXTCON_USB>;
                gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
        }
        ta_cable: extcon-gpio-1 {
                compatible = "extcon-gpio";
                extcon-id = <EXTCON_CHG_USB_DCP>;
                gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
                debounce-ms = <50>;     /* 50 millisecond */
                wakeup-source;
        }
        &dwc3_usb {
                extcon = <&usb_cable>;
        };
        &charger {
                extcon = <&ta_cable>;
        };

---
changes from v3:
- add description for wakeup-source in documentation
- change dts property extcon-gpio name to gpios
- use of_get_named_gpio_flags to get gpio number and flags Changes from v2:
- Add the more description for 'extcon-id' property in documentation Changes from v1:
- Create the include/dt-bindings/extcon/extcon.h including the identification of external connector. These definitions are used in dts file.
- Fix error if CONFIG_OF is disabled.
- Add signed-off tag by Myungjoo Ham
---

---
 .../devicetree/bindings/extcon/extcon-gpio.txt     |  48 +++++++++
 drivers/extcon/extcon-gpio.c                       | 109 +++++++++++++++++----
 include/dt-bindings/extcon/extcon.h                |  47 +++++++++
 include/linux/extcon/extcon-gpio.h                 |   8 +-
 4 files changed, 189 insertions(+), 23 deletions(-)  create mode
100644 Documentation/devicetree/bindings/extcon/extcon-gpio.txt
 create mode 100644 include/dt-bindings/extcon/extcon.h
Documentation/devicetree/bindings/extcon/extcon-gpio.txt new file +15 -0
new file mode 100644
index 0000000..81f7932
@@ -0,0 +1,48 @@
+GPIO Extcon device
+
+This is a virtual device used to generate the specific cable states
+from the GPIO pin.
+
+Required properties:
+- compatible: Must be "extcon-gpio".
+- extcon-id: The extcon support the various type of external
+connector to check
+  whether connector is attached or detached. The each external
+connector has
+  the unique number to identify it. So this property includes the
+unique number
+  which indicates the specific external connector. When external
+connector is

Documentation/devicetree/bindings/extcon/extcon-gpio.txt line 25

Quoted 10 lines
Documentation/devicetree/bindings/extcon/extcon-gpio.txt new file +10 -0
+  attached or detached, GPIO pin detect the changed state. See
+include/
+  dt-bindings/extcon/extcon.h which defines the unique number for
+supported
+  external connector from extcon framework.
+- gpios: GPIO pin to detect the external connector. See gpio binding.
+
+Optional properties:
+- debounce-ms: the debounce dealy for GPIO pin in millisecond.
+- wakeup-source: Boolean, extcon can wake-up the system from

suspend.

Quoted 37 lines
Documentation/devicetree/bindings/extcon/extcon-gpio.txt new file +32 -0
+  if gpio provided in extcon-gpio DT node is registered as interrupt,
+  then extcon can wake-up the system from suspend if wakeup-source
+property
+  is available in DT node, if gpio registered as interrupt but
+wakeup-source
+  is not available in DT node, then system wake-up due to extcon
+events
+  not supported.
+
+Example: Examples of extcon-gpio node as listed below:
+
+       usb_cable: extcon-gpio-0 {
+               compatible = "extcon-gpio";
+               extcon-id = <EXTCON_USB>;
+               extcon-gpio = <&gpio6 1 GPIO_ACTIVE_HIGH>;
+       }
+
+       ta_cable: extcon-gpio-1 {
+               compatible = "extcon-gpio";
+               extcon-id = <EXTCON_CHG_USB_DCP>;
+               extcon-gpio = <&gpio3 2 GPIO_ACTIVE_LOW>;
+               debounce-ms = <50>;     /* 50 millisecond */
+               wakeup-source;
+       }
+
+       &dwc3_usb {
+               extcon = <&usb_cable>;
+       };
+
+       &charger {
+               extcon = <&ta_cable>;
+       };
(quoted diff) +0 -0

b/drivers/extcon/extcon-gpio.c index d023789..592f395 100644

drivers/extcon/extcon-gpio.c line 7

Quoted 7 lines
drivers/extcon/extcon-gpio.c +0 -4
@@ -1,11 +1,9 @@
 /*
  * extcon_gpio.c - Single-state GPIO extcon driver based on extcon class
  *
- * Copyright (C) 2008 Google, Inc.
- * Author: Mike Lockwood <[email protected]>
- *
- * Modified by MyungJoo Ham <[email protected]> to

support

Quoted 3 lines

extcon
- * (originally switch class is supported)
+ * Copyright (C) 2016 Chanwoo Choi <[email protected]>,

Samsung

Quoted 4 lines

+ Electronics
+ * Copyright (C) 2012 MyungJoo Ham <[email protected]>,
+ Samsung Electronics
+ * Copyright (C) 2008 Mike Lockwood <[email protected]>, Google,

Inc.

drivers/extcon/extcon-gpio.c static void gpio_extcon_work(struct work_struct

Quoted 20 lines

*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation,
and @@ -25,13 +23,17 @@ #include <linux/interrupt.h> #include <linux/kernel.h> #include <linux/module.h>

drivers/extcon/extcon-gpio.c +4 -0
+#include <linux/of.h>
+#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
 
 struct gpio_extcon_data {
        struct extcon_dev *edev;
        int irq;
+       bool irq_wakeup;
        struct delayed_work work;
        unsigned long debounce_jiffies;
@@ -49,7 +51,7 @@ static void gpio_extcon_work(struct work_struct

*work)

Quoted 67 lines
drivers/extcon/extcon-gpio.c +39 -1
        state = gpiod_get_value_cansleep(data->id_gpiod);
        if (data->pdata->gpio_active_low)
                state = !state;
-       extcon_set_state(data->edev, state);
+       extcon_set_cable_state_(data->edev, data->pdata->extcon_id,
+ state);
 }
 
 static irqreturn_t gpio_irq_handler(int irq, void *dev_id) @@ -61,6
+63,42 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
+static int gpio_extcon_parse_of(struct platform_device *pdev,
+                               struct gpio_extcon_data *data) {
+       struct gpio_extcon_pdata *pdata;
+       struct device_node *np = pdev->dev.of_node;
+       enum of_gpio_flags flags;
+       int ret;
+
+       pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+       if (!pdata)
+               return -ENOMEM;
+
+       ret = device_property_read_u32(&pdev->dev, "extcon-id",
+                                        &pdata->extcon_id);
+       if (ret < 0)
+               return -EINVAL;
+
+       pdata->gpio = of_get_named_gpio_flags(np, "gpios", 0, &flags);
+       if (pdata->gpio < 0)
+               return -EINVAL;
+
+       if (flags & OF_GPIO_ACTIVE_LOW)
+               pdata->gpio_active_low = true;
+
+       data->irq_wakeup = device_property_read_bool(&pdev->dev,
+                                               "wakeup-source");
+
+       device_property_read_u32(&pdev->dev, "debounce-ms",
+ &pdata->debounce);
+
+       pdata->irq_flags = (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
+                               | IRQF_ONESHOT);
+
+       data->pdata = pdata;
+       return 0;
+}
+
 static int gpio_extcon_init(struct device *dev, struct
gpio_extcon_data *data)  {
        struct gpio_extcon_pdata *pdata = data->pdata; @@ -96,16
+134,20 @@ static int gpio_extcon_probe(struct platform_device *pdev)
        struct gpio_extcon_data *data;
        int ret;
drivers/extcon/extcon-gpio.c +1 -8
-       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);
+       data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
        if (!data)
                return -ENOMEM;
-       data->pdata = pdata;

drivers/extcon/extcon-gpio.c static int gpio_extcon_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/extcon/extcon-gpio.c +10 -0
+
+       if (!pdata) {
+               ret = gpio_extcon_parse_of(pdev, data);
+               if (ret < 0)
+                       return ret;
+       } else {
+               data->pdata = pdata;
+       }
+
+       if (!data->pdata->irq_flags || data->pdata->extcon_id ==

EXTCON_NONE)

drivers/extcon/extcon-gpio.c static int gpio_extcon_probe(struct

Quoted 17 lines

+ return -EINVAL;

        /* Initialize the gpio */
        ret = gpio_extcon_init(&pdev->dev, data); @@ -113,7 +155,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);

drivers/extcon/extcon-gpio.c +3 -0
+       data->edev = devm_extcon_dev_allocate(&pdev->dev,
+
+ &data->pdata->extcon_id);
        if (IS_ERR(data->edev)) {
                dev_err(&pdev->dev, "failed to allocate extcon device\n");
                return -ENOMEM;
@@ -130,7 +173,8 @@ static int gpio_extcon_probe(struct

platform_device *pdev)

drivers/extcon/extcon-gpio.c static int gpio_extcon_probe(struct

Quoted 10 lines
drivers/extcon/extcon-gpio.c +2 -1
         * is attached or detached.
         */
        ret = devm_request_any_context_irq(&pdev->dev, data->irq,
-                                       gpio_irq_handler, pdata->irq_flags,
+                                       gpio_irq_handler,
+                                       data->pdata->irq_flags,
                                        pdev->name, data);
        if (ret < 0)
                return ret;
@@ -139,6 +183,8 @@ static int gpio_extcon_probe(struct

platform_device *pdev)

drivers/extcon/extcon-gpio.c static struct platform_driver gpio_extcon_driver =

Quoted 52 lines
drivers/extcon/extcon-gpio.c +15 -3
        /* Perform initial detection */
        gpio_extcon_work(&data->work.work);
 
+       if (data->irq_wakeup)
+               device_init_wakeup(&pdev->dev, data->irq_wakeup);
        return 0;
 }
 
@@ -152,11 +198,23 @@ static int gpio_extcon_remove(struct
 platform_device *pdev)  }
 
 #ifdef CONFIG_PM_SLEEP
+static int gpio_extcon_suspend(struct device *dev) {
+       struct gpio_extcon_data *data = dev_get_drvdata(dev);
+
+       if (data->irq_wakeup)
+               enable_irq_wake(data->irq);
+
+       return 0;
+}
+
 static int gpio_extcon_resume(struct device *dev)  {
-       struct gpio_extcon_data *data;
+       struct gpio_extcon_data *data = dev_get_drvdata(dev);
+
+       if (data->irq_wakeup)
+               disable_irq_wake(data->irq);
 
-       data = dev_get_drvdata(dev);
        if (data->pdata->check_on_resume)
                queue_delayed_work(system_power_efficient_wq,
                        &data->work, data->debounce_jiffies); @@
-165,7 +223,18 @@ static int gpio_extcon_resume(struct device *dev)  }

#endif

-static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops, NULL, gpio_extcon_resume);

drivers/extcon/extcon-gpio.c +11 -0
+#if defined(CONFIG_OF)
+static const struct of_device_id gpio_extcon_of_match[] = {
+       { .compatible = "extcon-gpio", },
+       { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, gpio_extcon_of_match); #else
+#define gpio_extcon_of_match   NULL
+#endif
+
+static SIMPLE_DEV_PM_OPS(gpio_extcon_pm_ops,
+                       gpio_extcon_suspend, gpio_extcon_resume);
 
 static struct platform_driver gpio_extcon_driver = {
        .probe          = gpio_extcon_probe,
@@ -173,11 +242,13 @@ static struct platform_driver gpio_extcon_driver =

{

drivers/extcon/extcon-gpio.c static struct platform_driver gpio_extcon_driver = {

Quoted 12 lines
drivers/extcon/extcon-gpio.c +2 -0
        .driver         = {
                .name   = "extcon-gpio",
                .pm     = &gpio_extcon_pm_ops,
+               .of_match_table = gpio_extcon_of_match,
        },
 };
 
 module_platform_driver(gpio_extcon_driver);
 
+MODULE_AUTHOR("Chanwoo Choi <[email protected]>");
 MODULE_AUTHOR("Mike Lockwood <[email protected]>");
 MODULE_DESCRIPTION("GPIO extcon driver");  MODULE_LICENSE("GPL");

diff

Quoted 28 lines
drivers/extcon/extcon-gpio.c +0 -1
--git a/include/dt-bindings/extcon/extcon.h

b/include/dt-bindings/extcon/extcon.h
new file mode 100644
index 0000000..dbba588

include/dt-bindings/extcon/extcon.h new file +21 -0
@@ -0,0 +1,47 @@
+/*
+ * This header provides constants for most extcon bindings.
+ *
+ * Most extcon bindings include the unique identification format.
+ * In most cases, the unique id format uses the standard values/macro
+ * defined in this header.
+ */
+
+#ifndef _DT_BINDINGS_EXTCON_EXTCON_H
+#define _DT_BINDINGS_EXTCON_EXTCON_H
+
+/* USB external connector */
+#define EXTCON_USB             1
+#define EXTCON_USB_HOST                2
+
+/* Charging external connector */
+#define EXTCON_CHG_USB_SDP     5       /* Standard Downstream Port */
+#define EXTCON_CHG_USB_DCP     6       /* Dedicated Charging Port */
+#define EXTCON_CHG_USB_CDP     7       /* Charging Downstream Port */
+#define EXTCON_CHG_USB_ACA     8       /* Accessory Charger Adapter */
+#define EXTCON_CHG_USB_FAST    9

include/dt-bindings/extcon/extcon.h line 31

Quoted 10 lines
include/dt-bindings/extcon/extcon.h new file +10 -0
+#define EXTCON_CHG_USB_SLOW    10
+
+/* Jack external connector */
+#define EXTCON_JACK_MICROPHONE 20
+#define EXTCON_JACK_HEADPHONE  21
+#define EXTCON_JACK_LINE_IN    22
+#define EXTCON_JACK_LINE_OUT   23
+#define EXTCON_JACK_VIDEO_IN   24
+#define EXTCON_JACK_VIDEO_OUT  25
+#define EXTCON_JACK_SPDIF_IN   26      /* Sony Philips Digital InterFace

*/

include/dt-bindings/extcon/extcon.h

Quoted 4 lines
include/dt-bindings/extcon/extcon.h new file +4 -0
+#define EXTCON_JACK_SPDIF_OUT  27
+
+/* Display external connector */
+#define EXTCON_DISP_HDMI       40      /* High-Definition Multimedia

Interface */

include/dt-bindings/extcon/extcon.h line 36

Quoted 1 line
include/dt-bindings/extcon/extcon.h new file +1 -0
+#define EXTCON_DISP_MHL                41      /* Mobile High-Definition Link

*/

Quoted 17 lines
include/dt-bindings/extcon/extcon.h new file +11 -0
+#define EXTCON_DISP_DVI                42      /* Digital Visual Interface */
+#define EXTCON_DISP_VGA                43      /* Video Graphics Array */
+
+/* Miscellaneous external connector */
+#define EXTCON_DOCK            60
+#define EXTCON_JIG             61
+#define EXTCON_MECHANICAL      62
+
+#define EXTCON_NUM             63
+
+#endif /* _DT_BINDINGS_EXTCON_EXTCON_H */
include/linux/extcon/extcon-gpio.h +0 -0
index 7cacafb..f7e7673 100644

include/linux/extcon/extcon-gpio.h line 4

Quoted 6 lines
include/linux/extcon/extcon-gpio.h +1 -2
@@ -1,8 +1,8 @@
 /*
  * Single-state GPIO extcon driver based on extcon class
  *
- * Copyright (C) 2012 Samsung Electronics
- * Author: MyungJoo Ham <[email protected]>
+ * Copyright (C) 2016 Chanwoo Choi <[email protected]>,

Samsung

Quoted 22 lines
include/linux/extcon/extcon-gpio.h +5 -3
+ Electronics
+ * Copyright (C) 2012 MyungJoo Ham <[email protected]>,
+ Samsung Electronics
  *
  * based on switch class driver
  * Copyright (C) 2008 Google, Inc.
@@ -35,10 +35,10 @@
  *                     while resuming from sleep.
  */
 struct gpio_extcon_pdata {
-       unsigned int extcon_id;
+       u32 extcon_id;
        unsigned gpio;
        bool gpio_active_low;
-       unsigned long debounce;
+       u32 debounce;
        unsigned long irq_flags;
 
        bool check_on_resume;
--

2.1.4

maintainer
#4 lore raw
In reply to Venkat Reddy Talla
Quoted 3 lines · Venkat Reddy Talla

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id' and 'gpios' property.

I think extcon bindings are a mess in general...

Quoted 13 lines

For example:

	usb_cable: extcon-gpio-0 {
		compatible = "extcon-gpio";
		extcon-id = <EXTCON_USB>;
		gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
	}
	ta_cable: extcon-gpio-1 {
		compatible = "extcon-gpio";
		extcon-id = <EXTCON_CHG_USB_DCP>;
		gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
		debounce-ms = <50>;	/* 50 millisecond */
		wakeup-source;
	}

This is all 1 logical connector, the USB connector. Why are you describing cables? Those are not part of the h/w and are dynamic. Describe this as a connector which is one thing (i.e. node). Use a compatible string that reflects the type of connector (usb-microab-connector), not the driver you want to use. Then define GPIO lines needed to provide state information like VBus, ID, charger modes and control lines like soft connect (D+ pullup enable), VBus enable, etc.

Quoted 6 lines
	&dwc3_usb {
		extcon = <&usb_cable>;
	};
	&charger {
		extcon = <&ta_cable>;
	};

Rob

maintainer
#5 lore raw
Quoted 21 lines · Rob Herring
Quoted 3 lines · Venkat Reddy Talla

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id' and 'gpios' property.

I think extcon bindings are a mess in general...

Quoted 13 lines

For example:

	usb_cable: extcon-gpio-0 {
		compatible = "extcon-gpio";
		extcon-id = <EXTCON_USB>;
		gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
	}
	ta_cable: extcon-gpio-1 {
		compatible = "extcon-gpio";
		extcon-id = <EXTCON_CHG_USB_DCP>;
		gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
		debounce-ms = <50>;	/* 50 millisecond */
		wakeup-source;
	}
Quoted 8 lines

This is all 1 logical connector, the USB connector. Why are you describing cables? Those are not part of the h/w and are dynamic. Describe this as a connector which is one thing (i.e. node). Use a compatible string that reflects the type of connector (usb-microab-connector), not the driver you want to use. Then define GPIO lines needed to provide state information like VBus, ID, charger modes and control lines like soft connect (D+ pullup enable), VBus enable, etc.

You're right. The extcon-gpio driver will not use the "extcon-gpio" raw compatible. As you commented[1], the each connector will have the unique name to use the extcon-gpio.c driver.
[1] https://lkml.org/lkml/2015/10/21/906

For example,
The extcon-gpio.c driver may have the different name including the h/w information according to the kind of external connector.

static const struct of_device_id gpio_extcon_of_match[] = {
{
.compatible = "extcon-chg-sdp", /* SDP charger connector */
.data = EXTCON_CHG_SDP_DATA,
}, {
.compatible = "extcon-chg-dcp", /* DCP charger connector */
.data = EXTCON_CHG_DCP_DATA,
}, {
.compatible = "extcon-jack-microphone", /* Microphone jack connector */ .data = EXTCON_JACK_MICROPHONE_DATA,
}, {
.compatible = "extcon-disp-hdmi", /* HDMI connector*/ .data = EXTCON_DISP_HDMI_DATA,
},
......
};

Thanks,
Chanwoo Choi

maintainer
#6 lore raw

Hi Rob,

Quoted 40 lines · Chanwoo Choi
Quoted 21 lines · Rob Herring
Quoted 3 lines · Venkat Reddy Talla

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id' and 'gpios' property.

I think extcon bindings are a mess in general...

Quoted 13 lines

For example:

	usb_cable: extcon-gpio-0 {
		compatible = "extcon-gpio";
		extcon-id = <EXTCON_USB>;
		gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
	}
	ta_cable: extcon-gpio-1 {
		compatible = "extcon-gpio";
		extcon-id = <EXTCON_CHG_USB_DCP>;
		gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
		debounce-ms = <50>;	/* 50 millisecond */
		wakeup-source;
	}
Quoted 8 lines

This is all 1 logical connector, the USB connector. Why are you describing cables? Those are not part of the h/w and are dynamic. Describe this as a connector which is one thing (i.e. node). Use a compatible string that reflects the type of connector (usb-microab-connector), not the driver you want to use. Then define GPIO lines needed to provide state information like VBus, ID, charger modes and control lines like soft connect (D+ pullup enable), VBus enable, etc.

You're right. The extcon-gpio driver will not use the "extcon-gpio" raw compatible. As you commented[1], the each connector will have the unique name to use the extcon-gpio.c driver.
[1] https://lkml.org/lkml/2015/10/21/906

For example,
The extcon-gpio.c driver may have the different name including the h/w information according to the kind of external connector.

Quoted 16 lines

static const struct of_device_id gpio_extcon_of_match[] = {
{
.compatible = "extcon-chg-sdp", /* SDP charger connector */
.data = EXTCON_CHG_SDP_DATA,
}, {
.compatible = "extcon-chg-dcp", /* DCP charger connector */
.data = EXTCON_CHG_DCP_DATA,
}, {
.compatible = "extcon-jack-microphone", /* Microphone jack connector */ .data = EXTCON_JACK_MICROPHONE_DATA,
}, {
.compatible = "extcon-disp-hdmi", /* HDMI connector*/ .data = EXTCON_DISP_HDMI_DATA,
},
......
};

I reply it again.

The extcon-gpio.c is very similar with existing gpio_keys.c driver[1]
[1] drivers/input/keyboard/gpio_keys.c

The gpio_keys.c driver use the following style to support the device-tree. It use the "gpio-keys" compatible and this dt node include the specific 'key code' such as 'extcon-id = <EXTCON_CHG_USB_DCP>;'

	gpio_keys {
		compatible = "gpio-keys";

		power_key {
			gpios = <&gpx2 7 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_POWER>;
			label = "power key";
			debounce-interval = <10>;
			wakeup-source;
		};
	};

If the extcon-gpio.c driver should have the separate compatible according to the kind of external connector, the list of compatible name of extcon-gpio.c driver will be increased when new external connector is attached.

The extcon-gpio.c driver can separate the kind of external connector by using the 'extcon-id' property.

Thanks,
Chanwoo Choi

maintainer
#7 lore raw
Quoted 60 lines · Chanwoo Choi

Hi Rob,

Quoted 40 lines · Chanwoo Choi
Quoted 21 lines · Rob Herring
Quoted 3 lines · Venkat Reddy Talla

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id' and 'gpios' property.

I think extcon bindings are a mess in general...

Quoted 13 lines

For example:

    usb_cable: extcon-gpio-0 {
            compatible = "extcon-gpio";
            extcon-id = <EXTCON_USB>;
            gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
    }
    ta_cable: extcon-gpio-1 {
            compatible = "extcon-gpio";
            extcon-id = <EXTCON_CHG_USB_DCP>;
            gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
            debounce-ms = <50>;     /* 50 millisecond */
            wakeup-source;
    }
Quoted 8 lines

This is all 1 logical connector, the USB connector. Why are you describing cables? Those are not part of the h/w and are dynamic. Describe this as a connector which is one thing (i.e. node). Use a compatible string that reflects the type of connector (usb-microab-connector), not the driver you want to use. Then define GPIO lines needed to provide state information like VBus, ID, charger modes and control lines like soft connect (D+ pullup enable), VBus enable, etc.

You're right. The extcon-gpio driver will not use the "extcon-gpio" raw compatible. As you commented[1], the each connector will have the unique name to use the extcon-gpio.c driver.
[1] https://lkml.org/lkml/2015/10/21/906

For example,
The extcon-gpio.c driver may have the different name including the h/w information according to the kind of external connector.

Quoted 16 lines

static const struct of_device_id gpio_extcon_of_match[] = {
{
.compatible = "extcon-chg-sdp", /* SDP charger connector */ .data = EXTCON_CHG_SDP_DATA,
}, {
.compatible = "extcon-chg-dcp", /* DCP charger connector */ .data = EXTCON_CHG_DCP_DATA,
}, {
.compatible = "extcon-jack-microphone", /* Microphone jack connector */ .data = EXTCON_JACK_MICROPHONE_DATA,
}, {
.compatible = "extcon-disp-hdmi", /* HDMI connector*/ .data = EXTCON_DISP_HDMI_DATA,
},
......
};

Quoted 4 lines

I reply it again.

The extcon-gpio.c is very similar with existing gpio_keys.c driver[1]
[1] drivers/input/keyboard/gpio_keys.c

There is a big difference in that each gpio-key is independent. The only state is pressed or not. A USB connector has multiple pieces of state information. You may be treating them independently, but I don't think they should be.

Quoted 3 lines

The gpio_keys.c driver use the following style to support the device-tree. It use the "gpio-keys" compatible and this dt node include the specific 'key code' such as 'extcon-id = <EXTCON_CHG_USB_DCP>;'

This is state information about what is currently attached. The analogy with gpio-keys would be multiple key codes on one gpio which would be broken...

Quoted 13 lines
        gpio_keys {
                compatible = "gpio-keys";

                power_key {
                        gpios = <&gpx2 7 GPIO_ACTIVE_LOW>;
                        linux,code = <KEY_POWER>;
                        label = "power key";
                        debounce-interval = <10>;
                        wakeup-source;
                };
        };
Quoted 3 lines

If the extcon-gpio.c driver should have the separate compatible according to the kind of external connector, the list of compatible name of extcon-gpio.c driver will be increased when new external connector is attached.

So? Different h/w needs different compatible strings.

But again, you are mixing describing the connector (only what is soldered on a board) and state information (what is attached). Do not put state information into DT (describe the gpio signals or chip that provides the state information).

Quoted 2 lines

The extcon-gpio.c driver can separate the kind of external connector by using the 'extcon-id' property.

This use of DT is just broken. Come up with another way.

Rob

#8 lore raw

Hi Rob,

Quoted 6 lines · Rob Herring
Quoted 2 lines · Chanwoo Choi

The extcon-gpio.c driver can separate the kind of external connector by using the 'extcon-id' property.

This use of DT is just broken. Come up with another way.

Can we have the DT binding very similar to IIO, clock, reset etc?

Here is details for extcon-jack DT binding and its client:

The client can get the cable information through its node or extcon name
and once cable information is available, it can register for notification when state gets changed.

The typical dt nodes are:

    Extcon-driver node:

        extcon: arizona-extcon {
                compatible = "wlf,arizona-extcon";
                #extcon-cells = <1>;
        };



    Driver need to specify the cable ID as
     Cable                      ID
     ----------------------------
      Mechanical                0
      Microphone               1
      Headphone               2
      Line-out                    3

    Here #extcon-cells is must and specifies the size of extcon cells. 

The client need to provide the driver specific information as argument along with handle.

Extcon Client node:

        audio-controller@b0000 {
               ::::
                extcon-cables = <&extcon 1>, <&extcon 3>;
                extcon-cable-names = "Microphone", "Line-out";
        };

and client driver can register the cable by passing the cable name as above along with its node.

struct extcon_cable {
struct extcon_dev *edev,
int cable_id;
};

edev_mic_cable = extcon_get_extcon_cable(dev, "Microphone"); extcon_register_notification(edev_mic_cable, notifier);

edev_line_out_cable = extcon_get_extcon_cable(dev, "Line-out"); extcon_register_notification(edev_line_out_cable, notifier);

Prototype:
struct extcon_cable *extcon_get_extcon_cable(struct device *dev, const char *cable_name)

maintainer
#9 lore raw
Quoted 10 lines · Laxman Dewangan

Hi Rob,

Quoted 7 lines · Rob Herring
Quoted 3 lines · Chanwoo Choi

The extcon-gpio.c driver can separate the kind of external connector by using the 'extcon-id' property.

Quoted 6 lines
Quoted 3 lines

This use of DT is just broken. Come up with another way.

Can we have the DT binding very similar to IIO, clock, reset etc?

In what way? I'm guessing you mean to describe what controller a connector is associated with. Certainly, some sort of phandle reference will be needed. However. the node it points to is what needs a lot of work first.

Quoted 9 lines

Here is details for extcon-jack DT binding and its client:

The client can get the cable information through its node or extcon name and once cable information is available, it can register for notification when state gets changed.

The typical dt nodes are:

Quoted 10 lines
    Extcon-driver node:

        extcon: arizona-extcon {
                compatible = "wlf,arizona-extcon";
                #extcon-cells = <1>;
        };



    Driver need to specify the cable ID as

Unless you have cables hardwired to a board, please stop describing cables in DT. Connectors!

Quoted 6 lines
     Cable                      ID
     ----------------------------
      Mechanical                0
      Microphone               1
      Headphone               2
      Line-out                    3

No, please don't create some made up some number space. I don't see why you need this. You should just need the phandle to "the microphone jack" node.

Quoted 13 lines

Here #extcon-cells is must and specifies the size of extcon cells. The
client need to provide the driver specific information as argument along with handle.

Extcon Client node:

        audio-controller@b0000 {
               ::::
                extcon-cables = <&extcon 1>, <&extcon 3>;
                extcon-cable-names = "Microphone", "Line-out";
        };
Quoted 7 lines

and client driver can register the cable by passing the cable name as above along with its node.

struct extcon_cable {
struct extcon_dev *edev,
int cable_id;
};

If you are showing driver details to explain the binding, something is wrong.

Quoted 6 lines

edev_mic_cable = extcon_get_extcon_cable(dev, "Microphone"); extcon_register_notification(edev_mic_cable, notifier);

edev_line_out_cable = extcon_get_extcon_cable(dev, "Line-out"); extcon_register_notification(edev_line_out_cable, notifier);

Just remember that "*-names" should be optional (nor am I a fan of adding -names everywhere). This can be defined as first entry is mic and 2nd entry is line-out.

Rob

#10 lore raw
Quoted 12 lines · Rob Herring
Quoted 11 lines · Laxman Dewangan

Hi Rob,

Quoted 7 lines · Rob Herring
Quoted 2 lines · Chanwoo Choi

The extcon-gpio.c driver can separate the kind of external connector by using the 'extcon-id' property.

This use of DT is just broken. Come up with another way.

Quoted 5 lines
Quoted 1 line

Can we have the DT binding very similar to IIO, clock, reset etc?

In what way? I'm guessing you mean to describe what controller a connector is associated with. Certainly, some sort of phandle reference will be needed. However. the node it points to is what needs a lot of work first.

Here, we just need to define that controller support how many different cable? It does not say anything that which cable is what and all its on platform dependent.

So for gpio-extcon, it will just say 1 cable. the name is not decided by driver but it is by platform.

Quoted 17 lines
Quoted 17 lines

Here is details for extcon-jack DT binding and its client:

The client can get the cable information through its node or extcon name and once cable information is available, it can register for notification when state gets changed.

The typical dt nodes are:

     Extcon-driver node:

         extcon: arizona-extcon {
                 compatible = "wlf,arizona-extcon";
                 #extcon-cells = <1>;
         };
Quoted 3 lines
Quoted 1 line

Driver need to specify the cable ID as

Unless you have cables hardwired to a board, please stop describing cables in DT. Connectors!

If some controller only support cable with names then we need to do it. Like palmas extcon, it detect VBUS, ID_GND, RIDA, RIDB, RIDC. So for these cases, driver need to define cables. Driver can specify that cable index 0 is for VBUS, 1 is for ID-GND etc.

Quoted 10 lines
Quoted 7 lines
      Cable                      ID
      ----------------------------
       Mechanical                0
       Microphone               1
       Headphone               2
       Line-out                    3

No, please don't create some made up some number space. I don't see why you need this. You should just need the phandle to "the microphone jack" node.

I am thinking that I will need the phandle of extcon nodes with index for cable ID.

Quoted 13 lines
Quoted 13 lines

Here #extcon-cells is must and specifies the size of extcon cells. The
client need to provide the driver specific information as argument along with handle.

Extcon Client node:

         audio-controller@b0000 {
                ::::
                 extcon-cables = <&extcon 1>, <&extcon 3>;
                 extcon-cable-names = "Microphone", "Line-out";
         };
Quoted 8 lines
Quoted 7 lines

and client driver can register the cable by passing the cable name as above along with its node.

struct extcon_cable {
struct extcon_dev *edev,
int cable_id;
};

If you are showing driver details to explain the binding, something is wrong.

I have USB OTG driver which need the notification when VBUS or ID detected. For this, it can get the phandle of extcon and cable ID from that driver for "id" and "vbus".

I have platform like follows:
I have 2 gpios which detect the ID and VBUS.
Both are independent. My USB driver get the extcon handle from the DT:

extcon_vbus: extcon@0 {
        comptaible = "extcon-gpio";
        gpio = <&gpio JETSON_VBUS_GPIO 0>;
        #extcon-cells = <1>;
};
extcon_id: extcon@1 {
        comptaible = "extcon-gpio";
        gpio = <&gpio JETSON_ID_GPIO 0>;
        #extcon-cells = <1>;
};

usb-otg {
::

        extcon-cable = <&extcon_vbus 0 &extcon_d 0>;
        extcon-cable-names = "id", "vbus";

::
};

Quoted 10 lines
Quoted 5 lines

edev_mic_cable = extcon_get_extcon_cable(dev, "Microphone"); extcon_register_notification(edev_mic_cable, notifier);

edev_line_out_cable = extcon_get_extcon_cable(dev, "Line-out"); extcon_register_notification(edev_line_out_cable, notifier);

Just remember that "*-names" should be optional (nor am I a fan of adding -names everywhere). This can be defined as first entry is mic and 2nd entry is line-out.

Rob

maintainer
#11 lore raw
Quoted 28 lines · Laxman Dewangan
Quoted 18 lines · Rob Herring
Quoted 15 lines · Laxman Dewangan

Hi Rob,

Quoted 10 lines · Rob Herring
Quoted 3 lines · Chanwoo Choi

The extcon-gpio.c driver can separate the kind of external connector by using the 'extcon-id' property.

This use of DT is just broken. Come up with another way.

Quoted 6 lines
Quoted 1 line

Can we have the DT binding very similar to IIO, clock, reset etc?

In what way? I'm guessing you mean to describe what controller a connector is associated with. Certainly, some sort of phandle reference will be needed. However. the node it points to is what needs a lot of work first.

Quoted 6 lines

Here, we just need to define that controller support how many different cable? It does not say anything that which cable is what and all its on platform dependent.

So for gpio-extcon, it will just say 1 cable. the name is not decided by driver but it is by platform.

Why the fascination with cables? You need to describe the connector and circuitry between the connector and phy/controller, and its capabilities. Maybe those properties are implied or explicit. If you have some USB chip for Vbus control and charger detect, then it's all going to be implied by that chip's compatible. If you have gpio lines then the properties and capabilities are explicit.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Here is details for extcon-jack DT binding and its client:

The client can get the cable information through its node or extcon name and once cable information is available, it can register for notification when state gets changed.

The typical dt nodes are:

     Extcon-driver node:

         extcon: arizona-extcon {
                 compatible = "wlf,arizona-extcon";
                 #extcon-cells = <1>;
         };



     Driver need to specify the cable ID as
Quoted 7 lines
Quoted 2 lines

Unless you have cables hardwired to a board, please stop describing cables in DT. Connectors!

If some controller only support cable with names then we need to do it. Like palmas extcon, it detect VBUS, ID_GND, RIDA, RIDB, RIDC. So for these cases, driver need to define cables.

The only thing the DT should have is the palmas chip and any connections to it like regulators or interrupts. What the chip can control/detect doesn't belong in DT.

Quoted 1 line

Driver can specify that cable index 0 is for VBUS, 1 is for ID-GND etc.

You are still just making up indexes.

Quoted 38 lines
Quoted 10 lines
Quoted 6 lines
      Cable                      ID
      ----------------------------
       Mechanical                0
       Microphone               1
       Headphone               2
       Line-out                    3

No, please don't create some made up some number space. I don't see why you need this. You should just need the phandle to "the microphone jack" node.

I am thinking that I will need the phandle of extcon nodes with index for cable ID.

Quoted 22 lines
Quoted 21 lines

Here #extcon-cells is must and specifies the size of extcon cells.
The
client need to provide the driver specific information as argument along with handle.

Extcon Client node:

         audio-controller@b0000 {
                ::::
                 extcon-cables = <&extcon 1>, <&extcon 3>;
                 extcon-cable-names = "Microphone", "Line-out";
         };

and client driver can register the cable by passing the cable name as above along with its node.

struct extcon_cable {
struct extcon_dev *edev,
int cable_id;
};

Quoted 6 lines
Quoted 2 lines

If you are showing driver details to explain the binding, something is wrong.

I have USB OTG driver which need the notification when VBUS or ID detected.

That's a kernel architectural detail.

Quoted 2 lines

For this, it can get the phandle of extcon and cable ID from that driver for "id" and "vbus".

You only need to describe the connection of the connector to the controller. These details don't need to be in DT.

Quoted 12 lines

I have platform like follows:
I have 2 gpios which detect the ID and VBUS.
Both are independent. My USB driver get the extcon handle from the DT:

extcon_vbus: extcon@0 {
        comptaible = "extcon-gpio";
        gpio = <&gpio JETSON_VBUS_GPIO 0>;
        #extcon-cells = <1>;
};
Quoted 5 lines
extcon_id: extcon@1 {
        comptaible = "extcon-gpio";
        gpio = <&gpio JETSON_ID_GPIO 0>;
        #extcon-cells = <1>;
};

Sigh. These are all properties of one entity: a connector.

Quoted 7 lines

usb-otg {
::

        extcon-cable = <&extcon_vbus 0 &extcon_d 0>;
        extcon-cable-names = "id", "vbus";

::
};

Rob

#12 lore raw
In reply to Rob Herring

Hi Rob,

Quoted 63 lines · Rob Herring
Quoted 62 lines · Chanwoo Choi

Hi Rob,

Quoted 40 lines · Chanwoo Choi
Quoted 21 lines · Rob Herring
Quoted 3 lines · Venkat Reddy Talla

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id' and 'gpios' property.

I think extcon bindings are a mess in general...

Quoted 13 lines

For example:

    usb_cable: extcon-gpio-0 {
            compatible = "extcon-gpio";
            extcon-id = <EXTCON_USB>;
            gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
    }
    ta_cable: extcon-gpio-1 {
            compatible = "extcon-gpio";
            extcon-id = <EXTCON_CHG_USB_DCP>;
            gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
            debounce-ms = <50>;     /* 50 millisecond */
            wakeup-source;
    }
Quoted 8 lines

This is all 1 logical connector, the USB connector. Why are you describing cables? Those are not part of the h/w and are dynamic. Describe this as a connector which is one thing (i.e. node). Use a compatible string that reflects the type of connector (usb-microab-connector), not the driver you want to use. Then define GPIO lines needed to provide state information like VBus, ID, charger modes and control lines like soft connect (D+ pullup enable), VBus enable, etc.

You're right. The extcon-gpio driver will not use the "extcon-gpio" raw compatible. As you commented[1], the each connector will have the unique name to use the extcon-gpio.c driver.
[1] https://lkml.org/lkml/2015/10/21/906

For example,
The extcon-gpio.c driver may have the different name including the h/w information according to the kind of external connector.

Quoted 16 lines

static const struct of_device_id gpio_extcon_of_match[] = {
{
.compatible = "extcon-chg-sdp", /* SDP charger connector */ .data = EXTCON_CHG_SDP_DATA,
}, {
.compatible = "extcon-chg-dcp", /* DCP charger connector */ .data = EXTCON_CHG_DCP_DATA,
}, {
.compatible = "extcon-jack-microphone", /* Microphone jack connector */ .data = EXTCON_JACK_MICROPHONE_DATA,
}, {
.compatible = "extcon-disp-hdmi", /* HDMI connector*/ .data = EXTCON_DISP_HDMI_DATA,
},
......
};

I reply it again.

Quoted 7 lines
Quoted 2 lines

The extcon-gpio.c is very similar with existing gpio_keys.c driver[1]
[1] drivers/input/keyboard/gpio_keys.c

There is a big difference in that each gpio-key is independent. The only state is pressed or not. A USB connector has multiple pieces of state information. You may be treating them independently, but I don't think they should be.

I think that is it not different because the EXTCON can only notify the whether external connector is attached or detached such as gpio-key (pressed or not).

EXTCON don't handle the any additional state except for attached or detached.

Quoted 8 lines
Quoted 4 lines

The gpio_keys.c driver use the following style to support the device-tree. It use the "gpio-keys" compatible and this dt node include the specific 'key code' such as 'extcon-id = <EXTCON_CHG_USB_DCP>;'

This is state information about what is currently attached. The analogy with gpio-keys would be multiple key codes on one gpio which would be broken...

I compared between 'gpis-keys' and ' extcon-gpio' driver as following:

name | gpio-keys | extcon-gpio
---------------------------------------------------------------------------------------------
gpio | gpios = <> | extcon-gpio = <>
---------------------------------------------------------------------------------------------
type | linux,code = <> | extcon-id = <>
---------------------------------------------------------------------------------------------
key & | KEY_POWER | EXTCON_USB
extcon id | KEY_VOLUME_UP | EXTCON_CHG_USB_SDP

               | KEY_VOLUME_DOWN   | EXTCON_JACK_MICROPHONE
               | etc                                    | etc

---------------------------------------------------------------------------------------------
state | pressed or not | attached or detached
---------------------------------------------------------------------------------------------

Quoted 25 lines
Quoted 14 lines

        gpio_keys {
                compatible = "gpio-keys";

                power_key {
                        gpios = <&gpx2 7 GPIO_ACTIVE_LOW>;
                        linux,code = <KEY_POWER>;
                        label = "power key";
                        debounce-interval = <10>;
                        wakeup-source;
                };
        };
Quoted 3 lines

If the extcon-gpio.c driver should have the separate compatible according to the kind of external connector, the list of compatible name of extcon-gpio.c driver will be increased when new external connector is attached.

So? Different h/w needs different compatible strings.

But again, you are mixing describing the connector (only what is soldered on a board) and state information (what is attached). Do not put state information into DT (describe the gpio signals or chip that provides the state information).

Quoted 6 lines
Quoted 2 lines

The extcon-gpio.c driver can separate the kind of external connector by using the 'extcon-id' property.

This use of DT is just broken. Come up with another way.

Rob

Thanks,
Chanwoo Choi
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

Hi Rob,

I'm expecting your reply about comparision between gpio-keys and extcon-gpio. I think two drivers are very similar as following.

Thanks,
Chanwoo Choi

2016년 5월 31일 화요일, Chanwoo Choi<[email protected]>님이 작성한 메시지:

Quoted 159 lines

Hi Rob,

Quoted 1 line · On Tue, May 31, 2016 at 10:35 PM, Rob Herring <[email protected] <javascript:;>>…

On Tue, May 31, 2016 at 2:35 AM, Chanwoo Choi <[email protected]

Quoted 7 lines · <javascript:;>> wrote:
Quoted 7 lines

Hi Rob,

Quoted 4 lines · Chanwoo Choi
Quoted 3 lines · Rob Herring
Quoted 2 lines · Venkat Reddy Talla

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id'

and

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 1 line

'gpios' property.

I think extcon bindings are a mess in general...

Quoted 13 lines

For example:

    usb_cable: extcon-gpio-0 {
            compatible = "extcon-gpio";
            extcon-id = <EXTCON_USB>;
            gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
    }
    ta_cable: extcon-gpio-1 {
            compatible = "extcon-gpio";
            extcon-id = <EXTCON_CHG_USB_DCP>;
            gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
            debounce-ms = <50>;     /* 50 millisecond */
            wakeup-source;
    }

This is all 1 logical connector, the USB connector. Why are you describing cables? Those are not part of the h/w and are dynamic. Describe this as a connector which is one thing (i.e. node). Use a compatible string that reflects the type of connector (usb-microab-connector), not the driver you want to use. Then define GPIO lines needed to provide state information like VBus, ID, charger modes and control lines like soft connect (D+ pullup enable), VBus enable, etc.

Quoted 1 line
Quoted 1 line
Quoted 1 line

You're right. The extcon-gpio driver will not use the "extcon-gpio"

raw compatible.

Quoted 1 line
Quoted 1 line
Quoted 1 line

As you commented[1], the each connector will have the unique name to

use the extcon-gpio.c driver.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

[1] https://lkml.org/lkml/2015/10/21/906

For example,
The extcon-gpio.c driver may have the different name including the h/w

information

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

according to the kind of external connector.

static const struct of_device_id gpio_extcon_of_match[] = {
{
.compatible = "extcon-chg-sdp", /* SDP charger connector

*/

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

.data = EXTCON_CHG_SDP_DATA,
}, {
.compatible = "extcon-chg-dcp", /* DCP charger connector

*/

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

.data = EXTCON_CHG_DCP_DATA,
}, {
.compatible = "extcon-jack-microphone", /* Microphone

jack connector */

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines

.data = EXTCON_JACK_MICROPHONE_DATA,
}, {
.compatible = "extcon-disp-hdmi", /* HDMI connector*/ .data = EXTCON_DISP_HDMI_DATA,
},
......
};

I reply it again.

Quoted 7 lines
Quoted 2 lines

The extcon-gpio.c is very similar with existing gpio_keys.c driver[1]
[1] drivers/input/keyboard/gpio_keys.c

There is a big difference in that each gpio-key is independent. The only state is pressed or not. A USB connector has multiple pieces of state information. You may be treating them independently, but I don't think they should be.

I think that is it not different because the EXTCON can only notify the whether
external connector is attached or detached such as gpio-key (pressed or not).

EXTCON don't handle the any additional state except for attached or detached.

Quoted 2 lines
Quoted 2 lines

The gpio_keys.c driver use the following style to support the

device-tree.

Quoted 6 lines
Quoted 2 lines

It use the "gpio-keys" compatible and this dt node include the specific 'key code' such as 'extcon-id = <EXTCON_CHG_USB_DCP>;'

This is state information about what is currently attached. The analogy with gpio-keys would be multiple key codes on one gpio which would be broken...

I compared between 'gpis-keys' and ' extcon-gpio' driver as following:

name | gpio-keys | extcon-gpio

---------------------------------------------------------------------------------------------
gpio | gpios = <> | extcon-gpio = <>

---------------------------------------------------------------------------------------------
type | linux,code = <> | extcon-id = <>

---------------------------------------------------------------------------------------------
key & | KEY_POWER | EXTCON_USB
extcon id | KEY_VOLUME_UP | EXTCON_CHG_USB_SDP

               | KEY_VOLUME_DOWN   | EXTCON_JACK_MICROPHONE
               | etc                                    | etc

---------------------------------------------------------------------------------------------
state | pressed or not | attached or detached

---------------------------------------------------------------------------------------------

Quoted 14 lines
Quoted 14 lines

        gpio_keys {
                compatible = "gpio-keys";

                power_key {
                        gpios = <&gpx2 7 GPIO_ACTIVE_LOW>;
                        linux,code = <KEY_POWER>;
                        label = "power key";
                        debounce-interval = <10>;
                        wakeup-source;
                };
        };
Quoted 1 line
Quoted 1 line

If the extcon-gpio.c driver should have the separate compatible

according to

Quoted 1 line
Quoted 1 line

the kind of external connector, the list of compatible name of

extcon-gpio.c driver

Quoted 9 lines
Quoted 1 line

will be increased when new external connector is attached.

So? Different h/w needs different compatible strings.

But again, you are mixing describing the connector (only what is soldered on a board) and state information (what is attached). Do not put state information into DT (describe the gpio signals or chip that provides the state information).

Quoted 6 lines
Quoted 2 lines

The extcon-gpio.c driver can separate the kind of external connector by using the 'extcon-id' property.

This use of DT is just broken. Come up with another way.

Rob

Thanks,
Chanwoo Choi

maintainer
#14 lore raw
In reply to Chanwoo Choi

Ping.

Hi Rob,

I add some comment about gpio-keys and extcon-gpio. I'm waiting for your reply.

Quoted 133 lines · Chanwoo Choi

Hi Rob,

Quoted 63 lines · Rob Herring
Quoted 62 lines · Chanwoo Choi

Hi Rob,

Quoted 40 lines · Chanwoo Choi
Quoted 21 lines · Rob Herring
Quoted 3 lines · Venkat Reddy Talla

Add the support for Device tree bindings of extcon-gpio driver. The extcon-gpio device tree node must include the both 'extcon-id' and 'gpios' property.

I think extcon bindings are a mess in general...

Quoted 13 lines

For example:

    usb_cable: extcon-gpio-0 {
            compatible = "extcon-gpio";
            extcon-id = <EXTCON_USB>;
            gpios = <&gpio6 1 GPIO_ACTIVE_HIGH>;
    }
    ta_cable: extcon-gpio-1 {
            compatible = "extcon-gpio";
            extcon-id = <EXTCON_CHG_USB_DCP>;
            gpios = <&gpio3 2 GPIO_ACTIVE_LOW>;
            debounce-ms = <50>;     /* 50 millisecond */
            wakeup-source;
    }
Quoted 8 lines

This is all 1 logical connector, the USB connector. Why are you describing cables? Those are not part of the h/w and are dynamic. Describe this as a connector which is one thing (i.e. node). Use a compatible string that reflects the type of connector (usb-microab-connector), not the driver you want to use. Then define GPIO lines needed to provide state information like VBus, ID, charger modes and control lines like soft connect (D+ pullup enable), VBus enable, etc.

You're right. The extcon-gpio driver will not use the "extcon-gpio" raw compatible. As you commented[1], the each connector will have the unique name to use the extcon-gpio.c driver.
[1] https://lkml.org/lkml/2015/10/21/906

For example,
The extcon-gpio.c driver may have the different name including the h/w information according to the kind of external connector.

Quoted 16 lines

static const struct of_device_id gpio_extcon_of_match[] = {
{
.compatible = "extcon-chg-sdp", /* SDP charger connector */ .data = EXTCON_CHG_SDP_DATA,
}, {
.compatible = "extcon-chg-dcp", /* DCP charger connector */ .data = EXTCON_CHG_DCP_DATA,
}, {
.compatible = "extcon-jack-microphone", /* Microphone jack connector */ .data = EXTCON_JACK_MICROPHONE_DATA,
}, {
.compatible = "extcon-disp-hdmi", /* HDMI connector*/ .data = EXTCON_DISP_HDMI_DATA,
},
......
};

I reply it again.

Quoted 7 lines
Quoted 2 lines

The extcon-gpio.c is very similar with existing gpio_keys.c driver[1]
[1] drivers/input/keyboard/gpio_keys.c

There is a big difference in that each gpio-key is independent. The only state is pressed or not. A USB connector has multiple pieces of state information. You may be treating them independently, but I don't think they should be.

I think that is it not different because the EXTCON can only notify the whether external connector is attached or detached such as gpio-key (pressed or not).

EXTCON don't handle the any additional state except for attached or detached.

Quoted 8 lines
Quoted 4 lines

The gpio_keys.c driver use the following style to support the device-tree. It use the "gpio-keys" compatible and this dt node include the specific 'key code' such as 'extcon-id = <EXTCON_CHG_USB_DCP>;'

This is state information about what is currently attached. The analogy with gpio-keys would be multiple key codes on one gpio which would be broken...

I compared between 'gpis-keys' and ' extcon-gpio' driver as following:

name | gpio-keys | extcon-gpio
---------------------------------------------------------------------------------------------
gpio | gpios = <> | extcon-gpio = <>
---------------------------------------------------------------------------------------------
type | linux,code = <> | extcon-id = <>
---------------------------------------------------------------------------------------------

key &      | KEY_POWER                  | EXTCON_USB
extcon id  | KEY_VOLUME_UP         | EXTCON_CHG_USB_SDP
           | KEY_VOLUME_DOWN   | EXTCON_JACK_MICROPHONE
           | etc                                    | etc

---------------------------------------------------------------------------------------------
state | pressed or not | attached or detached
---------------------------------------------------------------------------------------------

Quoted 28 lines
Quoted 14 lines

        gpio_keys {
                compatible = "gpio-keys";

                power_key {
                        gpios = <&gpx2 7 GPIO_ACTIVE_LOW>;
                        linux,code = <KEY_POWER>;
                        label = "power key";
                        debounce-interval = <10>;
                        wakeup-source;
                };
        };
Quoted 3 lines

If the extcon-gpio.c driver should have the separate compatible according to the kind of external connector, the list of compatible name of extcon-gpio.c driver will be increased when new external connector is attached.

So? Different h/w needs different compatible strings.

But again, you are mixing describing the connector (only what is soldered on a board) and state information (what is attached). Do not put state information into DT (describe the gpio signals or chip that provides the state information).

Quoted 2 lines

The extcon-gpio.c driver can separate the kind of external connector by using the 'extcon-id' property.

Quoted 6 lines
Quoted 3 lines

This use of DT is just broken. Come up with another way.

Rob

Thanks,
Chanwoo Choi

Regards,
Chanwoo Choi