extcon: palmas: enable ID_GND and ID_FLOAT detection always
authorLaxman Dewangan <ldewangan@nvidia.com>
Tue, 9 Jul 2013 13:04:22 +0000 (18:34 +0530)
committerChanwoo Choi <cw00.choi@samsung.com>
Sun, 4 Aug 2013 23:53:34 +0000 (08:53 +0900)
When integrating driver with Tegra platform, it is found that
the ID pins get detected only once after booting system and
further removal and re-insert does not detect the ID pin.

Fixing this issue with enabling interrupt on ID_GND and ID_FLOAT
always  and clearing the status on LATCH register which actually
occurred.

Also if interrupt occurs with line status as zero then based on
previous status, set the cable state.

Add debug prints to display the cable state when any cable
insertion/removal happen.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Acked-by: Graeme Gregory <gg@slimlogic.co.uk>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Myungjoo Ham <myungjoo.ham@samsung.com>
drivers/extcon/extcon-palmas.c

index 7350ac2ec5e447a91a9b90479b5d8e4cf5321a37..ef77a461ca390ec7e278c14affceca1e922cddb3 100644 (file)
@@ -57,6 +57,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
                if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) {
                        palmas_usb->linkstat = PALMAS_USB_STATE_VBUS;
                        extcon_set_cable_state(&palmas_usb->edev, "USB", true);
+                       dev_info(palmas_usb->dev, "USB cable is attached\n");
                } else {
                        dev_dbg(palmas_usb->dev,
                                "Spurious connect event detected\n");
@@ -65,6 +66,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
                if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) {
                        palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
                        extcon_set_cable_state(&palmas_usb->edev, "USB", false);
+                       dev_info(palmas_usb->dev, "USB cable is detached\n");
                } else {
                        dev_dbg(palmas_usb->dev,
                                "Spurious disconnect event detected\n");
@@ -83,29 +85,24 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
                PALMAS_USB_ID_INT_LATCH_SET, &set);
 
        if (set & PALMAS_USB_ID_INT_SRC_ID_GND) {
-               palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
-                       PALMAS_USB_ID_INT_EN_HI_SET,
-                       PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
-               palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
-                       PALMAS_USB_ID_INT_EN_HI_CLR,
-                       PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
                palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
                        PALMAS_USB_ID_INT_LATCH_CLR,
                        PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
                palmas_usb->linkstat = PALMAS_USB_STATE_ID;
                extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", true);
+               dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
        } else if (set & PALMAS_USB_ID_INT_SRC_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_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
-                       PALMAS_USB_ID_INT_EN_HI_CLR,
-                       PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
                palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
                        PALMAS_USB_ID_INT_LATCH_CLR,
                        PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
                palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
                extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", false);
+               dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
+       } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
+                               (!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
+               palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
+               extcon_set_cable_state(&palmas_usb->edev, "USB-HOST", false);
+               dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
        }
 
        return IRQ_HANDLED;
@@ -122,7 +119,8 @@ static void palmas_enable_irq(struct palmas_usb *palmas_usb)
 
        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_GND |
+               PALMAS_USB_ID_INT_EN_HI_SET_ID_FLOAT);
 
        palmas_vbus_irq_handler(palmas_usb->vbus_irq, palmas_usb);