Commit 20f79588 authored by Tony Lindgren's avatar Tony Lindgren Committed by Kishon Vijay Abraham I

phy: phy-twl4030-usb: Fix cable state handling

With the recent regulator changes I noticed new warnings on doing rmmod of
phy-twl4030-usb:

WARNING: CPU: 0 PID: 1080 at drivers/regulator/core.c:2046 _regulator_put
...

Turns out we can currently miss disconnect at least for cases where status
is 0 and linkstat is 0. And in that case doing rmmod phy-twl4030-usb will
produce the regulator_put() warning.

This is because the missed disconnect causes unbalanced PM runtime calls
and the regulators will be on exit.

Let's fix the issue by using an atomic flag for the cable state to make
sure that PM runtime won't get out of sync with the cable state. That
way we can also simplify the code a bit.

Note that we can also drop the old comments, those relate to issues that
the battery charger driver and musb driver is dealing with rather than
the USB PHY driver.

Cc: NeilBrown <neilb@suse.com>
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
parent 9e98c678
...@@ -172,6 +172,7 @@ struct twl4030_usb { ...@@ -172,6 +172,7 @@ struct twl4030_usb {
int irq; int irq;
enum musb_vbus_id_status linkstat; enum musb_vbus_id_status linkstat;
atomic_t connected;
bool vbus_supplied; bool vbus_supplied;
bool musb_mailbox_pending; bool musb_mailbox_pending;
...@@ -575,39 +576,29 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl) ...@@ -575,39 +576,29 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
{ {
struct twl4030_usb *twl = _twl; struct twl4030_usb *twl = _twl;
enum musb_vbus_id_status status; enum musb_vbus_id_status status;
bool status_changed = false;
int err; int err;
status = twl4030_usb_linkstat(twl); status = twl4030_usb_linkstat(twl);
mutex_lock(&twl->lock); mutex_lock(&twl->lock);
if (status >= 0 && status != twl->linkstat) { twl->linkstat = status;
status_changed =
cable_present(twl->linkstat) !=
cable_present(status);
twl->linkstat = status;
}
mutex_unlock(&twl->lock); mutex_unlock(&twl->lock);
if (status_changed) { if (cable_present(status)) {
/* FIXME add a set_power() method so that B-devices can if (atomic_add_unless(&twl->connected, 1, 1)) {
* configure the charger appropriately. It's not always dev_dbg(twl->dev, "%s: cable connected %i\n",
* correct to consume VBUS power, and how much current to __func__, status);
* consume is a function of the USB configuration chosen
* by the host.
*
* REVISIT usb_gadget_vbus_connect(...) as needed, ditto
* its disconnect() sibling, when changing to/from the
* USB_LINK_VBUS state. musb_hdrc won't care until it
* starts to handle softconnect right.
*/
if (cable_present(status)) {
pm_runtime_get_sync(twl->dev); pm_runtime_get_sync(twl->dev);
} else { twl->musb_mailbox_pending = true;
}
} else {
if (atomic_add_unless(&twl->connected, -1, 0)) {
dev_dbg(twl->dev, "%s: cable disconnected %i\n",
__func__, status);
pm_runtime_mark_last_busy(twl->dev); pm_runtime_mark_last_busy(twl->dev);
pm_runtime_put_autosuspend(twl->dev); pm_runtime_put_autosuspend(twl->dev);
twl->musb_mailbox_pending = true;
} }
twl->musb_mailbox_pending = true;
} }
if (twl->musb_mailbox_pending) { if (twl->musb_mailbox_pending) {
err = musb_mailbox(status); err = musb_mailbox(status);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment