Re: [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection

2015-08-10 Thread Lee Jones
On Mon, 03 Aug 2015, Roger Quadros wrote:

 Some palmas based chip variants do not have OTG based ID logic.
 For these variants we rely on GPIO based USB ID detection.
 
 These chips do have VBUS comparator for VBUS detection so we
 continue to use the old way of detecting VBUS.
 
 Acked-by: Chanwoo Choi cw00.c...@samsung.com
 Signed-off-by: Roger Quadros rog...@ti.com
 ---
 v4: updated gpio debounce logic to use delayed_workqueue.
 
  .../devicetree/bindings/extcon/extcon-palmas.txt   |   5 +-
  drivers/extcon/extcon-palmas.c | 129 
 ++---
  drivers/extcon/extcon-usb-gpio.c   |   1 +
  include/linux/mfd/palmas.h |   7 ++
  4 files changed, 126 insertions(+), 16 deletions(-)

Acked-by: Lee Jones lee.jo...@linaro.org

 diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt 
 b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
 index 45414bb..f61d5af 100644
 --- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
 +++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
 @@ -10,8 +10,11 @@ Required Properties:
  
  Optional Properties:
   - ti,wakeup : To enable the wakeup comparator in probe
 - - ti,enable-id-detection: Perform ID detection.
 + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified
 + it performs id-detection using GPIO else using OTG core.
   - ti,enable-vbus-detection: Perform VBUS detection.
 + - id-gpio: gpio for GPIO ID detection. See gpio binding.
 + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds.
  
  palmas-usb {
 compatible = ti,twl6035-usb, ti,palmas-usb;
 diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
 index 8933e7e..662e917 100644
 --- a/drivers/extcon/extcon-palmas.c
 +++ b/drivers/extcon/extcon-palmas.c
 @@ -28,6 +28,10 @@
  #include linux/mfd/palmas.h
  #include linux/of.h
  #include linux/of_platform.h
 +#include linux/of_gpio.h
 +#include linux/workqueue.h
 +
 +#define USB_GPIO_DEBOUNCE_MS 20  /* ms */
  
  static const unsigned int palmas_extcon_cable[] = {
   EXTCON_USB,
 @@ -118,19 +122,54 @@ static irqreturn_t palmas_id_irq_handler(int irq, void 
 *_palmas_usb)
   return IRQ_HANDLED;
  }
  
 +static void palmas_gpio_id_detect(struct work_struct *work)
 +{
 + int id;
 + struct palmas_usb *palmas_usb = container_of(to_delayed_work(work),
 +  struct palmas_usb,
 +  wq_detectid);
 + struct extcon_dev *edev = palmas_usb-edev;
 +
 + if (!palmas_usb-id_gpiod)
 + return;
 +
 + id = gpiod_get_value_cansleep(palmas_usb-id_gpiod);
 +
 + if (id) {
 + extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
 + dev_info(palmas_usb-dev, USB-HOST cable is detached\n);
 + } else {
 + extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
 + dev_info(palmas_usb-dev, USB-HOST cable is attached\n);
 + }
 +}
 +
 +static irqreturn_t palmas_gpio_id_irq_handler(int irq, void *_palmas_usb)
 +{
 + struct palmas_usb *palmas_usb = _palmas_usb;
 +
 + queue_delayed_work(system_power_efficient_wq, palmas_usb-wq_detectid,
 +palmas_usb-sw_debounce_jiffies);
 +
 + return IRQ_HANDLED;
 +}
 +
  static void palmas_enable_irq(struct palmas_usb *palmas_usb)
  {
   palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
   PALMAS_USB_VBUS_CTRL_SET,
   PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP);
  
 - palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 - PALMAS_USB_ID_CTRL_SET, PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP);
 + if (palmas_usb-enable_id_detection) {
 + palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 +  PALMAS_USB_ID_CTRL_SET,
 +  PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP);
  
 - palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 - PALMAS_USB_ID_INT_EN_HI_SET,
 - PALMAS_USB_ID_INT_EN_HI_SET_ID_GND |
 - PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
 + palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 +  PALMAS_USB_ID_INT_EN_HI_SET,
 +  PALMAS_USB_ID_INT_EN_HI_SET_ID_GND |
 +  PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
 + }
  
   if (palmas_usb-enable_vbus_detection)
   palmas_vbus_irq_handler(palmas_usb-vbus_irq, palmas_usb);
 @@ -169,20 +208,36 @@ static int palmas_usb_probe(struct platform_device 
 *pdev)
   palmas_usb-wakeup = pdata-wakeup;
   }
  
 + palmas_usb-id_gpiod = devm_gpiod_get_optional(pdev-dev, id);
 + if (IS_ERR(palmas_usb-id_gpiod)) {
 + dev_err(pdev-dev, failed to get id gpio\n);
 + return PTR_ERR(palmas_usb-id_gpiod);
 + }
 +
 + if 

Re: [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection

2015-08-09 Thread Chanwoo Choi
Hi Lee,

This patch modified the header file in the MFD directory 
(include/linux/mfd/palmas.h).
After you review this patch, I'll apply it on extcon-next and sent the pull 
request for Linux 4.3.

Thanks,
Chanwoo Choi


On 08/07/2015 05:24 PM, Roger Quadros wrote:
 Hi Lee / Samuel,
 
 On 03/08/15 17:40, Roger Quadros wrote:
 Some palmas based chip variants do not have OTG based ID logic.
 For these variants we rely on GPIO based USB ID detection.

 These chips do have VBUS comparator for VBUS detection so we
 continue to use the old way of detecting VBUS.

 Acked-by: Chanwoo Choi cw00.c...@samsung.com
 Signed-off-by: Roger Quadros rog...@ti.com
 
 It seems the extcon maintainer Chanwoo needs either of your Ack
 to accept this patch.
 
 Can you please take a look and Ack if OK? Thanks.
 
 cheers,
 -roger
 
 ---
 v4: updated gpio debounce logic to use delayed_workqueue.

  .../devicetree/bindings/extcon/extcon-palmas.txt   |   5 +-
  drivers/extcon/extcon-palmas.c | 129 
 ++---
  drivers/extcon/extcon-usb-gpio.c   |   1 +
  include/linux/mfd/palmas.h |   7 ++
  4 files changed, 126 insertions(+), 16 deletions(-)

 diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt 
 b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
 index 45414bb..f61d5af 100644
 --- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
 +++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
 @@ -10,8 +10,11 @@ Required Properties:
  
  Optional Properties:
   - ti,wakeup : To enable the wakeup comparator in probe
 - - ti,enable-id-detection: Perform ID detection.
 + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified
 +it performs id-detection using GPIO else using OTG core.
   - ti,enable-vbus-detection: Perform VBUS detection.
 + - id-gpio: gpio for GPIO ID detection. See gpio binding.
 + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds.
  
  palmas-usb {
 compatible = ti,twl6035-usb, ti,palmas-usb;
 diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
 index 8933e7e..662e917 100644
 --- a/drivers/extcon/extcon-palmas.c
 +++ b/drivers/extcon/extcon-palmas.c
 @@ -28,6 +28,10 @@
  #include linux/mfd/palmas.h
  #include linux/of.h
  #include linux/of_platform.h
 +#include linux/of_gpio.h
 +#include linux/workqueue.h
 +
 +#define USB_GPIO_DEBOUNCE_MS20  /* ms */
  
  static const unsigned int palmas_extcon_cable[] = {
  EXTCON_USB,
 @@ -118,19 +122,54 @@ static irqreturn_t palmas_id_irq_handler(int irq, void 
 *_palmas_usb)
  return IRQ_HANDLED;
  }
  
 +static void palmas_gpio_id_detect(struct work_struct *work)
 +{
 +int id;
 +struct palmas_usb *palmas_usb = container_of(to_delayed_work(work),
 + struct palmas_usb,
 + wq_detectid);
 +struct extcon_dev *edev = palmas_usb-edev;
 +
 +if (!palmas_usb-id_gpiod)
 +return;
 +
 +id = gpiod_get_value_cansleep(palmas_usb-id_gpiod);
 +
 +if (id) {
 +extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
 +dev_info(palmas_usb-dev, USB-HOST cable is detached\n);
 +} else {
 +extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
 +dev_info(palmas_usb-dev, USB-HOST cable is attached\n);
 +}
 +}
 +
 +static irqreturn_t palmas_gpio_id_irq_handler(int irq, void *_palmas_usb)
 +{
 +struct palmas_usb *palmas_usb = _palmas_usb;
 +
 +queue_delayed_work(system_power_efficient_wq, palmas_usb-wq_detectid,
 +   palmas_usb-sw_debounce_jiffies);
 +
 +return IRQ_HANDLED;
 +}
 +
  static void palmas_enable_irq(struct palmas_usb *palmas_usb)
  {
  palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
  PALMAS_USB_VBUS_CTRL_SET,
  PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP);
  
 -palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 -PALMAS_USB_ID_CTRL_SET, PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP);
 +if (palmas_usb-enable_id_detection) {
 +palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 + PALMAS_USB_ID_CTRL_SET,
 + PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP);
  
 -palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 -PALMAS_USB_ID_INT_EN_HI_SET,
 -PALMAS_USB_ID_INT_EN_HI_SET_ID_GND |
 -PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
 +palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 + PALMAS_USB_ID_INT_EN_HI_SET,
 + PALMAS_USB_ID_INT_EN_HI_SET_ID_GND |
 + PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
 +}
  
  if (palmas_usb-enable_vbus_detection)
  palmas_vbus_irq_handler(palmas_usb-vbus_irq, palmas_usb);
 @@ -169,20 +208,36 @@ static int 

Re: [PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection

2015-08-07 Thread Roger Quadros
Hi Lee / Samuel,

On 03/08/15 17:40, Roger Quadros wrote:
 Some palmas based chip variants do not have OTG based ID logic.
 For these variants we rely on GPIO based USB ID detection.
 
 These chips do have VBUS comparator for VBUS detection so we
 continue to use the old way of detecting VBUS.
 
 Acked-by: Chanwoo Choi cw00.c...@samsung.com
 Signed-off-by: Roger Quadros rog...@ti.com

It seems the extcon maintainer Chanwoo needs either of your Ack
to accept this patch.

Can you please take a look and Ack if OK? Thanks.

cheers,
-roger

 ---
 v4: updated gpio debounce logic to use delayed_workqueue.
 
  .../devicetree/bindings/extcon/extcon-palmas.txt   |   5 +-
  drivers/extcon/extcon-palmas.c | 129 
 ++---
  drivers/extcon/extcon-usb-gpio.c   |   1 +
  include/linux/mfd/palmas.h |   7 ++
  4 files changed, 126 insertions(+), 16 deletions(-)
 
 diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt 
 b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
 index 45414bb..f61d5af 100644
 --- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
 +++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
 @@ -10,8 +10,11 @@ Required Properties:
  
  Optional Properties:
   - ti,wakeup : To enable the wakeup comparator in probe
 - - ti,enable-id-detection: Perform ID detection.
 + - ti,enable-id-detection: Perform ID detection. If id-gpio is specified
 + it performs id-detection using GPIO else using OTG core.
   - ti,enable-vbus-detection: Perform VBUS detection.
 + - id-gpio: gpio for GPIO ID detection. See gpio binding.
 + - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds.
  
  palmas-usb {
 compatible = ti,twl6035-usb, ti,palmas-usb;
 diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
 index 8933e7e..662e917 100644
 --- a/drivers/extcon/extcon-palmas.c
 +++ b/drivers/extcon/extcon-palmas.c
 @@ -28,6 +28,10 @@
  #include linux/mfd/palmas.h
  #include linux/of.h
  #include linux/of_platform.h
 +#include linux/of_gpio.h
 +#include linux/workqueue.h
 +
 +#define USB_GPIO_DEBOUNCE_MS 20  /* ms */
  
  static const unsigned int palmas_extcon_cable[] = {
   EXTCON_USB,
 @@ -118,19 +122,54 @@ static irqreturn_t palmas_id_irq_handler(int irq, void 
 *_palmas_usb)
   return IRQ_HANDLED;
  }
  
 +static void palmas_gpio_id_detect(struct work_struct *work)
 +{
 + int id;
 + struct palmas_usb *palmas_usb = container_of(to_delayed_work(work),
 +  struct palmas_usb,
 +  wq_detectid);
 + struct extcon_dev *edev = palmas_usb-edev;
 +
 + if (!palmas_usb-id_gpiod)
 + return;
 +
 + id = gpiod_get_value_cansleep(palmas_usb-id_gpiod);
 +
 + if (id) {
 + extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
 + dev_info(palmas_usb-dev, USB-HOST cable is detached\n);
 + } else {
 + extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
 + dev_info(palmas_usb-dev, USB-HOST cable is attached\n);
 + }
 +}
 +
 +static irqreturn_t palmas_gpio_id_irq_handler(int irq, void *_palmas_usb)
 +{
 + struct palmas_usb *palmas_usb = _palmas_usb;
 +
 + queue_delayed_work(system_power_efficient_wq, palmas_usb-wq_detectid,
 +palmas_usb-sw_debounce_jiffies);
 +
 + return IRQ_HANDLED;
 +}
 +
  static void palmas_enable_irq(struct palmas_usb *palmas_usb)
  {
   palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
   PALMAS_USB_VBUS_CTRL_SET,
   PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP);
  
 - palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 - PALMAS_USB_ID_CTRL_SET, PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP);
 + if (palmas_usb-enable_id_detection) {
 + palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 +  PALMAS_USB_ID_CTRL_SET,
 +  PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP);
  
 - palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 - PALMAS_USB_ID_INT_EN_HI_SET,
 - PALMAS_USB_ID_INT_EN_HI_SET_ID_GND |
 - PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
 + palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
 +  PALMAS_USB_ID_INT_EN_HI_SET,
 +  PALMAS_USB_ID_INT_EN_HI_SET_ID_GND |
 +  PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
 + }
  
   if (palmas_usb-enable_vbus_detection)
   palmas_vbus_irq_handler(palmas_usb-vbus_irq, palmas_usb);
 @@ -169,20 +208,36 @@ static int palmas_usb_probe(struct platform_device 
 *pdev)
   palmas_usb-wakeup = pdata-wakeup;
   }
  
 + palmas_usb-id_gpiod = devm_gpiod_get_optional(pdev-dev, id);
 + if (IS_ERR(palmas_usb-id_gpiod)) {
 + 

[PATCH v4 1/2] extcon: palmas: Support GPIO based USB ID detection

2015-08-03 Thread Roger Quadros
Some palmas based chip variants do not have OTG based ID logic.
For these variants we rely on GPIO based USB ID detection.

These chips do have VBUS comparator for VBUS detection so we
continue to use the old way of detecting VBUS.

Acked-by: Chanwoo Choi cw00.c...@samsung.com
Signed-off-by: Roger Quadros rog...@ti.com
---
v4: updated gpio debounce logic to use delayed_workqueue.

 .../devicetree/bindings/extcon/extcon-palmas.txt   |   5 +-
 drivers/extcon/extcon-palmas.c | 129 ++---
 drivers/extcon/extcon-usb-gpio.c   |   1 +
 include/linux/mfd/palmas.h |   7 ++
 4 files changed, 126 insertions(+), 16 deletions(-)

diff --git a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt 
b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
index 45414bb..f61d5af 100644
--- a/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
+++ b/Documentation/devicetree/bindings/extcon/extcon-palmas.txt
@@ -10,8 +10,11 @@ Required Properties:
 
 Optional Properties:
  - ti,wakeup : To enable the wakeup comparator in probe
- - ti,enable-id-detection: Perform ID detection.
+ - ti,enable-id-detection: Perform ID detection. If id-gpio is specified
+   it performs id-detection using GPIO else using OTG core.
  - ti,enable-vbus-detection: Perform VBUS detection.
+ - id-gpio: gpio for GPIO ID detection. See gpio binding.
+ - debounce-delay-ms: debounce delay for GPIO ID pin in milliseconds.
 
 palmas-usb {
compatible = ti,twl6035-usb, ti,palmas-usb;
diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index 8933e7e..662e917 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -28,6 +28,10 @@
 #include linux/mfd/palmas.h
 #include linux/of.h
 #include linux/of_platform.h
+#include linux/of_gpio.h
+#include linux/workqueue.h
+
+#define USB_GPIO_DEBOUNCE_MS   20  /* ms */
 
 static const unsigned int palmas_extcon_cable[] = {
EXTCON_USB,
@@ -118,19 +122,54 @@ static irqreturn_t palmas_id_irq_handler(int irq, void 
*_palmas_usb)
return IRQ_HANDLED;
 }
 
+static void palmas_gpio_id_detect(struct work_struct *work)
+{
+   int id;
+   struct palmas_usb *palmas_usb = container_of(to_delayed_work(work),
+struct palmas_usb,
+wq_detectid);
+   struct extcon_dev *edev = palmas_usb-edev;
+
+   if (!palmas_usb-id_gpiod)
+   return;
+
+   id = gpiod_get_value_cansleep(palmas_usb-id_gpiod);
+
+   if (id) {
+   extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
+   dev_info(palmas_usb-dev, USB-HOST cable is detached\n);
+   } else {
+   extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
+   dev_info(palmas_usb-dev, USB-HOST cable is attached\n);
+   }
+}
+
+static irqreturn_t palmas_gpio_id_irq_handler(int irq, void *_palmas_usb)
+{
+   struct palmas_usb *palmas_usb = _palmas_usb;
+
+   queue_delayed_work(system_power_efficient_wq, palmas_usb-wq_detectid,
+  palmas_usb-sw_debounce_jiffies);
+
+   return IRQ_HANDLED;
+}
+
 static void palmas_enable_irq(struct palmas_usb *palmas_usb)
 {
palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
PALMAS_USB_VBUS_CTRL_SET,
PALMAS_USB_VBUS_CTRL_SET_VBUS_ACT_COMP);
 
-   palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
-   PALMAS_USB_ID_CTRL_SET, PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP);
+   if (palmas_usb-enable_id_detection) {
+   palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
+PALMAS_USB_ID_CTRL_SET,
+PALMAS_USB_ID_CTRL_SET_ID_ACT_COMP);
 
-   palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
-   PALMAS_USB_ID_INT_EN_HI_SET,
-   PALMAS_USB_ID_INT_EN_HI_SET_ID_GND |
-   PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
+   palmas_write(palmas_usb-palmas, PALMAS_USB_OTG_BASE,
+PALMAS_USB_ID_INT_EN_HI_SET,
+PALMAS_USB_ID_INT_EN_HI_SET_ID_GND |
+PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
+   }
 
if (palmas_usb-enable_vbus_detection)
palmas_vbus_irq_handler(palmas_usb-vbus_irq, palmas_usb);
@@ -169,20 +208,36 @@ static int palmas_usb_probe(struct platform_device *pdev)
palmas_usb-wakeup = pdata-wakeup;
}
 
+   palmas_usb-id_gpiod = devm_gpiod_get_optional(pdev-dev, id);
+   if (IS_ERR(palmas_usb-id_gpiod)) {
+   dev_err(pdev-dev, failed to get id gpio\n);
+   return PTR_ERR(palmas_usb-id_gpiod);
+   }
+
+   if (palmas_usb-enable_id_detection  palmas_usb-id_gpiod) {
+   palmas_usb-enable_id_detection = false;
+