Skip to contentSkip to conversation

extcon-gpio: Add devicetree support

PATCH Applied Guenter Roeck 4 participants 28 messages Aug 30, 2013 – Sep 19, 2013

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

cover extcon-gpio: Add devicetree support

The first three patches of this series are either cleanup or add functionality unrelated to devicetree support and should hopefully be acceptable as-is or with minor modifications.

Patch 1 of this series is a tiny cleanup patch.
Patch 2 adds support for hardware debounce. If the gpio chip supports debounce, use it instead of software debounce.
Patch 3 adds support for low-active presence detect signals.

Patch 4 and 5 add devicetree support. Patch 4 is the actual code and patch 5 describes devicetree bindings. Both could possibly be merged into a single patch.

Patch 6 adds possible properties for connectors supporting multiple cable types to the devicetree bindings document. This is purely for discussion and would be implemented in a separate patch. While I don't need this code for our application, I would be happy to provide it if the community sees value in it.

#1 lore raw

PATCH 1/6 extcon-gpio: Do not unnecessarily initialize variables

---
 drivers/extcon/extcon-gpio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/extcon/extcon-gpio.c +1 -1
index 02bec32..77d35a7 100644
@@ -80,7 +80,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 {
 	struct gpio_extcon_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_extcon_data *extcon_data;
-	int ret = 0;
+	int ret;
 
 	if (!pdata)
 		return -EBUSY;
Signature · 1 line
1.7.9.7
maintainer Applied
#2 lore raw

Re: [PATCH 1/6] extcon-gpio: Do not unnecessarily initialize variables

Quoted 11 lines · Guenter Roeck
---
 drivers/extcon/extcon-gpio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/extcon/extcon-gpio.c +0 -0
index 02bec32..77d35a7 100644

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

Quoted 8 lines
drivers/extcon/extcon-gpio.c +1 -1
@@ -80,7 +80,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 {
 	struct gpio_extcon_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_extcon_data *extcon_data;
-	int ret = 0;
+	int ret;
 
 	if (!pdata)
 		return -EBUSY;

Applied it on extcon-linus branch.

Thanks.
Chanwoo Choi

#3 lore raw

PATCH 2/6 extcon-gpio: If the gpio driver/chip supports debounce, use it

In reply to Guenter Roeck
---
 drivers/extcon/extcon-gpio.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/extcon/extcon-gpio.c +5 -0
index 77d35a7..973600e 100644
@@ -111,6 +111,11 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto err;
 
+	/* Use gpio debounce if available. If so, don't debounce in software. */
+	if (pdata->debounce &&
+	    !gpio_set_debounce(extcon_data->gpio, pdata->debounce * 1000))
+		extcon_data->debounce_jiffies = 0;
+
 	INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work);
 
 	extcon_data->irq = gpio_to_irq(extcon_data->gpio);
Signature · 1 line
1.7.9.7
maintainer
#4 lore raw

Re: [PATCH 2/6] extcon-gpio: If the gpio driver/chip supports debounce, use it

Hi Guenter

I agree to use gpio_set_debounce() API but, I suggest following patch to code clean. and I'd like you to use declarative sentence on patch name instead of 'If ...'.

Quoted 12 lines · Guenter Roeck
---
 drivers/extcon/extcon-gpio.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/extcon/extcon-gpio.c +0 -0
index 77d35a7..973600e 100644
@@ -111,6 +111,11 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 	if (ret < 0)

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

Quoted 10 lines
drivers/extcon/extcon-gpio.c +5 -0
 		goto err;
 
+	/* Use gpio debounce if available. If so, don't debounce in software. */
+	if (pdata->debounce &&
+	    !gpio_set_debounce(extcon_data->gpio, pdata->debounce * 1000))
+		extcon_data->debounce_jiffies = 0;
+
 	INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work);
 
 	extcon_data->irq = gpio_to_irq(extcon_data->gpio);
drivers/extcon/extcon-gpio.c +14 -9
index 3943ce2..0777e72 100644
@@ -56,8 +56,10 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
 {
        struct gpio_extcon_data *extcon_data = dev_id;
 
-       queue_delayed_work(system_power_efficient_wq, &extcon_data->work,
-                             extcon_data->debounce_jiffies);
+       if (extcon_data->debounce_jiffies)
+               queue_delayed_work(system_power_efficient_wq,
+                                  &extcon_data->work,
+                                  extcon_data->debounce_jiffies);
        return IRQ_HANDLED;
 }
 
@@ -100,7 +102,14 @@ static int gpio_extcon_probe(struct platform_device *pdev)
        extcon_data->state_off = pdata->state_off;
        if (pdata->state_on && pdata->state_off)
                extcon_data->edev.print_state = extcon_gpio_print_state;
-       extcon_data->debounce_jiffies = msecs_to_jiffies(pdata->debounce);
+       extcon_data->debounce_jiffies = 0;
+       if (pdata->debounce) {
+               ret = gpio_set_debounce(extcon_data->gpio,
+                                       pdata->debounce * 1000);
+               if (ret < 0)
+                       extcon_data->debounce_jiffies =
+                               msecs_to_jiffies(pdata->debounce);
+       }
 
        ret = extcon_dev_register(&extcon_data->edev, &pdev->dev);
        if (ret < 0)
@@ -111,11 +120,6 @@ static int gpio_extcon_probe(struct platform_device *pdev)
        if (ret < 0)
                goto err;
 
-       /* Use gpio debounce if available. If so, don't debounce in software. */
-       if (pdata->debounce &&
-           !gpio_set_debounce(extcon_data->gpio, pdata->debounce * 1000))
-               extcon_data->debounce_jiffies = 0;
-
        INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work);
 
        extcon_data->irq = gpio_to_irq(extcon_data->gpio);
@@ -146,7 +150,8 @@ static int gpio_extcon_remove(struct platform_device *pdev)
 {
        struct gpio_extcon_data *extcon_data = platform_get_drvdata(pdev);
 
-       cancel_delayed_work_sync(&extcon_data->work);
+       if (extcon_data->debounce_jiffies)
+               cancel_delayed_work_sync(&extcon_data->work);
        free_irq(extcon_data->irq, extcon_data);
        extcon_dev_unregister(&extcon_data->edev);
 

Thanks,
Chanwoo Choi

#5 lore raw

Re: [PATCH 2/6] extcon-gpio: If the gpio driver/chip supports debounce, use it

Quoted 34 lines · Chanwoo Choi

Hi Guenter

I agree to use gpio_set_debounce() API but, I suggest following patch to code clean. and I'd like you to use declarative sentence on patch name instead of 'If ...'.

Quoted 22 lines · Guenter Roeck
---
  drivers/extcon/extcon-gpio.c |    5 +++++
  1 file changed, 5 insertions(+)
drivers/extcon/extcon-gpio.c +5 -0
index 77d35a7..973600e 100644
@@ -111,6 +111,11 @@ static int gpio_extcon_probe(struct platform_device *pdev)
  	if (ret < 0)
  		goto err;
 
+	/* Use gpio debounce if available. If so, don't debounce in software. */
+	if (pdata->debounce &&
+	    !gpio_set_debounce(extcon_data->gpio, pdata->debounce * 1000))
+		extcon_data->debounce_jiffies = 0;
+
  	INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work);
 
  	extcon_data->irq = gpio_to_irq(extcon_data->gpio);
drivers/extcon/extcon-gpio.c +0 -0
index 3943ce2..0777e72 100644

drivers/extcon/extcon-gpio.c static irqreturn_t gpio_irq_handler(int irq, void *dev_id) · line 62

Quoted 9 lines
drivers/extcon/extcon-gpio.c +4 -2
@@ -56,8 +56,10 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
  {
         struct gpio_extcon_data *extcon_data = dev_id;
 
-       queue_delayed_work(system_power_efficient_wq, &extcon_data->work,
-                             extcon_data->debounce_jiffies);
+       if (extcon_data->debounce_jiffies)
+               queue_delayed_work(system_power_efficient_wq,
+                                  &extcon_data->work,
+                                  extcon_data->debounce_jiffies);

I am a bit lost about this one. The above means that the workqueue would not be executed at all if debounce_jiffies is 0 (and if pdata->debounce is 0), meaning an event would never be generated. With the original code, the workqueue will be executed immediately if debounce_jiffies is 0, which I think is exactly what we need.

Quoted 7 lines
drivers/extcon/extcon-gpio.c +0 -0
         return IRQ_HANDLED;
  }
 
@@ -100,7 +102,14 @@ static int gpio_extcon_probe(struct platform_device *pdev)
         extcon_data->state_off = pdata->state_off;
         if (pdata->state_on && pdata->state_off)
                 extcon_data->edev.print_state = extcon_gpio_print_state;

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

Quoted 10 lines
drivers/extcon/extcon-gpio.c +8 -1
-       extcon_data->debounce_jiffies = msecs_to_jiffies(pdata->debounce);
+       extcon_data->debounce_jiffies = 0;
+       if (pdata->debounce) {
+               ret = gpio_set_debounce(extcon_data->gpio,
+                                       pdata->debounce * 1000);
+               if (ret < 0)
+                       extcon_data->debounce_jiffies =
+                               msecs_to_jiffies(pdata->debounce);
+       }
 

Ok, though it is unnecessary to initialize debounce_jiffies (it is pre-initialized from the allocation), so I'll drop that line.

Quoted 15 lines
drivers/extcon/extcon-gpio.c +0 -5
         ret = extcon_dev_register(&extcon_data->edev, &pdev->dev);
         if (ret < 0)
@@ -111,11 +120,6 @@ static int gpio_extcon_probe(struct platform_device *pdev)
         if (ret < 0)
                 goto err;
 
-       /* Use gpio debounce if available. If so, don't debounce in software. */
-       if (pdata->debounce &&
-           !gpio_set_debounce(extcon_data->gpio, pdata->debounce * 1000))
-               extcon_data->debounce_jiffies = 0;
-
         INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work);
 
         extcon_data->irq = gpio_to_irq(extcon_data->gpio);

drivers/extcon/extcon-gpio.c static int gpio_extcon_remove(struct platform_device *pdev) · line 154

Quoted 6 lines
drivers/extcon/extcon-gpio.c +2 -1
@@ -146,7 +150,8 @@ static int gpio_extcon_remove(struct platform_device *pdev)
  {
         struct gpio_extcon_data *extcon_data = platform_get_drvdata(pdev);
 
-       cancel_delayed_work_sync(&extcon_data->work);
+       if (extcon_data->debounce_jiffies)
+               cancel_delayed_work_sync(&extcon_data->work);

I think we would have to call cancel_work_sync() in the else case to make sure that no work is in the process of being executed - which just turns out to execute the same code as cancel_delayed_work_sync(). So the if/else would just add complexity with no real gain.

Thanks,
Guenter

Quoted 8 lines
drivers/extcon/extcon-gpio.c +0 -0
         free_irq(extcon_data->irq, extcon_data);
         extcon_dev_unregister(&extcon_data->edev);
 

Thanks,
Chanwoo Choi

maintainer
#6 lore raw

Re: [PATCH 2/6] extcon-gpio: If the gpio driver/chip supports debounce, use it

Quoted 53 lines · Guenter Roeck
Quoted 34 lines · Chanwoo Choi

Hi Guenter

I agree to use gpio_set_debounce() API but, I suggest following patch to code clean. and I'd like you to use declarative sentence on patch name instead of 'If ...'.

Quoted 22 lines · Guenter Roeck
---
  drivers/extcon/extcon-gpio.c |    5 +++++
  1 file changed, 5 insertions(+)
drivers/extcon/extcon-gpio.c +5 -0
index 77d35a7..973600e 100644
@@ -111,6 +111,11 @@ static int gpio_extcon_probe(struct platform_device *pdev)
      if (ret < 0)
          goto err;
 
+    /* Use gpio debounce if available. If so, don't debounce in software. */
+    if (pdata->debounce &&
+        !gpio_set_debounce(extcon_data->gpio, pdata->debounce * 1000))
+        extcon_data->debounce_jiffies = 0;
+
      INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work);
 
      extcon_data->irq = gpio_to_irq(extcon_data->gpio);
drivers/extcon/extcon-gpio.c +0 -0
index 3943ce2..0777e72 100644

drivers/extcon/extcon-gpio.c static irqreturn_t gpio_irq_handler(int irq, void *dev_id) · line 62

Quoted 9 lines
drivers/extcon/extcon-gpio.c +4 -2
@@ -56,8 +56,10 @@ static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
  {
         struct gpio_extcon_data *extcon_data = dev_id;
 
-       queue_delayed_work(system_power_efficient_wq, &extcon_data->work,
-                             extcon_data->debounce_jiffies);
+       if (extcon_data->debounce_jiffies)
+               queue_delayed_work(system_power_efficient_wq,
+                                  &extcon_data->work,
+                                  extcon_data->debounce_jiffies);

I am a bit lost about this one. The above means that the workqueue would not be executed at all if debounce_jiffies is 0 (and if pdata->debounce is 0), meaning an event would never be generated. With the original code, the workqueue will be executed immediately if debounce_jiffies is 0, which I think is exactly what we need.

Quoted 3 lines
drivers/extcon/extcon-gpio.c +0 -0
         return IRQ_HANDLED;
  }
 
Quoted 16 lines
Quoted 4 lines
drivers/extcon/extcon-gpio.c +0 -0
@@ -100,7 +102,14 @@ static int gpio_extcon_probe(struct platform_device *pdev)
         extcon_data->state_off = pdata->state_off;
         if (pdata->state_on && pdata->state_off)
                 extcon_data->edev.print_state = extcon_gpio_print_state;

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

Quoted 10 lines
drivers/extcon/extcon-gpio.c +8 -1
-       extcon_data->debounce_jiffies = msecs_to_jiffies(pdata->debounce);
+       extcon_data->debounce_jiffies = 0;
+       if (pdata->debounce) {
+               ret = gpio_set_debounce(extcon_data->gpio,
+                                       pdata->debounce * 1000);
+               if (ret < 0)
+                       extcon_data->debounce_jiffies =
+                               msecs_to_jiffies(pdata->debounce);
+       }
 

Ok, though it is unnecessary to initialize debounce_jiffies (it is pre-initialized from the allocation), so I'll drop that line.

OK.

Quoted 19 lines
Quoted 19 lines
drivers/extcon/extcon-gpio.c +0 -5
         ret = extcon_dev_register(&extcon_data->edev, &pdev->dev);
         if (ret < 0)
@@ -111,11 +120,6 @@ static int gpio_extcon_probe(struct platform_device *pdev)
         if (ret < 0)
                 goto err;
 
-       /* Use gpio debounce if available. If so, don't debounce in software. */
-       if (pdata->debounce &&
-           !gpio_set_debounce(extcon_data->gpio, pdata->debounce * 1000))
-               extcon_data->debounce_jiffies = 0;
-
         INIT_DELAYED_WORK(&extcon_data->work, gpio_extcon_work);
 
         extcon_data->irq = gpio_to_irq(extcon_data->gpio);
@@ -146,7 +150,8 @@ static int gpio_extcon_remove(struct platform_device *pdev)
  {
         struct gpio_extcon_data *extcon_data = platform_get_drvdata(pdev);
 
Quoted 8 lines

drivers/extcon/extcon-gpio.c static int gpio_extcon_remove(struct platform_device *pdev) · line 154

Quoted 3 lines
drivers/extcon/extcon-gpio.c +2 -1
-       cancel_delayed_work_sync(&extcon_data->work);
+       if (extcon_data->debounce_jiffies)
+               cancel_delayed_work_sync(&extcon_data->work);

I think we would have to call cancel_work_sync() in the else case to make sure that no work is in the process of being executed - which just turns out to execute the same code as cancel_delayed_work_sync(). So the if/else would just add complexity with no real gain.

OK.

Thanks,
Chanwoo Choi

#7 lore raw

PATCH v2 2/6 extcon-gpio: Use gpio driver/chip debounce if supported

In reply to Guenter Roeck

---
v2: rephrase patch subject
call gpio_set_debounce before registering extcon device, and set debounce_jiffies only if the call was not successful

 drivers/extcon/extcon-gpio.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/extcon/extcon-gpio.c +7 -1
index 77d35a7..e5a4405 100644
@@ -100,7 +100,13 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 	extcon_data->state_off = pdata->state_off;
 	if (pdata->state_on && pdata->state_off)
 		extcon_data->edev.print_state = extcon_gpio_print_state;
-	extcon_data->debounce_jiffies = msecs_to_jiffies(pdata->debounce);
+	if (pdata->debounce) {
+		ret = gpio_set_debounce(extcon_data->gpio,
+					pdata->debounce * 1000);
+		if (ret < 0)
+			extcon_data->debounce_jiffies =
+				msecs_to_jiffies(pdata->debounce);
+	}
 
 	ret = extcon_dev_register(&extcon_data->edev, &pdev->dev);
 	if (ret < 0)
Signature · 1 line
1.7.9.7
maintainer
#8 lore raw

Re: [PATCH v2 2/6] extcon-gpio: Use gpio driver/chip debounce if supported

Quoted 20 lines · Guenter Roeck

---
v2: rephrase patch subject
call gpio_set_debounce before registering extcon device, and set debounce_jiffies only if the call was not successful

 drivers/extcon/extcon-gpio.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/extcon/extcon-gpio.c +0 -1
index 77d35a7..e5a4405 100644
@@ -100,7 +100,13 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 	extcon_data->state_off = pdata->state_off;
 	if (pdata->state_on && pdata->state_off)
 		extcon_data->edev.print_state = extcon_gpio_print_state;
-	extcon_data->debounce_jiffies = msecs_to_jiffies(pdata->debounce);

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

Quoted 10 lines
drivers/extcon/extcon-gpio.c +7 -0
+	if (pdata->debounce) {
+		ret = gpio_set_debounce(extcon_data->gpio,
+					pdata->debounce * 1000);
+		if (ret < 0)
+			extcon_data->debounce_jiffies =
+				msecs_to_jiffies(pdata->debounce);
+	}
 
 	ret = extcon_dev_register(&extcon_data->edev, &pdev->dev);
 	if (ret < 0)

I'd like you to add patch description for patch feature. So I add a little description about using gpio_set_debounce()

I modify patch name as following to maintain patch naming style of extcon. Before
extcon-gpio: Do not unnecessarily initialize variables
extcon-gpio: Use gpio driver/chip debounce if supported
After
extcon: gpio: Do not unnecessarily initialize variables
extcon: gpio: Use gpio driver/chip debounce if supported

Applied it on extcon-linus.
You can check it on extcon-linus branch in a few minutes.

Thanks,
Chanwoo Choi

#9 lore raw

Re: [PATCH v2 2/6] extcon-gpio: Use gpio driver/chip debounce if supported

Quoted 35 lines · Chanwoo Choi
Quoted 20 lines · Guenter Roeck

---
v2: rephrase patch subject
call gpio_set_debounce before registering extcon device, and set debounce_jiffies only if the call was not successful

  drivers/extcon/extcon-gpio.c |    8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/extcon/extcon-gpio.c +0 -1
index 77d35a7..e5a4405 100644
@@ -100,7 +100,13 @@ static int gpio_extcon_probe(struct platform_device *pdev)
  	extcon_data->state_off = pdata->state_off;
  	if (pdata->state_on && pdata->state_off)
  		extcon_data->edev.print_state = extcon_gpio_print_state;
-	extcon_data->debounce_jiffies = msecs_to_jiffies(pdata->debounce);

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

Quoted 10 lines
drivers/extcon/extcon-gpio.c +7 -0
+	if (pdata->debounce) {
+		ret = gpio_set_debounce(extcon_data->gpio,
+					pdata->debounce * 1000);
+		if (ret < 0)
+			extcon_data->debounce_jiffies =
+				msecs_to_jiffies(pdata->debounce);
+	}
 
  	ret = extcon_dev_register(&extcon_data->edev, &pdev->dev);
  	if (ret < 0)

I'd like you to add patch description for patch feature. So I add a little description about using gpio_set_debounce()

Quoted 8 lines

I modify patch name as following to maintain patch naming style of extcon. Before
extcon-gpio: Do not unnecessarily initialize variables
extcon-gpio: Use gpio driver/chip debounce if supported
After
extcon: gpio: Do not unnecessarily initialize variables
extcon: gpio: Use gpio driver/chip debounce if supported

No problem. I'll try to remember next time. Too late for patch 3/6, though. Sorry for that.

Quoted 3 lines

Applied it on extcon-linus.
You can check it on extcon-linus branch in a few minutes.

Thanks,
Guenter

#10 lore raw

PATCH 3/6 extcon-gpio: Add support for active-low presence detect pins

In reply to Guenter Roeck
---
 drivers/extcon/extcon-gpio.c       |    4 +++-
 include/linux/extcon/extcon-gpio.h |    1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/extcon/extcon-gpio.c +3 -1
index 973600e..d4e3c89 100644
@@ -34,6 +34,7 @@
 struct gpio_extcon_data {
 	struct extcon_dev edev;
 	unsigned gpio;
+	bool gpio_active_low;
 	const char *state_on;
 	const char *state_off;
 	int irq;
@@ -48,7 +49,7 @@ static void gpio_extcon_work(struct work_struct *work)
 		container_of(to_delayed_work(work), struct gpio_extcon_data,
 			     work);
 
-	state = gpio_get_value(data->gpio);
+	state = gpio_get_value(data->gpio) ^ data->gpio_active_low;
 	extcon_set_state(&data->edev, state);
 }
 
@@ -96,6 +97,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 
 	extcon_data->edev.name = pdata->name;
 	extcon_data->gpio = pdata->gpio;
+	extcon_data->gpio_active_low = pdata->gpio_active_low;
 	extcon_data->state_on = pdata->state_on;
 	extcon_data->state_off = pdata->state_off;
 	if (pdata->state_on && pdata->state_off)
include/linux/extcon/extcon-gpio.h +1 -0
index 2d8307f..1613899 100644
@@ -41,6 +41,7 @@
 struct gpio_extcon_platform_data {
 	const char *name;
 	unsigned gpio;
+	bool gpio_active_low;
 	unsigned long debounce;
 	unsigned long irq_flags;
 
Signature · 1 line
1.7.9.7
maintainer
#11 lore raw

Re: [PATCH 3/6] extcon-gpio: Add support for active-low presence detect pins

Quoted 19 lines · Guenter Roeck
---
 drivers/extcon/extcon-gpio.c       |    4 +++-
 include/linux/extcon/extcon-gpio.h |    1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/extcon/extcon-gpio.c +1 -0
index 973600e..d4e3c89 100644
@@ -34,6 +34,7 @@
 struct gpio_extcon_data {
 	struct extcon_dev edev;
 	unsigned gpio;
+	bool gpio_active_low;
 	const char *state_on;
 	const char *state_off;
 	int irq;

drivers/extcon/extcon-gpio.c static void gpio_extcon_work(struct work_struct *work) · line 52

Quoted 5 lines
drivers/extcon/extcon-gpio.c +1 -1
@@ -48,7 +49,7 @@ static void gpio_extcon_work(struct work_struct *work)
 		container_of(to_delayed_work(work), struct gpio_extcon_data,
 			     work);
 
-	state = gpio_get_value(data->gpio);
+	state = gpio_get_value(data->gpio) ^ data->gpio_active_low;

I prefer below modified code instead of exclusive keyword(^) to improve readability.

       state = gpio_get_value(data->gpio);
       if (data->gpio_active_low)
               state = !state;
Quoted 16 lines
drivers/extcon/extcon-gpio.c +1 -0
 	extcon_set_state(&data->edev, state);
 }
 
@@ -96,6 +97,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 
 	extcon_data->edev.name = pdata->name;
 	extcon_data->gpio = pdata->gpio;
+	extcon_data->gpio_active_low = pdata->gpio_active_low;
 	extcon_data->state_on = pdata->state_on;
 	extcon_data->state_off = pdata->state_off;
 	if (pdata->state_on && pdata->state_off)
include/linux/extcon/extcon-gpio.h +0 -0
index 2d8307f..1613899 100644

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

Quoted 4 lines
include/linux/extcon/extcon-gpio.h +1 -0
@@ -41,6 +41,7 @@
 struct gpio_extcon_platform_data {
 	const char *name;
 	unsigned gpio;
+	bool gpio_active_low;

You have to add description of gpio_active_low as folloiwng patch:

include/linux/extcon/extcon-gpio.h +3 -0
index 7a2f27b..ff0bfcb 100644
@@ -27,6 +27,9 @@
  * struct gpio_extcon_platform_data - A simple GPIO-controlled extcon device.
  * @name:              The name of this GPIO extcon device.
  * @gpio:              Corresponding GPIO.
+ * @gpio_active_low:   Boolean which is whether gpio active state is 1 or 0
+ *                     If true, low state of gpio means active.
+ *                     If false, high state of gpio means active.
  * @debounce:          Debounce time for GPIO IRQ in ms.
  * @irq_flags:         IRQ Flags (e.g., IRQF_TRIGGER_LOW).
  * @state_on:          print_state is overriden with state_on if attached.

Thanks,
Chanwoo Choi

#12 lore raw

PATCH v2 3/6 extcon-gpio: Add support for active-low presence detect pins

---
v2: Document gpio_active_low variable in gpio_extcon_platform_data
Rewrite active-low logic to be easier to read.

 drivers/extcon/extcon-gpio.c       |    4 ++++
 include/linux/extcon/extcon-gpio.h |    5 +++++
 2 files changed, 9 insertions(+)
drivers/extcon/extcon-gpio.c +4 -0
index 862743b..8491f86 100644
@@ -34,6 +34,7 @@
 struct gpio_extcon_data {
 	struct extcon_dev edev;
 	unsigned gpio;
+	bool gpio_active_low;
 	const char *state_on;
 	const char *state_off;
 	int irq;
@@ -49,6 +50,8 @@ static void gpio_extcon_work(struct work_struct *work)
 			     work);
 
 	state = gpio_get_value(data->gpio);
+	if (data->gpio_active_low)
+		state = !state;
 	extcon_set_state(&data->edev, state);
 }
 
@@ -96,6 +99,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 
 	extcon_data->edev.name = pdata->name;
 	extcon_data->gpio = pdata->gpio;
+	extcon_data->gpio_active_low = pdata->gpio_active_low;
 	extcon_data->state_on = pdata->state_on;
 	extcon_data->state_off = pdata->state_off;
 	if (pdata->state_on && pdata->state_off)
include/linux/extcon/extcon-gpio.h +5 -0
index 2d8307f..51ef15c 100644
@@ -27,6 +27,10 @@
  * struct gpio_extcon_platform_data - A simple GPIO-controlled extcon device.
  * @name	The name of this GPIO extcon device.
  * @gpio	Corresponding GPIO.
+ * @gpio_active_low:
+ * 		Boolean describing whether gpio active state is 1 or 0
+ * 		If true, low state of gpio means active.
+ * 		If false, high state of gpio means active.
  * @debounce	Debounce time for GPIO IRQ in ms.
  * @irq_flags	IRQ Flags (e.g., IRQF_TRIGGER_LOW).
  * @state_on	print_state is overriden with state_on if attached. If Null,
@@ -41,6 +45,7 @@
 struct gpio_extcon_platform_data {
 	const char *name;
 	unsigned gpio;
+	bool gpio_active_low;
 	unsigned long debounce;
 	unsigned long irq_flags;
 
Signature · 1 line
1.7.9.7
maintainer
#13 lore raw

Re: [PATCH v2 3/6] extcon-gpio: Add support for active-low presence detect pins

Hi Guenter,

As I mentioned on previous reply, I modify patch name as following:
extcon-gpio: Add support for active-low presence detect pins ->
extcon: gpio: Add support for active-low presence detect pins

I prefer you could add patch description. Also, you should test on extcon latest branch to protect merge conflict. This patch has conflict issue on extcon-linus branch. I fix up and applied it.

And I think you might use tab size is 4 characters. you should change tab size from 4 characters to 8 characters. You can check linux kernel coding sytle on "/kernel/Documentation/CodingStyle - chapter 1: Indentation".

Quoted 44 lines · Guenter Roeck

---
v2: Document gpio_active_low variable in gpio_extcon_platform_data
Rewrite active-low logic to be easier to read.

 drivers/extcon/extcon-gpio.c       |    4 ++++
 include/linux/extcon/extcon-gpio.h |    5 +++++
 2 files changed, 9 insertions(+)
drivers/extcon/extcon-gpio.c +4 -0
index 862743b..8491f86 100644
@@ -34,6 +34,7 @@
 struct gpio_extcon_data {
 	struct extcon_dev edev;
 	unsigned gpio;
+	bool gpio_active_low;
 	const char *state_on;
 	const char *state_off;
 	int irq;
@@ -49,6 +50,8 @@ static void gpio_extcon_work(struct work_struct *work)
 			     work);
 
 	state = gpio_get_value(data->gpio);
+	if (data->gpio_active_low)
+		state = !state;
 	extcon_set_state(&data->edev, state);
 }
 
@@ -96,6 +99,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 
 	extcon_data->edev.name = pdata->name;
 	extcon_data->gpio = pdata->gpio;
+	extcon_data->gpio_active_low = pdata->gpio_active_low;
 	extcon_data->state_on = pdata->state_on;
 	extcon_data->state_off = pdata->state_off;
 	if (pdata->state_on && pdata->state_off)
include/linux/extcon/extcon-gpio.h +0 -0
index 2d8307f..51ef15c 100644

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

Quoted 7 lines
include/linux/extcon/extcon-gpio.h +4 -0
@@ -27,6 +27,10 @@
  * struct gpio_extcon_platform_data - A simple GPIO-controlled extcon device.
  * @name	The name of this GPIO extcon device.
  * @gpio	Corresponding GPIO.
+ * @gpio_active_low:
+ * 		Boolean describing whether gpio active state is 1 or 0
+ * 		If true, low state of gpio means active.
+ * 		If false, high state of gpio means active.

I think you may use tab size is 4 characters.

Quoted 12 lines
include/linux/extcon/extcon-gpio.h +1 -0
  * @debounce	Debounce time for GPIO IRQ in ms.
  * @irq_flags	IRQ Flags (e.g., IRQF_TRIGGER_LOW).
  * @state_on	print_state is overriden with state_on if attached. If Null,
@@ -41,6 +45,7 @@
 struct gpio_extcon_platform_data {
 	const char *name;
 	unsigned gpio;
+	bool gpio_active_low;
 	unsigned long debounce;
 	unsigned long irq_flags;
 
#14 lore raw

Re: [PATCH v2 3/6] extcon-gpio: Add support for active-low presence detect pins

Quoted 8 lines · Chanwoo Choi

Hi Guenter,

As I mentioned on previous reply, I modify patch name as following:
extcon-gpio: Add support for active-low presence detect pins ->
extcon: gpio: Add support for active-low presence detect pins

I prefer you could add patch description. Also, you should test

As mentioned before, I sent out v2 of this patch before I read your comments to the previous patch.

Quoted 3 lines

on extcon latest branch to protect merge conflict. This patch has conflict issue on extcon-linus branch. I fix up and applied it.

I'll make sure to so that in the future.

Quoted 2 lines

And I think you might use tab size is 4 characters. you should change tab size from 4 characters to 8 characters. You can check linux kernel coding sytle on

Thanks for the reminder, but the problem is a different one. See below.

Quoted 48 lines

"/kernel/Documentation/CodingStyle - chapter 1: Indentation".

Quoted 45 lines · Guenter Roeck

---
v2: Document gpio_active_low variable in gpio_extcon_platform_data
Rewrite active-low logic to be easier to read.

  drivers/extcon/extcon-gpio.c       |    4 ++++
  include/linux/extcon/extcon-gpio.h |    5 +++++
  2 files changed, 9 insertions(+)
drivers/extcon/extcon-gpio.c +4 -0
index 862743b..8491f86 100644
@@ -34,6 +34,7 @@
  struct gpio_extcon_data {
  	struct extcon_dev edev;
  	unsigned gpio;
+	bool gpio_active_low;
  	const char *state_on;
  	const char *state_off;
  	int irq;
@@ -49,6 +50,8 @@ static void gpio_extcon_work(struct work_struct *work)
  			     work);
 
  	state = gpio_get_value(data->gpio);
+	if (data->gpio_active_low)
+		state = !state;
  	extcon_set_state(&data->edev, state);
  }
 
@@ -96,6 +99,7 @@ static int gpio_extcon_probe(struct platform_device *pdev)
 
  	extcon_data->edev.name = pdata->name;
  	extcon_data->gpio = pdata->gpio;
+	extcon_data->gpio_active_low = pdata->gpio_active_low;
  	extcon_data->state_on = pdata->state_on;
  	extcon_data->state_off = pdata->state_off;
  	if (pdata->state_on && pdata->state_off)
include/linux/extcon/extcon-gpio.h +0 -0
index 2d8307f..51ef15c 100644
@@ -27,6 +27,10 @@
   * struct gpio_extcon_platform_data - A simple GPIO-controlled extcon device.
Quoted 9 lines

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

Quoted 6 lines
include/linux/extcon/extcon-gpio.h +4 -0
   * @name	The name of this GPIO extcon device.
   * @gpio	Corresponding GPIO.
+ * @gpio_active_low:
+ * 		Boolean describing whether gpio active state is 1 or 0
+ * 		If true, low state of gpio means active.
+ * 		If false, high state of gpio means active.

I think you may use tab size is 4 characters.

No, that isn't it. When I cut-and-pasted your proposed text I was not careful enough and did not remove a space after the '*'. No idea how it got there, but it isn't the tab setting.

Usually I _do_ run my patches through checkpatch.pl to avoid problems like that. Sorry, my bad; looks like I was shooting too quickly last night and didn't do that.

Guenter

#15 lore raw

RFC PATCH 4/6 extcon-gpio: Add devicetree support

In reply to Guenter Roeck
---
 drivers/extcon/extcon-gpio.c |   59 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)
drivers/extcon/extcon-gpio.c +57 -2
index d4e3c89..16951fe 100644
@@ -30,6 +30,8 @@
 #include <linux/gpio.h>
 #include <linux/extcon.h>
 #include <linux/extcon/extcon-gpio.h>
+#include <linux/of_gpio.h>
+#include <linux/err.h>
 
 struct gpio_extcon_data {
 	struct extcon_dev edev;
@@ -77,14 +79,66 @@ static ssize_t extcon_gpio_print_state(struct extcon_dev *edev, char *buf)
 	return -EINVAL;
 }
 
+#ifdef CONFIG_OF_GPIO
+
+static struct gpio_extcon_platform_data *
+extcon_gpio_config_of(struct device *dev)
+{
+	struct gpio_extcon_platform_data *pdata;
+	struct device_node *np = dev->of_node;
+	enum of_gpio_flags flags;
+	int gpio, ret;
+	u32 debounce;
+
+	gpio = of_get_named_gpio_flags(np, "presence-detect-gpios", 0, &flags);
+	if (gpio < 0)
+		return ERR_PTR(gpio);
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	pdata->gpio = gpio;
+	pdata->gpio_active_low = flags & OF_GPIO_ACTIVE_LOW;
+	pdata->irq_flags = IRQ_TYPE_EDGE_BOTH;
+
+	if (!of_property_read_u32(np, "debounce-interval", &debounce))
+		pdata->debounce = debounce;
+
+	ret = of_property_read_string(np, "name", &pdata->name);
+	if (ret < 0)
+		return ERR_PTR(ret);
+
+	of_property_read_string(np, "state-on", &pdata->state_on);
+	of_property_read_string(np, "state-off", &pdata->state_off);
+
+	return pdata;
+}
+
+static const struct of_device_id of_gpio_extcon_match[] = {
+	{ .compatible = "gpio-connector", },
+	{},
+};
+#else /* CONFIG_OF_GPIO */
+static struct gpio_extcon_platform_data *
+extcon_gpio_config_of(struct device *pdev)
+{
+	return ERR_PTR(-ENODEV);
+}
+#endif /* CONFIG_OF_GPIO */
+
 static int gpio_extcon_probe(struct platform_device *pdev)
 {
 	struct gpio_extcon_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_extcon_data *extcon_data;
 	int ret;
 
-	if (!pdata)
-		return -EBUSY;
+	if (!pdata) {
+		pdata = extcon_gpio_config_of(&pdev->dev);
+		if (IS_ERR(pdata))
+			return PTR_ERR(pdata);
+	}
+
 	if (!pdata->irq_flags) {
 		dev_err(&pdev->dev, "IRQ flag is not specified.\n");
 		return -EINVAL;
@@ -161,6 +215,7 @@ static struct platform_driver gpio_extcon_driver = {
 	.driver		= {
 		.name	= "extcon-gpio",
 		.owner	= THIS_MODULE,
+		.of_match_table = of_match_ptr(of_gpio_extcon_match),
 	},
 };
 
Signature · 1 line
1.7.9.7
#16 lore raw
Quoted 39 lines · Guenter Roeck
---
 drivers/extcon/extcon-gpio.c |   59 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)
drivers/extcon/extcon-gpio.c +19 -0
index d4e3c89..16951fe 100644
@@ -30,6 +30,8 @@
 #include <linux/gpio.h>
 #include <linux/extcon.h>
 #include <linux/extcon/extcon-gpio.h>
+#include <linux/of_gpio.h>
+#include <linux/err.h>
 
 struct gpio_extcon_data {
 	struct extcon_dev edev;
@@ -77,14 +79,66 @@ static ssize_t extcon_gpio_print_state(struct extcon_dev *edev, char *buf)
 	return -EINVAL;
 }
 
+#ifdef CONFIG_OF_GPIO
+
+static struct gpio_extcon_platform_data *
+extcon_gpio_config_of(struct device *dev)
+{
+	struct gpio_extcon_platform_data *pdata;
+	struct device_node *np = dev->of_node;
+	enum of_gpio_flags flags;
+	int gpio, ret;
+	u32 debounce;
+
+	gpio = of_get_named_gpio_flags(np, "presence-detect-gpios", 0, &flags);
+	if (gpio < 0)
+		return ERR_PTR(gpio);
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)

drivers/extcon/extcon-gpio.c static ssize_t extcon_gpio_print_state(struct extcon_dev *edev, char *buf) · line 108

Quoted 10 lines
drivers/extcon/extcon-gpio.c +10 -0
+		return ERR_PTR(-ENOMEM);
+
+	pdata->gpio = gpio;
+	pdata->gpio_active_low = flags & OF_GPIO_ACTIVE_LOW;
+	pdata->irq_flags = IRQ_TYPE_EDGE_BOTH;
+
+	if (!of_property_read_u32(np, "debounce-interval", &debounce))
+		pdata->debounce = debounce;
+
+	ret = of_property_read_string(np, "name", &pdata->name);

This wasn't listed in the binding. What's this for?

Thanks,
Mark.

Quoted 50 lines
drivers/extcon/extcon-gpio.c +28 -2
+	if (ret < 0)
+		return ERR_PTR(ret);
+
+	of_property_read_string(np, "state-on", &pdata->state_on);
+	of_property_read_string(np, "state-off", &pdata->state_off);
+
+	return pdata;
+}
+
+static const struct of_device_id of_gpio_extcon_match[] = {
+	{ .compatible = "gpio-connector", },
+	{},
+};
+#else /* CONFIG_OF_GPIO */
+static struct gpio_extcon_platform_data *
+extcon_gpio_config_of(struct device *pdev)
+{
+	return ERR_PTR(-ENODEV);
+}
+#endif /* CONFIG_OF_GPIO */
+
 static int gpio_extcon_probe(struct platform_device *pdev)
 {
 	struct gpio_extcon_platform_data *pdata = pdev->dev.platform_data;
 	struct gpio_extcon_data *extcon_data;
 	int ret;
 
-	if (!pdata)
-		return -EBUSY;
+	if (!pdata) {
+		pdata = extcon_gpio_config_of(&pdev->dev);
+		if (IS_ERR(pdata))
+			return PTR_ERR(pdata);
+	}
+
 	if (!pdata->irq_flags) {
 		dev_err(&pdev->dev, "IRQ flag is not specified.\n");
 		return -EINVAL;
@@ -161,6 +215,7 @@ static struct platform_driver gpio_extcon_driver = {
 	.driver		= {
 		.name	= "extcon-gpio",
 		.owner	= THIS_MODULE,
+		.of_match_table = of_match_ptr(of_gpio_extcon_match),
 	},
 };
 
Signature · 1 line
1.7.9.7
#17 lore raw
Quoted 44 lines · Mark Rutland
Quoted 43 lines · Guenter Roeck
---
 drivers/extcon/extcon-gpio.c |   59 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)
drivers/extcon/extcon-gpio.c +23 -0
index d4e3c89..16951fe 100644
@@ -30,6 +30,8 @@
 #include <linux/gpio.h>
 #include <linux/extcon.h>
 #include <linux/extcon/extcon-gpio.h>
+#include <linux/of_gpio.h>
+#include <linux/err.h>
 
 struct gpio_extcon_data {
 	struct extcon_dev edev;
@@ -77,14 +79,66 @@ static ssize_t extcon_gpio_print_state(struct extcon_dev *edev, char *buf)
 	return -EINVAL;
 }
 
+#ifdef CONFIG_OF_GPIO
+
+static struct gpio_extcon_platform_data *
+extcon_gpio_config_of(struct device *dev)
+{
+	struct gpio_extcon_platform_data *pdata;
+	struct device_node *np = dev->of_node;
+	enum of_gpio_flags flags;
+	int gpio, ret;
+	u32 debounce;
+
+	gpio = of_get_named_gpio_flags(np, "presence-detect-gpios", 0, &flags);
+	if (gpio < 0)
+		return ERR_PTR(gpio);
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	pdata->gpio = gpio;
+	pdata->gpio_active_low = flags & OF_GPIO_ACTIVE_LOW;
Quoted 9 lines

drivers/extcon/extcon-gpio.c static ssize_t extcon_gpio_print_state(struct extcon_dev *edev, char *buf) · line 108

Quoted 6 lines
drivers/extcon/extcon-gpio.c +6 -0
+	pdata->irq_flags = IRQ_TYPE_EDGE_BOTH;
+
+	if (!of_property_read_u32(np, "debounce-interval", &debounce))
+		pdata->debounce = debounce;
+
+	ret = of_property_read_string(np, "name", &pdata->name);

This wasn't listed in the binding. What's this for?

This returns the node name.
For example, if the bindings are

	my-connector {
		...
	};

it returns the string "my-connector".

I can add a reference to the bindings document if that helps. It is typically not mentioned in bindings, though, so I didn't do it either.

Thanks,
Guenter

#18 lore raw

RFC PATCH 5/6 extcon-gpio: Describe devicetree bindings

In reply to Guenter Roeck
---
 .../devicetree/bindings/extcon/extcon-gpio         |   23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio
Documentation/devicetree/bindings/extcon/extcon-gpio new file +23 -0
new file mode 100644
index 0000000..091ddc6
@@ -0,0 +1,23 @@
+Device-Tree bindings for extcon/extcon-gpio driver
+
+Required properties:
+	- compatible = "gpio-connector";
+	- presence-detect-gpios - presence detect gpio pin
+
+Optional properties:
+	- debounce-interval - debounce interval in milli-seconds
+	- state-on - on (connected) state
+	- state-off - off (disconnected) state
+	  Depending on the type of connector or cable, states may
+	  for example be reported as "connected"/"disconnected"
+	  or "inserted"/"removed".
+
+Example node:
+
+	some-connector {
+		compatible = "gpio-connector";
+		presence-detect-gpios = <&gpio1 7 1>;
+		debounce-interval = <1>;
+		state-on = "connected";
+		state-on = "disconnected";
+	};
Signature · 1 line
1.7.9.7
#19 lore raw

Re: [RFC PATCH 5/6] extcon-gpio: Describe devicetree bindings

Documentation/devicetree/bindings/extcon/extcon-gpio line 1

Quoted 13 lines · Guenter Roeck
---
 .../devicetree/bindings/extcon/extcon-gpio         |   23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio
Documentation/devicetree/bindings/extcon/extcon-gpio new file +1 -0
new file mode 100644
index 0000000..091ddc6
@@ -0,0 +1,23 @@
+Device-Tree bindings for extcon/extcon-gpio driver

Bindings shouldn't refer to Linux-specifics like particular drivers. What class of hardware are you actually trying to describe?

Documentation/devicetree/bindings/extcon/extcon-gpio line 13

Quoted 12 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +12 -0
+
+Required properties:
+	- compatible = "gpio-connector";
+	- presence-detect-gpios - presence detect gpio pin
+
+Optional properties:
+	- debounce-interval - debounce interval in milli-seconds
+	- state-on - on (connected) state
+	- state-off - off (disconnected) state
+	  Depending on the type of connector or cable, states may
+	  for example be reported as "connected"/"disconnected"
+	  or "inserted"/"removed".

I don't understand what the state-* properties describe. Do these provide semantic information to drivers? What is the full set of valid values?

Documentation/devicetree/bindings/extcon/extcon-gpio line 23

Quoted 10 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +10 -0
+
+Example node:
+
+	some-connector {
+		compatible = "gpio-connector";
+		presence-detect-gpios = <&gpio1 7 1>;
+		debounce-interval = <1>;
+		state-on = "connected";
+		state-on = "disconnected";
+	};

I'm not sure how much value this adds to bindings over describing the gpios directly. This seems to add a layer of indirection because of Linux internals.

Thanks,
Mark.

#20 lore raw

Re: [RFC PATCH 5/6] extcon-gpio: Describe devicetree bindings

Quoted 7 lines · Mark Rutland
Quoted 6 lines · Guenter Roeck
---
 .../devicetree/bindings/extcon/extcon-gpio         |   23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio
Quoted 11 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 1

Quoted 7 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +1 -0
new file mode 100644
index 0000000..091ddc6
@@ -0,0 +1,23 @@
+Device-Tree bindings for extcon/extcon-gpio driver

Bindings shouldn't refer to Linux-specifics like particular drivers. What class of hardware are you actually trying to describe?

Agreed. Question is where to put the bindings, as they are not really specific to the extcon driver. The extcon driver merely implements the bindings. This is why the "compatible" statement reads "gpio-connector" and not "extcon-something".

The bindings describe a connector managed through gpio pins.

Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +8 -0
+
+Required properties:
+	- compatible = "gpio-connector";
+	- presence-detect-gpios - presence detect gpio pin
+
+Optional properties:
+	- debounce-interval - debounce interval in milli-seconds
+	- state-on - on (connected) state
Quoted 9 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 13

Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +4 -0
+	- state-off - off (disconnected) state
+	  Depending on the type of connector or cable, states may
+	  for example be reported as "connected"/"disconnected"
+	  or "inserted"/"removed".

I don't understand what the state-* properties describe. Do these provide semantic information to drivers? What is the full set of valid values?

That is merely text which is ultimately passed on to the user. Guess 'semantic information' might be a way to phrase it.

Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +6 -0
+
+Example node:
+
+	some-connector {
+		compatible = "gpio-connector";
+		presence-detect-gpios = <&gpio1 7 1>;
Quoted 9 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 23

Quoted 4 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +4 -0
+		debounce-interval = <1>;
+		state-on = "connected";
+		state-on = "disconnected";
+	};

I'm not sure how much value this adds to bindings over describing the gpios directly. This seems to add a layer of indirection because of Linux internals.

Not sure I understand what you mean with "describing the gpios directly". Can you elaborate and/or provide an example ?

How would you describe the use of gpio pins used to detect board presence ? That doesn't seem very Linux specific to me.

Thanks,
Guenter

#21 lore raw

Re: [RFC PATCH 5/6] extcon-gpio: Describe devicetree bindings

Quoted 19 lines · Guenter Roeck
Quoted 7 lines · Mark Rutland
Quoted 6 lines · Guenter Roeck
---
 .../devicetree/bindings/extcon/extcon-gpio         |   23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio
Quoted 11 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 1

Quoted 7 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +1 -0
new file mode 100644
index 0000000..091ddc6
@@ -0,0 +1,23 @@
+Device-Tree bindings for extcon/extcon-gpio driver

Bindings shouldn't refer to Linux-specifics like particular drivers. What class of hardware are you actually trying to describe?

Quoted 6 lines

Agreed. Question is where to put the bindings, as they are not really specific to the extcon driver. The extcon driver merely implements the bindings. This is why the "compatible" statement reads "gpio-connector" and not "extcon-something".

The bindings describe a connector managed through gpio pins.

Ok, then that's what the binding document should state.

Quoted 18 lines
Quoted 18 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 13

Quoted 13 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +12 -0
+
+Required properties:
+	- compatible = "gpio-connector";
+	- presence-detect-gpios - presence detect gpio pin
+
+Optional properties:
+	- debounce-interval - debounce interval in milli-seconds
+	- state-on - on (connected) state
+	- state-off - off (disconnected) state
+	  Depending on the type of connector or cable, states may
+	  for example be reported as "connected"/"disconnected"
+	  or "inserted"/"removed".

I don't understand what the state-* properties describe. Do these provide semantic information to drivers? What is the full set of valid values?

Quoted 2 lines

That is merely text which is ultimately passed on to the user. Guess 'semantic information' might be a way to phrase it.

Where do these end up appearing to the user? Through names in the filesystem? That's an ABI, which should be thoroughly described...

If it's arbitrary, why is it necessary at all? Surely sensible names for the state of the connector can be coded in the driver for the device attached to said connectors (which can be consistent and later changed if necessary)...

Quoted 10 lines
Quoted 10 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 22

Quoted 10 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +9 -0
+
+Example node:
+
+	some-connector {
+		compatible = "gpio-connector";
+		presence-detect-gpios = <&gpio1 7 1>;
+		debounce-interval = <1>;
+		state-on = "connected";
+		state-on = "disconnected";

I don't think that's a valid dts. I assume the second is meant to be "state-off"?

Quoted 8 lines
Quoted 6 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 23

Quoted 1 line
Documentation/devicetree/bindings/extcon/extcon-gpio new file +1 -0
+	};

I'm not sure how much value this adds to bindings over describing the gpios directly. This seems to add a layer of indirection because of Linux internals.

Not sure I understand what you mean with "describing the gpios directly". Can you elaborate and/or provide an example ?

Take a look at the MMC bindings [1], specifically the cd-gpios and wp-gpios properties. I don't see why the connection of the GPIO needs to be described by a wrapper device that doesn't really exist, when it can be described directly.

Quoted 3 lines

How would you describe the use of gpio pins used to detect board presence ? That doesn't seem very Linux specific to me.

As above, with cd-gpios.

Thanks,
Mark.

[1] Documentation/devicetree/bindings/mmc/mmc.txt

#22 lore raw

Re: [RFC PATCH 5/6] extcon-gpio: Describe devicetree bindings

Quoted 47 lines · Mark Rutland
Quoted 19 lines · Guenter Roeck
Quoted 7 lines · Mark Rutland
Quoted 6 lines · Guenter Roeck
---
 .../devicetree/bindings/extcon/extcon-gpio         |   23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio
Quoted 11 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 1

Quoted 7 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +1 -0
new file mode 100644
index 0000000..091ddc6
@@ -0,0 +1,23 @@
+Device-Tree bindings for extcon/extcon-gpio driver

Bindings shouldn't refer to Linux-specifics like particular drivers. What class of hardware are you actually trying to describe?

Quoted 6 lines

Agreed. Question is where to put the bindings, as they are not really specific to the extcon driver. The extcon driver merely implements the bindings. This is why the "compatible" statement reads "gpio-connector" and not "extcon-something".

The bindings describe a connector managed through gpio pins.

Ok, then that's what the binding document should state.

Quoted 18 lines
Quoted 18 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 13

Quoted 13 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +12 -0
+
+Required properties:
+	- compatible = "gpio-connector";
+	- presence-detect-gpios - presence detect gpio pin
+
+Optional properties:
+	- debounce-interval - debounce interval in milli-seconds
+	- state-on - on (connected) state
+	- state-off - off (disconnected) state
+	  Depending on the type of connector or cable, states may
+	  for example be reported as "connected"/"disconnected"
+	  or "inserted"/"removed".

I don't understand what the state-* properties describe. Do these provide semantic information to drivers? What is the full set of valid values?

Quoted 4 lines
Quoted 2 lines

That is merely text which is ultimately passed on to the user. Guess 'semantic information' might be a way to phrase it.

Where do these end up appearing to the user? Through names in the

Yes.

Quoted 2 lines

filesystem? That's an ABI, which should be thoroughly described...

Tricky, as I can not really describe how the extcon driver implements it. I can add something like above explanation, ie that the implementation is expected to pass the property to the user. Would that be acceptable ?

Quoted 5 lines

If it's arbitrary, why is it necessary at all? Surely sensible names for the state of the connector can be coded in the driver for the device attached to said connectors (which can be consistent and later changed if necessary)...

Good point. I took a "hint" from the implementation in the extcon driver, which lets one do that. But doesn't your comment apply to pretty much all "label" and similar properties in the various devicetree descriptions ?

Quoted 14 lines
Quoted 10 lines
Quoted 10 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 22

Quoted 10 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +9 -0
+
+Example node:
+
+	some-connector {
+		compatible = "gpio-connector";
+		presence-detect-gpios = <&gpio1 7 1>;
+		debounce-interval = <1>;
+		state-on = "connected";
+		state-on = "disconnected";

I don't think that's a valid dts. I assume the second is meant to be "state-off"?

Yes, obviously.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 23

Quoted 1 line
Documentation/devicetree/bindings/extcon/extcon-gpio new file +1 -0
+	};

I'm not sure how much value this adds to bindings over describing the gpios directly. This seems to add a layer of indirection because of Linux internals.

Quoted 8 lines
Quoted 2 lines

Not sure I understand what you mean with "describing the gpios directly". Can you elaborate and/or provide an example ?

Take a look at the MMC bindings [1], specifically the cd-gpios and wp-gpios properties. I don't see why the connection of the GPIO needs to be described by a wrapper device that doesn't really exist, when it can be described directly.

Question is - described to what or for what ?

I think what you are saying is that describing a generic connector via devicetree is not acceptable, even though it _does_ describe hardware. I would have to describe a specific connector for a specific hardware instead, which in turn would need its own driver. Is that correct ?

Thanks,
Guenter
--
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

#23 lore raw

Re: [RFC PATCH 5/6] extcon-gpio: Describe devicetree bindings

Quoted 61 lines · Guenter Roeck
Quoted 47 lines · Mark Rutland
Quoted 19 lines · Guenter Roeck
Quoted 7 lines · Mark Rutland
Quoted 6 lines · Guenter Roeck
---
 .../devicetree/bindings/extcon/extcon-gpio         |   23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-gpio
Quoted 11 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 1

Quoted 7 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +1 -0
new file mode 100644
index 0000000..091ddc6
@@ -0,0 +1,23 @@
+Device-Tree bindings for extcon/extcon-gpio driver

Bindings shouldn't refer to Linux-specifics like particular drivers. What class of hardware are you actually trying to describe?

Quoted 6 lines

Agreed. Question is where to put the bindings, as they are not really specific to the extcon driver. The extcon driver merely implements the bindings. This is why the "compatible" statement reads "gpio-connector" and not "extcon-something".

The bindings describe a connector managed through gpio pins.

Ok, then that's what the binding document should state.

Quoted 18 lines
Quoted 18 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 13

Quoted 13 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +12 -0
+
+Required properties:
+	- compatible = "gpio-connector";
+	- presence-detect-gpios - presence detect gpio pin
+
+Optional properties:
+	- debounce-interval - debounce interval in milli-seconds
+	- state-on - on (connected) state
+	- state-off - off (disconnected) state
+	  Depending on the type of connector or cable, states may
+	  for example be reported as "connected"/"disconnected"
+	  or "inserted"/"removed".

I don't understand what the state-* properties describe. Do these provide semantic information to drivers? What is the full set of valid values?

Quoted 4 lines
Quoted 2 lines

That is merely text which is ultimately passed on to the user. Guess 'semantic information' might be a way to phrase it.

Where do these end up appearing to the user? Through names in the

Yes.

Quoted 2 lines

filesystem? That's an ABI, which should be thoroughly described...

Tricky, as I can not really describe how the extcon driver implements it. I can add something like above explanation, ie that the implementation is expected to pass the property to the user. Would that be acceptable ?

Quoted 8 lines
Quoted 5 lines

If it's arbitrary, why is it necessary at all? Surely sensible names for the state of the connector can be coded in the driver for the device attached to said connectors (which can be consistent and later changed if necessary)...

Good point. I took a "hint" from the implementation in the extcon driver, which lets one do that. But doesn't your comment apply to pretty much all "label" and similar properties in the various devicetree descriptions ?

I am also very much not a fan of those properties. They all give an ill-defined ABI where Linux-specific details are in the DT. I don't see why such properties should be necessary when it's possible to write drivers in such a way as to not require them.

Quoted 31 lines
Quoted 15 lines
Quoted 11 lines
Quoted 11 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 22

Quoted 11 lines
Documentation/devicetree/bindings/extcon/extcon-gpio new file +9 -0
+
+Example node:
+
+	some-connector {
+		compatible = "gpio-connector";
+		presence-detect-gpios = <&gpio1 7 1>;
+		debounce-interval = <1>;
+		state-on = "connected";
+		state-on = "disconnected";

I don't think that's a valid dts. I assume the second is meant to be "state-off"?

Yes, obviously.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Documentation/devicetree/bindings/extcon/extcon-gpio line 23

Quoted 1 line
Documentation/devicetree/bindings/extcon/extcon-gpio new file +1 -0
+	};

I'm not sure how much value this adds to bindings over describing the gpios directly. This seems to add a layer of indirection because of Linux internals.

Quoted 8 lines
Quoted 2 lines

Not sure I understand what you mean with "describing the gpios directly". Can you elaborate and/or provide an example ?

Take a look at the MMC bindings [1], specifically the cd-gpios and wp-gpios properties. I don't see why the connection of the GPIO needs to be described by a wrapper device that doesn't really exist, when it can be described directly.

Quoted 6 lines

Question is - described to what or for what ?

I think what you are saying is that describing a generic connector via devicetree is not acceptable, even though it _does_ describe hardware. I would have to describe a specific connector for a specific hardware instead, which in turn would need its own driver. Is that correct ?

Regardless of how the connector is described, the block of hardware it connects to will have to be described, and some description of the connector will be necessary (either in the node for the block, or by phandle to a node for the connector). I agree that having a combined IP block + connector driver for each permutation is not good.

What I'm worried about is that we're pushing bindings for simple cases (i.e. presences detect for single connectors detected via GPIOs) that we have other mechanisms for describing (e.g. directly describing said GPIOs), without considering the more general case and designing the bindings to support that more general case from the start. We'll end up designing bindings that are not flexible enough to describe the cases that we already know exist, and then we'll have real pain attempting to retrofit those cases into the binding.

The only existing consumer of extcon dt bindings seems to be omap-usb, which seems to want a single extcon device describing the "USB" and "USB-HOST" cables. I'm not happy with this binding staying in mainline as-is, as it makes several assumptions that limits how future extcon bindings can be implemented:
* It assumes an extcon provider (for lack of a better name) only has at most one cable of each type.
* It assumes the same extcon provider provides all cables required.
* It assumes extcon providers are referred to by phandle only (no additional cells of identifying information).

I think we need to consider the general case first, where a device monitors the state of multiple cables, which may be of uniform or disparate types.

I think it makes more sense to have a clk or gpio style binding, e.g.

gpio: {
	...
};
cables: some-extcon-provider {
	compatible = "vendor,cable-detect";
	/*
	 * This cable detector provides state detection for a power
	 * cable (0), and up to 8 USB host cables (1-8).
	 */
	#cable-detect-cells = <1>;
};
gpio-cable: some-gpio-detection {
	compatible = "linux,gpio-cable-detect";
	gpios = <&gpio 4 2 3>;
	/*
	 * Maybe multiple GPIOs could be allowed instead?
	 */
	#cable-detect-cells = <0>;
};
some-extcon-consumer {
	compatible = "vendor,usb-host-device";

	/*
	 * This could instead be separate power-cables and usb-cables
	 * properties like the gpio bindings, but then describing an
	 * arbitrary subset of USB host cables becomes difficult (you
	 * end up needing separate usbX-gpios properties, from the
	 * start).
	 */
	cables = <&cable 0>,
		 <&cable 5>,
		 <&cable 6>;,
		 <&gpio-cable>;
	cable-names = "power", "usb3", "usb4", "usb6";
};

Another concern is that extcon handles more than just a binary state for each cable type, and the precise definition of these states is Linux-specific AFAICS. I'd prefer to keep this concern out of the DT as much as possible -- an extcon driver should know the types of its cables, and the consumer should know the types it expects to request. As such, there's no need to encode "USB-HOST" and friends in the DT -- only the name of the particular instance of that type of cable should appear. This obviously makes it difficult to have generic wrappers such as those using GPIOs -- a platform may require an arbitrary set of GPIOs which detect an arbitrary value when a certain cable is in a specific state.

We *need* to consider the general case before we start proliferating bindings, or we'll end up creating bindings that cannot express the general case. Shortcuts we take early on to make implementation easier create real problems for us later on, because they become ABI.

Cheers,
Mark.
--
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

#24 lore raw

Re: [RFC PATCH 5/6] extcon-gpio: Describe devicetree bindings

Quoted 7 lines · Mark Rutland
Quoted 4 lines · Guenter Roeck

I think what you are saying is that describing a generic connector via devicetree is not acceptable, even though it _does_ describe hardware. I would have to describe a specific connector for a specific hardware instead, which in turn would need its own driver. Is that correct ?

Quoted 5 lines

Regardless of how the connector is described, the block of hardware it connects to will have to be described, and some description of the connector will be necessary (either in the node for the block, or by phandle to a node for the connector). I agree that having a combined IP block + connector driver for each permutation is not good.

Many of the things described only have passive components attached, or things that otherwise don't need drivers - things like power inputs or headphone connectors, they're mainly providing information to allow userspace to behave differently (eg, display a charging indicator in the UI). It's not 100% true but by and by large if detection is being done using a GPIO it's probably something like that.

#25 lore raw

Re: [RFC PATCH 5/6] extcon-gpio: Describe devicetree bindings

Quoted 14 lines · Mark Brown
Quoted 7 lines · Mark Rutland
Quoted 4 lines · Guenter Roeck

I think what you are saying is that describing a generic connector via devicetree is not acceptable, even though it _does_ describe hardware. I would have to describe a specific connector for a specific hardware instead, which in turn would need its own driver. Is that correct ?

Quoted 5 lines

Regardless of how the connector is described, the block of hardware it connects to will have to be described, and some description of the connector will be necessary (either in the node for the block, or by phandle to a node for the connector). I agree that having a combined IP block + connector driver for each permutation is not good.

Quoted 6 lines

Many of the things described only have passive components attached, or things that otherwise don't need drivers - things like power inputs or headphone connectors, they're mainly providing information to allow userspace to behave differently (eg, display a charging indicator in the UI). It's not 100% true but by and by large if detection is being done using a GPIO it's probably something like that.

Correct. However, gpio based 'detect' pins typically need debounce support which is not directly available through the gpio userspace API. I tried to add that earlier, but was told to use extcon instead as it provides the necessary infrastructure. Now it almost looks like I can not use it either because the required devicetree bindings may be considered unacceptable.

Guenter
--
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

#26 lore raw

Re: [RFC PATCH 5/6] extcon-gpio: Describe devicetree bindings

Quoted 9 lines · Guenter Roeck
Quoted 6 lines · Mark Brown

Many of the things described only have passive components attached, or things that otherwise don't need drivers - things like power inputs or headphone connectors, they're mainly providing information to allow userspace to behave differently (eg, display a charging indicator in the UI). It's not 100% true but by and by large if detection is being done using a GPIO it's probably something like that.

Quoted 5 lines

Correct. However, gpio based 'detect' pins typically need debounce support which is not directly available through the gpio userspace API. I tried to add that earlier, but was told to use extcon instead as it provides the necessary infrastructure. Now it almost looks like I can not use it either because the required devicetree bindings may be considered unacceptable.

Yes, I'm trying to explain to Mark why there are drivers just purely for the connector without any software for the connected device.

#27 lore raw

RFC PATCH 6/6 extcon-gpio: Describe possible properties to support multi-type cables

In reply to Guenter Roeck

This is purely a possible description and an RFC; there is no code (yet).

---
 .../devicetree/bindings/extcon/extcon-gpio         |   26 ++++++++++++++++++++
 1 file changed, 26 insertions(+)
Documentation/devicetree/bindings/extcon/extcon-gpio +26 -0
index 091ddc6..5836ac2 100644
@@ -21,3 +21,29 @@ Example node:
 		state-on = "connected";
 		state-on = "disconnected";
 	};
+
+---
+TBD: Add support for multiple connectors
+
+An example node with multiple connectors might look as follows.
+
+	some-connector {
+		#size-cells = <1>;
+		compatible = "gpio-connector";
+		presence-detect-gpios = <&gpio1 7 1>;
+		id-gpios = <&gpio1 8 0>;
+		debounce-interval = <1>;
+		state-on = "connected";
+		state-on = "disconnected";
+
+		USB {
+			reg = <0>;
+		};
+		USB-Host {
+			reg = <1>;
+		};
+	};
+
+This describes a cable with a (low-active) presence detect pin and an ID pin.
+If the value returned by the ID pin is 0, the connected cable type is "USB".
+If the value is 1, the connected cable type is "USB-Host".
Signature · 1 line
1.7.9.7