* [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks
@ 2026-07-24 8:43 Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 01/16] device property: Add fwnode_graph_get_port_by_id() Chen-Yu Tsai
` (15 more replies)
0 siblings, 16 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern
Hi everyone,
This is v7 of my attempt at integrating the power sequencing API into
the USB core to support the USB connection on M.2 E-key slots. M.2
E-key was enabled in v7.1-rc1 with just PCIe and UART supported [1].
Hopefully this is the last revision. However the pwrseq patches haven't
been reviewed yet, and the fwnode patches need a review from the fwnode
owners.
As for Sashiko's comment about fwnode_get_next_*() not putting the
reference to @prev when @node is NULL, I plan to update the kernel-doc
for all the functions in a separate patch later.
Changes since v6:
- Patch 3 (power: sequencing: Add pwrseq_get_state())
- Adopted enum for valid return codes (Bartosz)
- Patch 10 (usb hub pwrseq integration)
- Added braces ("{}") to for loop in hub_is_port_power_switchable() (Andy)
- Adapted usb_port_is_power_on() to new pwrseq_get_state() function
return values (Bartosz)
- Link to v6:
https://lore.kernel.org/all/20260721065413.2306137-1-wenst@chromium.org/
Changes since v5:
- Patch 1 (device property: Add fwnode_graph_get_port_by_id())
- Dropped left-over declaration in header (Sashiko)
- Patch 3 (power: sequencing: Add pwrseq_power_is_on())
- Reverted back to returning -EINVAL if descriptor is NULL (Andy /
Bartosz)
- Patch 6 (usb: hub: Associate port@ fwnode with USB port device)
- Added extra |struct fwnode_handle *| local variables to shorten lines (Andy)
- Added comment about passing fwnode_graph_get_port_by_id() return value
directly to device_set_node() (Andy)
- Patch 10 (usb hub pwrseq integration)
- Only assign port_dev->pwrseq if successfully retrieved pwrseq
descriptor (Andy)
- Dropped the pwrseq error pointer check in the release function
(Andy)
- Added check for port->pwrseq != NULL before calling
pwrseq_is_power_on() (API change from patch 3)
- Link to v5:
https://lore.kernel.org/all/20260715085348.3457359-1-wenst@chromium.org/
Changes since v4:
- Added flags parameter to fwnode_graph_get_port_by_id() so users can
specify whether incomplete ports are returned or not (Sashiko)
- Made pwrseq_power_is_on() return 1 if descriptor is NULL, i.e. if
the descriptor is optional, matching the other pwrseq consumer APIs
- Added patch to swap out conditional set_bit()/clear_bit() with
assign_bit() (split out from "usb: hub: Power on connected M.2 E-key
connectors with power sequencing API") (Andy)
- Call fwnode_graph_get_port_by_id() with FWNODE_GRAPH_DEVICE_DISABLED
so that even incomplete ports can be connected (Sashiko)
- Dropped unused |hdev| variable from usb_hub_remove_port_device()
(Greg / Sashiko)
- Dropped 'extern' from usb_port_is_power_on() header declaration (Andy)
- Patch 10 (usb hub pwrseq integration)
- Rewrote usb_port_is_power_on() to better express intent and
restrictions of pwrseq API (Andy)
- Switched to dev_fwnode() in port_pwrseq_is_supported() (Andy)
- Added blank line separating normal variable declarations and __free()
type declarations (Andy)
- Split out assign_bit() rewrite (Andy)
- Moved pwrseq_put() to release function to avoid UAF (Sashiko)
- Added back pwrseq_power_off() call in usb_hub_remove_port_device();
otherwise power off could be delayed to object release
- Don't clear hub->ports[port1 - 1] in main error path;
by that time the port device is registered and sysfs attributes are
available to userspace (Sashiko)
- Dropped blank line between __free() variable declaration and
subsequent use of the variable in conditional (Andy)
- Added patch to split Bluetooth pwrseq units (Wei)
- Link to v4:
https://lore.kernel.org/all/20260709095726.704448-1-wenst@chromium.org/
Changes since v3:
- Added missing stub function for !POWER_SEQUENCING (patch 3) (Sashiko)
- Added missing fwnode_handle_put() (patch 5) (Sashiko)
- Added new patch to move |struct usb_port| related declarations to
separate header (patch 6) (Andy)
- Patch 9 (usb hub pwrseq integration)
- Adapted to move of usb_port_is_power_on() to port.c and port.h
- Simplified usb_hub_set_port_pwrseq() (Andy)
- Renamed usb_hub_set_port_pwrseq()'s "set" parameter to "on"
- Dropped usb_hub_restore_port_pwrseq() (use usb_hub_set_port_pwrseq()
with inverted argument)
- Fixed off-by-one access in hub_is_port_power_switchable() (Sashiko)
- Assign retval from dev_err_probe() instead of the other way around (Andy)
- Clear hub->ports[port1 - 1] in USB port error and remove paths to
avoid other threads from accidental UAF while the USB hub device is
being unwound (Sashiko)
- Short-circuit out of helpers if !IS_ENABLED(CONFIG_POWER_SEQUENCING)
to avoid errors from stub functions (Sashiko)
- Drop redundant device node validity check; device_match_of_node()
does it internally (patch 11) (Andy)
- Link to v3:
https://lore.kernel.org/all/20260703110317.1283411-1-wenst@chromium.org/
Major changes since v2:
- Removed changes for MT8192 Asurada family: one of the device is
shipped with RTL8822CE-VR, which is PCIe + UART and needs more work.
- Removed changes for USB A ports: VBUS one the type A ports on
Chromebooks are not directly controllable from the OS and VBUS is
modeled as always on. As such the changes I made don't actually
change how the system works.
- Added new pwrseq_power_is_on() function
- Make new pwrseq integration effectively OF only by not assigning the
port fwnode if the hub's fwnode is an ACPI node
- Added patch to convert remaining instances of directly setting/clearing
USB_PORT_FEAT_POWER to usb_hub_set_port_power()
- Power sequencing state removed again in favor of state tracking by
pwrseq subsystem
- Power sequencing descriptor again separately requested for HS and SS
ports
- Dropped pwrseq_power_off() call before pwrseq_put(); the latter calls
the former implicitly if the power state was left on
- Squashed DT binding revert and addition into one patch
- Link to v2:
https://lore.kernel.org/all/20260610084053.2059858-1-wenst@chromium.org/
Major changes since v1:
- No longer adding the "index" parameter the power sequencing API
- Switched from OF graph to fwnode graph APIs
- Tie "port@" node to usb_port device, and use this device as consumer
to acquire power sequencing descriptor
- Power sequencing descriptor now only tied to USB 2.0 port to avoid
double reference
- Power sequencing state tracking added
- Link to v1
https://lore.kernel.org/all/20260515090149.3169406-1-wenst@chromium.org/
The series is based on next-20260723.
Patch 1 and 2 add new fwnode graph helpers. These are used by the patch
5 and 8, respectively.
Patch 3 adds a new pwrseq_get_state() for power sequencer consumers
to query the current request state. Note that this is not the _actual_
state.
Patch 4 swaps out the existing conditional set_bit()/clear_bit() with
assign_bit(), which does the same thing.
Patch 5 reworks the USB hub driver to return the actual error code from
hub_configure() in hub_probe(). This is needed in the next patch to
correctly return -EPROBE_DEFER returned by pwrseq_get() in patch 9.
Patch 6 makes the USB port device associated with a "port@" fwnode if
available. This depends on patch 1.
Patch 7 moves some |struct usb_port| related stuff from hub.c and hub.h
to port.c and port.h. No actual code or functionality is changed.
Patch 8 changes usb_port_is_power_on() so that |struct usb_port*| is
passed in instead of |struct usb_hub*|. This patch does not change any
functionality.
Patch 9 changes some USB hub port power control code that directly
toggles USB_PORT_FEAT_POWER to use usb_hub_set_port_power().
Patch 10 lets the USB hub driver look for power sequencers for each port.
Currently this only works for M.2 E-key connections, but it could be
extended to cover other cases. It should also make port reset via turning
off the port VBUS work, even when VBUS is not directly controlled by the
hub. This depends on patch 2 and 3 for the new helpers.
Patch 11 reverts an incorrectly modeled OF graph connection for the
MediaTek XHCI controller and adds a proper representation.
Patch 12 adds matching pwrseq consumer by "port@" node to the M.2 slot
driver. This is only used for the USB target, but there is no attempt
to differentiate the connection type. The driver simply tries matching
the "port@" node first, then falling back to the port parent or device's
node.
Patch 13 reworks the power sequencing targets for the E-key connector in
the pcie-m2 driver to add targets for USB and SDIO. The former is used
later on in this series.
Patch 14 splits the Bluetooth power sequencing unit so that the USB and
serdev consumers can separately toggle the actual state of W_DISABLE#2.
This patch is purposefully not squashed into the previous one to provide
a clear target for discussions.
Patches 15 and 16 enable the M.2 E-key slots (or slot-like integration)
found on MT8195 and MT8188 MediaTek-based Chromebooks.
This series unfortunately spans multiple trees. The way I see it:
- Patches 1 and 2 go through the driver core, and an immutable tag is
provided to be merged together with the USB patches.
- Patch 3 has an ack from Bartosz, and goes through the USB tree. But
Bartosz also wants an immutable branch/tag to have a copy in the
pwrseq tree.
- Patches 4 through 10 (all the USB related ones) go through the USB
tree, along with the dependencies above.
- Patches 11 and 12 go through the power sequencing tree.
- Patches 13 and 14 (device tree only) go through the soc tree via the
mediatek tree.
Some of us discussed v1 at Embedded Recipes, and I believe Bartosz, Mani
and I agree on this approach. The debate is likely going to be on
whether this should be integrated into the USB core or not. I believe it
should, so that the power sequencing timing is tied to the USB port
being brought up. I do have a fallback option of just enabling the USB
power sequencing target inside the M.2 slot driver if a valid OF graph
connection is seen. But this is less desired for the reason given above.
Please have a look and share your thoughts.
Thanks
ChenYu
[1] https://lore.kernel.org/all/20260326-pci-m2-e-v7-0-43324a7866e6@oss.qualcomm.com/
Chen-Yu Tsai (16):
device property: Add fwnode_graph_get_port_by_id()
device property: Add fwnode_graph_get_next_port_endpoint()
power: sequencing: Add pwrseq_get_state()
usb: hub: Use assign_bit() in usb_hub_set_port_power()
usb: hub: Return actual error from hub_configure() in hub_probe()
usb: hub: Associate port@ fwnode with USB port device
usb: core: Move struct usb_port and related APIs to port.h
usb: hub: Pass |struct usb_port*| to usb_port_is_power_on()
usb: hub: Use usb_hub_set_port_power() to control port power
everywhere
usb: hub: Power on connected M.2 E-key connectors with power
sequencing API
dt-bindings: usb: mediatek,mtk-xhci: Switch to ports for USB
connections
power: sequencing: pcie-m2: support matching on remote "port" node
power: sequencing: pcie-m2: Add usb and sdio targets for E-key
connector
power: sequencing: pcie-m2: Split Bluetooth unit based on interface
arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot
arm64: dts: mediatek: mt8188-geralt: Add WiFi/BT as M.2 E-key slot
.../bindings/usb/mediatek,mtk-xhci.yaml | 17 ++-
.../boot/dts/mediatek/mt8188-geralt.dtsi | 92 +++++++++++++++-
.../boot/dts/mediatek/mt8195-cherry.dtsi | 73 ++++++++++++-
drivers/base/property.c | 54 +++++++++
drivers/power/sequencing/core.c | 19 ++++
drivers/power/sequencing/pwrseq-pcie-m2.c | 64 ++++++++---
drivers/usb/Kconfig | 1 +
drivers/usb/core/hub.c | 72 ++++++------
drivers/usb/core/hub.h | 58 ++--------
drivers/usb/core/port.c | 103 +++++++++++++++++-
drivers/usb/core/port.h | 68 ++++++++++++
include/linux/property.h | 4 +
include/linux/pwrseq/consumer.h | 12 ++
13 files changed, 525 insertions(+), 112 deletions(-)
create mode 100644 drivers/usb/core/port.h
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v7 01/16] device property: Add fwnode_graph_get_port_by_id()
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 9:01 ` sashiko-bot
2026-07-24 8:43 ` [PATCH v7 02/16] device property: Add fwnode_graph_get_next_port_endpoint() Chen-Yu Tsai
` (14 subsequent siblings)
15 siblings, 1 reply; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
In some cases the driver needs a reference to the port firmware node.
Once such case is the upcoming USB power sequencing integration. The
USB hub port is tied to the corresponding port firmware node if it
exists.
Provide a helper for this.
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v5:
- Dropped left-over declaration in header (Sashiko)
Changes since v4:
- Added flags parameter so users can specify whether incomplete ports
are returned or not (Sashiko)
Changes since v2:
- Moved "Return:" kernel-doc section to the end. (Andy)
Changes since v1:
- New patch
---
drivers/base/property.c | 29 +++++++++++++++++++++++++++++
include/linux/property.h | 2 ++
2 files changed, 31 insertions(+)
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 9387bb83eb54..950defc0c55a 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1346,6 +1346,35 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
}
EXPORT_SYMBOL(fwnode_graph_parse_endpoint);
+/**
+ * fwnode_graph_get_port_by_id - get the port matching a given id
+ * @fwnode: parent fwnode_handle containing the graph
+ * @id: id of the port
+ * @flags: fwnode lookup flags
+ *
+ * The caller is responsible for calling fwnode_handle_put() on the returned
+ * fwnode pointer.
+ *
+ * Does not return ports that belong to disabled devices or endpoints that
+ * are unconnected, unless FWNODE_GRAPH_DEVICE_DISABLED is passed in @flags.
+ *
+ * Return: A 'port' firmware node pointer with refcount incremented.
+ */
+struct fwnode_handle *fwnode_graph_get_port_by_id(struct fwnode_handle *fwnode,
+ u32 id,
+ unsigned long flags)
+{
+ struct fwnode_handle *ep;
+
+ ep = fwnode_graph_get_endpoint_by_id(fwnode, id, 0,
+ flags | FWNODE_GRAPH_ENDPOINT_NEXT);
+ if (!ep)
+ return NULL;
+
+ return fwnode_get_next_parent(ep);
+}
+EXPORT_SYMBOL_GPL(fwnode_graph_get_port_by_id);
+
const void *device_get_match_data(const struct device *dev)
{
return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev);
diff --git a/include/linux/property.h b/include/linux/property.h
index 14c304db4664..01ea010cb2f9 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -505,6 +505,8 @@ int fwnode_get_phy_mode(const struct fwnode_handle *fwnode);
void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index);
+struct fwnode_handle *fwnode_graph_get_port_by_id(struct fwnode_handle *fwnode, u32 id,
+ unsigned long flags);
struct fwnode_handle *fwnode_graph_get_next_endpoint(
const struct fwnode_handle *fwnode, struct fwnode_handle *prev);
struct fwnode_handle *
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 02/16] device property: Add fwnode_graph_get_next_port_endpoint()
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 01/16] device property: Add fwnode_graph_get_port_by_id() Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 9:03 ` sashiko-bot
2026-07-24 8:43 ` [PATCH v7 03/16] power: sequencing: Add pwrseq_get_state() Chen-Yu Tsai
` (13 subsequent siblings)
15 siblings, 1 reply; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
Due to design constraints of the power sequencing API, the consumer
must first be sure that the other side is actually a provider, or it
will continually get -EPROBE_DEFER when requesting the power
sequencing descriptor.
In the upcoming USB power sequencing integration, the USB hub driver
first needs to check whether a graph connection exists, and whether
the other side of the connection is a supported connector type. The
USB port is tied to a "port" firmware node, and this new helper will
be used to get the endpoint under the known "port" firmware node.
Sashiko points out that the |prev| reference put is not done if |port|
is NULL. However it seems that the fwnode_*() and of_*() API design
implicitly makes the functions no-ops if the passed in node is NULL.
So this new addition follows the same pattern.
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v2:
- Dropped unused |ep| variable
- Rewrote as do {} while()
- Dropped WARN() use
---
drivers/base/property.c | 25 +++++++++++++++++++++++++
include/linux/property.h | 2 ++
2 files changed, 27 insertions(+)
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 950defc0c55a..5d3993bd8fc4 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1099,6 +1099,31 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name)
}
EXPORT_SYMBOL(fwnode_irq_get_byname);
+/**
+ * fwnode_graph_get_next_port_endpoint - Get next endpoint firmware node in port
+ * @port: Pointer to the target port firmware node
+ * @prev: Previous endpoint node or %NULL to get the first
+ *
+ * The caller is responsible for calling fwnode_handle_put() on the returned
+ * fwnode pointer. Note that this function also puts a reference to @prev
+ * unconditionally.
+ *
+ * Return: an endpoint firmware node pointer or %NULL if no more endpoints
+ * are available.
+ */
+struct fwnode_handle *fwnode_graph_get_next_port_endpoint(const struct fwnode_handle *port,
+ struct fwnode_handle *prev)
+{
+ do {
+ prev = fwnode_get_next_child_node(port, prev);
+ if (fwnode_name_eq(prev, "endpoint"))
+ break;
+ } while (prev);
+
+ return prev;
+}
+EXPORT_SYMBOL_GPL(fwnode_graph_get_next_port_endpoint);
+
/**
* fwnode_graph_get_next_endpoint - Get next endpoint firmware node
* @fwnode: Pointer to the parent firmware node
diff --git a/include/linux/property.h b/include/linux/property.h
index 01ea010cb2f9..9a784a856773 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -507,6 +507,8 @@ void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index);
struct fwnode_handle *fwnode_graph_get_port_by_id(struct fwnode_handle *fwnode, u32 id,
unsigned long flags);
+struct fwnode_handle *fwnode_graph_get_next_port_endpoint(
+ const struct fwnode_handle *port, struct fwnode_handle *prev);
struct fwnode_handle *fwnode_graph_get_next_endpoint(
const struct fwnode_handle *fwnode, struct fwnode_handle *prev);
struct fwnode_handle *
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 03/16] power: sequencing: Add pwrseq_get_state()
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 01/16] device property: Add fwnode_graph_get_port_by_id() Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 02/16] device property: Add fwnode_graph_get_next_port_endpoint() Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 04/16] usb: hub: Use assign_bit() in usb_hub_set_port_power() Chen-Yu Tsai
` (12 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
The power sequencing consumer API already does power on state tracking
internally. Expose the state to consumers through pwrseq_get_state()
so that they don't have to reimplement it locally.
Instead of just on/off and error codes, the function can also return
"unknown" state. This is in anticipation for "uncontrollable" power
sequencers (such as GPIOs left unconnected).
Acked-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v6:
- Changed to pwrseq_get_state() with enum return value
Changes since v5:
- Reverted back to returning -EINVAL if descriptor is NULL
Changes since v4:
- Make pwrseq_power_is_on() return 1 if descriptor is NULL, i.e. if
the descriptor is optional, matching the other pwrseq consumer APIs
Changes since v3:
- Added missing stub function for !POWER_SEQUENCING
Changes since v2:
- New patch
Needs to go in with "usb: hub: Power on connected M.2 E-key connectors"
as it is a build time dependency. Bartosz wants the change on an
immutable branch to pull into the pwrseq tree.
---
drivers/power/sequencing/core.c | 19 +++++++++++++++++++
include/linux/pwrseq/consumer.h | 12 ++++++++++++
2 files changed, 31 insertions(+)
diff --git a/drivers/power/sequencing/core.c b/drivers/power/sequencing/core.c
index 02f42da91598..701728e60a26 100644
--- a/drivers/power/sequencing/core.c
+++ b/drivers/power/sequencing/core.c
@@ -968,6 +968,25 @@ int pwrseq_power_off(struct pwrseq_desc *desc)
}
EXPORT_SYMBOL_GPL(pwrseq_power_off);
+/**
+ * pwrseq_get_state() - Queries the last requested state of the power sequencer.
+ * @desc: Descriptor referencing the power sequencer.
+ *
+ * This returns the last requested state of the power sequencer.
+ *
+ * Returns:
+ * On success, PWRSEQ_STATE_ON for on and PWRSEQ_STATE_OFF for off;
+ * negative error number on failure.
+ */
+int pwrseq_get_state(struct pwrseq_desc *desc)
+{
+ if (!desc)
+ return -EINVAL;
+
+ return desc->powered_on ? PWRSEQ_STATE_ON : PWRSEQ_STATE_OFF;
+}
+EXPORT_SYMBOL_GPL(pwrseq_get_state);
+
/**
* pwrseq_to_device() - Get the pwrseq device pointer from a descriptor.
* @desc: Descriptor referencing the power sequencer.
diff --git a/include/linux/pwrseq/consumer.h b/include/linux/pwrseq/consumer.h
index 3c907c9e1885..af949e756bbd 100644
--- a/include/linux/pwrseq/consumer.h
+++ b/include/linux/pwrseq/consumer.h
@@ -11,6 +11,12 @@
struct device;
struct pwrseq_desc;
+enum {
+ PWRSEQ_STATE_UNKNOWN,
+ PWRSEQ_STATE_ON,
+ PWRSEQ_STATE_OFF,
+};
+
#if IS_ENABLED(CONFIG_POWER_SEQUENCING)
struct pwrseq_desc * __must_check
@@ -22,6 +28,7 @@ devm_pwrseq_get(struct device *dev, const char *target);
int pwrseq_power_on(struct pwrseq_desc *desc);
int pwrseq_power_off(struct pwrseq_desc *desc);
+int pwrseq_get_state(struct pwrseq_desc *desc);
struct device *pwrseq_to_device(struct pwrseq_desc *desc);
@@ -53,6 +60,11 @@ static inline int pwrseq_power_off(struct pwrseq_desc *desc)
return -ENOSYS;
}
+static inline int pwrseq_get_state(struct pwrseq_desc *desc)
+{
+ return -ENOSYS;
+}
+
static inline struct device *pwrseq_to_device(struct pwrseq_desc *desc)
{
return NULL;
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 04/16] usb: hub: Use assign_bit() in usb_hub_set_port_power()
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (2 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 03/16] power: sequencing: Add pwrseq_get_state() Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 05/16] usb: hub: Return actual error from hub_configure() in hub_probe() Chen-Yu Tsai
` (11 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
usb_hub_set_port_power() open-codes assign_bit(). Just use the
assign_bit() macro instead. This makes subsequent additions to
usb_hub_set_port_power() easier to read.
This change does not introduce any functional changes.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Attributing suggestion to Andy, since the change was originally
requested as part of a review.
Changes since v4:
- New patch (split out from "usb: hub: Power on connected M.2 E-key
connectors with power sequencing API") (Andy)
---
drivers/usb/core/hub.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 2cfe09a141d8..715f26f05a31 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -10,6 +10,7 @@
* Released under the GPLv2 only.
*/
+#include <linux/bitops.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/module.h>
@@ -899,10 +900,7 @@ int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
if (ret)
return ret;
- if (set)
- set_bit(port1, hub->power_bits);
- else
- clear_bit(port1, hub->power_bits);
+ assign_bit(port1, hub->power_bits, set);
return 0;
}
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 05/16] usb: hub: Return actual error from hub_configure() in hub_probe()
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (3 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 04/16] usb: hub: Use assign_bit() in usb_hub_set_port_power() Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 06/16] usb: hub: Associate port@ fwnode with USB port device Chen-Yu Tsai
` (10 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
The addition of power sequencing descriptor handling in the USB hub code
requires dealing with deferred probing from pwrseq_get(). The power
sequencing provider may not yet be available when the USB hub probes.
Return the actual error code from hub_configure() when it fails, so that
the driver core can notice the deferred probe request.
Also rewrite this section into the standard error handling pattern:
if (error) {
# handle error
return error;
}
# do more work
return 0;
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v2:
- Rewrite into standard error handling pattern
Changes since v1:
- Moved "int ret" declaration in hub_configure() over here from the next
patch
---
drivers/usb/core/hub.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 715f26f05a31..8f8624a0d36a 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1875,6 +1875,7 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
struct usb_host_interface *desc;
struct usb_device *hdev;
struct usb_hub *hub;
+ int ret;
desc = intf->cur_altsetting;
hdev = interface_to_usbdev(intf);
@@ -2006,14 +2007,15 @@ static int hub_probe(struct usb_interface *intf, const struct usb_device_id *id)
usb_set_interface(hdev, 0, 0);
}
- if (hub_configure(hub, &desc->endpoint[0].desc) >= 0) {
- onboard_dev_create_pdevs(hdev, &hub->onboard_devs);
-
- return 0;
+ ret = hub_configure(hub, &desc->endpoint[0].desc);
+ if (ret < 0) {
+ hub_disconnect(intf);
+ return ret;
}
- hub_disconnect(intf);
- return -ENODEV;
+ onboard_dev_create_pdevs(hdev, &hub->onboard_devs);
+
+ return 0;
}
static int
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 06/16] usb: hub: Associate port@ fwnode with USB port device
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (4 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 05/16] usb: hub: Return actual error from hub_configure() in hub_probe() Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 07/16] usb: core: Move struct usb_port and related APIs to port.h Chen-Yu Tsai
` (9 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
When a USB hub port is connected to a connector in a firmware node
graph, the port itself has a node in the graph.
Associate the port's firmware node with the USB port's device,
usb_port::dev. This is used in later changes for the M.2 slot power
sequencing provider to match against the requesting port.
To avoid potential conflicts with ACPI firmware nodes and then causing
power management issues, only assign the firmware node if the hub's
firmware node is not an ACPI firmware node.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v5:
- Added extra |struct fwnode_handle *| local variables to shorten lines
(Andy)
- Added comment about passing fwnode_graph_get_port_by_id() return value
directly to device_set_node() (Andy)
Changes since v4:
- Dropped unused |hdev| variable
- Added flags for fwnode_graph_get_port_by_id() with
FWNODE_GRAPH_DEVICE_DISABLED so that even incomplete
ports can be connected
Changes since v3:
- Added missing fwnode_handle_put()
Changes since v2:
- Skip assignment if hub firmware node is ACPI node
---
drivers/usb/core/port.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index b4452b665f59..c0a51d9b06a6 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -7,6 +7,7 @@
* Author: Lan Tianyu <tianyu.lan@intel.com>
*/
+#include <linux/acpi.h>
#include <linux/kstrtox.h>
#include <linux/slab.h>
#include <linux/string_choices.h>
@@ -358,6 +359,11 @@ static void usb_port_device_release(struct device *dev)
{
struct usb_port *port_dev = to_usb_port(dev);
+ /*
+ * At this point ACPI nodes and swnodes have been removed by
+ * device_platform_notify_remove() in device_del().
+ */
+ fwnode_handle_put(dev_fwnode(dev));
kfree(port_dev->req);
kfree(port_dev);
}
@@ -754,6 +760,7 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
{
struct usb_port *port_dev;
struct usb_device *hdev = hub->hdev;
+ struct fwnode_handle *fwnode = dev_fwnode(&hdev->dev);
int retval;
port_dev = kzalloc_obj(*port_dev);
@@ -782,6 +789,24 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
port_dev->dev.driver = &usb_port_driver;
dev_set_name(&port_dev->dev, "%s-port%d", dev_name(&hub->hdev->dev),
port1);
+
+ /*
+ * ACPI FW nodes are associated later when device_register() happens.
+ * Skip assigning one here to avoid potential conflicts.
+ */
+ if (!is_acpi_node(fwnode)) {
+ struct fwnode_handle *port;
+
+ /*
+ * fwnode_graph_get_port_by_id() returns either a valid fwnode handle
+ * or NULL. Passing NULL to device_set_node() clears any associated
+ * fwnode. It is effectively a no-op here, since no fwnode has been
+ * assigned to the newly created device yet.
+ */
+ port = fwnode_graph_get_port_by_id(fwnode, port1, FWNODE_GRAPH_DEVICE_DISABLED);
+ device_set_node(&port_dev->dev, port);
+ }
+
mutex_init(&port_dev->status_lock);
retval = device_register(&port_dev->dev);
if (retval) {
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 07/16] usb: core: Move struct usb_port and related APIs to port.h
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (5 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 06/16] usb: hub: Associate port@ fwnode with USB port device Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 08/16] usb: hub: Pass |struct usb_port*| to usb_port_is_power_on() Chen-Yu Tsai
` (8 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
|struct usb_port| and its matching container_of() macro should live in
its own port.h, matching the split we have for .c files.
Move them as described. Also move usb_port_is_power_on(), since in the
next change its |struct usb_hub *| parameter will be changed to
|struct usb_port *|, and becomes a non-static function that only
references |struct usb_port|.
port.h is only included from hub.h, as a subsequent patch will directly
use fields from |struct usb_port| in a static inline helper in hub.h.
The USB internal headers don't have header guards to help with this.
Also drop 'extern' from the header declaration of usb_port_is_power_on().
This is not needed in modern C.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v4:
- Dropped 'extern' (Andy)
Changes since v3:
- New patch (Andy)
---
drivers/usb/core/hub.c | 16 ----------
drivers/usb/core/hub.h | 48 ++---------------------------
drivers/usb/core/port.c | 16 ++++++++++
drivers/usb/core/port.h | 68 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 86 insertions(+), 62 deletions(-)
create mode 100644 drivers/usb/core/port.h
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 8f8624a0d36a..a6c4e4c0368a 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -3240,22 +3240,6 @@ static bool hub_port_stop_enumerate(struct usb_hub *hub, int port1, int retries)
return port_dev->ignore_event;
}
-/* Check if a port is power on */
-int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus)
-{
- int ret = 0;
-
- if (hub_is_superspeed(hub->hdev)) {
- if (portstatus & USB_SS_PORT_STAT_POWER)
- ret = 1;
- } else {
- if (portstatus & USB_PORT_STAT_POWER)
- ret = 1;
- }
-
- return ret;
-}
-
static void usb_lock_port(struct usb_port *port_dev)
__acquires(&port_dev->status_lock)
{
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index 9ebc5ef54a32..de524c6da9fc 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -15,7 +15,9 @@
#include <linux/usb/ch11.h>
#include <linux/usb/hcd.h>
#include <linux/usb/typec.h>
+
#include "usb.h"
+#include "port.h"
struct usb_hub {
struct device *intfdev; /* the "interface" device */
@@ -78,51 +80,6 @@ struct usb_hub {
struct list_head onboard_devs;
};
-/**
- * struct usb port - kernel's representation of a usb port
- * @child: usb device attached to the port
- * @dev: generic device interface
- * @port_owner: port's owner
- * @peer: related usb2 and usb3 ports (share the same connector)
- * @connector: USB Type-C connector
- * @req: default pm qos request for hubs without port power control
- * @connect_type: port's connect type
- * @state: device state of the usb device attached to the port
- * @state_kn: kernfs_node of the sysfs attribute that accesses @state
- * @location: opaque representation of platform connector location
- * @status_lock: synchronize port_event() vs usb_port_{suspend|resume}
- * @portnum: port index num based one
- * @is_superspeed cache super-speed status
- * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted.
- * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted.
- * @early_stop: whether port initialization will be stopped earlier.
- * @ignore_event: whether events of the port are ignored.
- */
-struct usb_port {
- struct usb_device *child;
- struct device dev;
- struct usb_dev_state *port_owner;
- struct usb_port *peer;
- struct typec_connector *connector;
- struct dev_pm_qos_request *req;
- enum usb_port_connect_type connect_type;
- enum usb_device_state state;
- struct kernfs_node *state_kn;
- usb_port_location_t location;
- struct mutex status_lock;
- u32 over_current_count;
- u8 portnum;
- u32 quirks;
- unsigned int early_stop:1;
- unsigned int ignore_event:1;
- unsigned int is_superspeed:1;
- unsigned int usb3_lpm_u1_permit:1;
- unsigned int usb3_lpm_u2_permit:1;
-};
-
-#define to_usb_port(_dev) \
- container_of(_dev, struct usb_port, dev)
-
extern int usb_hub_create_port_device(struct usb_hub *hub,
int port1);
extern void usb_hub_remove_port_device(struct usb_hub *hub,
@@ -138,7 +95,6 @@ extern int usb_clear_port_feature(struct usb_device *hdev,
int port1, int feature);
extern int usb_hub_port_status(struct usb_hub *hub, int port1,
u16 *status, u16 *change);
-extern int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus);
static inline bool hub_is_port_power_switchable(struct usb_hub *hub)
{
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index c0a51d9b06a6..b2e953f137f8 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -22,6 +22,22 @@ static int usb_port_block_power_off;
static const struct attribute_group *port_dev_group[];
+/* Check if a port is power on */
+int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus)
+{
+ int ret = 0;
+
+ if (hub_is_superspeed(hub->hdev)) {
+ if (portstatus & USB_SS_PORT_STAT_POWER)
+ ret = 1;
+ } else {
+ if (portstatus & USB_PORT_STAT_POWER)
+ ret = 1;
+ }
+
+ return ret;
+}
+
static bool usb_port_allow_power_off(struct usb_device *hdev,
struct usb_hub *hub,
struct usb_port *port_dev)
diff --git a/drivers/usb/core/port.h b/drivers/usb/core/port.h
new file mode 100644
index 000000000000..00f7500af336
--- /dev/null
+++ b/drivers/usb/core/port.h
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * usb hub driver head file
+ *
+ * Copyright (C) 1999 Linus Torvalds
+ * Copyright (C) 1999 Johannes Erdfelt
+ * Copyright (C) 1999 Gregory P. Smith
+ * Copyright (C) 2001 Brad Hards (bhards@bigpond.net.au)
+ * Copyright (C) 2012 Intel Corp (tianyu.lan@intel.com)
+ *
+ * move struct usb_port to this file.
+ */
+
+#include <linux/container_of.h>
+#include <linux/device.h>
+#include <linux/mutex_types.h>
+#include <linux/usb.h>
+
+#include <uapi/linux/usb/ch9.h>
+
+/**
+ * struct usb port - kernel's representation of a usb port
+ * @child: usb device attached to the port
+ * @dev: generic device interface
+ * @port_owner: port's owner
+ * @peer: related usb2 and usb3 ports (share the same connector)
+ * @connector: USB Type-C connector
+ * @req: default pm qos request for hubs without port power control
+ * @connect_type: port's connect type
+ * @state: device state of the usb device attached to the port
+ * @state_kn: kernfs_node of the sysfs attribute that accesses @state
+ * @location: opaque representation of platform connector location
+ * @status_lock: synchronize port_event() vs usb_port_{suspend|resume}
+ * @portnum: port index num based one
+ * @is_superspeed cache super-speed status
+ * @usb3_lpm_u1_permit: whether USB3 U1 LPM is permitted.
+ * @usb3_lpm_u2_permit: whether USB3 U2 LPM is permitted.
+ * @early_stop: whether port initialization will be stopped earlier.
+ * @ignore_event: whether events of the port are ignored.
+ */
+struct usb_port {
+ struct usb_device *child;
+ struct device dev;
+ struct usb_dev_state *port_owner;
+ struct usb_port *peer;
+ struct typec_connector *connector;
+ struct dev_pm_qos_request *req;
+ enum usb_port_connect_type connect_type;
+ enum usb_device_state state;
+ struct kernfs_node *state_kn;
+ usb_port_location_t location;
+ struct mutex status_lock;
+ u32 over_current_count;
+ u8 portnum;
+ u32 quirks;
+ unsigned int early_stop:1;
+ unsigned int ignore_event:1;
+ unsigned int is_superspeed:1;
+ unsigned int usb3_lpm_u1_permit:1;
+ unsigned int usb3_lpm_u2_permit:1;
+};
+
+#define to_usb_port(_dev) \
+ container_of(_dev, struct usb_port, dev)
+
+struct usb_hub;
+
+int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus);
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 08/16] usb: hub: Pass |struct usb_port*| to usb_port_is_power_on()
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (6 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 07/16] usb: core: Move struct usb_port and related APIs to port.h Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 09/16] usb: hub: Use usb_hub_set_port_power() to control port power everywhere Chen-Yu Tsai
` (7 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
usb_port_is_power_on() currently takes |struct usb_hub*|, but only needs
it to tell if the hub/port is SuperSpeed or not.
In a subsequent change, usb_port_is_power_on() needs access to a pwrseq
state tracking field in |struct usb_port|. Either structure can be used
to identify whether a port/hub is SuperSpeed or not, as the field in
|struct usb_port| is inherited from the hub:
port->is_superspeed = hub_is_superspeed(hub)
Replace usb_port_is_power_on()'s |struct usb_hub*| parameter with
|struct usb_port*| so a subsequent change can use it.
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v3:
- Adapted to move of usb_port_is_power_on() to port.c and port.h
---
drivers/usb/core/hub.c | 7 ++++---
drivers/usb/core/port.c | 6 +++---
drivers/usb/core/port.h | 4 +---
3 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index a6c4e4c0368a..6671b5e45191 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -3291,7 +3291,7 @@ static int check_port_resume_type(struct usb_device *udev,
}
/* Is the device still present? */
else if (status || port_is_suspended(hub, portstatus) ||
- !usb_port_is_power_on(hub, portstatus)) {
+ !usb_port_is_power_on(port_dev, portstatus)) {
if (status >= 0)
status = -ENODEV;
} else if (!(portstatus & USB_PORT_STAT_CONNECTION)) {
@@ -3733,12 +3733,13 @@ static int wait_for_connected(struct usb_device *udev,
struct usb_hub *hub, int port1,
u16 *portchange, u16 *portstatus)
{
+ struct usb_port *port_dev = hub->ports[port1 - 1];
int status = 0, delay_ms = 0;
while (delay_ms < 2000) {
if (status || *portstatus & USB_PORT_STAT_CONNECTION)
break;
- if (!usb_port_is_power_on(hub, *portstatus)) {
+ if (!usb_port_is_power_on(port_dev, *portstatus)) {
status = -ENODEV;
break;
}
@@ -5434,7 +5435,7 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
* but only if the port isn't owned by someone else.
*/
if (hub_is_port_power_switchable(hub)
- && !usb_port_is_power_on(hub, portstatus)
+ && !usb_port_is_power_on(port_dev, portstatus)
&& !port_dev->port_owner)
set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index b2e953f137f8..8d686d43e996 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -23,11 +23,11 @@ static int usb_port_block_power_off;
static const struct attribute_group *port_dev_group[];
/* Check if a port is power on */
-int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus)
+int usb_port_is_power_on(struct usb_port *port, unsigned int portstatus)
{
int ret = 0;
- if (hub_is_superspeed(hub->hdev)) {
+ if (port->is_superspeed) {
if (portstatus & USB_SS_PORT_STAT_POWER)
ret = 1;
} else {
@@ -114,7 +114,7 @@ static ssize_t disable_show(struct device *dev,
}
usb_hub_port_status(hub, port1, &portstatus, &unused);
- disabled = !usb_port_is_power_on(hub, portstatus);
+ disabled = !usb_port_is_power_on(port_dev, portstatus);
out_hdev_lock:
usb_unlock_device(hdev);
diff --git a/drivers/usb/core/port.h b/drivers/usb/core/port.h
index 00f7500af336..2f4349b3ce6b 100644
--- a/drivers/usb/core/port.h
+++ b/drivers/usb/core/port.h
@@ -63,6 +63,4 @@ struct usb_port {
#define to_usb_port(_dev) \
container_of(_dev, struct usb_port, dev)
-struct usb_hub;
-
-int usb_port_is_power_on(struct usb_hub *hub, unsigned int portstatus);
+int usb_port_is_power_on(struct usb_port *port, unsigned int portstatus);
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 09/16] usb: hub: Use usb_hub_set_port_power() to control port power everywhere
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (7 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 08/16] usb: hub: Pass |struct usb_port*| to usb_port_is_power_on() Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 10/16] usb: hub: Power on connected M.2 E-key connectors with power sequencing API Chen-Yu Tsai
` (6 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
There are still some instances in the USB hub driver where port power is
directly controlled by toggling the USB_PORT_FEAT_POWER feature flag.
Switch these instances over to usb_hub_set_port_power() so that only one
unified function to do this exists. This makes adding external power
control with the power sequencing API easier and consistently applied.
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v2:
- New patch
---
drivers/usb/core/hub.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 6671b5e45191..a5c5038e1604 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -976,11 +976,8 @@ static void hub_power_on(struct usb_hub *hub, bool do_delay)
dev_dbg(hub->intfdev, "trying to enable port power on "
"non-switchable hub\n");
for (port1 = 1; port1 <= hub->hdev->maxchild; port1++)
- if (test_bit(port1, hub->power_bits))
- set_port_feature(hub->hdev, port1, USB_PORT_FEAT_POWER);
- else
- usb_clear_port_feature(hub->hdev, port1,
- USB_PORT_FEAT_POWER);
+ usb_hub_set_port_power(hub->hdev, hub, port1,
+ test_bit(port1, hub->power_bits));
if (do_delay)
msleep(hub_power_on_good_delay(hub));
}
@@ -5437,7 +5434,7 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
if (hub_is_port_power_switchable(hub)
&& !usb_port_is_power_on(port_dev, portstatus)
&& !port_dev->port_owner)
- set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
+ usb_hub_set_port_power(hdev, hub, port1, true);
if (portstatus & USB_PORT_STAT_ENABLE)
goto done;
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 10/16] usb: hub: Power on connected M.2 E-key connectors with power sequencing API
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (8 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 09/16] usb: hub: Use usb_hub_set_port_power() to control port power everywhere Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 9:02 ` sashiko-bot
2026-07-24 8:43 ` [PATCH v7 11/16] dt-bindings: usb: mediatek,mtk-xhci: Switch to ports for USB connections Chen-Yu Tsai
` (5 subsequent siblings)
15 siblings, 1 reply; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
The new M.2 E-key connector can have a USB connection. For the USB device
on this connector to work, its power must be enabled and the W_DISABLE2#
signal deasserted. The connector driver handles this and provides a
toggle over the power sequencing API.
This feature currently only supports a directly connected (no mux in
between) M.2 E-key connector. Existing USB connector types are not
covered. The USB A connector was recently added to the onboard devices
driver. USB B connectors have historically been managed by the USB
gadget or dual-role device controller drivers. USB C connectors are
handled by TCPM drivers.
The power sequencing API does not know whether a power sequence provider
is not needed or not available yet, so we only request it for connectors
that we know need it, which at this time is just the E-key connector.
On the USB side, the port firmware node (if present) is tied to the
usb_port device. This device is used to acquire the power sequencing
descriptor. This allows the provider to tell the different ports on one
hub apart.
This feature is not implemented in the onboard USB devices driver. The
power sequencing API expects the consumer device to make the request,
but there is no device node to instantiate a platform device to tie
the driver to. The connector is not a child node of the USB host or
hub, and the graph connection is from a USB port to the connector.
And the connector itself already has a driver.
Power sequencing is not directly enabled in the connector driver as
that would completely decouple the timing of it from the USB subsystem.
It would not be possible for the USB subsystem to toggle the power
for a power cycle or to disable the port.
Sashiko mentions possible use-after-free of hub->ports from the sysfs
callbacks. This is actually not possible, since the sysfs callbacks
acquire the hub device and its lock, and then check if it is in the
process of disconnect / removal. If it is, then the callbacks just
error out.
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v6:
- Added braces ("{}") to for loop in hub_is_port_power_switchable() (Andy)
- Adapted usb_port_is_power_on() to new pwrseq_get_state() function
return values (Bartosz)
Changes since v5:
- Only assign port_dev->pwrseq if successfully retrieved pwrseq
descriptor (Andy)
- Dropped the pwrseq error pointer check in the release function (Andy)
- Added check for port->pwrseq != NULL before calling
pwrseq_is_power_on() (API change in patch 3)
Changes since v4:
- Rewrote usb_port_is_power_on() to better express intent and
restrictions of pwrseq API (Andy)
- Switched to dev_fwnode() in port_pwrseq_is_supported() (Andy)
- Added blank line separating normal variable declarations and __free()
type declarations (Andy)
- Split out assign_bit() rewrite (Andy)
- Moved pwrseq_put() to release function to avoid UAF (Sashiko)
- Added back pwrseq_power_off() call in usb_hub_remove_port_device();
otherwise power off could be delayed to object release
- Don't clear hub->ports[port1 - 1] in main error path;
by that time the port device is registered and sysfs attributes are
available to userspace (Sashiko)
Changes since v3:
- Adapted to move of usb_port_is_power_on() to port.c and port.h
- Simplified usb_hub_set_port_pwrseq() (Andy)
- Renamed usb_hub_set_port_pwrseq()'s "set" parameter to "on"
- Dropped usb_hub_restore_port_pwrseq() (use usb_hub_set_port_pwrseq()
with inverted argument)
- Fixed off-by-one access in hub_is_port_power_switchable() (Sashiko)
- Assign retval from dev_err_probe() instead of the other way around (Andy)
- Clear hub->ports[port1 - 1] in USB port error and remove paths to
avoid other threads from accidental UAF while the USB hub device is
being unwound (Sashiko)
- Short-circuit out of helpers if !IS_ENABLED(CONFIG_POWER_SEQUENCING)
to avoid errors from stub functions (Sashiko)
Changes since v2:
- Expanded subject to mention power sequencing API
- Dropped commit message bit about power sequencing Kconfig symbol change
to bool
- Added optional dependency on POWER_SEQUENCING to USB
- Split out pwrseq_power_*() calls into separate helpers
- Rewrote set_bit() and clear_bit() branches with assign_bit()
- Dropped the pwrseq_power_off() before pwrseq_put(): pwrseq_put() does it
automatically.
- Removed pwrseq_power_on() from usb_hub_create_port_device(); it will
get called through usb_hub_set_port_power() in hub_activate().
- Added checks for port->pwrseq in hub_is_port_power_switchable()
- Use separate pwrseq descriptors for HighSpeed and SuperSpeed ports.
This makes things simpler. On the other hand to power cycle a port
userspace needs to toggle it on both the HS and SS ports together.
- Dropped pwrseq state tracking again
The power sequencing consumer API already tracks the state internally;
doing it again in |struct usb_port| is not necessary especially now
that the descriptors aren't shared.
It's unclear to me how actual hubs reconcile USB_PORT_FEAT_POWER settings
from the HS side and SS side. One hub chip vendor said that VBUS_EN for
a port is on if the flag is set on either side; however actually testing
on one of their hubs showed that VBUS was cut as soon as the flag is
cleared on the HS port. Maybe it could be different if a SS device was
connected? That scenario was not tested. Testing on another retail
bought hub seemed to work exactly as described though: USB_PORT_FEAT_POWER
needed to be clear on both HS and SS ports to turn off VBUS.
Under this scheme, I'm not sure how the power cycle in hub_port_connect()
would work correctly.
- Link to v2:
https://lore.kernel.org/all/20260610084053.2059858-1-wenst@chromium.org/
Changes since v1:
- Switch to fwnode instead of OF
- Tie port@ fwnode to usb_port device
- Move remote node compatible checking to separate helper
- Use usb_port device to request power sequencing descriptor
- Drop "index" parameter from pwrseq_get()
- Do not get pwrseq descriptor for SuperSpeed port; share one for one
physical port
- Add pwrseq state tracking
- Link to v1:
https://lore.kernel.org/all/20260515090149.3169406-1-wenst@chromium.org/
---
drivers/usb/Kconfig | 1 +
drivers/usb/core/hub.c | 20 ++++++++++++-
drivers/usb/core/hub.h | 10 ++++++-
drivers/usb/core/port.c | 62 ++++++++++++++++++++++++++++++++++++++++-
drivers/usb/core/port.h | 2 ++
5 files changed, 92 insertions(+), 3 deletions(-)
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index abf8c6cdea9e..ef1959363fb1 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -44,6 +44,7 @@ config USB_ARCH_HAS_HCD
config USB
tristate "Support for Host-side USB"
depends on USB_ARCH_HAS_HCD
+ depends on POWER_SEQUENCING if POWER_SEQUENCING
select GENERIC_ALLOCATOR
select USB_COMMON
select NLS # for UTF-8 strings
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index a5c5038e1604..35e035cfeb4d 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -33,6 +33,7 @@
#include <linux/mutex.h>
#include <linux/random.h>
#include <linux/pm_qos.h>
+#include <linux/pwrseq/consumer.h>
#include <linux/kobject.h>
#include <linux/bitfield.h>
@@ -875,6 +876,16 @@ static void hub_tt_work(struct work_struct *work)
spin_unlock_irqrestore(&hub->tt.lock, flags);
}
+static int usb_hub_set_port_pwrseq(struct usb_port *port, bool on)
+{
+ if (!IS_ENABLED(CONFIG_POWER_SEQUENCING))
+ return 0;
+
+ if (on)
+ return pwrseq_power_on(port->pwrseq);
+ return pwrseq_power_off(port->pwrseq);
+}
+
/**
* usb_hub_set_port_power - control hub port's power state
* @hdev: USB device belonging to the usb hub
@@ -890,15 +901,22 @@ static void hub_tt_work(struct work_struct *work)
int usb_hub_set_port_power(struct usb_device *hdev, struct usb_hub *hub,
int port1, bool set)
{
+ struct usb_port *pwrseq_port = hub->ports[port1 - 1];
int ret;
+ ret = usb_hub_set_port_pwrseq(pwrseq_port, set);
+ if (ret)
+ return ret;
+
if (set)
ret = set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
else
ret = usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
- if (ret)
+ if (ret) {
+ usb_hub_set_port_pwrseq(pwrseq_port, !set);
return ret;
+ }
assign_bit(port1, hub->power_bits, set);
return 0;
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index de524c6da9fc..3f403a56e5f7 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -103,7 +103,15 @@ static inline bool hub_is_port_power_switchable(struct usb_hub *hub)
if (!hub)
return false;
hcs = hub->descriptor->wHubCharacteristics;
- return (le16_to_cpu(hcs) & HUB_CHAR_LPSM) < HUB_CHAR_NO_LPSM;
+ if ((le16_to_cpu(hcs) & HUB_CHAR_LPSM) < HUB_CHAR_NO_LPSM)
+ return true;
+ /* check for controllable external power sequencers */
+ for (unsigned int i = 0; i < hub->hdev->maxchild; i++) {
+ if (hub->ports[i] && hub->ports[i]->pwrseq)
+ return true;
+ }
+
+ return false;
}
static inline int hub_is_superspeed(struct usb_device *hdev)
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index 8d686d43e996..c0490f616c23 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -8,11 +8,14 @@
*/
#include <linux/acpi.h>
+#include <linux/cleanup.h>
#include <linux/kstrtox.h>
#include <linux/slab.h>
#include <linux/string_choices.h>
#include <linux/sysfs.h>
#include <linux/pm_qos.h>
+#include <linux/property.h>
+#include <linux/pwrseq/consumer.h>
#include <linux/component.h>
#include <linux/usb/of.h>
@@ -26,6 +29,7 @@ static const struct attribute_group *port_dev_group[];
int usb_port_is_power_on(struct usb_port *port, unsigned int portstatus)
{
int ret = 0;
+ int pwrseq_state;
if (port->is_superspeed) {
if (portstatus & USB_SS_PORT_STAT_POWER)
@@ -35,7 +39,13 @@ int usb_port_is_power_on(struct usb_port *port, unsigned int portstatus)
ret = 1;
}
- return ret;
+ /* stub function returns error */
+ pwrseq_state = pwrseq_get_state(port->pwrseq);
+ /* fall back to port status if pwrseq is in unknown state */
+ if (pwrseq_state < 0 || pwrseq_state == PWRSEQ_STATE_UNKNOWN)
+ return ret;
+
+ return ret && pwrseq_state == PWRSEQ_STATE_ON;
}
static bool usb_port_allow_power_off(struct usb_device *hdev,
@@ -45,6 +55,9 @@ static bool usb_port_allow_power_off(struct usb_device *hdev,
if (hub_is_port_power_switchable(hub))
return true;
+ if (port_dev->pwrseq)
+ return true;
+
if (!IS_ENABLED(CONFIG_ACPI))
return false;
@@ -380,6 +393,8 @@ static void usb_port_device_release(struct device *dev)
* device_platform_notify_remove() in device_del().
*/
fwnode_handle_put(dev_fwnode(dev));
+ /* usb_hub_create_port_device() could leave an error value */
+ pwrseq_put(port_dev->pwrseq);
kfree(port_dev->req);
kfree(port_dev);
}
@@ -772,11 +787,46 @@ static const struct component_ops connector_ops = {
.unbind = connector_unbind,
};
+static bool port_pwrseq_is_supported(struct usb_port *port_dev)
+{
+ struct device *dev = &port_dev->dev;
+ struct fwnode_handle *port = dev_fwnode(dev);
+
+ struct fwnode_handle *ep __free(fwnode_handle) =
+ fwnode_graph_get_next_port_endpoint(port, NULL);
+ if (!ep)
+ return false;
+
+ struct fwnode_handle *remote __free(fwnode_handle) =
+ fwnode_graph_get_remote_port_parent(ep);
+ if (!remote)
+ return false;
+
+ if (!fwnode_device_is_compatible(remote, "pcie-m2-e-connector")) {
+ dev_dbg(dev, "remote endpoint %pfw is not a supported connector", remote);
+ return false;
+ }
+
+ return true;
+}
+
+static struct pwrseq_desc *usb_hub_port_pwrseq_get(struct usb_port *port_dev)
+{
+ if (!IS_ENABLED(CONFIG_POWER_SEQUENCING))
+ return NULL;
+
+ if (!port_pwrseq_is_supported(port_dev))
+ return NULL;
+
+ return pwrseq_get(&port_dev->dev, "usb");
+}
+
int usb_hub_create_port_device(struct usb_hub *hub, int port1)
{
struct usb_port *port_dev;
struct usb_device *hdev = hub->hdev;
struct fwnode_handle *fwnode = dev_fwnode(&hdev->dev);
+ struct pwrseq_desc *pwrseq;
int retval;
port_dev = kzalloc_obj(*port_dev);
@@ -827,6 +877,7 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
retval = device_register(&port_dev->dev);
if (retval) {
put_device(&port_dev->dev);
+ hub->ports[port1 - 1] = NULL;
return retval;
}
@@ -844,6 +895,14 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
goto err_put_kn;
}
+ pwrseq = usb_hub_port_pwrseq_get(port_dev);
+ if (IS_ERR(pwrseq)) {
+ retval = dev_err_probe(&port_dev->dev, PTR_ERR(pwrseq),
+ "failed to get power sequencing descriptor\n");
+ goto err_put_kn;
+ }
+ port_dev->pwrseq = pwrseq;
+
retval = component_add(&port_dev->dev, &connector_ops);
if (retval) {
dev_warn(&port_dev->dev, "failed to add component\n");
@@ -901,6 +960,7 @@ void usb_hub_remove_port_device(struct usb_hub *hub, int port1)
peer = port_dev->peer;
if (peer)
unlink_peers(port_dev, peer);
+ pwrseq_power_off(port_dev->pwrseq);
component_del(&port_dev->dev, &connector_ops);
sysfs_put(port_dev->state_kn);
device_unregister(&port_dev->dev);
diff --git a/drivers/usb/core/port.h b/drivers/usb/core/port.h
index 2f4349b3ce6b..088a182332d4 100644
--- a/drivers/usb/core/port.h
+++ b/drivers/usb/core/port.h
@@ -25,6 +25,7 @@
* @port_owner: port's owner
* @peer: related usb2 and usb3 ports (share the same connector)
* @connector: USB Type-C connector
+ * @pwrseq: power sequencing descriptor for the port
* @req: default pm qos request for hubs without port power control
* @connect_type: port's connect type
* @state: device state of the usb device attached to the port
@@ -44,6 +45,7 @@ struct usb_port {
struct usb_dev_state *port_owner;
struct usb_port *peer;
struct typec_connector *connector;
+ struct pwrseq_desc *pwrseq;
struct dev_pm_qos_request *req;
enum usb_port_connect_type connect_type;
enum usb_device_state state;
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 11/16] dt-bindings: usb: mediatek,mtk-xhci: Switch to ports for USB connections
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (9 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 10/16] usb: hub: Power on connected M.2 E-key connectors with power sequencing API Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 12/16] power: sequencing: pcie-m2: support matching on remote "port" node Chen-Yu Tsai
` (4 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Krzysztof Kozlowski, Bartosz Golaszewski
This reverts commit 454a1e3cd36c113341d7b71e8e691c6e47ab4a8a.
MediaTek's XHCI implementation supports both USB 2.0 High Speed (HS)
and USB 3.x Super Speed (SS). The block can also be synthesized with
either HS-only capability or HS+SS capability. The SSUSB controller
handles the device or gadget mode. Saying that SSUSB handles the HS
portion is wrong.
For example, on the MT8195, the first two instances support both HS and
SS, while the latter two instances support only HS.
Switch to a "ports" sub-node for describing USB connections. Port 1 is
Super Speed if the controller is SS-capable, otherwise it is High Speed.
Port 2 is High Speed if SS-capable. This port mapping scheme directly
matches what the hardware returns in its capability registers.
Fixes: 454a1e3cd36c ("dt-bindings: usb: mediatek,mtk-xhci: Add port for SuperSpeed EP")
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v1:
- Squashed DT binding revert and addition together
- Dropped reviewed-by from Bartosz
---
.../bindings/usb/mediatek,mtk-xhci.yaml | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
index 231e6f35a986..d6c75bd20b78 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.yaml
@@ -107,10 +107,6 @@ properties:
- description: USB3/SS(P) PHY
- description: USB2/HS PHY
- port:
- $ref: /schemas/graph.yaml#/properties/port
- description: Super Speed (SS) Output endpoint to a Type-C connector
-
vusb33-supply:
description: Regulator of USB AVDD3.3v
@@ -188,6 +184,19 @@ properties:
"#size-cells":
const: 0
+ ports:
+ $ref: /schemas/graph.yaml#/properties/ports
+
+ properties:
+ port@1:
+ $ref: /schemas/graph.yaml#/properties/port
+ description: Super Speed (SS) data bus if SS-capable;
+ otherwise High Speed (HS) data bus.
+
+ port@2:
+ $ref: /schemas/graph.yaml#/properties/port
+ description: High Speed (HS) data bus if controller is SS-capable.
+
patternProperties:
"@[0-9a-f]{1}$":
type: object
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 12/16] power: sequencing: pcie-m2: support matching on remote "port" node
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (10 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 11/16] dt-bindings: usb: mediatek,mtk-xhci: Switch to ports for USB connections Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 13/16] power: sequencing: pcie-m2: Add usb and sdio targets for E-key connector Chen-Yu Tsai
` (3 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern
A USB hub can have multiple ports, and this driver needs to
differentiate which port is being matched to. The USB hub driver now
associates the "port" node with the usb_port device, so here we can
use the remote "port" node to check for a match. Then fall back to
the remote device node for the other connection types.
Also rewrite the existing "remote == dev_of_node(dev)" with
device_match_of_node() for consistency.
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v4:
- Dropped blank line between __free() variable declaration and
subsequent use of the variable in conditional
Changes since v3:
- Drop redundant device node validity check; device_match_of_node()
does it internally
Changes since v2:
- Use device_match_of_node()
---
drivers/power/sequencing/pwrseq-pcie-m2.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/power/sequencing/pwrseq-pcie-m2.c b/drivers/power/sequencing/pwrseq-pcie-m2.c
index 83fe6a1396bc..691cad0a6dd0 100644
--- a/drivers/power/sequencing/pwrseq-pcie-m2.c
+++ b/drivers/power/sequencing/pwrseq-pcie-m2.c
@@ -175,9 +175,16 @@ static int pwrseq_pcie_m2_match(struct pwrseq_device *pwrseq,
* parent matches the OF node of 'dev'.
*/
for_each_endpoint_of_node(ctx->of_node, endpoint) {
+ /* USB port devices are tied to the port nodes. */
+ struct device_node *remote_port __free(device_node) =
+ of_graph_get_remote_port(endpoint);
+ if (device_match_of_node(dev, remote_port))
+ return PWRSEQ_MATCH_OK;
+
+ /* Try the remote port parent for other types. */
struct device_node *remote __free(device_node) =
of_graph_get_remote_port_parent(endpoint);
- if (remote && (remote == dev_of_node(dev)))
+ if (device_match_of_node(dev, remote))
return PWRSEQ_MATCH_OK;
}
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 13/16] power: sequencing: pcie-m2: Add usb and sdio targets for E-key connector
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (11 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 12/16] power: sequencing: pcie-m2: support matching on remote "port" node Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 14/16] power: sequencing: pcie-m2: Split Bluetooth unit based on interface Chen-Yu Tsai
` (2 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern
The M.2 E-key connector allows either PCIe or SDIO for WiFi and USB or
UART for BT. Currently the driver only supports PCIe and UART.
Add power sequencing targets for SDIO and USB. To avoid adding a
complicated dependency tree, rename the existing power sequencing units
"pcie" and "uart" to "wifi" and "bt". The existing target names are left
untouched. The new "sdio" and "usb" targets just point to the renamed
"wifi" and "bt" units.
The "unit" names are internal to the power sequencing framework, and
should be confined to a single provider. The names are only
informational. Dependencies are tracked with pointers to other units.
The "target" names are the strings that the consumer uses to acquire a
descriptor with. As these remain the same, existing users will continue
to work.
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v2:
- Expand commit message
---
drivers/power/sequencing/pwrseq-pcie-m2.c | 41 +++++++++++++++--------
1 file changed, 27 insertions(+), 14 deletions(-)
diff --git a/drivers/power/sequencing/pwrseq-pcie-m2.c b/drivers/power/sequencing/pwrseq-pcie-m2.c
index 691cad0a6dd0..693b0d33f8cf 100644
--- a/drivers/power/sequencing/pwrseq-pcie-m2.c
+++ b/drivers/power/sequencing/pwrseq-pcie-m2.c
@@ -69,46 +69,46 @@ static const struct pwrseq_unit_data *pwrseq_pcie_m2_unit_deps[] = {
NULL
};
-static int pwrseq_pci_m2_e_uart_enable(struct pwrseq_device *pwrseq)
+static int pwrseq_pci_m2_e_bt_enable(struct pwrseq_device *pwrseq)
{
struct pwrseq_pcie_m2_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
return gpiod_set_value_cansleep(ctx->w_disable2_gpio, 0);
}
-static int pwrseq_pci_m2_e_uart_disable(struct pwrseq_device *pwrseq)
+static int pwrseq_pci_m2_e_bt_disable(struct pwrseq_device *pwrseq)
{
struct pwrseq_pcie_m2_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
return gpiod_set_value_cansleep(ctx->w_disable2_gpio, 1);
}
-static const struct pwrseq_unit_data pwrseq_pcie_m2_e_uart_unit_data = {
- .name = "uart-enable",
+static const struct pwrseq_unit_data pwrseq_pcie_m2_e_bt_unit_data = {
+ .name = "bt-enable",
.deps = pwrseq_pcie_m2_unit_deps,
- .enable = pwrseq_pci_m2_e_uart_enable,
- .disable = pwrseq_pci_m2_e_uart_disable,
+ .enable = pwrseq_pci_m2_e_bt_enable,
+ .disable = pwrseq_pci_m2_e_bt_disable,
};
-static int pwrseq_pci_m2_e_pcie_enable(struct pwrseq_device *pwrseq)
+static int pwrseq_pci_m2_e_wifi_enable(struct pwrseq_device *pwrseq)
{
struct pwrseq_pcie_m2_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
return gpiod_set_value_cansleep(ctx->w_disable1_gpio, 0);
}
-static int pwrseq_pci_m2_e_pcie_disable(struct pwrseq_device *pwrseq)
+static int pwrseq_pci_m2_e_wifi_disable(struct pwrseq_device *pwrseq)
{
struct pwrseq_pcie_m2_ctx *ctx = pwrseq_device_get_drvdata(pwrseq);
return gpiod_set_value_cansleep(ctx->w_disable1_gpio, 1);
}
-static const struct pwrseq_unit_data pwrseq_pcie_m2_e_pcie_unit_data = {
- .name = "pcie-enable",
+static const struct pwrseq_unit_data pwrseq_pcie_m2_e_wifi_unit_data = {
+ .name = "wifi-enable",
.deps = pwrseq_pcie_m2_unit_deps,
- .enable = pwrseq_pci_m2_e_pcie_enable,
- .disable = pwrseq_pci_m2_e_pcie_disable,
+ .enable = pwrseq_pci_m2_e_wifi_enable,
+ .disable = pwrseq_pci_m2_e_wifi_disable,
};
static const struct pwrseq_unit_data pwrseq_pcie_m2_m_pcie_unit_data = {
@@ -130,13 +130,24 @@ static int pwrseq_pcie_m2_e_pwup_delay(struct pwrseq_device *pwrseq)
static const struct pwrseq_target_data pwrseq_pcie_m2_e_uart_target_data = {
.name = "uart",
- .unit = &pwrseq_pcie_m2_e_uart_unit_data,
+ .unit = &pwrseq_pcie_m2_e_bt_unit_data,
.post_enable = pwrseq_pcie_m2_e_pwup_delay,
};
+static const struct pwrseq_target_data pwrseq_pcie_m2_e_usb_target_data = {
+ .name = "usb",
+ .unit = &pwrseq_pcie_m2_e_bt_unit_data,
+};
+
static const struct pwrseq_target_data pwrseq_pcie_m2_e_pcie_target_data = {
.name = "pcie",
- .unit = &pwrseq_pcie_m2_e_pcie_unit_data,
+ .unit = &pwrseq_pcie_m2_e_wifi_unit_data,
+ .post_enable = pwrseq_pcie_m2_e_pwup_delay,
+};
+
+static const struct pwrseq_target_data pwrseq_pcie_m2_e_sdio_target_data = {
+ .name = "sdio",
+ .unit = &pwrseq_pcie_m2_e_wifi_unit_data,
.post_enable = pwrseq_pcie_m2_e_pwup_delay,
};
@@ -147,7 +158,9 @@ static const struct pwrseq_target_data pwrseq_pcie_m2_m_pcie_target_data = {
static const struct pwrseq_target_data *pwrseq_pcie_m2_e_targets[] = {
&pwrseq_pcie_m2_e_pcie_target_data,
+ &pwrseq_pcie_m2_e_sdio_target_data,
&pwrseq_pcie_m2_e_uart_target_data,
+ &pwrseq_pcie_m2_e_usb_target_data,
NULL
};
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 14/16] power: sequencing: pcie-m2: Split Bluetooth unit based on interface
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (12 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 13/16] power: sequencing: pcie-m2: Add usb and sdio targets for E-key connector Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 15/16] arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 16/16] arm64: dts: mediatek: mt8188-geralt: Add WiFi/BT as " Chen-Yu Tsai
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern
Some UART / serdev based Bluetooth drivers need to be able to reset the
hardware during initialization or recovery. This is not possible with
the current power sequencing API if a unit is shared between USB and
UART interfaces.
For now, split the Bluetooth unit into two, one for each interface.
This allows either interface to independently toggle the power, with
the last action prevailing, thereby unbreaking the Qualcomm Bluetooth
serdev driver. This is also needed for the Realtek Bluetooth serdev
driver (hci_h5).
Having independent control from either interface unfortunately means
that userspace is able to shut down the controller from sysfs using
the USB port's "disable" setting without the serdev driver knowing
about it. On the USB side, independent control is also desired, as it
allows the USB core to power cycle the port/device during faults, and
for userspace to initiate reset and recovery using the aforementioned
"disable" setting. However when USB is used, a serdev device is not
created, and there is no conflicting usage, which allows the power
sequencing to work even without the split unit.
Suggested-by: Wei Deng <wei.deng@oss.qualcomm.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v4:
- New patch
This patch is _not_ squashed into the previous to provide clear context
on the change, and the less than perfect nature of it.
I think what we need in this case is some sort of lockout. The serdev
consumer would want "exclusive" access, locking out the USB consumer,
which can tolerate "shared" access.
Something similar would be needed for the WiFi if we ever add support
for SDIO for toggling the state of W_DISABLE#1. At least the SDIO and
PCIe reset signals are separate.
---
drivers/power/sequencing/pwrseq-pcie-m2.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/drivers/power/sequencing/pwrseq-pcie-m2.c b/drivers/power/sequencing/pwrseq-pcie-m2.c
index 693b0d33f8cf..56e4f40e0480 100644
--- a/drivers/power/sequencing/pwrseq-pcie-m2.c
+++ b/drivers/power/sequencing/pwrseq-pcie-m2.c
@@ -83,8 +83,22 @@ static int pwrseq_pci_m2_e_bt_disable(struct pwrseq_device *pwrseq)
return gpiod_set_value_cansleep(ctx->w_disable2_gpio, 1);
}
-static const struct pwrseq_unit_data pwrseq_pcie_m2_e_bt_unit_data = {
- .name = "bt-enable",
+/*
+ * XXX There are two Bluetooth units to allow either one to be able to power
+ * off and thus reset the controller. In practice only one of the interfaces
+ * is used, so there is no conflict. However userspace could power off the
+ * USB unit by disabling the associated USB port, without the UART unit or
+ * its consumer ever knowing.
+ */
+static const struct pwrseq_unit_data pwrseq_pcie_m2_e_bt_uart_unit_data = {
+ .name = "bt-uart-enable",
+ .deps = pwrseq_pcie_m2_unit_deps,
+ .enable = pwrseq_pci_m2_e_bt_enable,
+ .disable = pwrseq_pci_m2_e_bt_disable,
+};
+
+static const struct pwrseq_unit_data pwrseq_pcie_m2_e_bt_usb_unit_data = {
+ .name = "bt-usb-enable",
.deps = pwrseq_pcie_m2_unit_deps,
.enable = pwrseq_pci_m2_e_bt_enable,
.disable = pwrseq_pci_m2_e_bt_disable,
@@ -130,13 +144,13 @@ static int pwrseq_pcie_m2_e_pwup_delay(struct pwrseq_device *pwrseq)
static const struct pwrseq_target_data pwrseq_pcie_m2_e_uart_target_data = {
.name = "uart",
- .unit = &pwrseq_pcie_m2_e_bt_unit_data,
+ .unit = &pwrseq_pcie_m2_e_bt_uart_unit_data,
.post_enable = pwrseq_pcie_m2_e_pwup_delay,
};
static const struct pwrseq_target_data pwrseq_pcie_m2_e_usb_target_data = {
.name = "usb",
- .unit = &pwrseq_pcie_m2_e_bt_unit_data,
+ .unit = &pwrseq_pcie_m2_e_bt_usb_unit_data,
};
static const struct pwrseq_target_data pwrseq_pcie_m2_e_pcie_target_data = {
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 15/16] arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (13 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 14/16] power: sequencing: pcie-m2: Split Bluetooth unit based on interface Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
2026-07-24 9:03 ` sashiko-bot
2026-07-24 8:43 ` [PATCH v7 16/16] arm64: dts: mediatek: mt8188-geralt: Add WiFi/BT as " Chen-Yu Tsai
15 siblings, 1 reply; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
The Mt8195 Cherry design features an M.2 E-key slot for WiFi/BT combo
cards. Only PCIe and USB are wired from the SoC to the slot, along with
some auxiliary signals.
Add the proper representation for it, replacing the PCIe wifi node and
vpcie3v3-supply property under the PCIe controller, and the vbus-supply
property under the xhci3 node.
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v2:
- Drop default GPIO output state from kill pins pinconfig
---
.../boot/dts/mediatek/mt8195-cherry.dtsi | 73 +++++++++++++++++--
1 file changed, 68 insertions(+), 5 deletions(-)
diff --git a/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi b/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
index ef7afc436aef..8d4cc30d91e4 100644
--- a/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
@@ -266,6 +266,47 @@ tboard_thermistor2: thermal-sensor-t2 {
120000 51
125000 44>;
};
+
+ wifi-bt-connector {
+ compatible = "pcie-m2-e-connector";
+ pinctrl-names = "default";
+ pinctrl-0 = <&m2_e_key_kill_pins>;
+ vpcie3v3-supply = <&pp3300_wlan>;
+ w-disable1-gpios = <&pio 61 GPIO_ACTIVE_LOW>;
+ w-disable2-gpios = <&pio 59 GPIO_ACTIVE_LOW>;
+ /* PCIe auxiliary signals wired to controller. */
+
+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ /* PCIe for WiFi */
+ port@0 {
+ reg = <0>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ wifi_ep: endpoint@0 {
+ reg = <0>;
+ remote-endpoint = <&pcie1_ep>;
+ };
+ };
+
+ /* USB for Bluetooth */
+ port@2 {
+ reg = <2>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ bt_ep: endpoint@0 {
+ reg = <0>;
+ remote-endpoint = <&usb3_ep>;
+ };
+ };
+
+ /* SDIO, UART and I2S not implemented */
+ };
+ };
};
&adsp {
@@ -791,14 +832,14 @@ pcie@0 {
reg = <0 0 0 0 0>;
device_type = "pci";
num-lanes = <1>;
- vpcie3v3-supply = <&pp3300_wlan>;
#address-cells = <3>;
#size-cells = <2>;
ranges;
- wifi@0 {
- reg = <0 0 0 0 0>;
- wakeup-source;
+ port {
+ pcie1_ep: endpoint {
+ remote-endpoint = <&wifi_ep>;
+ };
};
};
};
@@ -1085,6 +1126,13 @@ pins-bus {
};
};
+ m2_e_key_kill_pins: m2-e-key-kill-pins {
+ pins-kill {
+ pinmux = <PINMUX_GPIO61__FUNC_GPIO61>,
+ <PINMUX_GPIO59__FUNC_GPIO59>;
+ };
+ };
+
mmc0_pins_default: mmc0-default-pins {
pins-cmd-dat {
pinmux = <PINMUX_GPIO126__FUNC_MSDC0_DAT0>,
@@ -1637,9 +1685,24 @@ &xhci2 {
&xhci3 {
/* MT7921's USB Bluetooth has issues with USB2 LPM */
usb2-lpm-disable;
- vbus-supply = <&pp3300_wlan>;
vusb33-supply = <&mt6359_vusb_ldo_reg>;
status = "okay";
+
+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@1 {
+ reg = <1>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ usb3_ep: endpoint@0 {
+ reg = <0>;
+ remote-endpoint = <&bt_ep>;
+ };
+ };
+ };
};
#include <arm/cros-ec-keyboard.dtsi>
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v7 16/16] arm64: dts: mediatek: mt8188-geralt: Add WiFi/BT as M.2 E-key slot
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
` (14 preceding siblings ...)
2026-07-24 8:43 ` [PATCH v7 15/16] arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot Chen-Yu Tsai
@ 2026-07-24 8:43 ` Chen-Yu Tsai
15 siblings, 0 replies; 21+ messages in thread
From: Chen-Yu Tsai @ 2026-07-24 8:43 UTC (permalink / raw)
To: Bartosz Golaszewski, Greg Kroah-Hartman, Andy Shevchenko,
Daniel Scally, Heikki Krogerus, Sakari Ailus, Rafael J. Wysocki,
Danilo Krummrich, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: Wei Deng, Chen-Yu Tsai, linux-acpi, driver-core, linux-pm,
linux-usb, devicetree, linux-mediatek, linux-arm-kernel,
linux-kernel, Manivannan Sadhasivam, Alan Stern,
Bartosz Golaszewski
The MT8188 Geralt design features a chip-on-board WiFi/BT solution. This
is a M.2 E-key WiFi/BT board layout directly inserted into the mainboard
design. The connections to the rest of the board are almost the same as
if it were a separate M.2 card. The only addition is the PMU_EN pin on
the chip; on M.2 cards this would be tied to the primary power source.
Model the chip-on-board WiFi/BT solution as a M.2 E-key slot with PCIe,
USB and auxiliary signals. The PMU_EN pin, which enables the internal
power controls and regulators, is modeled as a regulator fed by the
pp3300_wlan regulator. Since power sequencing is now correctly modeled
using the M.2 E-key slot, drop the "regulator-always-on" property one
pp3300_wlan regulator. Also drop the comment in xhci2 saying "MT7921's
power is controlled by PCIe".
Also drop the voltage range on the pp3300_wlan regulator. This
"regulator" is just a load switch and does not provide any regulation.
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v2:
- Drop default GPIO output state from kill pins pinconfig
---
.../boot/dts/mediatek/mt8188-geralt.dtsi | 92 ++++++++++++++++++-
1 file changed, 88 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/boot/dts/mediatek/mt8188-geralt.dtsi b/arch/arm64/boot/dts/mediatek/mt8188-geralt.dtsi
index dee946309121..73b5c0fdeae6 100644
--- a/arch/arm64/boot/dts/mediatek/mt8188-geralt.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8188-geralt.dtsi
@@ -88,13 +88,11 @@ pp3300_z1: regulator-pp3300-z1 {
pp3300_wlan: regulator-pp3300-wlan {
compatible = "regulator-fixed";
regulator-name = "pp3300_wlan";
- regulator-always-on;
- regulator-min-microvolt = <3300000>;
- regulator-max-microvolt = <3300000>;
enable-active-high;
gpio = <&pio 12 GPIO_ACTIVE_HIGH>;
pinctrl-0 = <&wlan_en>;
pinctrl-names = "default";
+ /* load switch */
vin-supply = <&pp3300_z1>;
};
@@ -161,6 +159,17 @@ ppvar_mipi_disp_avee: regulator-ppvar-mipi-disp-avee {
vin-supply = <&pp5000_z1>;
};
+ /* PMU_EN pin controls internal regulators and power sequence */
+ wlan_pmu: regulator-wlan-pmu {
+ compatible = "regulator-fixed";
+ regulator-name = "wlan-pmu";
+ enable-active-high;
+ gpio = <&pio 145 GPIO_ACTIVE_HIGH>;
+ pinctrl-0 = <&wlan_pmu_en>;
+ pinctrl-names = "default";
+ vin-supply = <&pp3300_wlan>;
+ };
+
reserved_memory: reserved-memory {
#address-cells = <2>;
#size-cells = <2>;
@@ -195,6 +204,39 @@ adsp_dma_mem: memory@61000000 {
no-map;
};
};
+
+ wifi-bt-connector {
+ compatible = "pcie-m2-e-connector";
+ pinctrl-names = "default";
+ pinctrl-0 = <&m2_e_key_kill_pins>;
+ vpcie1v8-supply = <&mt6359_vcn18_ldo_reg>;
+ vpcie3v3-supply = <&wlan_pmu>;
+ w-disable1-gpios = <&pio 13 GPIO_ACTIVE_LOW>;
+ w-disable2-gpios = <&pio 14 GPIO_ACTIVE_LOW>;
+
+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ /* PCIe for WiFi */
+ port@0 {
+ reg = <0>;
+
+ wifi_ep: endpoint {
+ remote-endpoint = <&pcie_ep>;
+ };
+ };
+
+ /* USB for Bluetooth */
+ port@2 {
+ reg = <2>;
+
+ bt_ep: endpoint {
+ remote-endpoint = <&usb2_ep>;
+ };
+ };
+ };
+ };
};
&adsp {
@@ -659,6 +701,22 @@ &pcie {
pinctrl-names = "default";
pinctrl-0 = <&pcie_pins>;
status = "okay";
+
+ pcie@0 {
+ compatible = "pciclass,0604";
+ reg = <0 0 0 0 0>;
+ device_type = "pci";
+ num-lanes = <1>;
+ #address-cells = <3>;
+ #size-cells = <2>;
+ ranges;
+
+ port {
+ pcie_ep: endpoint {
+ remote-endpoint = <&wifi_ep>;
+ };
+ };
+ };
};
&pciephy {
@@ -1002,6 +1060,13 @@ pins-bus {
};
};
+ m2_e_key_kill_pins: m2-e-key-kill-pins {
+ pins-kill {
+ pinmux = <PINMUX_GPIO13__FUNC_B_GPIO13>,
+ <PINMUX_GPIO14__FUNC_B_GPIO14>;
+ };
+ };
+
mipi_disp_avdd_en: mipi-disp-avdd-en-pins {
pins-en-ppvar-mipi-disp {
pinmux = <PINMUX_GPIO3__FUNC_B_GPIO3>;
@@ -1174,6 +1239,13 @@ pins-bus {
};
};
+ wlan_pmu_en: wlan-pmu-en-pins {
+ pins-wlan-pmu-en {
+ pinmux = <PINMUX_GPIO145__FUNC_B_GPIO145>;
+ output-low;
+ };
+ };
+
wlan_en: wlan-en-pins {
pins-en-pp3300-wlan {
pinmux = <PINMUX_GPIO12__FUNC_B_GPIO12>;
@@ -1417,10 +1489,22 @@ vdosys1_ep_ext: endpoint@1 {
};
&xhci2 {
- /* no power supply since MT7921's power is controlled by PCIe */
/* MT7921's USB BT has issues with USB2 LPM */
usb2-lpm-disable;
status = "okay";
+
+ ports {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ port@1 {
+ reg = <1>;
+
+ usb2_ep: endpoint {
+ remote-endpoint = <&bt_ep>;
+ };
+ };
+ };
};
#include <arm/cros-ec-keyboard.dtsi>
--
2.55.0.229.g6434b31f56-goog
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v7 01/16] device property: Add fwnode_graph_get_port_by_id()
2026-07-24 8:43 ` [PATCH v7 01/16] device property: Add fwnode_graph_get_port_by_id() Chen-Yu Tsai
@ 2026-07-24 9:01 ` sashiko-bot
0 siblings, 0 replies; 21+ messages in thread
From: sashiko-bot @ 2026-07-24 9:01 UTC (permalink / raw)
To: Chen-Yu Tsai; +Cc: conor+dt, robh, devicetree
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] fwnode_graph_get_port_by_id() silently fails to find port nodes that do not contain any endpoints, breaking parity with of_graph_get_port_by_id() and limiting its intended use case.
--
--- Patch [1]: [PATCH v7 01/16] device property: Add fwnode_graph_get_port_by_id() ---
commit d1b7173e906ae494c3f7042d2841d794c9508816
Author: Chen-Yu Tsai <wenst@chromium.org>
device property: Add fwnode_graph_get_port_by_id()
This commit introduces a helper to retrieve a port firmware node by its ID.
It is intended to support USB power sequencing by allowing drivers to get
references to port nodes that might describe power topology.
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index e08eadd66f4f9..0bd45f8b01c14 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
[ ... ]
> +struct fwnode_handle *fwnode_graph_get_port_by_id(struct fwnode_handle *fwnode,
> + u32 id,
> + unsigned long flags)
> +{
> + struct fwnode_handle *ep;
> +
> + ep = fwnode_graph_get_endpoint_by_id(fwnode, id, 0,
> + flags | FWNODE_GRAPH_ENDPOINT_NEXT);
> + if (!ep)
> + return NULL;
[Severity: High]
Will this silently fail to find valid port nodes if they don't contain any
endpoints?
The underlying graph iteration (e.g. of_graph_get_next_endpoint())
intentionally skips port nodes that do not contain any endpoint subnodes.
If a device has a port subnode used solely for power topology (like a
vbus-supply property) without any endpoints, fwnode_graph_get_endpoint_by_id()
would return NULL here.
Does this limit the intended use case for USB power sequencing, where ports
might only contain power properties but no endpoints, and break parity with
of_graph_get_port_by_id()?
> +
> + return fwnode_get_next_parent(ep);
> +}
> +EXPORT_SYMBOL_GPL(fwnode_graph_get_port_by_id);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724084328.3943997-1-wenst@chromium.org?part=1
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v7 10/16] usb: hub: Power on connected M.2 E-key connectors with power sequencing API
2026-07-24 8:43 ` [PATCH v7 10/16] usb: hub: Power on connected M.2 E-key connectors with power sequencing API Chen-Yu Tsai
@ 2026-07-24 9:02 ` sashiko-bot
0 siblings, 0 replies; 21+ messages in thread
From: sashiko-bot @ 2026-07-24 9:02 UTC (permalink / raw)
To: Chen-Yu Tsai; +Cc: conor+dt, devicetree, robh
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] hub_is_port_power_switchable() incorrectly elevates a per-port power sequencer property to a hub-wide capability.
--
--- Patch [10]: [PATCH v7 10/16] usb: hub: Power on connected M.2 E-key connectors with power sequencing API ---
commit 5b4df25e39c50f42b92c649d3b30e831a5d2dc33
Author: Chen-Yu Tsai <wenst@chromium.org>
usb: hub: Power on connected M.2 E-key connectors with power sequencing API
This commit adds support for powering on M.2 E-key connectors that have a
USB connection using the power sequencing API. It uses the usb_port device
to acquire the power sequencing descriptor, allowing the power sequence
provider to differentiate between ports on a hub.
Link: https://lore.kernel.org/all/20260610084053.2059858-1-wenst@chromium.org/
Link: https://lore.kernel.org/all/20260515090149.3169406-1-wenst@chromium.org/
[ ... ]
> diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
> index de524c6da9fc4..3f403a56e5f75 100644
> --- a/drivers/usb/core/hub.h
> +++ b/drivers/usb/core/hub.h
> @@ -103,7 +103,15 @@ static inline bool hub_is_port_power_switchable(struct usb_hub *hub)
> if (!hub)
> return false;
> hcs = hub->descriptor->wHubCharacteristics;
> - return (le16_to_cpu(hcs) & HUB_CHAR_LPSM) < HUB_CHAR_NO_LPSM;
> + if ((le16_to_cpu(hcs) & HUB_CHAR_LPSM) < HUB_CHAR_NO_LPSM)
> + return true;
> + /* check for controllable external power sequencers */
> + for (unsigned int i = 0; i < hub->hdev->maxchild; i++) {
> + if (hub->ports[i] && hub->ports[i]->pwrseq)
> + return true;
> + }
> +
> + return false;
> }
[Severity: Medium]
Does this code incorrectly elevate a per-port property to a hub-wide
capability?
If a natively non-switchable USB hub is connected and at least one of its
ports has an external power sequencer, hub_is_port_power_switchable() will
return true for the entire hub.
This causes runtime operations like hub_port_connect_change() to act on all
ports as if they are switchable:
drivers/usb/core/hub.c:hub_port_connect_change() {
...
if (hub_is_port_power_switchable(hub)
&& !usb_port_is_power_on(port_dev, portstatus)
&& !port_dev->port_owner)
usb_hub_set_port_power(hdev, hub, port1, true);
...
}
Will this erroneously issue SetPortFeature(PORT_POWER) commands for ports on
the hub that neither support power switching nor possess a power sequencer?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724084328.3943997-1-wenst@chromium.org?part=10
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v7 15/16] arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot
2026-07-24 8:43 ` [PATCH v7 15/16] arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot Chen-Yu Tsai
@ 2026-07-24 9:03 ` sashiko-bot
0 siblings, 0 replies; 21+ messages in thread
From: sashiko-bot @ 2026-07-24 9:03 UTC (permalink / raw)
To: Chen-Yu Tsai; +Cc: conor+dt, devicetree, robh
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Removal of the `wifi@0` device tree node silently breaks Wake-on-WLAN (WoWLAN) capability for the MT7921 WiFi device.
--
--- Patch [15]: [PATCH v7 15/16] arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot ---
commit f3cf400c3b922d9936d6cc4d1a7c83d4b85941b6
Author: Chen-Yu Tsai <wenst@chromium.org>
arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot
The Mt8195 Cherry design features an M.2 E-key slot for WiFi/BT combo cards.
This patch adds the proper representation for it, replacing the PCIe wifi node
and supply properties under the PCIe controller and xhci3 nodes.
> diff --git a/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi b/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
> --- a/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
> +++ b/arch/arm64/boot/dts/mediatek/mt8195-cherry.dtsi
[ ... ]
> @@ -791,14 +832,14 @@ pcie@0 {
> reg = <0 0 0 0 0>;
> device_type = "pci";
> num-lanes = <1>;
> - vpcie3v3-supply = <&pp3300_wlan>;
> #address-cells = <3>;
> #size-cells = <2>;
> ranges;
>
> - wifi@0 {
> - reg = <0 0 0 0 0>;
> - wakeup-source;
> + port {
> + pcie1_ep: endpoint {
> + remote-endpoint = <&wifi_ep>;
> + };
> };
[Severity: Medium]
Does removing the wifi@0 node silently break Wake-on-WLAN capability for the
MT7921 WiFi device?
Looking at the driver in mt7921/pci.c, it probes the device and explicitly
checks for the wakeup-source property on its associated device tree node.
Since the wifi@0 node is completely replaced by the OF graph port node here,
which does not represent a PCI device and has no reg property, it appears
the PCI core will no longer assign an OF node to the MT7921 device. Will
this cause the wakeup-source check to fail and leave WoWLAN permanently
disabled?
> };
> };
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724084328.3943997-1-wenst@chromium.org?part=15
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v7 02/16] device property: Add fwnode_graph_get_next_port_endpoint()
2026-07-24 8:43 ` [PATCH v7 02/16] device property: Add fwnode_graph_get_next_port_endpoint() Chen-Yu Tsai
@ 2026-07-24 9:03 ` sashiko-bot
0 siblings, 0 replies; 21+ messages in thread
From: sashiko-bot @ 2026-07-24 9:03 UTC (permalink / raw)
To: Chen-Yu Tsai; +Cc: conor+dt, robh, devicetree
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] The new helper `fwnode_graph_get_next_port_endpoint` ignores the ACPI-specific compatibility logic for identifying endpoint nodes by hardcoding an OF-specific naming convention.
Pre-existing issues:
- [Critical] `fwnode_get_next_child_node` improperly handles transitioning from the primary fwnode to the secondary fwnode, causing double frees, reference leaks, and an infinite loop. This problem wasn't introduced by this patch, but it is a critical pre-existing issue exposed by new loops.
- [High] Calling `mutex_lock(&fwnode_link_lock)` while holding `raw_spin_lock_irqsave(&devtree_lock)` causes a sleeping in atomic context BUG when the last reference to a dynamic OF node is dropped during iteration. This problem wasn't introduced by this patch, but it is a severe pre-existing locking violation.
--
--- Patch [2]: [PATCH v7 02/16] device property: Add fwnode_graph_get_next_port_endpoint() ---
commit 0be52c3289b5692b190b7583fe9b05fd00691fca
Author: Chen-Yu Tsai <wenst@chromium.org>
device property: Add fwnode_graph_get_next_port_endpoint()
Due to design constraints of the power sequencing API, the consumer must first
be sure that the other side is actually a provider, or it will continually get
-EPROBE_DEFER when requesting the power sequencing descriptor. This commit
introduces a helper to get the endpoint under a known port firmware node.
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index 0bd45f8b01c14..62c6221d65d05 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
[ ... ]
> @@ -1099,6 +1099,31 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name)
> }
> EXPORT_SYMBOL(fwnode_irq_get_byname);
>
> +/**
> + * fwnode_graph_get_next_port_endpoint - Get next endpoint firmware node in port
> + * @port: Pointer to the target port firmware node
> + * @prev: Previous endpoint node or %NULL to get the first
> + *
> + * The caller is responsible for calling fwnode_handle_put() on the returned
> + * fwnode pointer. Note that this function also puts a reference to @prev
> + * unconditionally.
> + *
> + * Return: an endpoint firmware node pointer or %NULL if no more endpoints
> + * are available.
> + */
> +struct fwnode_handle *fwnode_graph_get_next_port_endpoint(const struct fwnode_handle *port,
> + struct fwnode_handle *prev)
> +{
> + do {
> + prev = fwnode_get_next_child_node(port, prev);
[Severity: Critical]
This is a pre-existing issue, but does fwnode_get_next_child_node() improperly
handle transitioning from the primary fwnode to the secondary fwnode?
When the primary fwnode iterator exhausts its children, it drops the reference
to the child node and returns NULL.
Inside fwnode_get_next_child_node(), it then passes this already-freed child
pointer to the secondary fwnode's iterator:
drivers/base/property.c:fwnode_get_next_child_node() {
...
/* Try to find a child in primary fwnode */
next = fwnode_call_ptr_op(fwnode, get_next_child_node, child);
if (next)
return next;
/* When no more children in primary, continue with secondary */
return fwnode_call_ptr_op(fwnode->secondary, get_next_child_node, child);
}
Checking is_software_node(child) inside the secondary iterator accesses the
freed node's ops, causing a UAF. Since child is not a software node, the
iterator returns the first software node child. On the subsequent iteration,
this software node is passed back into the primary OF iterator, which ignores
it and restarts from the first OF child, resulting in an infinite loop.
Can this be triggered by any device graph traversal on a parent node possessing
both primary and secondary children?
[Severity: High]
This is also a pre-existing issue, but is there a risk of a sleeping in atomic
context BUG here when dropping the final reference to a dynamic OF node?
Iterator functions within the OF subsystem (like of_get_next_status_child) drop
the reference to the prev fwnode using of_node_put() while explicitly holding
the devtree_lock raw spinlock.
If the node being put is dynamically allocated (e.g., from DT overlays) and this
is its final reference, of_node_put() synchronously invokes of_node_release().
This release function then calls fwnode_links_purge(), which attempts to
acquire the fwnode_link_lock mutex:
drivers/base/core.c:fwnode_links_purge_suppliers() {
...
guard(mutex)(&fwnode_link_lock);
...
}
Will this lock nesting hierarchy violation trigger a BUG on both RT and non-RT
kernels when terminating the loop on the final reference of a dynamically
allocated node?
> + if (fwnode_name_eq(prev, "endpoint"))
[Severity: High]
Does this strict naming check ignore the ACPI-specific compatibility logic for
identifying endpoint nodes?
In the ACPI subsystem, graph nodes are often identified by the presence of an
endpoint property rather than their exact node name (e.g., as handled by
is_acpi_graph_node()).
If drivers using this generic fwnode_graph_* API on ACPI platforms don't have
the literal name "endpoint", will they fail to find valid endpoints and break
device functionality?
> + break;
> + } while (prev);
> +
> + return prev;
> +}
> +EXPORT_SYMBOL_GPL(fwnode_graph_get_next_port_endpoint);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260724084328.3943997-1-wenst@chromium.org?part=2
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2026-07-24 9:03 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24 8:43 [PATCH v7 00/16] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 01/16] device property: Add fwnode_graph_get_port_by_id() Chen-Yu Tsai
2026-07-24 9:01 ` sashiko-bot
2026-07-24 8:43 ` [PATCH v7 02/16] device property: Add fwnode_graph_get_next_port_endpoint() Chen-Yu Tsai
2026-07-24 9:03 ` sashiko-bot
2026-07-24 8:43 ` [PATCH v7 03/16] power: sequencing: Add pwrseq_get_state() Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 04/16] usb: hub: Use assign_bit() in usb_hub_set_port_power() Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 05/16] usb: hub: Return actual error from hub_configure() in hub_probe() Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 06/16] usb: hub: Associate port@ fwnode with USB port device Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 07/16] usb: core: Move struct usb_port and related APIs to port.h Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 08/16] usb: hub: Pass |struct usb_port*| to usb_port_is_power_on() Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 09/16] usb: hub: Use usb_hub_set_port_power() to control port power everywhere Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 10/16] usb: hub: Power on connected M.2 E-key connectors with power sequencing API Chen-Yu Tsai
2026-07-24 9:02 ` sashiko-bot
2026-07-24 8:43 ` [PATCH v7 11/16] dt-bindings: usb: mediatek,mtk-xhci: Switch to ports for USB connections Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 12/16] power: sequencing: pcie-m2: support matching on remote "port" node Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 13/16] power: sequencing: pcie-m2: Add usb and sdio targets for E-key connector Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 14/16] power: sequencing: pcie-m2: Split Bluetooth unit based on interface Chen-Yu Tsai
2026-07-24 8:43 ` [PATCH v7 15/16] arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot Chen-Yu Tsai
2026-07-24 9:03 ` sashiko-bot
2026-07-24 8:43 ` [PATCH v7 16/16] arm64: dts: mediatek: mt8188-geralt: Add WiFi/BT as " Chen-Yu Tsai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox