hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/phy/ti/phy-twl4030-usb.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * twl4030_usb - TWL4030 USB transceiver, talking to OMAP OTG controller
34 *
45 * Copyright (C) 2004-2007 Texas Instruments
56 * Copyright (C) 2008 Nokia Corporation
67 * Contact: Felipe Balbi <felipe.balbi@nokia.com>
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
218 *
229 * Current status:
2310 * - HS USB ULPI mode works.
....@@ -172,6 +159,7 @@
172159
173160 int irq;
174161 enum musb_vbus_id_status linkstat;
162
+ atomic_t connected;
175163 bool vbus_supplied;
176164 bool musb_mailbox_pending;
177165
....@@ -575,39 +563,29 @@
575563 {
576564 struct twl4030_usb *twl = _twl;
577565 enum musb_vbus_id_status status;
578
- bool status_changed = false;
579566 int err;
580567
581568 status = twl4030_usb_linkstat(twl);
582569
583570 mutex_lock(&twl->lock);
584
- if (status >= 0 && status != twl->linkstat) {
585
- status_changed =
586
- cable_present(twl->linkstat) !=
587
- cable_present(status);
588
- twl->linkstat = status;
589
- }
571
+ twl->linkstat = status;
590572 mutex_unlock(&twl->lock);
591573
592
- if (status_changed) {
593
- /* FIXME add a set_power() method so that B-devices can
594
- * configure the charger appropriately. It's not always
595
- * correct to consume VBUS power, and how much current to
596
- * consume is a function of the USB configuration chosen
597
- * by the host.
598
- *
599
- * REVISIT usb_gadget_vbus_connect(...) as needed, ditto
600
- * its disconnect() sibling, when changing to/from the
601
- * USB_LINK_VBUS state. musb_hdrc won't care until it
602
- * starts to handle softconnect right.
603
- */
604
- if (cable_present(status)) {
574
+ if (cable_present(status)) {
575
+ if (atomic_add_unless(&twl->connected, 1, 1)) {
576
+ dev_dbg(twl->dev, "%s: cable connected %i\n",
577
+ __func__, status);
605578 pm_runtime_get_sync(twl->dev);
606
- } else {
579
+ twl->musb_mailbox_pending = true;
580
+ }
581
+ } else {
582
+ if (atomic_add_unless(&twl->connected, -1, 0)) {
583
+ dev_dbg(twl->dev, "%s: cable disconnected %i\n",
584
+ __func__, status);
607585 pm_runtime_mark_last_busy(twl->dev);
608586 pm_runtime_put_autosuspend(twl->dev);
587
+ twl->musb_mailbox_pending = true;
609588 }
610
- twl->musb_mailbox_pending = true;
611589 }
612590 if (twl->musb_mailbox_pending) {
613591 err = musb_mailbox(status);