* [PATCH v7 0/3] xhci: tegra: USB2 pad power controls
@ 2022-11-11 10:18 Jim Lin
2022-11-11 10:18 ` [PATCH v7 1/3] xhci: Add hub_control to xhci_driver_overrides Jim Lin
` (3 more replies)
0 siblings, 4 replies; 15+ messages in thread
From: Jim Lin @ 2022-11-11 10:18 UTC (permalink / raw)
To: thierry.reding, gregkh, jonathanh
Cc: mathias.nyman, linux-usb, linux-kernel, linux-tegra, Jim Lin
1. Export symbol on xhci_hub_control
2. Add hub_control to xhci_driver_overrides
3. Program USB2 pad PD controls during port connect/disconnect, port
suspend/resume, and test mode, to reduce power consumption on
disconnect or suspend.
Patch
xhci: tegra: USB2 pad power controls
depends on
xhci: hub: export symbol on xhci_hub_control
xhci: Add hub_control to xhci_driver_overrides
Jim Lin (3):
xhci: Add hub_control to xhci_driver_overrides
xhci: hub: export symbol on xhci_hub_control
xhci: tegra: USB2 pad power controls
drivers/usb/host/xhci-hub.c | 1 +
drivers/usb/host/xhci-tegra.c | 125 ++++++++++++++++++++++++++++++++++
drivers/usb/host/xhci.c | 2 +
drivers/usb/host/xhci.h | 2 +
4 files changed, 130 insertions(+)
--
2.17.1
^ permalink raw reply [flat|nested] 15+ messages in thread* [PATCH v7 1/3] xhci: Add hub_control to xhci_driver_overrides 2022-11-11 10:18 [PATCH v7 0/3] xhci: tegra: USB2 pad power controls Jim Lin @ 2022-11-11 10:18 ` Jim Lin 2022-11-11 14:39 ` Jon Hunter 2022-11-17 22:29 ` Thierry Reding 2022-11-11 10:18 ` [PATCH v7 2/3] xhci: hub: export symbol on xhci_hub_control Jim Lin ` (2 subsequent siblings) 3 siblings, 2 replies; 15+ messages in thread From: Jim Lin @ 2022-11-11 10:18 UTC (permalink / raw) To: thierry.reding, gregkh, jonathanh Cc: mathias.nyman, linux-usb, linux-kernel, linux-tegra, Jim Lin Add a hub_control() callback to the xhci_driver_overrides structure to allow host drivers to override the default hub_control function. This is required for Tegra which requires device specific actions for power management to be executed during USB state transitions. Signed-off-by: Jim Lin <jilin@nvidia.com> --- v5: new change v6: adjust parameter alignment (xhci.h hub_control) v7: change commit message drivers/usb/host/xhci.c | 2 ++ drivers/usb/host/xhci.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 902f410874e8..3c7bf0a0e0b4 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -5461,6 +5461,8 @@ void xhci_init_driver(struct hc_driver *drv, drv->check_bandwidth = over->check_bandwidth; if (over->reset_bandwidth) drv->reset_bandwidth = over->reset_bandwidth; + if (over->hub_control) + drv->hub_control = over->hub_control; } } EXPORT_SYMBOL_GPL(xhci_init_driver); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 5a75fe563123..f51b674fc10c 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1943,6 +1943,8 @@ struct xhci_driver_overrides { struct usb_host_endpoint *ep); int (*check_bandwidth)(struct usb_hcd *, struct usb_device *); void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *); + int (*hub_control)(struct usb_hcd *hcd, u16 typeReq, u16 wValue, + u16 wIndex, char *buf, u16 wLength); }; #define XHCI_CFC_DELAY 10 -- 2.17.1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v7 1/3] xhci: Add hub_control to xhci_driver_overrides 2022-11-11 10:18 ` [PATCH v7 1/3] xhci: Add hub_control to xhci_driver_overrides Jim Lin @ 2022-11-11 14:39 ` Jon Hunter 2022-11-17 22:29 ` Thierry Reding 1 sibling, 0 replies; 15+ messages in thread From: Jon Hunter @ 2022-11-11 14:39 UTC (permalink / raw) To: Jim Lin, thierry.reding, gregkh Cc: mathias.nyman, linux-usb, linux-kernel, linux-tegra On 11/11/2022 10:18, Jim Lin wrote: > Add a hub_control() callback to the xhci_driver_overrides structure to > allow host drivers to override the default hub_control function. This > is required for Tegra which requires device specific actions for power > management to be executed during USB state transitions. > > Signed-off-by: Jim Lin <jilin@nvidia.com> > > --- > v5: new change > v6: adjust parameter alignment (xhci.h hub_control) > v7: change commit message > > drivers/usb/host/xhci.c | 2 ++ > drivers/usb/host/xhci.h | 2 ++ > 2 files changed, 4 insertions(+) > > diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c > index 902f410874e8..3c7bf0a0e0b4 100644 > --- a/drivers/usb/host/xhci.c > +++ b/drivers/usb/host/xhci.c > @@ -5461,6 +5461,8 @@ void xhci_init_driver(struct hc_driver *drv, > drv->check_bandwidth = over->check_bandwidth; > if (over->reset_bandwidth) > drv->reset_bandwidth = over->reset_bandwidth; > + if (over->hub_control) > + drv->hub_control = over->hub_control; > } > } > EXPORT_SYMBOL_GPL(xhci_init_driver); > diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h > index 5a75fe563123..f51b674fc10c 100644 > --- a/drivers/usb/host/xhci.h > +++ b/drivers/usb/host/xhci.h > @@ -1943,6 +1943,8 @@ struct xhci_driver_overrides { > struct usb_host_endpoint *ep); > int (*check_bandwidth)(struct usb_hcd *, struct usb_device *); > void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *); > + int (*hub_control)(struct usb_hcd *hcd, u16 typeReq, u16 wValue, > + u16 wIndex, char *buf, u16 wLength); > }; > > #define XHCI_CFC_DELAY 10 Reviewed-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Thanks Jon -- nvpublic ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v7 1/3] xhci: Add hub_control to xhci_driver_overrides 2022-11-11 10:18 ` [PATCH v7 1/3] xhci: Add hub_control to xhci_driver_overrides Jim Lin 2022-11-11 14:39 ` Jon Hunter @ 2022-11-17 22:29 ` Thierry Reding 1 sibling, 0 replies; 15+ messages in thread From: Thierry Reding @ 2022-11-17 22:29 UTC (permalink / raw) To: Jim Lin Cc: gregkh, jonathanh, mathias.nyman, linux-usb, linux-kernel, linux-tegra [-- Attachment #1: Type: text/plain, Size: 660 bytes --] On Fri, Nov 11, 2022 at 06:18:11PM +0800, Jim Lin wrote: > Add a hub_control() callback to the xhci_driver_overrides structure to > allow host drivers to override the default hub_control function. This > is required for Tegra which requires device specific actions for power > management to be executed during USB state transitions. > > Signed-off-by: Jim Lin <jilin@nvidia.com> > > --- > v5: new change > v6: adjust parameter alignment (xhci.h hub_control) > v7: change commit message > > drivers/usb/host/xhci.c | 2 ++ > drivers/usb/host/xhci.h | 2 ++ > 2 files changed, 4 insertions(+) Acked-by: Thierry Reding <treding@nvidia.com> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v7 2/3] xhci: hub: export symbol on xhci_hub_control 2022-11-11 10:18 [PATCH v7 0/3] xhci: tegra: USB2 pad power controls Jim Lin 2022-11-11 10:18 ` [PATCH v7 1/3] xhci: Add hub_control to xhci_driver_overrides Jim Lin @ 2022-11-11 10:18 ` Jim Lin 2022-11-11 14:39 ` Jon Hunter 2022-11-17 22:30 ` Thierry Reding 2022-11-11 10:18 ` [PATCH v7 3/3] xhci: tegra: USB2 pad power controls Jim Lin 2023-01-06 14:56 ` [PATCH v7 0/3] " Jon Hunter 3 siblings, 2 replies; 15+ messages in thread From: Jim Lin @ 2022-11-11 10:18 UTC (permalink / raw) To: thierry.reding, gregkh, jonathanh Cc: mathias.nyman, linux-usb, linux-kernel, linux-tegra, Jim Lin XHCI host drivers may override the default xhci_hub_control() with their own device specific function. To allow these host drivers to call the xhci_hub_control() function from within their own hub_control() callback and be built as a module, export the symbol for xhci_hub_control. Signed-off-by: Jim Lin <jilin@nvidia.com> --- v5: new change v6: modify commit message v7: change commit message drivers/usb/host/xhci-hub.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index af946c42b6f0..4f20cdae2a89 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -1604,6 +1604,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, spin_unlock_irqrestore(&xhci->lock, flags); return retval; } +EXPORT_SYMBOL_GPL(xhci_hub_control); /* * Returns 0 if the status hasn't changed, or the number of bytes in buf. -- 2.17.1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v7 2/3] xhci: hub: export symbol on xhci_hub_control 2022-11-11 10:18 ` [PATCH v7 2/3] xhci: hub: export symbol on xhci_hub_control Jim Lin @ 2022-11-11 14:39 ` Jon Hunter 2022-11-17 22:30 ` Thierry Reding 1 sibling, 0 replies; 15+ messages in thread From: Jon Hunter @ 2022-11-11 14:39 UTC (permalink / raw) To: Jim Lin, thierry.reding, gregkh Cc: mathias.nyman, linux-usb, linux-kernel, linux-tegra On 11/11/2022 10:18, Jim Lin wrote: > XHCI host drivers may override the default xhci_hub_control() with > their own device specific function. To allow these host drivers to > call the xhci_hub_control() function from within their own > hub_control() callback and be built as a module, export the symbol > for xhci_hub_control. > > Signed-off-by: Jim Lin <jilin@nvidia.com> > > --- > v5: new change > v6: modify commit message > v7: change commit message > > drivers/usb/host/xhci-hub.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c > index af946c42b6f0..4f20cdae2a89 100644 > --- a/drivers/usb/host/xhci-hub.c > +++ b/drivers/usb/host/xhci-hub.c > @@ -1604,6 +1604,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, > spin_unlock_irqrestore(&xhci->lock, flags); > return retval; > } > +EXPORT_SYMBOL_GPL(xhci_hub_control); > > /* > * Returns 0 if the status hasn't changed, or the number of bytes in buf. Reviewed-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Thanks Jon -- nvpublic ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v7 2/3] xhci: hub: export symbol on xhci_hub_control 2022-11-11 10:18 ` [PATCH v7 2/3] xhci: hub: export symbol on xhci_hub_control Jim Lin 2022-11-11 14:39 ` Jon Hunter @ 2022-11-17 22:30 ` Thierry Reding 1 sibling, 0 replies; 15+ messages in thread From: Thierry Reding @ 2022-11-17 22:30 UTC (permalink / raw) To: Jim Lin Cc: gregkh, jonathanh, mathias.nyman, linux-usb, linux-kernel, linux-tegra [-- Attachment #1: Type: text/plain, Size: 617 bytes --] On Fri, Nov 11, 2022 at 06:18:12PM +0800, Jim Lin wrote: > XHCI host drivers may override the default xhci_hub_control() with > their own device specific function. To allow these host drivers to > call the xhci_hub_control() function from within their own > hub_control() callback and be built as a module, export the symbol > for xhci_hub_control. > > Signed-off-by: Jim Lin <jilin@nvidia.com> > > --- > v5: new change > v6: modify commit message > v7: change commit message > > drivers/usb/host/xhci-hub.c | 1 + > 1 file changed, 1 insertion(+) Acked-by: Thierry Reding <treding@nvidia.com> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v7 3/3] xhci: tegra: USB2 pad power controls 2022-11-11 10:18 [PATCH v7 0/3] xhci: tegra: USB2 pad power controls Jim Lin 2022-11-11 10:18 ` [PATCH v7 1/3] xhci: Add hub_control to xhci_driver_overrides Jim Lin 2022-11-11 10:18 ` [PATCH v7 2/3] xhci: hub: export symbol on xhci_hub_control Jim Lin @ 2022-11-11 10:18 ` Jim Lin 2022-11-11 14:42 ` Jon Hunter 2022-11-17 22:30 ` Thierry Reding 2023-01-06 14:56 ` [PATCH v7 0/3] " Jon Hunter 3 siblings, 2 replies; 15+ messages in thread From: Jim Lin @ 2022-11-11 10:18 UTC (permalink / raw) To: thierry.reding, gregkh, jonathanh Cc: mathias.nyman, linux-usb, linux-kernel, linux-tegra, Petlozu Pravareshwar, Jim Lin From: Petlozu Pravareshwar <petlozup@nvidia.com> Program USB2 pad PD controls during port connect/disconnect, port suspend/resume, and test mode, to reduce power consumption on disconnect or suspend. Signed-off-by: Petlozu Pravareshwar <petlozup@nvidia.com> Co-developed-by: Jim Lin <jilin@nvidia.com> Signed-off-by: Jim Lin <jilin@nvidia.com> --- v2: Fix issue that wrong tegra->phys[] may be accessed on tegra124 v3: No change on copyright v4: Remove hcd_to_tegra_xusb() function which is used only once. v5: Update .hub_control in tegra_xhci_overrides (xhci-tegra.c) Invoke xhci_hub_control() directly (xhci-tegra.c) v6: Change author to Petlozu Changed from u32 to u8 for variable enable_utmi_pad_after_lp0_exit Modified tegra_xhci_disable_phy_wake(), tegra_xhci_program_utmi_power_lp0_exit(), tegra_xhci_hub_control() v7: no change drivers/usb/host/xhci-tegra.c | 125 ++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c index c8af2cd2216d..b5ed06ddbbac 100644 --- a/drivers/usb/host/xhci-tegra.c +++ b/drivers/usb/host/xhci-tegra.c @@ -274,6 +274,7 @@ struct tegra_xusb { bool suspended; struct tegra_xusb_context context; + u8 lp0_utmi_pad_mask; }; static struct hc_driver __read_mostly tegra_xhci_hc_driver; @@ -1951,10 +1952,24 @@ static void tegra_xhci_disable_phy_wake(struct tegra_xusb *tegra) struct tegra_xusb_padctl *padctl = tegra->padctl; unsigned int i; + for (i = 0; i < tegra->num_usb_phys; i++) { + struct phy *phy = tegra_xusb_get_phy(tegra, "usb2", i); + + if (!phy) + continue; + + if (tegra_xusb_padctl_remote_wake_detected(padctl, phy)) + tegra_phy_xusb_utmi_pad_power_on(phy); + } + for (i = 0; i < tegra->num_phys; i++) { if (!tegra->phys[i]) continue; + if (tegra_xusb_padctl_remote_wake_detected(padctl, tegra->phys[i])) + dev_dbg(tegra->dev, "%pOF remote wake detected\n", + tegra->phys[i]->dev.of_node); + tegra_xusb_padctl_disable_phy_wake(padctl, tegra->phys[i]); } } @@ -1972,6 +1987,28 @@ static void tegra_xhci_disable_phy_sleepwalk(struct tegra_xusb *tegra) } } +static void tegra_xhci_program_utmi_power_lp0_exit(struct tegra_xusb *tegra) +{ + unsigned int i, index_to_usb2; + struct phy *phy; + + for (i = 0; i < tegra->soc->num_types; i++) { + if (strcmp(tegra->soc->phy_types[i].name, "usb2") == 0) + index_to_usb2 = i; + } + + for (i = 0; i < tegra->num_usb_phys; i++) { + if (!is_host_mode_phy(tegra, index_to_usb2, i)) + continue; + + phy = tegra_xusb_get_phy(tegra, "usb2", i); + if (tegra->lp0_utmi_pad_mask & BIT(i)) + tegra_phy_xusb_utmi_pad_power_on(phy); + else + tegra_phy_xusb_utmi_pad_power_down(phy); + } +} + static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool runtime) { struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); @@ -1980,6 +2017,7 @@ static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool runtime) unsigned int i; int err; u32 usbcmd; + u32 portsc; dev_dbg(dev, "entering ELPG\n"); @@ -1993,6 +2031,15 @@ static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool runtime) goto out; } + for (i = 0; i < tegra->num_usb_phys; i++) { + if (!xhci->usb2_rhub.ports[i]) + continue; + portsc = readl(xhci->usb2_rhub.ports[i]->addr); + tegra->lp0_utmi_pad_mask &= ~BIT(i); + if (((portsc & PORT_PLS_MASK) == XDEV_U3) || ((portsc & DEV_SPEED_MASK) == XDEV_FS)) + tegra->lp0_utmi_pad_mask |= BIT(i); + } + err = xhci_suspend(xhci, wakeup); if (err < 0) { dev_err(tegra->dev, "failed to suspend XHCI: %d\n", err); @@ -2066,6 +2113,8 @@ static int tegra_xusb_exit_elpg(struct tegra_xusb *tegra, bool runtime) phy_power_on(tegra->phys[i]); } + if (tegra->suspended) + tegra_xhci_program_utmi_power_lp0_exit(tegra); tegra_xusb_config(tegra); tegra_xusb_restore_context(tegra); @@ -2437,8 +2486,84 @@ static int tegra_xhci_setup(struct usb_hcd *hcd) return xhci_gen_setup(hcd, tegra_xhci_quirks); } +static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index, + char *buf, u16 length) +{ + struct tegra_xusb *tegra = dev_get_drvdata(hcd->self.controller); + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + struct xhci_hub *rhub; + struct xhci_bus_state *bus_state; + int port = (index & 0xff) - 1; + unsigned int i; + struct xhci_port **ports; + u32 portsc; + int ret; + struct phy *phy; + + rhub = &xhci->usb2_rhub; + bus_state = &rhub->bus_state; + if (bus_state->resuming_ports && hcd->speed == HCD_USB2) { + ports = rhub->ports; + i = rhub->num_ports; + while (i--) { + if (!test_bit(i, &bus_state->resuming_ports)) + continue; + portsc = readl(ports[i]->addr); + if ((portsc & PORT_PLS_MASK) == XDEV_RESUME) + tegra_phy_xusb_utmi_pad_power_on( + tegra_xusb_get_phy(tegra, "usb2", (int) i)); + } + } + + if (hcd->speed == HCD_USB2) { + phy = tegra_xusb_get_phy(tegra, "usb2", port); + if ((type_req == ClearPortFeature) && (value == USB_PORT_FEAT_SUSPEND)) { + if (!index || index > rhub->num_ports) + return -EPIPE; + tegra_phy_xusb_utmi_pad_power_on(phy); + } + if ((type_req == SetPortFeature) && (value == USB_PORT_FEAT_RESET)) { + if (!index || index > rhub->num_ports) + return -EPIPE; + ports = rhub->ports; + portsc = readl(ports[port]->addr); + if (portsc & PORT_CONNECT) + tegra_phy_xusb_utmi_pad_power_on(phy); + } + } + + ret = xhci_hub_control(hcd, type_req, value, index, buf, length); + if (ret < 0) + return ret; + + if (hcd->speed == HCD_USB2) { + /* Use phy where we set previously */ + if ((type_req == SetPortFeature) && (value == USB_PORT_FEAT_SUSPEND)) + /* We don't suspend the PAD while HNP role swap happens on the OTG port */ + if (!((hcd->self.otg_port == (port + 1)) && hcd->self.b_hnp_enable)) + tegra_phy_xusb_utmi_pad_power_down(phy); + + if ((type_req == ClearPortFeature) && (value == USB_PORT_FEAT_C_CONNECTION)) { + ports = rhub->ports; + portsc = readl(ports[port]->addr); + if (!(portsc & PORT_CONNECT)) { + /* We don't suspend the PAD while HNP role swap happens on the OTG + * port + */ + if (!((hcd->self.otg_port == (port + 1)) && hcd->self.b_hnp_enable)) + tegra_phy_xusb_utmi_pad_power_down(phy); + } + } + if ((type_req == SetPortFeature) && (value == USB_PORT_FEAT_TEST)) + tegra_phy_xusb_utmi_pad_power_on(phy); + } + + return ret; +} + static const struct xhci_driver_overrides tegra_xhci_overrides __initconst = { .reset = tegra_xhci_setup, + .hub_control = tegra_xhci_hub_control, }; static int __init tegra_xusb_init(void) -- 2.17.1 ^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v7 3/3] xhci: tegra: USB2 pad power controls 2022-11-11 10:18 ` [PATCH v7 3/3] xhci: tegra: USB2 pad power controls Jim Lin @ 2022-11-11 14:42 ` Jon Hunter 2022-11-17 22:30 ` Thierry Reding 1 sibling, 0 replies; 15+ messages in thread From: Jon Hunter @ 2022-11-11 14:42 UTC (permalink / raw) To: Jim Lin, thierry.reding, gregkh Cc: mathias.nyman, linux-usb, linux-kernel, linux-tegra, Petlozu Pravareshwar On 11/11/2022 10:18, Jim Lin wrote: > From: Petlozu Pravareshwar <petlozup@nvidia.com> > > Program USB2 pad PD controls during port connect/disconnect, port > suspend/resume, and test mode, to reduce power consumption on > disconnect or suspend. > > Signed-off-by: Petlozu Pravareshwar <petlozup@nvidia.com> > Co-developed-by: Jim Lin <jilin@nvidia.com> > Signed-off-by: Jim Lin <jilin@nvidia.com> > > --- > v2: Fix issue that wrong tegra->phys[] may be accessed on tegra124 > v3: No change on copyright > v4: Remove hcd_to_tegra_xusb() function which is used only once. > v5: Update .hub_control in tegra_xhci_overrides (xhci-tegra.c) > Invoke xhci_hub_control() directly (xhci-tegra.c) > v6: Change author to Petlozu > Changed from u32 to u8 for variable enable_utmi_pad_after_lp0_exit > Modified tegra_xhci_disable_phy_wake(), tegra_xhci_program_utmi_power_lp0_exit(), > tegra_xhci_hub_control() > v7: no change > > drivers/usb/host/xhci-tegra.c | 125 ++++++++++++++++++++++++++++++++++ > 1 file changed, 125 insertions(+) > > diff --git a/drivers/usb/host/xhci-tegra.c b/drivers/usb/host/xhci-tegra.c > index c8af2cd2216d..b5ed06ddbbac 100644 > --- a/drivers/usb/host/xhci-tegra.c > +++ b/drivers/usb/host/xhci-tegra.c > @@ -274,6 +274,7 @@ struct tegra_xusb { > > bool suspended; > struct tegra_xusb_context context; > + u8 lp0_utmi_pad_mask; > }; > > static struct hc_driver __read_mostly tegra_xhci_hc_driver; > @@ -1951,10 +1952,24 @@ static void tegra_xhci_disable_phy_wake(struct tegra_xusb *tegra) > struct tegra_xusb_padctl *padctl = tegra->padctl; > unsigned int i; > > + for (i = 0; i < tegra->num_usb_phys; i++) { > + struct phy *phy = tegra_xusb_get_phy(tegra, "usb2", i); > + > + if (!phy) > + continue; > + > + if (tegra_xusb_padctl_remote_wake_detected(padctl, phy)) > + tegra_phy_xusb_utmi_pad_power_on(phy); > + } > + > for (i = 0; i < tegra->num_phys; i++) { > if (!tegra->phys[i]) > continue; > > + if (tegra_xusb_padctl_remote_wake_detected(padctl, tegra->phys[i])) > + dev_dbg(tegra->dev, "%pOF remote wake detected\n", > + tegra->phys[i]->dev.of_node); > + > tegra_xusb_padctl_disable_phy_wake(padctl, tegra->phys[i]); > } > } > @@ -1972,6 +1987,28 @@ static void tegra_xhci_disable_phy_sleepwalk(struct tegra_xusb *tegra) > } > } > > +static void tegra_xhci_program_utmi_power_lp0_exit(struct tegra_xusb *tegra) > +{ > + unsigned int i, index_to_usb2; > + struct phy *phy; > + > + for (i = 0; i < tegra->soc->num_types; i++) { > + if (strcmp(tegra->soc->phy_types[i].name, "usb2") == 0) > + index_to_usb2 = i; > + } > + > + for (i = 0; i < tegra->num_usb_phys; i++) { > + if (!is_host_mode_phy(tegra, index_to_usb2, i)) > + continue; > + > + phy = tegra_xusb_get_phy(tegra, "usb2", i); > + if (tegra->lp0_utmi_pad_mask & BIT(i)) > + tegra_phy_xusb_utmi_pad_power_on(phy); > + else > + tegra_phy_xusb_utmi_pad_power_down(phy); > + } > +} > + > static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool runtime) > { > struct xhci_hcd *xhci = hcd_to_xhci(tegra->hcd); > @@ -1980,6 +2017,7 @@ static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool runtime) > unsigned int i; > int err; > u32 usbcmd; > + u32 portsc; > > dev_dbg(dev, "entering ELPG\n"); > > @@ -1993,6 +2031,15 @@ static int tegra_xusb_enter_elpg(struct tegra_xusb *tegra, bool runtime) > goto out; > } > > + for (i = 0; i < tegra->num_usb_phys; i++) { > + if (!xhci->usb2_rhub.ports[i]) > + continue; > + portsc = readl(xhci->usb2_rhub.ports[i]->addr); > + tegra->lp0_utmi_pad_mask &= ~BIT(i); > + if (((portsc & PORT_PLS_MASK) == XDEV_U3) || ((portsc & DEV_SPEED_MASK) == XDEV_FS)) > + tegra->lp0_utmi_pad_mask |= BIT(i); > + } > + > err = xhci_suspend(xhci, wakeup); > if (err < 0) { > dev_err(tegra->dev, "failed to suspend XHCI: %d\n", err); > @@ -2066,6 +2113,8 @@ static int tegra_xusb_exit_elpg(struct tegra_xusb *tegra, bool runtime) > > phy_power_on(tegra->phys[i]); > } > + if (tegra->suspended) > + tegra_xhci_program_utmi_power_lp0_exit(tegra); > > tegra_xusb_config(tegra); > tegra_xusb_restore_context(tegra); > @@ -2437,8 +2486,84 @@ static int tegra_xhci_setup(struct usb_hcd *hcd) > return xhci_gen_setup(hcd, tegra_xhci_quirks); > } > > +static int tegra_xhci_hub_control(struct usb_hcd *hcd, u16 type_req, u16 value, u16 index, > + char *buf, u16 length) > +{ > + struct tegra_xusb *tegra = dev_get_drvdata(hcd->self.controller); > + struct xhci_hcd *xhci = hcd_to_xhci(hcd); > + struct xhci_hub *rhub; > + struct xhci_bus_state *bus_state; > + int port = (index & 0xff) - 1; > + unsigned int i; > + struct xhci_port **ports; > + u32 portsc; > + int ret; > + struct phy *phy; > + > + rhub = &xhci->usb2_rhub; > + bus_state = &rhub->bus_state; > + if (bus_state->resuming_ports && hcd->speed == HCD_USB2) { > + ports = rhub->ports; > + i = rhub->num_ports; > + while (i--) { > + if (!test_bit(i, &bus_state->resuming_ports)) > + continue; > + portsc = readl(ports[i]->addr); > + if ((portsc & PORT_PLS_MASK) == XDEV_RESUME) > + tegra_phy_xusb_utmi_pad_power_on( > + tegra_xusb_get_phy(tegra, "usb2", (int) i)); > + } > + } > + > + if (hcd->speed == HCD_USB2) { > + phy = tegra_xusb_get_phy(tegra, "usb2", port); > + if ((type_req == ClearPortFeature) && (value == USB_PORT_FEAT_SUSPEND)) { > + if (!index || index > rhub->num_ports) > + return -EPIPE; > + tegra_phy_xusb_utmi_pad_power_on(phy); > + } > + if ((type_req == SetPortFeature) && (value == USB_PORT_FEAT_RESET)) { > + if (!index || index > rhub->num_ports) > + return -EPIPE; > + ports = rhub->ports; > + portsc = readl(ports[port]->addr); > + if (portsc & PORT_CONNECT) > + tegra_phy_xusb_utmi_pad_power_on(phy); > + } > + } > + > + ret = xhci_hub_control(hcd, type_req, value, index, buf, length); > + if (ret < 0) > + return ret; > + > + if (hcd->speed == HCD_USB2) { > + /* Use phy where we set previously */ > + if ((type_req == SetPortFeature) && (value == USB_PORT_FEAT_SUSPEND)) > + /* We don't suspend the PAD while HNP role swap happens on the OTG port */ > + if (!((hcd->self.otg_port == (port + 1)) && hcd->self.b_hnp_enable)) > + tegra_phy_xusb_utmi_pad_power_down(phy); > + > + if ((type_req == ClearPortFeature) && (value == USB_PORT_FEAT_C_CONNECTION)) { > + ports = rhub->ports; > + portsc = readl(ports[port]->addr); > + if (!(portsc & PORT_CONNECT)) { > + /* We don't suspend the PAD while HNP role swap happens on the OTG > + * port > + */ > + if (!((hcd->self.otg_port == (port + 1)) && hcd->self.b_hnp_enable)) > + tegra_phy_xusb_utmi_pad_power_down(phy); > + } > + } > + if ((type_req == SetPortFeature) && (value == USB_PORT_FEAT_TEST)) > + tegra_phy_xusb_utmi_pad_power_on(phy); > + } > + > + return ret; > +} > + > static const struct xhci_driver_overrides tegra_xhci_overrides __initconst = { > .reset = tegra_xhci_setup, > + .hub_control = tegra_xhci_hub_control, > }; > > static int __init tegra_xusb_init(void) Reviewed-by: Jon Hunter <jonathanh@nvidia.com> Tested-by: Jon Hunter <jonathanh@nvidia.com> Thanks Jon -- nvpublic ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v7 3/3] xhci: tegra: USB2 pad power controls 2022-11-11 10:18 ` [PATCH v7 3/3] xhci: tegra: USB2 pad power controls Jim Lin 2022-11-11 14:42 ` Jon Hunter @ 2022-11-17 22:30 ` Thierry Reding 1 sibling, 0 replies; 15+ messages in thread From: Thierry Reding @ 2022-11-17 22:30 UTC (permalink / raw) To: Jim Lin Cc: gregkh, jonathanh, mathias.nyman, linux-usb, linux-kernel, linux-tegra, Petlozu Pravareshwar [-- Attachment #1: Type: text/plain, Size: 1143 bytes --] On Fri, Nov 11, 2022 at 06:18:13PM +0800, Jim Lin wrote: > From: Petlozu Pravareshwar <petlozup@nvidia.com> > > Program USB2 pad PD controls during port connect/disconnect, port > suspend/resume, and test mode, to reduce power consumption on > disconnect or suspend. > > Signed-off-by: Petlozu Pravareshwar <petlozup@nvidia.com> > Co-developed-by: Jim Lin <jilin@nvidia.com> > Signed-off-by: Jim Lin <jilin@nvidia.com> > > --- > v2: Fix issue that wrong tegra->phys[] may be accessed on tegra124 > v3: No change on copyright > v4: Remove hcd_to_tegra_xusb() function which is used only once. > v5: Update .hub_control in tegra_xhci_overrides (xhci-tegra.c) > Invoke xhci_hub_control() directly (xhci-tegra.c) > v6: Change author to Petlozu > Changed from u32 to u8 for variable enable_utmi_pad_after_lp0_exit > Modified tegra_xhci_disable_phy_wake(), tegra_xhci_program_utmi_power_lp0_exit(), > tegra_xhci_hub_control() > v7: no change > > drivers/usb/host/xhci-tegra.c | 125 ++++++++++++++++++++++++++++++++++ > 1 file changed, 125 insertions(+) Acked-by: Thierry Reding <treding@nvidia.com> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 833 bytes --] ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v7 0/3] xhci: tegra: USB2 pad power controls 2022-11-11 10:18 [PATCH v7 0/3] xhci: tegra: USB2 pad power controls Jim Lin ` (2 preceding siblings ...) 2022-11-11 10:18 ` [PATCH v7 3/3] xhci: tegra: USB2 pad power controls Jim Lin @ 2023-01-06 14:56 ` Jon Hunter 2023-01-06 15:25 ` Greg KH 3 siblings, 1 reply; 15+ messages in thread From: Jon Hunter @ 2023-01-06 14:56 UTC (permalink / raw) To: Jim Lin, thierry.reding, gregkh Cc: mathias.nyman, linux-usb, linux-kernel, linux-tegra Hi Greg, On 11/11/2022 10:18, Jim Lin wrote: > 1. Export symbol on xhci_hub_control > 2. Add hub_control to xhci_driver_overrides > 3. Program USB2 pad PD controls during port connect/disconnect, port > suspend/resume, and test mode, to reduce power consumption on > disconnect or suspend. > > Patch > xhci: tegra: USB2 pad power controls > depends on > xhci: hub: export symbol on xhci_hub_control > xhci: Add hub_control to xhci_driver_overrides > > Jim Lin (3): > xhci: Add hub_control to xhci_driver_overrides > xhci: hub: export symbol on xhci_hub_control > xhci: tegra: USB2 pad power controls > > drivers/usb/host/xhci-hub.c | 1 + > drivers/usb/host/xhci-tegra.c | 125 ++++++++++++++++++++++++++++++++++ > drivers/usb/host/xhci.c | 2 + > drivers/usb/host/xhci.h | 2 + > 4 files changed, 130 insertions(+) > I have verified that this still applies cleanly on top of -next. Please let us know if this can be queued up for Linux v6.3? Thanks Jon -- nvpublic ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v7 0/3] xhci: tegra: USB2 pad power controls 2023-01-06 14:56 ` [PATCH v7 0/3] " Jon Hunter @ 2023-01-06 15:25 ` Greg KH 2023-01-09 8:28 ` Mathias Nyman 0 siblings, 1 reply; 15+ messages in thread From: Greg KH @ 2023-01-06 15:25 UTC (permalink / raw) To: Jon Hunter Cc: Jim Lin, thierry.reding, mathias.nyman, linux-usb, linux-kernel, linux-tegra On Fri, Jan 06, 2023 at 02:56:51PM +0000, Jon Hunter wrote: > Hi Greg, > > On 11/11/2022 10:18, Jim Lin wrote: > > 1. Export symbol on xhci_hub_control > > 2. Add hub_control to xhci_driver_overrides > > 3. Program USB2 pad PD controls during port connect/disconnect, port > > suspend/resume, and test mode, to reduce power consumption on > > disconnect or suspend. > > > > Patch > > xhci: tegra: USB2 pad power controls > > depends on > > xhci: hub: export symbol on xhci_hub_control > > xhci: Add hub_control to xhci_driver_overrides > > > > Jim Lin (3): > > xhci: Add hub_control to xhci_driver_overrides > > xhci: hub: export symbol on xhci_hub_control > > xhci: tegra: USB2 pad power controls > > > > drivers/usb/host/xhci-hub.c | 1 + > > drivers/usb/host/xhci-tegra.c | 125 ++++++++++++++++++++++++++++++++++ > > drivers/usb/host/xhci.c | 2 + > > drivers/usb/host/xhci.h | 2 + > > 4 files changed, 130 insertions(+) > > > > > I have verified that this still applies cleanly on top of -next. Please let > us know if this can be queued up for Linux v6.3? Normally for xhci stuff I want it to go through Mathias for things that are outside of just xhci-tegra.c. thanks, greg k-h ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v7 0/3] xhci: tegra: USB2 pad power controls 2023-01-06 15:25 ` Greg KH @ 2023-01-09 8:28 ` Mathias Nyman 2023-01-16 11:50 ` Jon Hunter 0 siblings, 1 reply; 15+ messages in thread From: Mathias Nyman @ 2023-01-09 8:28 UTC (permalink / raw) To: Greg KH, Jon Hunter Cc: Jim Lin, thierry.reding, mathias.nyman, linux-usb, linux-kernel, linux-tegra On 6.1.2023 17.25, Greg KH wrote: > On Fri, Jan 06, 2023 at 02:56:51PM +0000, Jon Hunter wrote: >> Hi Greg, >> >> On 11/11/2022 10:18, Jim Lin wrote: >>> 1. Export symbol on xhci_hub_control >>> 2. Add hub_control to xhci_driver_overrides >>> 3. Program USB2 pad PD controls during port connect/disconnect, port >>> suspend/resume, and test mode, to reduce power consumption on >>> disconnect or suspend. >>> >>> Patch >>> xhci: tegra: USB2 pad power controls >>> depends on >>> xhci: hub: export symbol on xhci_hub_control >>> xhci: Add hub_control to xhci_driver_overrides >>> >>> Jim Lin (3): >>> xhci: Add hub_control to xhci_driver_overrides >>> xhci: hub: export symbol on xhci_hub_control >>> xhci: tegra: USB2 pad power controls >>> >>> drivers/usb/host/xhci-hub.c | 1 + >>> drivers/usb/host/xhci-tegra.c | 125 ++++++++++++++++++++++++++++++++++ >>> drivers/usb/host/xhci.c | 2 + >>> drivers/usb/host/xhci.h | 2 + >>> 4 files changed, 130 insertions(+) >>> >> >> >> I have verified that this still applies cleanly on top of -next. Please let >> us know if this can be queued up for Linux v6.3? > > Normally for xhci stuff I want it to go through Mathias for things that > are outside of just xhci-tegra.c. Looks good to me, can be picked up directly Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com> Or I can add this to the series going to usb-next if that is preferred. Thanks Mathias > > thanks, > > greg k-h ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v7 0/3] xhci: tegra: USB2 pad power controls 2023-01-09 8:28 ` Mathias Nyman @ 2023-01-16 11:50 ` Jon Hunter 2023-01-16 12:23 ` Greg KH 0 siblings, 1 reply; 15+ messages in thread From: Jon Hunter @ 2023-01-16 11:50 UTC (permalink / raw) To: Mathias Nyman, Greg KH Cc: Jim Lin, thierry.reding, mathias.nyman, linux-usb, linux-kernel, linux-tegra On 09/01/2023 08:28, Mathias Nyman wrote: > On 6.1.2023 17.25, Greg KH wrote: >> On Fri, Jan 06, 2023 at 02:56:51PM +0000, Jon Hunter wrote: >>> Hi Greg, >>> >>> On 11/11/2022 10:18, Jim Lin wrote: >>>> 1. Export symbol on xhci_hub_control >>>> 2. Add hub_control to xhci_driver_overrides >>>> 3. Program USB2 pad PD controls during port connect/disconnect, port >>>> suspend/resume, and test mode, to reduce power consumption on >>>> disconnect or suspend. >>>> >>>> Patch >>>> xhci: tegra: USB2 pad power controls >>>> depends on >>>> xhci: hub: export symbol on xhci_hub_control >>>> xhci: Add hub_control to xhci_driver_overrides >>>> >>>> Jim Lin (3): >>>> xhci: Add hub_control to xhci_driver_overrides >>>> xhci: hub: export symbol on xhci_hub_control >>>> xhci: tegra: USB2 pad power controls >>>> >>>> drivers/usb/host/xhci-hub.c | 1 + >>>> drivers/usb/host/xhci-tegra.c | 125 >>>> ++++++++++++++++++++++++++++++++++ >>>> drivers/usb/host/xhci.c | 2 + >>>> drivers/usb/host/xhci.h | 2 + >>>> 4 files changed, 130 insertions(+) >>>> >>> >>> >>> I have verified that this still applies cleanly on top of -next. >>> Please let >>> us know if this can be queued up for Linux v6.3? >> >> Normally for xhci stuff I want it to go through Mathias for things that >> are outside of just xhci-tegra.c. > > Looks good to me, can be picked up directly > Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com> > > Or I can add this to the series going to usb-next if that is preferred. I did not see this in -next yet. Mathias, are you able to pick this up? Thanks Jon -- nvpublic ^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v7 0/3] xhci: tegra: USB2 pad power controls 2023-01-16 11:50 ` Jon Hunter @ 2023-01-16 12:23 ` Greg KH 0 siblings, 0 replies; 15+ messages in thread From: Greg KH @ 2023-01-16 12:23 UTC (permalink / raw) To: Jon Hunter Cc: Mathias Nyman, Jim Lin, thierry.reding, mathias.nyman, linux-usb, linux-kernel, linux-tegra On Mon, Jan 16, 2023 at 11:50:19AM +0000, Jon Hunter wrote: > > On 09/01/2023 08:28, Mathias Nyman wrote: > > On 6.1.2023 17.25, Greg KH wrote: > > > On Fri, Jan 06, 2023 at 02:56:51PM +0000, Jon Hunter wrote: > > > > Hi Greg, > > > > > > > > On 11/11/2022 10:18, Jim Lin wrote: > > > > > 1. Export symbol on xhci_hub_control > > > > > 2. Add hub_control to xhci_driver_overrides > > > > > 3. Program USB2 pad PD controls during port connect/disconnect, port > > > > > suspend/resume, and test mode, to reduce power consumption on > > > > > disconnect or suspend. > > > > > > > > > > Patch > > > > > xhci: tegra: USB2 pad power controls > > > > > depends on > > > > > xhci: hub: export symbol on xhci_hub_control > > > > > xhci: Add hub_control to xhci_driver_overrides > > > > > > > > > > Jim Lin (3): > > > > > xhci: Add hub_control to xhci_driver_overrides > > > > > xhci: hub: export symbol on xhci_hub_control > > > > > xhci: tegra: USB2 pad power controls > > > > > > > > > > drivers/usb/host/xhci-hub.c | 1 + > > > > > drivers/usb/host/xhci-tegra.c | 125 > > > > > ++++++++++++++++++++++++++++++++++ > > > > > drivers/usb/host/xhci.c | 2 + > > > > > drivers/usb/host/xhci.h | 2 + > > > > > 4 files changed, 130 insertions(+) > > > > > > > > > > > > > > > > > I have verified that this still applies cleanly on top of -next. > > > > Please let > > > > us know if this can be queued up for Linux v6.3? > > > > > > Normally for xhci stuff I want it to go through Mathias for things that > > > are outside of just xhci-tegra.c. > > > > Looks good to me, can be picked up directly > > Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com> > > > > Or I can add this to the series going to usb-next if that is preferred. > > > I did not see this in -next yet. > > Mathias, are you able to pick this up? I will when I catch up with linux-usb patches this week, sorry for the delay, too many fires this early in the year... ^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2023-01-16 12:23 UTC | newest] Thread overview: 15+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-11-11 10:18 [PATCH v7 0/3] xhci: tegra: USB2 pad power controls Jim Lin 2022-11-11 10:18 ` [PATCH v7 1/3] xhci: Add hub_control to xhci_driver_overrides Jim Lin 2022-11-11 14:39 ` Jon Hunter 2022-11-17 22:29 ` Thierry Reding 2022-11-11 10:18 ` [PATCH v7 2/3] xhci: hub: export symbol on xhci_hub_control Jim Lin 2022-11-11 14:39 ` Jon Hunter 2022-11-17 22:30 ` Thierry Reding 2022-11-11 10:18 ` [PATCH v7 3/3] xhci: tegra: USB2 pad power controls Jim Lin 2022-11-11 14:42 ` Jon Hunter 2022-11-17 22:30 ` Thierry Reding 2023-01-06 14:56 ` [PATCH v7 0/3] " Jon Hunter 2023-01-06 15:25 ` Greg KH 2023-01-09 8:28 ` Mathias Nyman 2023-01-16 11:50 ` Jon Hunter 2023-01-16 12:23 ` Greg KH
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).