Commit Graph

16 Commits

Author SHA1 Message Date
Desnes Nunes 7e7c12f5c8 usb: common: usb-conn-gpio: Prevent bailing out if initial role is none
JIRA: https://issues.redhat.com/browse/RHEL-15948

commit 8e21a620c7e6e00347ade1a6ed4967b359eada5a
Author: Prashanth K <quic_prashk@quicinc.com>
Date: Tue, 1 Aug 2023 14:33:52 +0530

  Currently if we bootup a device without cable connected, then
  usb-conn-gpio won't call set_role() because last_role is same
  as current role. This happens since last_role gets initialised
  to zero during the probe.

  To avoid this, add a new flag initial_detection into struct
  usb_conn_info, which prevents bailing out during initial
  detection.

  Cc: <stable@vger.kernel.org> # 5.4
  Fixes: 4602f3bff2 ("usb: common: add USB GPIO based connection detection driver")
  Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
  Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
  Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
  Link: https://lore.kernel.org/r/1690880632-12588-1-git-send-email-quic_prashk@quicinc.com
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2023-11-21 15:33:04 -03:00
Desnes Nunes e100f897de Revert "usb: common: usb-conn-gpio: Set last role to unknown before initial detection"
JIRA: https://issues.redhat.com/browse/RHEL-15948

commit df49f2a0ac4a34c0cb4b5c233fcfa0add644c43c
Author: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: Thu, 15 Jun 2023 11:30:35 +0200

  This reverts commit edd60d24bd858cef165274e4cd6cab43bdc58d15.

  Heikki reports that this should not be a global flag just to work around
  one broken driver and should be fixed differently, so revert it.

  Reported-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
  Fixes: edd60d24bd85 ("usb: common: usb-conn-gpio: Set last role to unknown before initial detection")
  Link: https://lore.kernel.org/r/ZImE4L3YgABnCIsP@kuha.fi.intel.com
  Cc: Prashanth K <quic_prashk@quicinc.com>
  Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2023-11-21 15:32:57 -03:00
Desnes Nunes ee67b2a4cc usb: common: usb-conn-gpio: Set last role to unknown before initial detection
JIRA: https://issues.redhat.com/browse/RHEL-15948

commit edd60d24bd858cef165274e4cd6cab43bdc58d15
Author: Prashanth K <quic_prashk@quicinc.com>
Date: Wed, 31 May 2023 20:11:14 +0530

  Currently if we bootup a device without cable connected, then
  usb-conn-gpio won't call set_role() since last_role is same as
  current role. This happens because during probe last_role gets
  initialised to zero.

  To avoid this, added a new constant in enum usb_role, last_role
  is set to USB_ROLE_UNKNOWN before performing initial detection.

  While at it, also handle default case for the usb_role switch
  in cdns3, intel-xhci-usb-role-switch & musb/jz4740 to avoid
  build warnings.

  Fixes: 4602f3bff2 ("usb: common: add USB GPIO based connection detection driver")
  Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
  Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
  Message-ID: <1685544074-17337-1-git-send-email-quic_prashk@quicinc.com>
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2023-11-21 15:32:56 -03:00
Desnes Nunes d89be8a3e9 usb: common: usb-conn-gpio: Convert to platform remove callback returning void
JIRA: https://issues.redhat.com/browse/RHEL-15948

commit 4f5bcf19bd2ab8ac4c94bb39951f43e0c5ecd2b0
Author: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= <u.kleine-koenig@pengutronix.de>
Date: Thu, 18 May 2023 01:01:12 +0200

  The .remove() callback for a platform driver returns an int which makes
  many driver authors wrongly assume it's possible to do error handling by
  returning an error code. However the value returned is ignored (apart from
  emitting a warning) and this typically results in resource leaks. To improve
  here there is a quest to make the remove callback return void. In the first
  step of this quest all drivers are converted to .remove_new() which already
  returns void. Eventually after all drivers are converted, .remove_new() is
  renamed to .remove().

  Trivially convert this driver from always returning zero in the remove
  callback to the void returning variant.

  Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
  Link: https://lore.kernel.org/r/20230517230239.187727-11-u.kleine-koenig@pengutronix.de
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2023-11-21 15:32:55 -03:00
Desnes Nunes daa8f30e1d usb: common: usb-conn-gpio: Simplify some error message
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2181663
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80f4ecb95270d0ecd6646aca44f4c180d3140b0

commit d80f4ecb95270d0ecd6646aca44f4c180d3140b0
Author: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Tue, 9 Aug 2022 22:28:42 +0200

  dev_err_probe() already prints the error code in a human readable way, so
  there is no need to duplicate it as a numerical value at the end of the
  message.

  Reviewed-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
  Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
  Link: https://lore.kernel.org/r/7505a9dfa1e097070c492d6f6f84afa2a490b040.1659763173.git.christophe.jaillet@wanadoo.fr
  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Desnes Nunes <desnesn@redhat.com>
2023-04-03 20:35:47 -03:00
Torez Smith 6dcaf688e4 usb: common: usb-conn-gpio: Allow wakeup from system suspend
Bugzilla: http://bugzilla.redhat.com/2113003
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=48723298
Tested: HP ZBook 15 G5/80D5 Laptop
  ThinkPad P1 Gen5  TB4
  HP zBook Fury

commit 7afe69ad9221a77dc782b81f49cd7f99987740ed
Author: Prashanth K <quic_prashk@quicinc.com>
Date:   Fri May 27 12:19:06 2022 +0530

    usb: common: usb-conn-gpio: Allow wakeup from system suspend

    Currently the VBUS/ID detection interrupts are disabled during system
    suspend. So the USB cable connect/disconnect event can't wakeup the
    system from low power mode. To allow this, we keep these interrupts
    enabled and configure them as wakeup capable. This behavior can be
    controlled through device wakeup source policy by the user space.

    Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
    Link: https://lore.kernel.org/r/1653634146-12215-1-git-send-email-quic_prashk@quicinc.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-11-01 22:28:26 -04:00
Torez Smith 46629e5603 usb: common: usb-conn-gpio: Make VBUS supply completely optional
Bugzilla: http://bugzilla.redhat.com/2084667
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=46653455
Tested: HP ZBook 15 G5/80D5 Laptop

commit d790a9db918f7c2356ea2f775cd868551218fc07
Author: Alexander Stein <alexander.stein@ew.tq-group.com>
Date:   Wed Mar 9 10:38:42 2022 +0100

    usb: common: usb-conn-gpio: Make VBUS supply completely optional

    It makes sense that if the USB connector is a child of an USB port
    providing VBUS supply, there is no need to do it again.
    But this does not handle the case where VBUS is controlled by PWR from
    USB host controller, without any regulator at all.
    Support this by making VBUS pure optional.

    Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
    Link: https://lore.kernel.org/r/20220309093842.113260-1-alexander.stein@ew.tq-group.com
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Signed-off-by: Torez Smith <torez@redhat.com>
2022-07-25 15:37:57 -04:00
Chunfeng Yun baabd69492 usb: common: usb-conn-gpio: use usb_role_string() to print role status
Use usb_role_string() to print role status, make the log readable.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Link: https://lore.kernel.org/r/1621932786-9335-2-git-send-email-chunfeng.yun@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-05-27 09:17:18 +02:00
Chunfeng Yun ddaf0d6dc4 usb: common: usb-conn-gpio: use dev_err_probe() to print log
Use dev_err_probe() to print debug or error message depending on
whether the error value is -DPROBE_DEFER or not.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Link: https://lore.kernel.org/r/1621406386-18838-2-git-send-email-chunfeng.yun@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-05-21 14:09:54 +02:00
Chunfeng Yun 880287910b usb: common: usb-conn-gpio: fix NULL pointer dereference of charger
When power on system with OTG cable, IDDIG's interrupt arises before
the charger registration, it will cause a NULL pointer dereference,
fix the issue by registering the power supply before requesting
IDDIG/VBUS irq.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Link: https://lore.kernel.org/r/1621406386-18838-1-git-send-email-chunfeng.yun@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-05-21 14:09:54 +02:00
Thierry Reding f06c206aad usb: common: usb-conn-gpio: Print error on failure to get VBUS
The exact error that happened trying to get the VBUS supply can be
useful to troubleshoot what's going on.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Link: https://lore.kernel.org/r/20200806160248.3936771-2-thierry.reding@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-08-18 12:13:44 +02:00
Thierry Reding 4ddf1ac79e usb: common: usb-conn-gpio: Make VBUS supply optional
If the connector is the child of a USB port and that USB port already
has a VBUS supply attached to it, it would be redundant to require the
connector to have a VBUS supply. In this case, allow the VBUS supply to
be optional.

Signed-off-by: Thierry Reding <treding@nvidia.com>
Link: https://lore.kernel.org/r/20200806160248.3936771-1-thierry.reding@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-08-18 12:13:44 +02:00
Paul Cercueil e3ee0e740c usb: common: usb-conn-gpio: Register charger
Register a power supply charger, whose online state depends on whether
the USB role is set to device or not.

This is useful when the USB role is the only way to know if the device
is charging from USB. The API is the standard power supply charger API,
you get a /sys/class/power_supply/xxx/online node which tells you the
state of the charger.

The sole purpose of this is to give userspace applications a way to
know whether or not the charger is plugged.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Link: https://lore.kernel.org/r/20200727170413.23131-1-paul@crapouillou.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-07-30 08:45:24 +02:00
Lee Jones 11d96a5912 usb: common: usb-conn-gpio: Demote comment block which is clearly not kerneldoc
This block lacks a title and argument descriptions.

Fixes the following W=1 kernel build warning:

 drivers/usb/common/usb-conn-gpio.c:44: warning: Cannot understand  * "DEVICE" = VBUS and "HOST" = !ID, so we have:
 on line 44 - I thought it was a doc line

Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Link: https://lore.kernel.org/r/20200702144625.2533530-5-lee.jones@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-07-03 09:34:11 +02:00
Bryan O'Donoghue 59120962e4 usb: common: usb-conn-gpio: Don't log an error on probe deferral
This patch makes the printout of the error message for failing to get a
VBUS regulator handle conditional on the error code being something other
than -EPROBE_DEFER.

Deferral is a normal thing, we don't need an error message for this.

Cc: Chunfeng Yun <chunfeng.yun@mediatek.com>
Cc: Nagarjuna Kristam <nkristam@nvidia.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20191128134358.3880498-2-bryan.odonoghue@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-12-10 11:41:20 +01:00
Chunfeng Yun 4602f3bff2 usb: common: add USB GPIO based connection detection driver
Due to the requirement of usb-connector.txt binding, the old way
using extcon to support USB Dual-Role switch is now deprecated
when use Type-B connector.
This patch introduces a USB GPIO based connection detection driver,
used to support Type-B connector which typically uses an input GPIO
to detect USB ID pin, and try to replace the function provided
by the extcon-usb-gpio driver

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Tested-by: Nagarjuna Kristam <nkristam@nvidia.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/1567070558-29417-11-git-send-email-chunfeng.yun@mediatek.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-03 19:01:04 +02:00