Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: twl4030-usb: fix minor reporting goofage

Fix a reporting glitch in the twl4030 USB transceiver code.
It wasn't properly distinguishing the two types of active
USB link: ID grounded, vs not. In the current code that
distinction doesn't much matter; in the future this bugfix
should help support better USB controller communications.

Provide a comment sorting out some of the cryptic bits of
the manual: different sections use different names for
key signals, and the register definitions don't help much
without the explanations and diagrams.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

David Brownell and committed by
Greg Kroah-Hartman
def6f8b9 dc2f2b75

+19 -7
+19 -7
drivers/usb/otg/twl4030-usb.c
··· 217 217 218 218 /* In module TWL4030_MODULE_PM_MASTER */ 219 219 #define PROTECT_KEY 0x0E 220 + #define STS_HW_CONDITIONS 0x0F 220 221 221 222 /* In module TWL4030_MODULE_PM_RECEIVER */ 222 223 #define VUSB_DEDICATED1 0x7D ··· 352 351 int status; 353 352 int linkstat = USB_LINK_UNKNOWN; 354 353 355 - /* STS_HW_CONDITIONS */ 356 - status = twl4030_readb(twl, TWL4030_MODULE_PM_MASTER, 0x0f); 354 + /* 355 + * For ID/VBUS sensing, see manual section 15.4.8 ... 356 + * except when using only battery backup power, two 357 + * comparators produce VBUS_PRES and ID_PRES signals, 358 + * which don't match docs elsewhere. But ... BIT(7) 359 + * and BIT(2) of STS_HW_CONDITIONS, respectively, do 360 + * seem to match up. If either is true the USB_PRES 361 + * signal is active, the OTG module is activated, and 362 + * its interrupt may be raised (may wake the system). 363 + */ 364 + status = twl4030_readb(twl, TWL4030_MODULE_PM_MASTER, 365 + STS_HW_CONDITIONS); 357 366 if (status < 0) 358 367 dev_err(twl->dev, "USB link status err %d\n", status); 359 - else if (status & BIT(7)) 360 - linkstat = USB_LINK_VBUS; 361 - else if (status & BIT(2)) 362 - linkstat = USB_LINK_ID; 363 - else 368 + else if (status & (BIT(7) | BIT(2))) { 369 + if (status & BIT(2)) 370 + linkstat = USB_LINK_ID; 371 + else 372 + linkstat = USB_LINK_VBUS; 373 + } else 364 374 linkstat = USB_LINK_NONE; 365 375 366 376 dev_dbg(twl->dev, "HW_CONDITIONS 0x%02x/%d; link %d\n",