PCI/pwrctrl: Major rework to integrate pwrctrl devices with controller drivers
Subsystems (6)
v5 cover PCI/pwrctrl: Major rework to integrate pwrctrl devices with controller drivers
Hi,
This series provides a major rework for the PCI power control (pwrctrl) framework to enable the pwrctrl devices to be controlled by the PCI controller drivers.
Problem Statement
=================
Currently, the pwrctrl framework faces two major issues:
1. Missing PERST# integration
2. Inability to properly handle bus extenders such as PCIe switch devices
First issue arises from the disconnect between the PCI controller drivers and pwrctrl framework. At present, the pwrctrl framework just operates on its own with the help of the PCI core. The pwrctrl devices are created by the PCI core during initial bus scan and the pwrctrl drivers once bind, just power on the PCI devices during their probe(). This design conflicts with the PCI Express Card Electromechanical Specification requirements for PERST# timing. The reason is, PERST# signals are mostly handled by the controller drivers and often deasserted even before the pwrctrl drivers probe. According to the spec, PERST# should be deasserted only after power and reference clock to the device are stable, within predefined timing parameters.
The second issue stems from the PCI bus scan completing before pwrctrl drivers probe. This poses a significant problem for PCI bus extenders like switches because the PCI core allocates upstream bridge resources during the initial scan. If the upstream bridge is not hotplug capable, resources are allocated only for the number of downstream buses detected at scan time, which might be just one if the switch was not powered and enumerated at that time. Later, when the pwrctrl driver powers on and enumerates the switch, enumeration fails due to insufficient upstream bridge resources.
Proposal
========
This series addresses both issues by introducing new individual APIs for pwrctrl device creation, destruction, power on, and power off operations. Controller drivers are expected to invoke these APIs during their probe(), remove(), suspend(), and resume() operations. This integration allows better coordination between controller drivers and the pwrctrl framework, enabling enhanced features such as D3Cold support.
The original design aimed to avoid modifying controller drivers for pwrctrl integration. However, this approach lacked scalability because different controllers have varying requirements for when devices should be powered on. For example, controller drivers require devices to be powered on early for successful PHY initialization.
By using these explicit APIs, controller drivers gain fine grained control over their associated pwrctrl devices.
This series modified the pcie-qcom driver (only consumer of pwrctrl framework) to adopt to these APIs and also removed the old pwrctrl code from PCI core. This could be used as a reference to add pwrctrl support for other controller drivers also.
For example, to control the 3.3v supply to the PCI slot where the NVMe device is connected, below modifications are required:
Devicetree
----------
// In SoC dtsi:
pci@1bf8000 { // controller node
...
pcie1_port0: pcie@0 { // PCI Root Port node
compatible = "pciclass,0604"; // required for pwrctrl
driver bind
...
};
};
// In board dts:
&pcie1_port0 {
reset-gpios = <&tlmm 152 GPIO_ACTIVE_LOW>; // optional
vpcie3v3-supply = <&vreg_nvme>; // NVMe power supply
};Controller driver
-----------------
// Select PCI_PWRCTRL_SLOT in controller Kconfig
probe() {
...
// Initialize controller resources
pci_pwrctrl_create_devices(&pdev->dev);
pci_pwrctrl_power_on_devices(&pdev->dev);
// Deassert PERST# (optional)
...
pci_host_probe(); // Allocate host bridge and start bus scan
}
suspend {
// PME_Turn_Off broadcast
// Assert PERST# (optional)
pci_pwrctrl_power_off_devices(&pdev->dev);
...
}
resume {
...
pci_pwrctrl_power_on_devices(&pdev->dev);
// Deassert PERST# (optional)
}I will add a documentation for the pwrctrl framework in the coming days to make it easier to use.
Testing
=======
This series is tested on the Lenovo Thinkpad T14s laptop based on Qcom X1E chipset and RB3Gen2 development board with TC9563 switch based on Qcom QCS6490 chipset.
**NOTE**: With this series, the controller driver may undergo multiple probe deferral if the pwrctrl driver was not available during the controller driver probe. This is pretty much required to avoid the resource allocation issue. I plan to replace probe deferral with blocking wait in the coming days.
---
Changes in v5:
- Incorporated cleanups from Bjorn
- Splitted the power on/off callback changes
- Collected tags
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Used platform_device_put()
- Changed the return value of power_off() callback to 'int'
- Splitted patch 6 into two and reworded the commit message
- Collected tags
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Integrated TC9563 change
- Reworked the power_on API to properly power off the devices in error path
- Fixed the error path in pcie-qcom.c to not destroy pwrctrl devices during
probe deferral
- Rebased on top of pci/controller/dwc-qcom branch and dropped the PERST# patch
- Added a patch for TC9563 to fix the refcount dropping for i2c adapter
- Added patches to drop the assert_perst callback and rename the PERST# helpers in pcie-qcom.c
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Exported of_pci_supply_present() API
- Demoted the -EPROBE_DEFER log to dev_dbg()
- Collected tags and rebased on top of v6.19-rc1
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Bjorn Helgaas (5):
PCI/pwrctrl: pwrseq: Rename private struct and pointers for consistency PCI/pwrctrl: slot: Rename private struct and pointers for consistency PCI/pwrctrl: tc9563: Clean up whitespace
PCI/pwrctrl: tc9563: Add local variables to reduce repetition PCI/pwrctrl: tc9563: Rename private struct and pointers for consistency
Krishna Chaitanya Chundru (1):
PCI/pwrctrl: Add APIs to create, destroy pwrctrl devices
Manivannan Sadhasivam (9):
PCI/pwrctrl: tc9563: Use put_device() instead of i2c_put_adapter() PCI/pwrctrl: slot: Factor out power on/off code to helpers PCI/pwrctrl: pwrseq: Factor out power on/off code to helpers PCI/pwrctrl: Add 'struct pci_pwrctrl::power_{on/off}' callbacks PCI/pwrctrl: Add APIs to power on/off pwrctrl devices PCI/pwrctrl: Switch to pwrctrl create, power on/off, destroy APIs
PCI: qcom: Drop the assert_perst() callbacks
PCI: Drop the assert_perst() callback
PCI: qcom: Rename PERST# assert/deassert helpers for uniformity
drivers/pci/bus.c | 19 -- drivers/pci/controller/dwc/pcie-designware-host.c | 9 - drivers/pci/controller/dwc/pcie-designware.h | 9 - drivers/pci/controller/dwc/pcie-qcom.c | 55 +++-- drivers/pci/of.c | 1 + drivers/pci/probe.c | 59 ----- drivers/pci/pwrctrl/core.c | 259 ++++++++++++++++++++-- drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c | 50 +++-- drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c | 226 ++++++++++--------- drivers/pci/pwrctrl/slot.c | 60 +++-- drivers/pci/remove.c | 20 -- include/linux/pci-pwrctrl.h | 16 +- include/linux/pci.h | 1 - 13 files changed, 484 insertions(+), 300 deletions(-)
---
base-commit: 3e7f562e20ee87a25e104ef4fce557d39d62fa85
change-id: 20251124-pci-pwrctrl-rework-c91a6e16c2f6
Best regards,
Signature · 1 line
Manivannan Sadhasivam <[email protected]>
PATCH v5 1/15 PCI/pwrctrl: pwrseq: Rename private struct and pointers for consistency
From: Bjorn Helgaas <[email protected]>
Previously the pwrseq, tc9563, and slot pwrctrl drivers used different naming conventions for their private data structs and pointers to them, which makes patches hard to read:
Previous names New names
------------------------------------ ----------------------------------
struct pci_pwrctrl_pwrseq_data { struct pci_pwrctrl_pwrseq {
struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl; struct pci_pwrctrl_pwrseq_data *data struct pci_pwrctrl_pwrseq *pwrseq
struct tc9563_pwrctrl_ctx { struct pci_pwrctrl_tc9563 {
struct tc9563_pwrctrl_ctx *ctx struct pci_pwrctrl_tc9563 *tc9563
struct pci_pwrctrl_slot_data { struct pci_pwrctrl_slot {
struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl;
struct pci_pwrctrl_slot_data *slot struct pci_pwrctrl_slot *slotRename "struct pci_pwrctrl_pwrseq_data" to "pci_pwrctrl_pwrseq".
Rename the "struct pci_pwrctrl ctx" member to "struct pci_pwrctrl pwrctrl".
Rename pointers from "struct pci_pwrctrl_pwrseq_data *data" to "struct pci_pwrctrl_pwrseq *pwrseq".
No functional change intended.
--- drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c +12 -12
@@ -13,8 +13,8 @@#include <linux/slab.h> #include <linux/types.h> -struct pci_pwrctrl_pwrseq_data { -struct pci_pwrctrl ctx; +struct pci_pwrctrl_pwrseq { +struct pci_pwrctrl pwrctrl;struct pwrseq_desc *pwrseq; };
@@ -62,7 +62,7 @@ static void devm_pci_pwrctrl_pwrseq_power_off(void *data)static int pci_pwrctrl_pwrseq_probe (struct platform_device *pdev) {const struct pci_pwrctrl_pwrseq_pdata *pdata; -struct pci_pwrctrl_pwrseq_data *data; +struct pci_pwrctrl_pwrseq *pwrseq;struct device *dev = &pdev->dev;int ret;
@@ -76,28 +76,28 @@ static int pci_pwrctrl_pwrseq_probe(struct platform_device *pdev)return ret; } - data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL ); -if (!data) + pwrseq =devm_kzalloc (dev,sizeof (*pwrseq),GFP_KERNEL ); +if (!pwrseq)return -ENOMEM ; - data->pwrseq =devm_pwrseq_get (dev, pdata->target); -if (IS_ERR (data->pwrseq)) -return dev_err_probe (dev,PTR_ERR (data->pwrseq), + pwrseq->pwrseq =devm_pwrseq_get (dev, pdata->target); +if (IS_ERR (pwrseq->pwrseq)) +return dev_err_probe (dev,PTR_ERR (pwrseq->pwrseq),"Failed to get the power sequencer\n" ); - ret =pwrseq_power_on (data->pwrseq); + ret =pwrseq_power_on (pwrseq->pwrseq);if (ret)return dev_err_probe (dev, ret,"Failed to power-on the device\n" ); ret =devm_add_action_or_reset (dev, devm_pci_pwrctrl_pwrseq_power_off, - data->pwrseq); + pwrseq->pwrseq);if (ret)return ret; -pci_pwrctrl_init (&data->ctx, dev); +pci_pwrctrl_init (&pwrseq->pwrctrl, dev); - ret =devm_pci_pwrctrl_device_set_ready (dev, &data->ctx); + ret =devm_pci_pwrctrl_device_set_ready (dev, &pwrseq->pwrctrl);if (ret)return dev_err_probe (dev, ret,"Failed to register the pwrctrl wrapper\n" );
Signature · 1 line
2.48.1
Re: [PATCH v5 01/15] PCI/pwrctrl: pwrseq: Rename private struct and pointers for consistency
Quoted 23 lines · On Thu, 15 Jan 2026 08:28:53 +0100, Manivannan Sadhasivam via B4 Relay…
From: Bjorn Helgaas <[email protected]>
Previously the pwrseq, tc9563, and slot pwrctrl drivers used different naming conventions for their private data structs and pointers to them, which makes patches hard to read:
Previous names New names ------------------------------------ ---------------------------------- struct pci_pwrctrl_pwrseq_data { struct pci_pwrctrl_pwrseq { struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl;struct
pci_pwrctrl_pwrseq_data*data structpci_pwrctrl_pwrseq*pwrseqstruct tc9563_pwrctrl_ctx { struct pci_pwrctrl_tc9563 { struct tc9563_pwrctrl_ctx *ctx struct pci_pwrctrl_tc9563 *tc9563 struct pci_pwrctrl_slot_data { struct pci_pwrctrl_slot { struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl; struct pci_pwrctrl_slot_data *slot struct pci_pwrctrl_slot *slotRename "struct
pci_pwrctrl_pwrseq_data" to "pci_pwrctrl_pwrseq".Rename the "struct
pci_pwrctrlctx" member to "structpci_pwrctrlpwrctrl".
Quoted 8 lines
Rename pointers from "struct
pci_pwrctrl_pwrseq_data*data" to "structpci_pwrctrl_pwrseq*pwrseq".No functional change intended.
Signed-off-by Bjorn Helgaas <[email protected]>Signed-off-by Manivannan Sadhasivam <[email protected]>---
PATCH v5 2/15 PCI/pwrctrl: slot: Rename private struct and pointers for consistency
In reply to Manivannan SadhasivamFrom: Bjorn Helgaas <[email protected]>
Previously the pwrseq, tc9563, and slot pwrctrl drivers used different naming conventions for their private data structs and pointers to them, which makes patches hard to read:
Previous names New names
------------------------------------ ----------------------------------
struct pci_pwrctrl_pwrseq_data { struct pci_pwrctrl_pwrseq {
struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl; struct pci_pwrctrl_pwrseq_data *data struct pci_pwrctrl_pwrseq *pwrseq
struct tc9563_pwrctrl_ctx { struct pci_pwrctrl_tc9563 {
struct tc9563_pwrctrl_ctx *ctx struct pci_pwrctrl_tc9563 *tc9563
struct pci_pwrctrl_slot_data { struct pci_pwrctrl_slot {
struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl;
struct pci_pwrctrl_slot_data *slot struct pci_pwrctrl_slot *slotRename "struct pci_pwrctrl_slot_data" to "struct pci_pwrctrl_slot".
Rename the "struct pci_pwrctrl ctx" member to "struct pci_pwrctrl pwrctrl".
No functional change intended.
--- drivers/pci/pwrctrl/slot.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/pci/pwrctrl/slot.c +6 -6
@@ -13,15 +13,15 @@#include <linux/regulator/consumer.h> #include <linux/slab.h> -struct pci_pwrctrl_slot_data { -struct pci_pwrctrl ctx; +struct pci_pwrctrl_slot { +struct pci_pwrctrl pwrctrl;struct regulator_bulk_data *supplies;int num_supplies; };static void devm_pci_pwrctrl_slot_power_off (void *data) { -struct pci_pwrctrl_slot_data *slot = data; +struct pci_pwrctrl_slot *slot = data;regulator_bulk_disable (slot->num_supplies, slot->supplies);regulator_bulk_free (slot->num_supplies, slot->supplies);
@@ -29,7 +29,7 @@ static void devm_pci_pwrctrl_slot_power_off(void *data)static int pci_pwrctrl_slot_probe (struct platform_device *pdev) { -struct pci_pwrctrl_slot_data *slot; +struct pci_pwrctrl_slot *slot;struct device *dev = &pdev->dev;struct clk *clk;int ret;
@@ -64,9 +64,9 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev) "Failed to enable slot clock\n"); } -pci_pwrctrl_init (&slot->ctx, dev); +pci_pwrctrl_init (&slot->pwrctrl, dev); - ret =devm_pci_pwrctrl_device_set_ready (dev, &slot->ctx); + ret =devm_pci_pwrctrl_device_set_ready (dev, &slot->pwrctrl);if (ret)return dev_err_probe (dev, ret,"Failed to register pwrctrl driver\n" );
Signature · 1 line
2.48.1
Re: [PATCH v5 02/15] PCI/pwrctrl: slot: Rename private struct and pointers for consistency
Quoted 21 lines · On Thu, 15 Jan 2026 08:28:54 +0100, Manivannan Sadhasivam via B4 Relay…
From: Bjorn Helgaas <[email protected]>
Previously the pwrseq, tc9563, and slot pwrctrl drivers used different naming conventions for their private data structs and pointers to them, which makes patches hard to read:
Previous names New names ------------------------------------ ---------------------------------- struct pci_pwrctrl_pwrseq_data { struct pci_pwrctrl_pwrseq { struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl;struct
pci_pwrctrl_pwrseq_data*data structpci_pwrctrl_pwrseq*pwrseqstruct tc9563_pwrctrl_ctx { struct pci_pwrctrl_tc9563 { struct tc9563_pwrctrl_ctx *ctx struct pci_pwrctrl_tc9563 *tc9563 struct pci_pwrctrl_slot_data { struct pci_pwrctrl_slot { struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl; struct pci_pwrctrl_slot_data *slot struct pci_pwrctrl_slot *slotRename "struct
pci_pwrctrl_slot_data" to "structpci_pwrctrl_slot".
Quoted 7 lines
Rename the "struct
pci_pwrctrlctx" member to "structpci_pwrctrlpwrctrl".No functional change intended.
Signed-off-by Bjorn Helgaas <[email protected]>Signed-off-by Manivannan Sadhasivam <[email protected]>---
PATCH v5 3/15 PCI/pwrctrl: tc9563: Use put_device() instead of i2c_put_adapter()
In reply to Manivannan SadhasivamThe API comment for of_find_i2c_adapter_by_node() recommends using put_device() to drop the reference count of I2C adapter instead of using i2c_put_adapter(). So replace i2c_put_adapter() with put_device().
--- drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c +3 -3
@@ -533,7 +533,7 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev) ctx->client =i2c_new_dummy_device (ctx->adapter, addr);if (IS_ERR (ctx->client)) {dev_err (dev,"Failed to create I2C client\n" ); -i2c_put_adapter (ctx->adapter); +put_device (&ctx->adapter->dev);return PTR_ERR (ctx->client); }
@@ -613,7 +613,7 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)tc9563_pwrctrl_power_off (ctx); remove_i2c:i2c_unregister_device (ctx->client); -i2c_put_adapter (ctx->adapter); +put_device (&ctx->adapter->dev);return ret; }
@@ -623,7 +623,7 @@ static void tc9563_pwrctrl_remove(struct platform_device *pdev)tc9563_pwrctrl_power_off (ctx);i2c_unregister_device (ctx->client); -i2c_put_adapter (ctx->adapter); +put_device (&ctx->adapter->dev); }static const struct of_device_id tc9563_pwrctrl_of_match[] = {
Signature · 1 line
2.48.1
PATCH v5 4/15 PCI/pwrctrl: tc9563: Clean up whitespace
In reply to Manivannan SadhasivamFrom: Bjorn Helgaas <[email protected]>
Most of pci-pwrctrl-tc9563.c fits in 80 columns. Wrap lines that are gratuitously longer. Whitespace changes only.
--- drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c | 65 +++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 23 deletions(-)
drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c +42 -23
@@ -59,7 +59,7 @@#define TC9563_POWER_CONTROL_OVREN 0x82b2c8#define TC9563_GPIO_MASK 0xfffffff3 -#define TC9563_GPIO_DEASSERT_BITS 0xc/* Bits to clear for GPIO deassert */ +#define TC9563_GPIO_DEASSERT_BITS 0xc/* Clear to deassert GPIO */ #define TC9563_TX_MARGIN_MIN_UA 400000
@@ -69,7 +69,7 @@*/ #define TC9563_OSC_STAB_DELAY_US (10 * USEC_PER_MSEC) -#define TC9563_L0S_L1_DELAY_UNIT_NS 256/* Each unit represents 256 nanoseconds */ +#define TC9563_L0S_L1_DELAY_UNIT_NS 256/* Each unit represents 256 ns */ struct tc9563_pwrctrl_reg_setting {unsigned int offset;
@@ -217,7 +217,8 @@ static int tc9563_pwrctrl_i2c_read(struct i2c_client *client, }static int tc9563_pwrctrl_i2c_bulk_write (struct i2c_client *client, -const struct tc9563_pwrctrl_reg_setting *seq,int len) +const struct tc9563_pwrctrl_reg_setting *seq, +int len) {int ret, i;
@@ -252,12 +253,13 @@ static int tc9563_pwrctrl_disable_port(struct tc9563_pwrctrl_ctx *ctx,if (ret)return ret; -return tc9563_pwrctrl_i2c_bulk_write (ctx->client, - common_pwroff_seq,ARRAY_SIZE (common_pwroff_seq)); +return tc9563_pwrctrl_i2c_bulk_write (ctx->client, common_pwroff_seq, +ARRAY_SIZE (common_pwroff_seq)); }static int tc9563_pwrctrl_set_l0s_l1_entry_delay (struct tc9563_pwrctrl_ctx *ctx, -enum tc9563_pwrctrl_ports port,bool is_l1,u32 ns) +enum tc9563_pwrctrl_ports port, +bool is_l1,u32 ns) {u32 rd_val, units;int ret;
@@ -269,24 +271,32 @@ static int tc9563_pwrctrl_set_l0s_l1_entry_delay(struct tc9563_pwrctrl_ctx *ctx, units = ns /TC9563_L0S_L1_DELAY_UNIT_NS ;if (port ==TC9563_ETHERNET ) { - ret =tc9563_pwrctrl_i2c_read (ctx->client,TC9563_EMBEDDED_ETH_DELAY , &rd_val); + ret =tc9563_pwrctrl_i2c_read (ctx->client, +TC9563_EMBEDDED_ETH_DELAY , + &rd_val);if (ret)return ret;if (is_l1) - rd_val =u32_replace_bits (rd_val, units,TC9563_ETH_L1_DELAY_MASK ); + rd_val =u32_replace_bits (rd_val, units, +TC9563_ETH_L1_DELAY_MASK );else - rd_val =u32_replace_bits (rd_val, units,TC9563_ETH_L0S_DELAY_MASK ); + rd_val =u32_replace_bits (rd_val, units, +TC9563_ETH_L0S_DELAY_MASK ); -return tc9563_pwrctrl_i2c_write (ctx->client,TC9563_EMBEDDED_ETH_DELAY , rd_val); +return tc9563_pwrctrl_i2c_write (ctx->client, +TC9563_EMBEDDED_ETH_DELAY , + rd_val); } - ret =tc9563_pwrctrl_i2c_write (ctx->client,TC9563_PORT_SELECT ,BIT (port)); + ret =tc9563_pwrctrl_i2c_write (ctx->client,TC9563_PORT_SELECT , +BIT (port));if (ret)return ret;return tc9563_pwrctrl_i2c_write (ctx->client, - is_l1 ?TC9563_PORT_L1_DELAY :TC9563_PORT_L0S_DELAY , units); + is_l1 ?TC9563_PORT_L1_DELAY :TC9563_PORT_L0S_DELAY , + units); } static int tc9563_pwrctrl_set_tx_amplitude(struct tc9563_pwrctrl_ctx *ctx,
@@ -321,7 +331,8 @@ static int tc9563_pwrctrl_set_tx_amplitude(struct tc9563_pwrctrl_ctx *ctx, {TC9563_TX_MARGIN, amp}, }; -return tc9563_pwrctrl_i2c_bulk_write (ctx->client, tx_amp_seq,ARRAY_SIZE (tx_amp_seq)); +return tc9563_pwrctrl_i2c_bulk_write (ctx->client, tx_amp_seq, +ARRAY_SIZE (tx_amp_seq)); } static int tc9563_pwrctrl_disable_dfe(struct tc9563_pwrctrl_ctx *ctx,
@@ -364,8 +375,8 @@ static int tc9563_pwrctrl_disable_dfe(struct tc9563_pwrctrl_ctx *ctx, {TC9563_PHY_RATE_CHANGE_OVERRIDE, 0x0}, }; -return tc9563_pwrctrl_i2c_bulk_write (ctx->client, - disable_dfe_seq,ARRAY_SIZE (disable_dfe_seq)); +return tc9563_pwrctrl_i2c_bulk_write (ctx->client, disable_dfe_seq, +ARRAY_SIZE (disable_dfe_seq)); } static int tc9563_pwrctrl_set_nfts(struct tc9563_pwrctrl_ctx *ctx,
@@ -381,18 +392,22 @@ static int tc9563_pwrctrl_set_nfts(struct tc9563_pwrctrl_ctx *ctx,if (!nfts[0 ])return 0 ; - ret =tc9563_pwrctrl_i2c_write (ctx->client,TC9563_PORT_SELECT ,BIT (port)); + ret =tc9563_pwrctrl_i2c_write (ctx->client,TC9563_PORT_SELECT , +BIT (port));if (ret)return ret; -return tc9563_pwrctrl_i2c_bulk_write (ctx->client, nfts_seq,ARRAY_SIZE (nfts_seq)); +return tc9563_pwrctrl_i2c_bulk_write (ctx->client, nfts_seq, +ARRAY_SIZE (nfts_seq)); } -static int tc9563_pwrctrl_assert_deassert_reset (struct tc9563_pwrctrl_ctx *ctx,bool deassert) +static int tc9563_pwrctrl_assert_deassert_reset (struct tc9563_pwrctrl_ctx *ctx, +bool deassert) {int ret, val; - ret =tc9563_pwrctrl_i2c_write (ctx->client,TC9563_GPIO_CONFIG ,TC9563_GPIO_MASK ); + ret =tc9563_pwrctrl_i2c_write (ctx->client,TC9563_GPIO_CONFIG , +TC9563_GPIO_MASK );if (ret)return ret;
@@ -401,7 +416,8 @@ static int tc9563_pwrctrl_assert_deassert_reset(struct tc9563_pwrctrl_ctx *ctx,return tc9563_pwrctrl_i2c_write (ctx->client,TC9563_RESET_GPIO , val); } -static int tc9563_pwrctrl_parse_device_dt (struct tc9563_pwrctrl_ctx *ctx,struct device_node *node, +static int tc9563_pwrctrl_parse_device_dt (struct tc9563_pwrctrl_ctx *ctx, +struct device_node *node,enum tc9563_pwrctrl_ports port) {struct tc9563_pwrctrl_cfg *cfg = &ctx->cfg[port];
@@ -540,7 +556,8 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)for (int i =0 ; i <ARRAY_SIZE (tc9563_supply_names); i++) ctx->supplies[i].supply = tc9563_supply_names[i]; - ret =devm_regulator_bulk_get (dev,TC9563_PWRCTL_MAX_SUPPLY , ctx->supplies); + ret =devm_regulator_bulk_get (dev,TC9563_PWRCTL_MAX_SUPPLY , + ctx->supplies);if (ret) {dev_err_probe (dev, ret,"failed to get supply regulator\n" ); goto remove_i2c;
@@ -563,7 +580,8 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)/* * Downstream ports are always children of the upstream port. -* The first node represents DSP1, the second node represents DSP2, and so on. +* The first node represents DSP1, the second node represents DSP2, +* and so on. */ for_each_child_of_node_scoped (pdev->dev.of_node, child) { port++;
@@ -574,7 +592,8 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)if (port ==TC9563_DSP3 ) {for_each_child_of_node_scoped (child, child1) { port++; - ret =tc9563_pwrctrl_parse_device_dt (ctx, child1, port); + ret =tc9563_pwrctrl_parse_device_dt (ctx, + child1, port);if (ret)break ; }
Signature · 1 line
2.48.1
Re: [PATCH v5 04/15] PCI/pwrctrl: tc9563: Clean up whitespace
Quoted 8 lines · On Thu, 15 Jan 2026 08:28:56 +0100, Manivannan Sadhasivam via B4 Relay…
From: Bjorn Helgaas <[email protected]>
Most of
pci-pwrctrl-tc9563.cfits in 80 columns. Wrap lines that are gratuitously longer. Whitespace changes only.Signed-off-by Bjorn Helgaas <[email protected]>Signed-off-by Manivannan Sadhasivam <[email protected]>---
PATCH v5 5/15 PCI/pwrctrl: tc9563: Add local variables to reduce repetition
In reply to Manivannan SadhasivamFrom: Bjorn Helgaas <[email protected]>
Add local struct device * and struct device_node * variables to reduce repetitive pointer chasing. No functional changes intended.
--- drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c +12 -10
@@ -459,12 +459,13 @@ static void tc9563_pwrctrl_power_off(struct tc9563_pwrctrl_ctx *ctx)static int tc9563_pwrctrl_bring_up (struct tc9563_pwrctrl_ctx *ctx) { +struct device *dev = ctx->pwrctrl.dev;struct tc9563_pwrctrl_cfg *cfg;int ret, i; ret =regulator_bulk_enable (ARRAY_SIZE (ctx->supplies), ctx->supplies);if (ret <0 ) -return dev_err_probe (ctx->pwrctrl.dev, ret,"cannot enable regulators\n" ); +return dev_err_probe (dev, ret,"cannot enable regulators\n" );gpiod_set_value (ctx->reset_gpio,0 );
@@ -478,37 +479,37 @@ static int tc9563_pwrctrl_bring_up(struct tc9563_pwrctrl_ctx *ctx) cfg = &ctx->cfg[i]; ret =tc9563_pwrctrl_disable_port (ctx, i);if (ret) { -dev_err (ctx->pwrctrl.dev,"Disabling port failed\n" ); +dev_err (dev,"Disabling port failed\n" ); goto power_off; } ret =tc9563_pwrctrl_set_l0s_l1_entry_delay (ctx, i, false, cfg->l0s_delay);if (ret) { -dev_err (ctx->pwrctrl.dev,"Setting L0s entry delay failed\n" ); +dev_err (dev,"Setting L0s entry delay failed\n" ); goto power_off; } ret =tc9563_pwrctrl_set_l0s_l1_entry_delay (ctx, i, true, cfg->l1_delay);if (ret) { -dev_err (ctx->pwrctrl.dev,"Setting L1 entry delay failed\n" ); +dev_err (dev,"Setting L1 entry delay failed\n" ); goto power_off; } ret =tc9563_pwrctrl_set_tx_amplitude (ctx, i);if (ret) { -dev_err (ctx->pwrctrl.dev,"Setting Tx amplitude failed\n" ); +dev_err (dev,"Setting Tx amplitude failed\n" ); goto power_off; } ret =tc9563_pwrctrl_set_nfts (ctx, i);if (ret) { -dev_err (ctx->pwrctrl.dev,"Setting N_FTS failed\n" ); +dev_err (dev,"Setting N_FTS failed\n" ); goto power_off; } ret =tc9563_pwrctrl_disable_dfe (ctx, i);if (ret) { -dev_err (ctx->pwrctrl.dev,"Disabling DFE failed\n" ); +dev_err (dev,"Disabling DFE failed\n" ); goto power_off; } }
@@ -525,6 +526,7 @@ static int tc9563_pwrctrl_bring_up(struct tc9563_pwrctrl_ctx *ctx)static int tc9563_pwrctrl_probe (struct platform_device *pdev) {struct pci_host_bridge *bridge =to_pci_host_bridge (pdev->dev.parent); +struct device_node *node = pdev->dev.of_node;struct pci_bus *bus = bridge->bus;struct device *dev = &pdev->dev;enum tc9563_pwrctrl_ports port;
@@ -536,7 +538,7 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)if (!ctx)return -ENOMEM ; - ret =of_property_read_u32_index (pdev->dev.of_node,"i2c-parent" ,1 , &addr); + ret =of_property_read_u32_index (node,"i2c-parent" ,1 , &addr);if (ret)return dev_err_probe (dev, ret,"Failed to read i2c-parent property\n" );
@@ -572,7 +574,7 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)pci_pwrctrl_init (&ctx->pwrctrl, dev); port =TC9563_USP ; - ret =tc9563_pwrctrl_parse_device_dt (ctx, pdev->dev.of_node, port); + ret =tc9563_pwrctrl_parse_device_dt (ctx, node, port);if (ret) {dev_err (dev,"failed to parse device tree properties: %d\n" , ret); goto remove_i2c;
@@ -583,7 +585,7 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)* The first node represents DSP1, the second node represents DSP2, * and so on. */ -for_each_child_of_node_scoped (pdev->dev.of_node, child) { +for_each_child_of_node_scoped (node, child) { port++; ret =tc9563_pwrctrl_parse_device_dt (ctx, child, port);if (ret)
Signature · 1 line
2.48.1
Re: [PATCH v5 05/15] PCI/pwrctrl: tc9563: Add local variables to reduce repetition
Quoted 8 lines · On Thu, 15 Jan 2026 08:28:57 +0100, Manivannan Sadhasivam via B4 Relay…
From: Bjorn Helgaas <[email protected]>
Add local struct device * and struct
device_node* variables to reduce repetitive pointer chasing. No functional changes intended.Signed-off-by Bjorn Helgaas <[email protected]>Signed-off-by Manivannan Sadhasivam <[email protected]>---
PATCH v5 6/15 PCI/pwrctrl: tc9563: Rename private struct and pointers for consistency
In reply to Manivannan SadhasivamFrom: Bjorn Helgaas <[email protected]>
Previously the pwrseq, tc9563, and slot pwrctrl drivers used different naming conventions for their private data structs and pointers to them, which makes patches hard to read:
Previous names New names
------------------------------------ ----------------------------------
struct pci_pwrctrl_pwrseq_data { struct pci_pwrctrl_pwrseq {
struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl; struct pci_pwrctrl_pwrseq_data *data struct pci_pwrctrl_pwrseq *pwrseq
struct tc9563_pwrctrl_ctx { struct pci_pwrctrl_tc9563 {
struct tc9563_pwrctrl_ctx *ctx struct pci_pwrctrl_tc9563 *tc9563
struct pci_pwrctrl_slot_data { struct pci_pwrctrl_slot {
struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl;
struct pci_pwrctrl_slot_data *slot struct pci_pwrctrl_slot *slotRename "struct tc9563_pwrctrl_ctx" to "pci_pwrctrl_tc9563".
Move the struct pci_pwrctrl member to be the first element in struct pci_pwrctrl_tc9563, as it is in the other drivers.
Rename pointers from "struct tc9563_pwrctrl_ctx *ctx" to "struct pci_pwrctrl_tc9563 *tc9563".
No functional change intended.
--- drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c | 143 ++++++++++++++++--------------- 1 file changed, 72 insertions(+), 71 deletions(-)
drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c +72 -71
@@ -105,13 +105,13 @@ static const char *const tc9563_supply_names[TC9563_PWRCTL_MAX_SUPPLY] = { "vddio18", }; -struct tc9563_pwrctrl_ctx { +struct pci_pwrctrl_tc9563 { +struct pci_pwrctrl pwrctrl;struct regulator_bulk_data supplies[TC9563_PWRCTL_MAX_SUPPLY ];struct tc9563_pwrctrl_cfg cfg[TC9563_MAX ];struct gpio_desc *reset_gpio;struct i2c_adapter *adapter;struct i2c_client *client; -struct pci_pwrctrl pwrctrl; };/*
@@ -231,10 +231,10 @@ static int tc9563_pwrctrl_i2c_bulk_write(struct i2c_client *client,return 0 ; } -static int tc9563_pwrctrl_disable_port (struct tc9563_pwrctrl_ctx *ctx, +static int tc9563_pwrctrl_disable_port (struct pci_pwrctrl_tc9563 *tc9563,enum tc9563_pwrctrl_ports port) { -struct tc9563_pwrctrl_cfg *cfg = &ctx->cfg[port]; +struct tc9563_pwrctrl_cfg *cfg = &tc9563->cfg[port];const struct tc9563_pwrctrl_reg_setting *seq;int ret, len;
@@ -249,15 +249,15 @@ static int tc9563_pwrctrl_disable_port(struct tc9563_pwrctrl_ctx *ctx, len =ARRAY_SIZE (dsp2_pwroff_seq); } - ret =tc9563_pwrctrl_i2c_bulk_write (ctx->client, seq, len); + ret =tc9563_pwrctrl_i2c_bulk_write (tc9563->client, seq, len);if (ret)return ret; -return tc9563_pwrctrl_i2c_bulk_write (ctx->client, common_pwroff_seq, +return tc9563_pwrctrl_i2c_bulk_write (tc9563->client, common_pwroff_seq,ARRAY_SIZE (common_pwroff_seq)); } -static int tc9563_pwrctrl_set_l0s_l1_entry_delay (struct tc9563_pwrctrl_ctx *ctx, +static int tc9563_pwrctrl_set_l0s_l1_entry_delay (struct pci_pwrctrl_tc9563 *tc9563,enum tc9563_pwrctrl_ports port,bool is_l1,u32 ns) {
@@ -271,7 +271,7 @@ static int tc9563_pwrctrl_set_l0s_l1_entry_delay(struct tc9563_pwrctrl_ctx *ctx, units = ns /TC9563_L0S_L1_DELAY_UNIT_NS ;if (port ==TC9563_ETHERNET ) { - ret =tc9563_pwrctrl_i2c_read (ctx->client, + ret =tc9563_pwrctrl_i2c_read (tc9563->client,TC9563_EMBEDDED_ETH_DELAY , &rd_val);if (ret)
@@ -284,25 +284,25 @@ static int tc9563_pwrctrl_set_l0s_l1_entry_delay(struct tc9563_pwrctrl_ctx *ctx, rd_val =u32_replace_bits (rd_val, units,TC9563_ETH_L0S_DELAY_MASK ); -return tc9563_pwrctrl_i2c_write (ctx->client, +return tc9563_pwrctrl_i2c_write (tc9563->client,TC9563_EMBEDDED_ETH_DELAY , rd_val); } - ret =tc9563_pwrctrl_i2c_write (ctx->client,TC9563_PORT_SELECT , + ret =tc9563_pwrctrl_i2c_write (tc9563->client,TC9563_PORT_SELECT ,BIT (port));if (ret)return ret; -return tc9563_pwrctrl_i2c_write (ctx->client, +return tc9563_pwrctrl_i2c_write (tc9563->client, is_l1 ?TC9563_PORT_L1_DELAY :TC9563_PORT_L0S_DELAY , units); } -static int tc9563_pwrctrl_set_tx_amplitude (struct tc9563_pwrctrl_ctx *ctx, +static int tc9563_pwrctrl_set_tx_amplitude (struct pci_pwrctrl_tc9563 *tc9563,enum tc9563_pwrctrl_ports port) { -u32 amp = ctx->cfg[port].tx_amp; +u32 amp = tc9563->cfg[port].tx_amp;int port_access;if (amp <TC9563_TX_MARGIN_MIN_UA )
@@ -331,14 +331,14 @@ static int tc9563_pwrctrl_set_tx_amplitude(struct tc9563_pwrctrl_ctx *ctx, {TC9563_TX_MARGIN, amp}, }; -return tc9563_pwrctrl_i2c_bulk_write (ctx->client, tx_amp_seq, +return tc9563_pwrctrl_i2c_bulk_write (tc9563->client, tx_amp_seq,ARRAY_SIZE (tx_amp_seq)); } -static int tc9563_pwrctrl_disable_dfe (struct tc9563_pwrctrl_ctx *ctx, +static int tc9563_pwrctrl_disable_dfe (struct pci_pwrctrl_tc9563 *tc9563,enum tc9563_pwrctrl_ports port) { -struct tc9563_pwrctrl_cfg *cfg = &ctx->cfg[port]; +struct tc9563_pwrctrl_cfg *cfg = &tc9563->cfg[port];int port_access, lane_access =0x3 ;u32 phy_rate =0x21 ;
@@ -375,14 +375,14 @@ static int tc9563_pwrctrl_disable_dfe(struct tc9563_pwrctrl_ctx *ctx, {TC9563_PHY_RATE_CHANGE_OVERRIDE, 0x0}, }; -return tc9563_pwrctrl_i2c_bulk_write (ctx->client, disable_dfe_seq, +return tc9563_pwrctrl_i2c_bulk_write (tc9563->client, disable_dfe_seq,ARRAY_SIZE (disable_dfe_seq)); } -static int tc9563_pwrctrl_set_nfts (struct tc9563_pwrctrl_ctx *ctx, +static int tc9563_pwrctrl_set_nfts (struct pci_pwrctrl_tc9563 *tc9563,enum tc9563_pwrctrl_ports port) { -u8 *nfts = ctx->cfg[port].nfts; +u8 *nfts = tc9563->cfg[port].nfts;struct tc9563_pwrctrl_reg_setting nfts_seq[] = { {TC9563_NFTS_2_5_GT , nfts[0 ]}, {TC9563_NFTS_5_GT , nfts[1 ]},
@@ -392,35 +392,35 @@ static int tc9563_pwrctrl_set_nfts(struct tc9563_pwrctrl_ctx *ctx,if (!nfts[0 ])return 0 ; - ret =tc9563_pwrctrl_i2c_write (ctx->client,TC9563_PORT_SELECT , + ret =tc9563_pwrctrl_i2c_write (tc9563->client,TC9563_PORT_SELECT ,BIT (port));if (ret)return ret; -return tc9563_pwrctrl_i2c_bulk_write (ctx->client, nfts_seq, +return tc9563_pwrctrl_i2c_bulk_write (tc9563->client, nfts_seq,ARRAY_SIZE (nfts_seq)); } -static int tc9563_pwrctrl_assert_deassert_reset (struct tc9563_pwrctrl_ctx *ctx, +static int tc9563_pwrctrl_assert_deassert_reset (struct pci_pwrctrl_tc9563 *tc9563,bool deassert) {int ret, val; - ret =tc9563_pwrctrl_i2c_write (ctx->client,TC9563_GPIO_CONFIG , + ret =tc9563_pwrctrl_i2c_write (tc9563->client,TC9563_GPIO_CONFIG ,TC9563_GPIO_MASK );if (ret)return ret; val = deassert ?TC9563_GPIO_DEASSERT_BITS :0 ; -return tc9563_pwrctrl_i2c_write (ctx->client,TC9563_RESET_GPIO , val); +return tc9563_pwrctrl_i2c_write (tc9563->client,TC9563_RESET_GPIO , val); } -static int tc9563_pwrctrl_parse_device_dt (struct tc9563_pwrctrl_ctx *ctx, +static int tc9563_pwrctrl_parse_device_dt (struct pci_pwrctrl_tc9563 *tc9563,struct device_node *node,enum tc9563_pwrctrl_ports port) { -struct tc9563_pwrctrl_cfg *cfg = &ctx->cfg[port]; +struct tc9563_pwrctrl_cfg *cfg = &tc9563->cfg[port];int ret;/* Disable port if the status of the port is disabled. */
@@ -450,76 +450,77 @@ static int tc9563_pwrctrl_parse_device_dt(struct tc9563_pwrctrl_ctx *ctx,return 0 ; } -static void tc9563_pwrctrl_power_off (struct tc9563_pwrctrl_ctx *ctx) +static void tc9563_pwrctrl_power_off (struct pci_pwrctrl_tc9563 *tc9563) { -gpiod_set_value (ctx->reset_gpio,1 ); +gpiod_set_value (tc9563->reset_gpio,1 ); -regulator_bulk_disable (ARRAY_SIZE (ctx->supplies), ctx->supplies); +regulator_bulk_disable (ARRAY_SIZE (tc9563->supplies), tc9563->supplies); } -static int tc9563_pwrctrl_bring_up (struct tc9563_pwrctrl_ctx *ctx) +static int tc9563_pwrctrl_bring_up (struct pci_pwrctrl_tc9563 *tc9563) { -struct device *dev = ctx->pwrctrl.dev; +struct device *dev = tc9563->pwrctrl.dev;struct tc9563_pwrctrl_cfg *cfg;int ret, i; - ret =regulator_bulk_enable (ARRAY_SIZE (ctx->supplies), ctx->supplies); + ret =regulator_bulk_enable (ARRAY_SIZE (tc9563->supplies), + tc9563->supplies);if (ret <0 )return dev_err_probe (dev, ret,"cannot enable regulators\n" ); -gpiod_set_value (ctx->reset_gpio,0 ); +gpiod_set_value (tc9563->reset_gpio,0 );fsleep (TC9563_OSC_STAB_DELAY_US ); - ret =tc9563_pwrctrl_assert_deassert_reset (ctx, false); + ret =tc9563_pwrctrl_assert_deassert_reset (tc9563, false);if (ret) goto power_off;for (i =0 ; i <TC9563_MAX ; i++) { - cfg = &ctx->cfg[i]; - ret =tc9563_pwrctrl_disable_port (ctx, i); + cfg = &tc9563->cfg[i]; + ret =tc9563_pwrctrl_disable_port (tc9563, i);if (ret) {dev_err (dev,"Disabling port failed\n" ); goto power_off; } - ret =tc9563_pwrctrl_set_l0s_l1_entry_delay (ctx, i, false, cfg->l0s_delay); + ret =tc9563_pwrctrl_set_l0s_l1_entry_delay (tc9563, i, false, cfg->l0s_delay);if (ret) {dev_err (dev,"Setting L0s entry delay failed\n" ); goto power_off; } - ret =tc9563_pwrctrl_set_l0s_l1_entry_delay (ctx, i, true, cfg->l1_delay); + ret =tc9563_pwrctrl_set_l0s_l1_entry_delay (tc9563, i, true, cfg->l1_delay);if (ret) {dev_err (dev,"Setting L1 entry delay failed\n" ); goto power_off; } - ret =tc9563_pwrctrl_set_tx_amplitude (ctx, i); + ret =tc9563_pwrctrl_set_tx_amplitude (tc9563, i);if (ret) {dev_err (dev,"Setting Tx amplitude failed\n" ); goto power_off; } - ret =tc9563_pwrctrl_set_nfts (ctx, i); + ret =tc9563_pwrctrl_set_nfts (tc9563, i);if (ret) {dev_err (dev,"Setting N_FTS failed\n" ); goto power_off; } - ret =tc9563_pwrctrl_disable_dfe (ctx, i); + ret =tc9563_pwrctrl_disable_dfe (tc9563, i);if (ret) {dev_err (dev,"Disabling DFE failed\n" ); goto power_off; } } - ret =tc9563_pwrctrl_assert_deassert_reset (ctx, true); + ret =tc9563_pwrctrl_assert_deassert_reset (tc9563, true);if (!ret)return 0 ; power_off: -tc9563_pwrctrl_power_off (ctx); +tc9563_pwrctrl_power_off (tc9563);return ret; }
@@ -530,12 +531,12 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)struct pci_bus *bus = bridge->bus;struct device *dev = &pdev->dev;enum tc9563_pwrctrl_ports port; -struct tc9563_pwrctrl_ctx *ctx; +struct pci_pwrctrl_tc9563 *tc9563;struct device_node *i2c_node;int ret, addr; - ctx =devm_kzalloc (dev,sizeof (*ctx),GFP_KERNEL ); -if (!ctx) + tc9563 =devm_kzalloc (dev,sizeof (*tc9563),GFP_KERNEL ); +if (!tc9563)return -ENOMEM ; ret =of_property_read_u32_index (node,"i2c-parent" ,1 , &addr);
@@ -543,38 +544,38 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)return dev_err_probe (dev, ret,"Failed to read i2c-parent property\n" ); i2c_node =of_parse_phandle (dev->of_node,"i2c-parent" ,0 ); - ctx->adapter =of_find_i2c_adapter_by_node (i2c_node); + tc9563->adapter =of_find_i2c_adapter_by_node (i2c_node);of_node_put (i2c_node); -if (!ctx->adapter) +if (!tc9563->adapter)return dev_err_probe (dev, -EPROBE_DEFER ,"Failed to find I2C adapter\n" ); - ctx->client =i2c_new_dummy_device (ctx->adapter, addr); -if (IS_ERR (ctx->client)) { + tc9563->client =i2c_new_dummy_device (tc9563->adapter, addr); +if (IS_ERR (tc9563->client)) {dev_err (dev,"Failed to create I2C client\n" ); -put_device (&ctx->adapter->dev); -return PTR_ERR (ctx->client); +put_device (&tc9563->adapter->dev); +return PTR_ERR (tc9563->client); }for (int i =0 ; i <ARRAY_SIZE (tc9563_supply_names); i++) - ctx->supplies[i].supply = tc9563_supply_names[i]; + tc9563->supplies[i].supply = tc9563_supply_names[i]; ret =devm_regulator_bulk_get (dev,TC9563_PWRCTL_MAX_SUPPLY , - ctx->supplies); + tc9563->supplies);if (ret) {dev_err_probe (dev, ret,"failed to get supply regulator\n" ); goto remove_i2c; } - ctx->reset_gpio =devm_gpiod_get (dev,"resx" ,GPIOD_OUT_HIGH ); -if (IS_ERR (ctx->reset_gpio)) { - ret =dev_err_probe (dev,PTR_ERR (ctx->reset_gpio),"failed to get resx GPIO\n" ); + tc9563->reset_gpio =devm_gpiod_get (dev,"resx" ,GPIOD_OUT_HIGH ); +if (IS_ERR (tc9563->reset_gpio)) { + ret =dev_err_probe (dev,PTR_ERR (tc9563->reset_gpio),"failed to get resx GPIO\n" ); goto remove_i2c; } -pci_pwrctrl_init (&ctx->pwrctrl, dev); +pci_pwrctrl_init (&tc9563->pwrctrl, dev); port =TC9563_USP ; - ret =tc9563_pwrctrl_parse_device_dt (ctx, node, port); + ret =tc9563_pwrctrl_parse_device_dt (tc9563, node, port);if (ret) {dev_err (dev,"failed to parse device tree properties: %d\n" , ret); goto remove_i2c;
@@ -587,14 +588,14 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)*/ for_each_child_of_node_scoped (node, child) { port++; - ret =tc9563_pwrctrl_parse_device_dt (ctx, child, port); + ret =tc9563_pwrctrl_parse_device_dt (tc9563, child, port);if (ret)break ;/* Embedded ethernet device are under DSP3 */ if (port ==TC9563_DSP3 ) {for_each_child_of_node_scoped (child, child1) { port++; - ret =tc9563_pwrctrl_parse_device_dt (ctx, + ret =tc9563_pwrctrl_parse_device_dt (tc9563, child1, port);if (ret)break ;
@@ -612,7 +613,7 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev) goto remove_i2c; } - ret =tc9563_pwrctrl_bring_up (ctx); + ret =tc9563_pwrctrl_bring_up (tc9563);if (ret) goto remove_i2c;
@@ -622,29 +623,29 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev) goto power_off; } - ret =devm_pci_pwrctrl_device_set_ready (dev, &ctx->pwrctrl); + ret =devm_pci_pwrctrl_device_set_ready (dev, &tc9563->pwrctrl);if (ret) goto power_off; -platform_set_drvdata (pdev, ctx); +platform_set_drvdata (pdev, tc9563);return 0 ; power_off: -tc9563_pwrctrl_power_off (ctx); +tc9563_pwrctrl_power_off (tc9563); remove_i2c: -i2c_unregister_device (ctx->client); -put_device (&ctx->adapter->dev); +i2c_unregister_device (tc9563->client); +put_device (&tc9563->adapter->dev);return ret; }static void tc9563_pwrctrl_remove (struct platform_device *pdev) { -struct tc9563_pwrctrl_ctx *ctx =platform_get_drvdata (pdev); +struct pci_pwrctrl_tc9563 *tc9563 =platform_get_drvdata (pdev); -tc9563_pwrctrl_power_off (ctx); -i2c_unregister_device (ctx->client); -put_device (&ctx->adapter->dev); +tc9563_pwrctrl_power_off (tc9563); +i2c_unregister_device (tc9563->client); +put_device (&tc9563->adapter->dev); }static const struct of_device_id tc9563_pwrctrl_of_match[] = {
Signature · 1 line
2.48.1
Re: [PATCH v5 06/15] PCI/pwrctrl: tc9563: Rename private struct and pointers for consistency
Quoted 24 lines · On Thu, 15 Jan 2026 08:28:58 +0100, Manivannan Sadhasivam via B4 Relay…
From: Bjorn Helgaas <[email protected]>
Previously the pwrseq, tc9563, and slot pwrctrl drivers used different naming conventions for their private data structs and pointers to them, which makes patches hard to read:
Previous names New names ------------------------------------ ---------------------------------- struct pci_pwrctrl_pwrseq_data { struct pci_pwrctrl_pwrseq { struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl;struct
pci_pwrctrl_pwrseq_data*data structpci_pwrctrl_pwrseq*pwrseqstruct tc9563_pwrctrl_ctx { struct pci_pwrctrl_tc9563 { struct tc9563_pwrctrl_ctx *ctx struct pci_pwrctrl_tc9563 *tc9563 struct pci_pwrctrl_slot_data { struct pci_pwrctrl_slot { struct pci_pwrctrl ctx; struct pci_pwrctrl pwrctrl; struct pci_pwrctrl_slot_data *slot struct pci_pwrctrl_slot *slotRename "struct
tc9563_pwrctrl_ctx" to "pci_pwrctrl_tc9563".Move the struct
pci_pwrctrlmember to be the first element in structpci_pwrctrl_tc9563, as it is in the other drivers.
Quoted 8 lines
Rename pointers from "struct
tc9563_pwrctrl_ctx*ctx" to "structpci_pwrctrl_tc9563*tc9563".No functional change intended.
Signed-off-by Bjorn Helgaas <[email protected]>Signed-off-by Manivannan Sadhasivam <[email protected]>---
Makes sense, thanks!
PATCH v5 7/15 PCI/pwrctrl: slot: Factor out power on/off code to helpers
In reply to Manivannan SadhasivamIn order to allow the pwrctrl core to control the power on/off logic of the pwrctrl slot driver, move the power on/off code to pci_pwrctrl_slot_power_{off/on} helper functions.
--- drivers/pci/pwrctrl/slot.c | 49 +++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-)
drivers/pci/pwrctrl/slot.c +35 -14
@@ -17,13 +17,40 @@ struct pci_pwrctrl_slot {struct pci_pwrctrl pwrctrl;struct regulator_bulk_data *supplies;int num_supplies; +struct clk *clk; }; -static void devm_pci_pwrctrl_slot_power_off (void *data) +static int pci_pwrctrl_slot_power_on (struct pci_pwrctrl *pwrctrl) { -struct pci_pwrctrl_slot *slot = data; +struct pci_pwrctrl_slot *slot =container_of (pwrctrl, + struct pci_pwrctrl_slot, pwrctrl); +int ret; + + ret =regulator_bulk_enable (slot->num_supplies, slot->supplies); +if (ret <0 ) { +dev_err (slot->pwrctrl.dev,"Failed to enable slot regulators\n" ); +return ret; + } + +return clk_prepare_enable (slot->clk); +} + +static int pci_pwrctrl_slot_power_off (struct pci_pwrctrl *pwrctrl) +{ +struct pci_pwrctrl_slot *slot =container_of (pwrctrl, + struct pci_pwrctrl_slot, pwrctrl);regulator_bulk_disable (slot->num_supplies, slot->supplies); +clk_disable_unprepare (slot->clk); + +return 0 ; +} + +static void devm_pci_pwrctrl_slot_release (void *data) +{ +struct pci_pwrctrl_slot *slot = data; + +pci_pwrctrl_slot_power_off (&slot->pwrctrl);regulator_bulk_free (slot->num_supplies, slot->supplies); }
@@ -31,7 +58,6 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev) {struct pci_pwrctrl_slot *slot;struct device *dev = &pdev->dev; -struct clk *clk;int ret; slot =devm_kzalloc (dev,sizeof (*slot),GFP_KERNEL );
@@ -46,23 +72,18 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev) } slot->num_supplies = ret; - ret =regulator_bulk_enable (slot->num_supplies, slot->supplies); -if (ret <0 ) { -dev_err_probe (dev, ret,"Failed to enable slot regulators\n" ); -regulator_bulk_free (slot->num_supplies, slot->supplies); -return ret; - } - ret =devm_add_action_or_reset (dev, devm_pci_pwrctrl_slot_power_off, + ret =devm_add_action_or_reset (dev, devm_pci_pwrctrl_slot_release, slot);if (ret)return ret; - clk =devm_clk_get_optional_enabled (dev,NULL ); -if (IS_ERR (clk)) { -return dev_err_probe (dev,PTR_ERR (clk), + slot->clk =devm_clk_get_optional (dev,NULL ); +if (IS_ERR (slot->clk)) +return dev_err_probe (dev,PTR_ERR (slot->clk),"Failed to enable slot clock\n" ); - } + +pci_pwrctrl_slot_power_on (&slot->pwrctrl);pci_pwrctrl_init (&slot->pwrctrl, dev);
Signature · 1 line
2.48.1
Re: [PATCH v5 07/15] PCI/pwrctrl: slot: Factor out power on/off code to helpers
Quoted 8 lines · On Thu, 15 Jan 2026 08:28:59 +0100, Manivannan Sadhasivam via B4 Relay…
From: Manivannan Sadhasivam <[email protected]>
In order to allow the pwrctrl core to control the power on/off logic of the pwrctrl slot driver, move the power on/off code to pci_pwrctrl_slot_power_{off/on} helper functions.
Signed-off-by Manivannan Sadhasivam <[email protected]>---
PATCH v5 8/15 PCI/pwrctrl: pwrseq: Factor out power on/off code to helpers
In reply to Manivannan SadhasivamIn order to allow the pwrctrl core to control the power on/off logic of the pwrctrl pwrseq driver, move the power on/off code to pci_pwrctrl_pwrseq_power_{off/on} helper functions.
--- drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c +20 -4
@@ -52,11 +52,27 @@ static const struct pci_pwrctrl_pwrseq_pdata pci_pwrctrl_pwrseq_qcom_wcn_pdata = .validate_device = pci_pwrctrl_pwrseq_qcm_wcn_validate_device, }; +static int pci_pwrctrl_pwrseq_power_on (struct pci_pwrctrl *pwrctrl) +{ +struct pci_pwrctrl_pwrseq *pwrseq =container_of (pwrctrl, + struct pci_pwrctrl_pwrseq, pwrctrl); + +return pwrseq_power_on (pwrseq->pwrseq); +} + +static int pci_pwrctrl_pwrseq_power_off (struct pci_pwrctrl *pwrctrl) +{ +struct pci_pwrctrl_pwrseq *pwrseq =container_of (pwrctrl, + struct pci_pwrctrl_pwrseq, pwrctrl); + +return pwrseq_power_off (pwrseq->pwrseq); +} +static void devm_pci_pwrctrl_pwrseq_power_off (void *data) { -struct pwrseq_desc *pwrseq = data; +struct pci_pwrctrl_pwrseq *pwrseq = data; -pwrseq_power_off (pwrseq); +pci_pwrctrl_pwrseq_power_off (&pwrseq->pwrctrl); }static int pci_pwrctrl_pwrseq_probe (struct platform_device *pdev)
@@ -85,13 +101,13 @@ static int pci_pwrctrl_pwrseq_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (pwrseq->pwrseq),"Failed to get the power sequencer\n" ); - ret =pwrseq_power_on (pwrseq->pwrseq); + ret =pci_pwrctrl_pwrseq_power_on (&pwrseq->pwrctrl);if (ret)return dev_err_probe (dev, ret,"Failed to power-on the device\n" ); ret =devm_add_action_or_reset (dev, devm_pci_pwrctrl_pwrseq_power_off, - pwrseq->pwrseq); + pwrseq);if (ret)return ret;
Signature · 1 line
2.48.1
Re: [PATCH v5 08/15] PCI/pwrctrl: pwrseq: Factor out power on/off code to helpers
Quoted 8 lines · On Thu, 15 Jan 2026 08:29:00 +0100, Manivannan Sadhasivam via B4 Relay…
From: Manivannan Sadhasivam <[email protected]>
In order to allow the pwrctrl core to control the power on/off logic of the pwrctrl pwrseq driver, move the power on/off code to pci_pwrctrl_pwrseq_power_{off/on} helper functions.
Signed-off-by Manivannan Sadhasivam <[email protected]>---
PATCH v5 9/15 PCI/pwrctrl: Add 'struct pci_pwrctrl::power_{on/off}' callbacks
In reply to Manivannan SadhasivamTo allow the pwrctrl core to control the power on/off sequences of the pwrctrl drivers, add the 'struct pci_pwrctrl::power_{on/off}' callbacks and populate them in the respective pwrctrl drivers.
The pwrctrl drivers still power on the resources on their own now. So there is no functional change.
--- drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c | 3 +++ drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c | 22 ++++++++++++++++------ drivers/pci/pwrctrl/slot.c | 3 +++ include/linux/pci-pwrctrl.h | 4 ++++ 4 files changed, 26 insertions(+), 6 deletions(-)
drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c +3 -0
@@ -111,6 +111,9 @@ static int pci_pwrctrl_pwrseq_probe(struct platform_device *pdev)if (ret)return ret; + pwrseq->pwrctrl.power_on = pci_pwrctrl_pwrseq_power_on; + pwrseq->pwrctrl.power_off = pci_pwrctrl_pwrseq_power_off; +pci_pwrctrl_init (&pwrseq->pwrctrl, dev); ret =devm_pci_pwrctrl_device_set_ready (dev, &pwrseq->pwrctrl);
drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c +16 -6
@@ -450,15 +450,22 @@ static int tc9563_pwrctrl_parse_device_dt(struct pci_pwrctrl_tc9563 *tc9563,return 0 ; } -static void tc9563_pwrctrl_power_off (struct pci_pwrctrl_tc9563 *tc9563) +static int tc9563_pwrctrl_power_off (struct pci_pwrctrl *pwrctrl) { +struct pci_pwrctrl_tc9563 *tc9563 =container_of (pwrctrl, + struct pci_pwrctrl_tc9563, pwrctrl); +gpiod_set_value (tc9563->reset_gpio,1 );regulator_bulk_disable (ARRAY_SIZE (tc9563->supplies), tc9563->supplies); + +return 0 ; } -static int tc9563_pwrctrl_bring_up (struct pci_pwrctrl_tc9563 *tc9563) +static int tc9563_pwrctrl_power_on (struct pci_pwrctrl *pwrctrl) { +struct pci_pwrctrl_tc9563 *tc9563 =container_of (pwrctrl, + struct pci_pwrctrl_tc9563, pwrctrl);struct device *dev = tc9563->pwrctrl.dev;struct tc9563_pwrctrl_cfg *cfg;int ret, i;
@@ -520,7 +527,7 @@ static int tc9563_pwrctrl_bring_up(struct pci_pwrctrl_tc9563 *tc9563)return 0 ; power_off: -tc9563_pwrctrl_power_off (tc9563); +tc9563_pwrctrl_power_off (&tc9563->pwrctrl);return ret; }
@@ -613,7 +620,7 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev) goto remove_i2c; } - ret =tc9563_pwrctrl_bring_up (tc9563); + ret =tc9563_pwrctrl_power_on (&tc9563->pwrctrl);if (ret) goto remove_i2c;
@@ -623,6 +630,9 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev) goto power_off; } + tc9563->pwrctrl.power_on = tc9563_pwrctrl_power_on; + tc9563->pwrctrl.power_off = tc9563_pwrctrl_power_off; + ret =devm_pci_pwrctrl_device_set_ready (dev, &tc9563->pwrctrl);if (ret) goto power_off;
@@ -632,7 +642,7 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)return 0 ; power_off: -tc9563_pwrctrl_power_off (tc9563); +tc9563_pwrctrl_power_off (&tc9563->pwrctrl); remove_i2c:i2c_unregister_device (tc9563->client);put_device (&tc9563->adapter->dev);
@@ -643,7 +653,7 @@ static void tc9563_pwrctrl_remove(struct platform_device *pdev) {struct pci_pwrctrl_tc9563 *tc9563 =platform_get_drvdata (pdev); -tc9563_pwrctrl_power_off (tc9563); +tc9563_pwrctrl_power_off (&tc9563->pwrctrl);i2c_unregister_device (tc9563->client);put_device (&tc9563->adapter->dev); }
drivers/pci/pwrctrl/slot.c +3 -0
@@ -85,6 +85,9 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev)pci_pwrctrl_slot_power_on (&slot->pwrctrl); + slot->pwrctrl.power_on = pci_pwrctrl_slot_power_on; + slot->pwrctrl.power_off = pci_pwrctrl_slot_power_off; +pci_pwrctrl_init (&slot->pwrctrl, dev); ret =devm_pci_pwrctrl_device_set_ready (dev, &slot->pwrctrl);
include/linux/pci-pwrctrl.h +4 -0
@@ -31,6 +31,8 @@ struct device_link;/** * struct pci_pwrctrl - PCI device power control context. * @dev: Address of the power controlling device. +* @power_on: Callback to power on the power controlling device. +* @power_off: Callback to power off the power controlling device. * * An object of this type must be allocated by the PCI power control device and * passed to the pwrctrl subsystem to trigger a bus rescan and setup a device
@@ -38,6 +40,8 @@ struct device_link;*/ struct pci_pwrctrl {struct device *dev; +int (*power_on)(struct pci_pwrctrl *pwrctrl); +int (*power_off)(struct pci_pwrctrl *pwrctrl);/* private: internal use only */ struct notifier_block nb;
Signature · 1 line
2.48.1
PATCH v5 10/15 PCI/pwrctrl: Add APIs to create, destroy pwrctrl devices
In reply to Manivannan SadhasivamFrom: Krishna Chaitanya Chundru <[email protected]>
Previously, the PCI core created pwrctrl devices during pci_scan_device() on its own and then skipped enumeration of those devices, hoping the pwrctrl driver would power them on and trigger a bus rescan.
This approach works for endpoint devices directly connected to Root Ports, but it fails for PCIe switches acting as bus extenders. When the switch requires pwrctrl support and the pwrctrl driver is not available during the pwrctrl device creation, its enumeration will be skipped during the initial PCI bus scan.
This premature scan leads the PCI core to allocate resources (bridge windows, bus numbers) for the upstream bridge based on available downstream buses at scan time. For non-hotplug capable bridges, PCI core typically allocates resources based on the number of buses available during the initial bus scan, which happens to be just one if the switch is not powered on and enumerated at that time. When the switch gets enumerated later on, it will fail due to the lack of upstream resources.
As a result, a PCIe switch powered on by the pwrctrl driver cannot be reliably enumerated currently. Either the switch has to be enabled in the bootloader or the switch pwrctrl driver has to be loaded during the pwrctrl device creation time to work around these issues.
Introduce new APIs to explicitly create and destroy pwrctrl devices from controller drivers by recursively scanning the PCI child nodes of the controller. These APIs allow creating pwrctrl devices based on the original criteria and are intended to be called during controller probe and removal.
These APIs, together with the upcoming APIs for power on/off will allow the controller drivers to power on all the devices before starting the initial bus scan, thereby solving the resource allocation issue.
--- drivers/pci/of.c | 1 + drivers/pci/pwrctrl/core.c | 114 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci-pwrctrl.h | 8 +++- 3 files changed, 122 insertions(+), 1 deletion(-)
drivers/pci/of.c +1 -0
@@ -867,6 +867,7 @@ bool of_pci_supply_present(struct device_node *np) return false; } +EXPORT_SYMBOL_GPL (of_pci_supply_present);#endif /* CONFIG_PCI */
drivers/pci/pwrctrl/core.c +114 -0
134 lines not on this page · raw message
include/linux/pci-pwrctrl.h +7 -1
@@ -54,5 +54,11 @@ int pci_pwrctrl_device_set_ready(struct pci_pwrctrl *pwrctrl);void pci_pwrctrl_device_unset_ready (struct pci_pwrctrl *pwrctrl);int devm_pci_pwrctrl_device_set_ready (struct device *dev,struct pci_pwrctrl *pwrctrl); - +#if IS_ENABLED (CONFIG_PCI_PWRCTRL ) +int pci_pwrctrl_create_devices (struct device *parent); +void pci_pwrctrl_destroy_devices (struct device *parent); +#else +static inline int pci_pwrctrl_create_devices (struct device *parent) {return 0 ; } +static void pci_pwrctrl_destroy_devices (struct device *parent) { } +#endif #endif /* __PCI_PWRCTRL_H__ */
Signature · 1 line
2.48.1
PATCH v5 11/15 PCI/pwrctrl: Add APIs to power on/off pwrctrl devices
In reply to Manivannan SadhasivamTo fix bridge resource allocation issues when powering PCI bridges with the pwrctrl driver, introduce APIs to explicitly power on and off all related devices simultaneously.
Previously, the individual pwrctrl drivers powered on/off the PCI devices autonomously, without any control from the controller drivers. But to enforce ordering with respect to powering on the devices, these APIs will power on/off all the devices at the same time.
The pci_pwrctrl_power_on_devices() API recursively scans the PCI child nodes, makes sure that pwrctrl drivers are bound to devices, and calls their power_on() callbacks. If any pwrctrl driver is not bound, it will return -EPROBE_DEFER.
Similarly, pci_pwrctrl_power_off_devices() API powers off devices recursively via their power_off() callbacks.
These APIs are expected to be called during the controller probe and suspend/resume time to power on/off the devices. But before calling these APIs, the pwrctrl devices should be created using the pci_pwrctrl_{create/destroy}_devices() APIs.
--- drivers/pci/pwrctrl/core.c | 130 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/pci-pwrctrl.h | 4 ++ 2 files changed, 134 insertions(+)
drivers/pci/pwrctrl/core.c +130 -0
@@ -65,6 +65,7 @@ void pci_pwrctrl_init(struct pci_pwrctrl *pwrctrl, struct device *dev) { pwrctrl->dev = dev;INIT_WORK (&pwrctrl->work, rescan_work_func); +dev_set_drvdata (dev, pwrctrl); }EXPORT_SYMBOL_GPL (pci_pwrctrl_init);
@@ -152,6 +153,135 @@ int devm_pci_pwrctrl_device_set_ready(struct device *dev, }EXPORT_SYMBOL_GPL (devm_pci_pwrctrl_device_set_ready); +static int __pci_pwrctrl_power_off_device (struct device *dev) +{ +struct pci_pwrctrl *pwrctrl =dev_get_drvdata (dev); + +if (!pwrctrl) +return 0 ; + +return pwrctrl->power_off (pwrctrl); +} + +static void pci_pwrctrl_power_off_device (struct device_node *np) +{ +struct platform_device *pdev; +int ret; + +for_each_available_child_of_node_scoped (np, child) +pci_pwrctrl_power_off_device (child); + + pdev =of_find_device_by_node (np); +if (!pdev) +return ; + +if (device_is_bound (&pdev->dev)) { + ret =__pci_pwrctrl_power_off_device (&pdev->dev); +if (ret) +dev_err (&pdev->dev,"Failed to power off device: %d" , ret); + } + +platform_device_put (pdev); +} + +/** +* pci_pwrctrl_power_off_devices - Power off pwrctrl devices +* +* @parent: PCI host controller device +* +* Recursively traverse all pwrctrl devices for the devicetree hierarchy +* below the specified PCI host controller and power them off in a depth +* first manner. +*/ +void pci_pwrctrl_power_off_devices (struct device *parent) +{ +struct device_node *np = parent->of_node; + +for_each_available_child_of_node_scoped (np, child) +pci_pwrctrl_power_off_device (child); +} +EXPORT_SYMBOL_GPL (pci_pwrctrl_power_off_devices); + +static int __pci_pwrctrl_power_on_device (struct device *dev) +{ +struct pci_pwrctrl *pwrctrl =dev_get_drvdata (dev); + +if (!pwrctrl) +return 0 ; + +return pwrctrl->power_on (pwrctrl); +} + +/* +* Power on the devices in a depth first manner. Before powering on the device, +* make sure its driver is bound. +*/ +static int pci_pwrctrl_power_on_device (struct device_node *np) +{ +struct platform_device *pdev; +int ret; + +for_each_available_child_of_node_scoped (np, child) { + ret =pci_pwrctrl_power_on_device (child); +if (ret) +return ret; + } + + pdev =of_find_device_by_node (np); +if (!pdev) +return 0 ; + +if (device_is_bound (&pdev->dev)) { + ret =__pci_pwrctrl_power_on_device (&pdev->dev); + }else { +/* FIXME: Use blocking wait instead of probe deferral */ +dev_dbg (&pdev->dev,"driver is not bound\n" ); + ret = -EPROBE_DEFER ; + } + +platform_device_put (pdev); + +return ret; +} + +/** +* pci_pwrctrl_power_on_devices - Power on pwrctrl devices +* +* @parent: PCI host controller device +* +* Recursively traverse all pwrctrl devices for the devicetree hierarchy +* below the specified PCI host controller and power them on in a depth +* first manner. On error, all powered on devices will be powered off. +* +* Return: 0 on success, -EPROBE_DEFER if any pwrctrl driver is not bound, an +* appropriate error code otherwise. +*/ +int pci_pwrctrl_power_on_devices (struct device *parent) +{ +struct device_node *np = parent->of_node; +struct device_node *child =NULL ; +int ret; + +for_each_available_child_of_node (np, child) { + ret =pci_pwrctrl_power_on_device (child); +if (ret) + goto err_power_off; + } + +return 0 ; + +err_power_off: +for_each_available_child_of_node_scoped (np, tmp) { +if (tmp == child) +break ; +pci_pwrctrl_power_off_device (tmp); + } +of_node_put (child); + +return ret; +} +EXPORT_SYMBOL_GPL (pci_pwrctrl_power_on_devices); +static int pci_pwrctrl_create_device (struct device_node *np,struct device *parent) {
include/linux/pci-pwrctrl.h +4 -0
@@ -57,8 +57,12 @@ int devm_pci_pwrctrl_device_set_ready(struct device *dev,#if IS_ENABLED (CONFIG_PCI_PWRCTRL )int pci_pwrctrl_create_devices (struct device *parent);void pci_pwrctrl_destroy_devices (struct device *parent); +int pci_pwrctrl_power_on_devices (struct device *parent); +void pci_pwrctrl_power_off_devices (struct device *parent);#else static inline int pci_pwrctrl_create_devices (struct device *parent) {return 0 ; }static void pci_pwrctrl_destroy_devices (struct device *parent) { } +static inline int pci_pwrctrl_power_on_devices (struct device *parent) {return 0 ; } +static void pci_pwrctrl_power_off_devices (struct device *parent) { }#endif #endif /* __PCI_PWRCTRL_H__ */
Signature · 1 line
2.48.1
PATCH v5 12/15 PCI/pwrctrl: Switch to pwrctrl create, power on/off, destroy APIs
In reply to Manivannan SadhasivamAdopt pwrctrl APIs to create, power on/off, and destroy pwrctrl devices.
In qcom_pcie_host_init(), call pci_pwrctrl_create_devices() to create devices, then pci_pwrctrl_power_on_devices() to power them on, both after controller resource initialization. Once successful, deassert PERST# for all devices.
In qcom_pcie_host_deinit(), call pci_pwrctrl_power_off_devices() after asserting PERST#. Note that pci_pwrctrl_destroy_devices() is not called here, as deinit is only invoked during system suspend where device destruction is unnecessary. If the driver becomes removable in future, pci_pwrctrl_destroy_devices() should be called in the remove() handler.
Remove the old pwrctrl framework code from the PCI core (including devlinks) as the new APIs are now the sole consumer of pwrctrl functionality. And also do not power on the pwrctrl drivers during probe() as this is now handled by the APIs.
--- drivers/pci/bus.c | 19 ---------- drivers/pci/controller/dwc/pcie-qcom.c | 24 +++++++++++-- drivers/pci/probe.c | 59 -------------------------------- drivers/pci/pwrctrl/core.c | 15 -------- drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c | 5 --- drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c | 24 ++----------- drivers/pci/pwrctrl/slot.c | 2 -- drivers/pci/remove.c | 20 ----------- 8 files changed, 25 insertions(+), 143 deletions(-)
drivers/pci/bus.c +0 -19
@@ -344,7 +344,6 @@ void __weak pcibios_bus_add_device(struct pci_dev *pdev) { }void pci_bus_add_device (struct pci_dev *dev) {struct device_node *dn = dev->dev.of_node; -struct platform_device *pdev;/* * Can not put in pci_device_add yet because resources
@@ -361,24 +360,6 @@ void pci_bus_add_device(struct pci_dev *dev)/* Save config space for error recoverability */ pci_save_state (dev); -/* -* If the PCI device is associated with a pwrctrl device with a -* power supply, create a device link between the PCI device and -* pwrctrl device. This ensures that pwrctrl drivers are probed -* before PCI client drivers. -*/ - pdev =of_find_device_by_node (dn); -if (pdev) { -if (of_pci_supply_present (dn)) { -if (!device_link_add (&dev->dev, &pdev->dev, -DL_FLAG_AUTOREMOVE_CONSUMER )) { -pci_err (dev,"failed to add device link to power control device %s\n" , - pdev->name); - } - } -put_device (&pdev->dev); - } -if (!dn ||of_device_is_available (dn))pci_dev_allow_binding (dev);
drivers/pci/controller/dwc/pcie-qcom.c +22 -2
@@ -24,6 +24,7 @@#include <linux/of_pci.h> #include <linux/pci.h> #include <linux/pci-ecam.h> +#include <linux/pci-pwrctrl.h> #include <linux/pm_opp.h> #include <linux/pm_runtime.h> #include <linux/platform_device.h>
@@ -1310,10 +1311,18 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp)if (ret) goto err_deinit; + ret =pci_pwrctrl_create_devices (pci->dev); +if (ret) + goto err_disable_phy; + + ret =pci_pwrctrl_power_on_devices (pci->dev); +if (ret) + goto err_pwrctrl_destroy; +if (pcie->cfg->ops->post_init) { ret = pcie->cfg->ops->post_init (pcie);if (ret) - goto err_disable_phy; + goto err_pwrctrl_power_off; }qcom_ep_reset_deassert (pcie);
@@ -1328,6 +1337,11 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp) err_assert_reset:qcom_ep_reset_assert (pcie); +err_pwrctrl_power_off: +pci_pwrctrl_power_off_devices (pci->dev); +err_pwrctrl_destroy: +if (ret != -EPROBE_DEFER ) +pci_pwrctrl_destroy_devices (pci->dev); err_disable_phy:qcom_pcie_phy_power_off (pcie); err_deinit:
@@ -1342,6 +1356,12 @@ static void qcom_pcie_host_deinit(struct dw_pcie_rp *pp)struct qcom_pcie *pcie =to_qcom_pcie (pci);qcom_ep_reset_assert (pcie); + +/* +* No need to destroy pwrctrl devices as this function only gets called +* during system suspend as of now. +*/ +pci_pwrctrl_power_off_devices (pci->dev);qcom_pcie_phy_power_off (pcie); pcie->cfg->ops->deinit (pcie); }
@@ -1961,7 +1981,7 @@ static int qcom_pcie_probe(struct platform_device *pdev) ret =dw_pcie_host_init (pp);if (ret) { -dev_err (dev,"cannot initialize host\n" ); +dev_err_probe (dev, ret,"cannot initialize host\n" ); goto err_phy_exit; }
drivers/pci/probe.c +0 -59
71 lines not on this page · raw message
drivers/pci/pwrctrl/core.c +0 -15
@@ -45,16 +45,6 @@ static int pci_pwrctrl_notify(struct notifier_block *nb, unsigned long action,return NOTIFY_DONE ; } -static void rescan_work_func (struct work_struct *work) -{ -struct pci_pwrctrl *pwrctrl =container_of (work, - struct pci_pwrctrl, work); - -pci_lock_rescan_remove (); -pci_rescan_bus (to_pci_host_bridge (pwrctrl->dev->parent)->bus); -pci_unlock_rescan_remove (); -} -/** * pci_pwrctrl_init() - Initialize the PCI power control context struct *
@@ -64,7 +54,6 @@ static void rescan_work_func(struct work_struct *work)void pci_pwrctrl_init (struct pci_pwrctrl *pwrctrl,struct device *dev) { pwrctrl->dev = dev; -INIT_WORK (&pwrctrl->work, rescan_work_func);dev_set_drvdata (dev, pwrctrl); }EXPORT_SYMBOL_GPL (pci_pwrctrl_init);
@@ -95,8 +84,6 @@ int pci_pwrctrl_device_set_ready(struct pci_pwrctrl *pwrctrl)if (ret)return ret; -schedule_work (&pwrctrl->work); -return 0 ; }EXPORT_SYMBOL_GPL (pci_pwrctrl_device_set_ready);
@@ -109,8 +96,6 @@ EXPORT_SYMBOL_GPL(pci_pwrctrl_device_set_ready);*/ void pci_pwrctrl_device_unset_ready (struct pci_pwrctrl *pwrctrl) { -cancel_work_sync (&pwrctrl->work); -/* * We don't have to delete the link here. Typically, this function * is only called when the power control device is being detached. If
drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c +0 -5
@@ -101,11 +101,6 @@ static int pci_pwrctrl_pwrseq_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (pwrseq->pwrseq),"Failed to get the power sequencer\n" ); - ret =pci_pwrctrl_pwrseq_power_on (&pwrseq->pwrctrl); -if (ret) -return dev_err_probe (dev, ret, -"Failed to power-on the device\n" ); - ret =devm_add_action_or_reset (dev, devm_pci_pwrctrl_pwrseq_power_off, pwrseq);if (ret)
drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c +3 -21
@@ -533,9 +533,7 @@ static int tc9563_pwrctrl_power_on(struct pci_pwrctrl *pwrctrl)static int tc9563_pwrctrl_probe (struct platform_device *pdev) { -struct pci_host_bridge *bridge =to_pci_host_bridge (pdev->dev.parent);struct device_node *node = pdev->dev.of_node; -struct pci_bus *bus = bridge->bus;struct device *dev = &pdev->dev;enum tc9563_pwrctrl_ports port;struct pci_pwrctrl_tc9563 *tc9563;
@@ -614,22 +612,6 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev) goto remove_i2c; } -if (bridge->ops->assert_perst) { - ret = bridge->ops->assert_perst (bus, true); -if (ret) - goto remove_i2c; - } - - ret =tc9563_pwrctrl_power_on (&tc9563->pwrctrl); -if (ret) - goto remove_i2c; - -if (bridge->ops->assert_perst) { - ret = bridge->ops->assert_perst (bus, false); -if (ret) - goto power_off; - } - tc9563->pwrctrl.power_on = tc9563_pwrctrl_power_on; tc9563->pwrctrl.power_off = tc9563_pwrctrl_power_off;
@@ -637,8 +619,6 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)if (ret) goto power_off; -platform_set_drvdata (pdev, tc9563); -return 0 ; power_off:
@@ -651,7 +631,9 @@ static int tc9563_pwrctrl_probe(struct platform_device *pdev)static void tc9563_pwrctrl_remove (struct platform_device *pdev) { -struct pci_pwrctrl_tc9563 *tc9563 =platform_get_drvdata (pdev); +struct pci_pwrctrl *pwrctrl =dev_get_drvdata (&pdev->dev); +struct pci_pwrctrl_tc9563 *tc9563 =container_of (pwrctrl, + struct pci_pwrctrl_tc9563, pwrctrl);tc9563_pwrctrl_power_off (&tc9563->pwrctrl);i2c_unregister_device (tc9563->client);
drivers/pci/pwrctrl/slot.c +0 -2
@@ -83,8 +83,6 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (slot->clk),"Failed to enable slot clock\n" ); -pci_pwrctrl_slot_power_on (&slot->pwrctrl); - slot->pwrctrl.power_on = pci_pwrctrl_slot_power_on; slot->pwrctrl.power_off = pci_pwrctrl_slot_power_off;
drivers/pci/remove.c +0 -20
@@ -17,25 +17,6 @@ static void pci_free_resources(struct pci_dev *dev) } } -static void pci_pwrctrl_unregister (struct device *dev) -{ -struct device_node *np; -struct platform_device *pdev; - - np =dev_of_node (dev); -if (!np) -return ; - - pdev =of_find_device_by_node (np); -if (!pdev) -return ; - -of_device_unregister (pdev); -put_device (&pdev->dev); - -of_node_clear_flag (np,OF_POPULATED ); -} -static void pci_stop_dev (struct pci_dev *dev) {pci_pme_active (dev, false);
@@ -73,7 +54,6 @@ static void pci_destroy_dev(struct pci_dev *dev)pci_ide_destroy (dev);pcie_aspm_exit_link_state (dev);pci_bridge_d3_update (dev); -pci_pwrctrl_unregister (&dev->dev);pci_free_resources (dev);put_device (&dev->dev); }
Signature · 1 line
2.48.1
PATCH v5 13/15 PCI: qcom: Drop the assert_perst() callbacks
In reply to Manivannan SadhasivamPreviously, the pcie-qcom driver probed first, deasserted PERST#, enabled link training and scanned the bus. By the time the pwrctrl driver probe got called, link training was already enabled by the controller driver.
Thus the pwrctrl drivers had to call the .assert_perst() callback, to assert PERST#, power on the needed resources, and then call the .assert_perst() callback to deassert PERST#.
Now since all pwrctrl drivers and this controller driver have been converted to the new pwrctrl design where the pwrctrl drivers will first power on the devices before this driver deasserts PERST# and scan the bus. So there is no longer a need for .assert_perst() callback in this driver and in DWC core driver. Hence, drop them.
--- drivers/pci/controller/dwc/pcie-designware-host.c | 9 --------- drivers/pci/controller/dwc/pcie-designware.h | 9 --------- drivers/pci/controller/dwc/pcie-qcom.c | 13 ------------- 3 files changed, 31 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +0 -9
@@ -857,19 +857,10 @@ static void __iomem *dw_pcie_ecam_conf_map_bus(struct pci_bus *bus, unsigned intreturn pci->dbi_base + where; } -static int dw_pcie_op_assert_perst (struct pci_bus *bus,bool assert) -{ -struct dw_pcie_rp *pp = bus->sysdata; -struct dw_pcie *pci =to_dw_pcie_from_pp (pp); - -return dw_pcie_assert_perst (pci, assert); -} -static struct pci_ops dw_pcie_ops = { .map_bus = dw_pcie_own_conf_map_bus, .read = pci_generic_config_read, .write = pci_generic_config_write, - .assert_perst = dw_pcie_op_assert_perst, };static struct pci_ops dw_pcie_ecam_ops = {
drivers/pci/controller/dwc/pcie-designware.h +0 -9
@@ -493,7 +493,6 @@ struct dw_pcie_ops {enum dw_pcie_ltssm (*get_ltssm)(struct dw_pcie *pcie);int (*start_link)(struct dw_pcie *pcie);void (*stop_link)(struct dw_pcie *pcie); -int (*assert_perst)(struct dw_pcie *pcie,bool assert); };struct debugfs_info {
@@ -798,14 +797,6 @@ static inline void dw_pcie_stop_link(struct dw_pcie *pci) pci->ops->stop_link (pci); } -static inline int dw_pcie_assert_perst (struct dw_pcie *pci,bool assert) -{ -if (pci->ops && pci->ops->assert_perst) -return pci->ops->assert_perst (pci, assert); - -return 0 ; -} -static inline enum dw_pcie_ltssm dw_pcie_get_ltssm (struct dw_pcie *pci) {u32 val;
drivers/pci/controller/dwc/pcie-qcom.c +0 -13
@@ -642,18 +642,6 @@ static int qcom_pcie_post_init_1_0_0(struct qcom_pcie *pcie)return 0 ; } -static int qcom_pcie_assert_perst (struct dw_pcie *pci,bool assert) -{ -struct qcom_pcie *pcie =to_qcom_pcie (pci); - -if (assert) -qcom_ep_reset_assert (pcie); -else -qcom_ep_reset_deassert (pcie); - -return 0 ; -} -static void qcom_pcie_2_3_2_ltssm_enable (struct qcom_pcie *pcie) {u32 val;
@@ -1514,7 +1502,6 @@ static const struct qcom_pcie_cfg cfg_fw_managed = {static const struct dw_pcie_ops dw_pcie_ops = { .link_up = qcom_pcie_link_up, .start_link = qcom_pcie_start_link, - .assert_perst = qcom_pcie_assert_perst, };static int qcom_pcie_icc_init (struct qcom_pcie *pcie)
Signature · 1 line
2.48.1
Re: [PATCH v5 13/15] PCI: qcom: Drop the assert_perst() callbacks
Quoted 10 lines · On Thu, 15 Jan 2026 08:29:05 +0100, Manivannan Sadhasivam via B4 Relay…
From: Manivannan Sadhasivam <[email protected]>
Previously, the pcie-qcom driver probed first, deasserted PERST#, enabled link training and scanned the bus. By the time the pwrctrl driver probe got called, link training was already enabled by the controller driver.
Thus the pwrctrl drivers had to call the .assert_perst() callback, to assert PERST#, power on the needed resources, and then call the .assert_perst() callback to deassert PERST#.
Quoted 8 lines
Now since all pwrctrl drivers and this controller driver have been converted to the new pwrctrl design where the pwrctrl drivers will first power on the devices before this driver deasserts PERST# and scan the bus. So there is no longer a need for .assert_perst() callback in this driver and in DWC core driver. Hence, drop them.
Signed-off-by Manivannan Sadhasivam <[email protected]>---
PATCH v5 14/15 PCI: Drop the assert_perst() callback
In reply to Manivannan SadhasivamNow since all .assert_callback() implementations have been removed from the controller drivers, drop the .assert_callback callback from pci.h.
--- include/linux/pci.h | 1 - 1 file changed, 1 deletion(-)
include/linux/pci.h +0 -1
@@ -854,7 +854,6 @@ struct pci_ops {void __iomem *(*map_bus)(struct pci_bus *bus,unsigned int devfn,int where);int (*read)(struct pci_bus *bus,unsigned int devfn,int where,int size,u32 *val);int (*write)(struct pci_bus *bus,unsigned int devfn,int where,int size,u32 val); -int (*assert_perst)(struct pci_bus *bus,bool assert); };/*
Signature · 1 line
2.48.1
PATCH v5 15/15 PCI: qcom: Rename PERST# assert/deassert helpers for uniformity
In reply to Manivannan SadhasivamRename the PERST# assert/deassert helpers from qcom_ep_reset_{assert/deassert}() to qcom_pcie_perst_{assert/deassert}() to maintain uniformity.
--- drivers/pci/controller/dwc/pcie-qcom.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/pci/controller/dwc/pcie-qcom.c +9 -9
@@ -290,7 +290,7 @@ struct qcom_pcie {#define to_qcom_pcie (x) dev_get_drvdata((x)->dev) -static void qcom_perst_assert (struct qcom_pcie *pcie,bool assert) +static void __qcom_pcie_perst_assert (struct qcom_pcie *pcie,bool assert) {struct qcom_pcie_port *port;int val = assert ?1 :0 ;
@@ -301,16 +301,16 @@ static void qcom_perst_assert(struct qcom_pcie *pcie, bool assert)usleep_range (PERST_DELAY_US ,PERST_DELAY_US +500 ); } -static void qcom_ep_reset_assert (struct qcom_pcie *pcie) +static void qcom_pcie_perst_assert (struct qcom_pcie *pcie) { -qcom_perst_assert (pcie, true); +__qcom_pcie_perst_assert (pcie, true); } -static void qcom_ep_reset_deassert (struct qcom_pcie *pcie) +static void qcom_pcie_perst_deassert (struct qcom_pcie *pcie) {/* Ensure that PERST has been asserted for at least 100 ms */ msleep (PCIE_T_PVPERL_MS ); -qcom_perst_assert (pcie, false); +__qcom_pcie_perst_assert (pcie, false); }static int qcom_pcie_start_link (struct dw_pcie *pci)
@@ -1289,7 +1289,7 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp)struct qcom_pcie *pcie =to_qcom_pcie (pci);int ret; -qcom_ep_reset_assert (pcie); +qcom_pcie_perst_assert (pcie); ret = pcie->cfg->ops->init (pcie);if (ret)
@@ -1313,7 +1313,7 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp) goto err_pwrctrl_power_off; } -qcom_ep_reset_deassert (pcie); +qcom_pcie_perst_deassert (pcie);if (pcie->cfg->ops->config_sid) { ret = pcie->cfg->ops->config_sid (pcie);
@@ -1324,7 +1324,7 @@ static int qcom_pcie_host_init(struct dw_pcie_rp *pp)return 0 ; err_assert_reset: -qcom_ep_reset_assert (pcie); +qcom_pcie_perst_assert (pcie); err_pwrctrl_power_off:pci_pwrctrl_power_off_devices (pci->dev); err_pwrctrl_destroy:
@@ -1343,7 +1343,7 @@ static void qcom_pcie_host_deinit(struct dw_pcie_rp *pp)struct dw_pcie *pci =to_dw_pcie_from_pp (pp);struct qcom_pcie *pcie =to_qcom_pcie (pci); -qcom_ep_reset_assert (pcie); +qcom_pcie_perst_assert (pcie);/* * No need to destroy pwrctrl devices as this function only gets called
Signature · 1 line
2.48.1
Bjorn Helgaas
AppliedQuoted 193 lines · On Thu, Jan 15, 2026 at 12:58:52PM +0530, Manivannan Sadhasivam via B4 Relay…
Hi,
This series provides a major rework for the PCI power control (pwrctrl) framework to enable the pwrctrl devices to be controlled by the PCI controller drivers.
Problem Statement
=================Currently, the pwrctrl framework faces two major issues:
1. Missing PERST# integration
2. Inability to properly handle bus extenders such as PCIe switch devicesFirst issue arises from the disconnect between the PCI controller drivers and pwrctrl framework. At present, the pwrctrl framework just operates on its own with the help of the PCI core. The pwrctrl devices are created by the PCI core during initial bus scan and the pwrctrl drivers once bind, just power on the PCI devices during their
probe(). This design conflicts with the PCI Express Card Electromechanical Specification requirements for PERST# timing. The reason is, PERST# signals are mostly handled by the controller drivers and often deasserted even before the pwrctrl drivers probe. According to the spec, PERST# should be deasserted only after power and reference clock to the device are stable, within predefined timing parameters.The second issue stems from the PCI bus scan completing before pwrctrl drivers probe. This poses a significant problem for PCI bus extenders like switches because the PCI core allocates upstream bridge resources during the initial scan. If the upstream bridge is not hotplug capable, resources are allocated only for the number of downstream buses detected at scan time, which might be just one if the switch was not powered and enumerated at that time. Later, when the pwrctrl driver powers on and enumerates the switch, enumeration fails due to insufficient upstream bridge resources.
Proposal
========This series addresses both issues by introducing new individual APIs for pwrctrl device creation, destruction, power on, and power off operations. Controller drivers are expected to invoke these APIs during their
probe(),remove(),suspend(), andresume()operations. This integration allows better coordination between controller drivers and the pwrctrl framework, enabling enhanced features such as D3Cold support.The original design aimed to avoid modifying controller drivers for pwrctrl integration. However, this approach lacked scalability because different controllers have varying requirements for when devices should be powered on. For example, controller drivers require devices to be powered on early for successful PHY initialization.
By using these explicit APIs, controller drivers gain fine grained control over their associated pwrctrl devices.
This series modified the pcie-qcom driver (only consumer of pwrctrl framework) to adopt to these APIs and also removed the old pwrctrl code from PCI core. This could be used as a reference to add pwrctrl support for other controller drivers also.
For example, to control the 3.3v supply to the PCI slot where the NVMe device is connected, below modifications are required:
Devicetree
----------// In SoC dtsi: pci@1bf8000 { // controller node ... pcie1_port0: pcie@0 { // PCI Root Port node compatible = "pciclass,0604"; // required for pwrctrl driver bind ... }; }; // In board dts: &pcie1_port0 { reset-gpios = <&tlmm 152 GPIO_ACTIVE_LOW>; // optional vpcie3v3-supply = <&vreg_nvme>; // NVMe power supply };Controller driver
-----------------// Select PCI_PWRCTRL_SLOT in controller Kconfig probe() { ... // Initialize controller resources pci_pwrctrl_create_devices(&pdev->dev); pci_pwrctrl_power_on_devices(&pdev->dev); // Deassert PERST# (optional) ... pci_host_probe(); // Allocate host bridge and start bus scan } suspend { // PME_Turn_Off broadcast // Assert PERST# (optional) pci_pwrctrl_power_off_devices(&pdev->dev); ... } resume { ... pci_pwrctrl_power_on_devices(&pdev->dev); // Deassert PERST# (optional) }I will add a documentation for the pwrctrl framework in the coming days to make it easier to use.
Testing
=======This series is tested on the Lenovo Thinkpad T14s laptop based on Qcom X1E chipset and RB3Gen2 development board with TC9563 switch based on Qcom QCS6490 chipset.
**NOTE**: With this series, the controller driver may undergo multiple probe deferral if the pwrctrl driver was not available during the controller driver probe. This is pretty much required to avoid the resource allocation issue. I plan to replace probe deferral with blocking wait in the coming days.
Signed-off-by Manivannan Sadhasivam <[email protected]>---
Changes in v5:
- Incorporated cleanups from Bjorn
- Splitted the power on/off callback changes
- Collected tags
- Link to v4: https://lore.kernel.org/r/[email protected]Changes in v4:
- Usedplatform_device_put()
- Changed the return value ofpower_off()callback to 'int'
- Splitted patch 6 into two and reworded the commit message
- Collected tags
- Link to v3: https://lore.kernel.org/r/[email protected]Changes in v3:
- Integrated TC9563 change
- Reworked thepower_onAPI to properly power off the devices in error path
- Fixed the error path inpcie-qcom.cto not destroy pwrctrl devices during
probe deferral
- Rebased on top of pci/controller/dwc-qcom branch and dropped the PERST# patch
- Added a patch for TC9563 to fix the refcount dropping for i2c adapter
- Added patches to drop theassert_perstcallback and rename the PERST# helpers inpcie-qcom.c
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Exportedof_pci_supply_present()API
- Demoted the -EPROBE_DEFER log todev_dbg()
- Collected tags and rebased on top of v6.19-rc1
- Link to v1: https://lore.kernel.org/r/[email protected]---
Bjorn Helgaas (5):
PCI/pwrctrl: pwrseq: Rename private struct and pointers for consistency PCI/pwrctrl: slot: Rename private struct and pointers for consistency PCI/pwrctrl: tc9563: Clean up whitespace
PCI/pwrctrl: tc9563: Add local variables to reduce repetition PCI/pwrctrl: tc9563: Rename private struct and pointers for consistencyKrishna Chaitanya Chundru (1):
PCI/pwrctrl: Add APIs to create, destroy pwrctrl devicesManivannan Sadhasivam (9):
PCI/pwrctrl: tc9563: Useput_device()instead ofi2c_put_adapter()PCI/pwrctrl: slot: Factor out power on/off code to helpers PCI/pwrctrl: pwrseq: Factor out power on/off code to helpers PCI/pwrctrl: Add 'struct pci_pwrctrl::power_{on/off}' callbacks PCI/pwrctrl: Add APIs to power on/off pwrctrl devices PCI/pwrctrl: Switch to pwrctrl create, power on/off, destroy APIs
PCI: qcom: Drop theassert_perst()callbacks
PCI: Drop theassert_perst()callback
PCI: qcom: Rename PERST# assert/deassert helpers for uniformitydrivers/pci/bus.c | 19 -- drivers/pci/controller/dwc/pcie-designware-host.c | 9 - drivers/pci/controller/dwc/pcie-designware.h | 9 - drivers/pci/controller/dwc/pcie-qcom.c | 55 +++-- drivers/pci/of.c | 1 + drivers/pci/probe.c | 59 ----- drivers/pci/pwrctrl/core.c | 259 ++++++++++++++++++++-- drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c | 50 +++-- drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c | 226 ++++++++++--------- drivers/pci/pwrctrl/slot.c | 60 +++-- drivers/pci/remove.c | 20 -- include/linux/pci-pwrctrl.h | 16 +- include/linux/pci.h | 1 - 13 files changed, 484 insertions(+), 300 deletions(-)
Quoted 3 lines
---
base-commit:3e7f562e20ee87a25e104ef4fce557d39d62fa85
change-id: 20251124-pci-pwrctrl-rework-c91a6e16c2f6
Applied to pci/pwrctrl for v6.20, thanks!
I reworked the renaming as we talked about off-line to drop "pci" (seems redundant) and put the device or driver name first, e.g., pci_pwrctrl_slot_probe() -> slot_pwrctrl_probe().
I noticed when build testing that I had to tweak drivers/pci/pwrctrl/Kconfig to let me build pci-pwrctrl-pwrseq.c. It would be nice if COMPILE_TEST could enable that.