summaryrefslogtreecommitdiff
path: root/drivers/pci/pwrctrl
diff options
context:
space:
mode:
authorManivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>2026-01-16 12:14:55 -0600
committerBjorn Helgaas <bhelgaas@google.com>2026-01-16 13:23:37 -0600
commit0afc90ced0955d1ad2b65379e6771e4fb19ce769 (patch)
tree2bddc844052587f22b66feef08a8e0e84c58e7ec /drivers/pci/pwrctrl
parent370d2de0fb65ed954c0b6375e36d0fa12c9323be (diff)
downloadlwn-0afc90ced0955d1ad2b65379e6771e4fb19ce769.tar.gz
lwn-0afc90ced0955d1ad2b65379e6771e4fb19ce769.zip
PCI/pwrctrl: slot: Factor out power on/off code to helpers
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 <manivannan.sadhasivam@oss.qualcomm.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> Link: https://patch.msgid.link/20260115-pci-pwrctrl-rework-v5-7-9d26da3ce903@oss.qualcomm.com
Diffstat (limited to 'drivers/pci/pwrctrl')
-rw-r--r--drivers/pci/pwrctrl/slot.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/drivers/pci/pwrctrl/slot.c b/drivers/pci/pwrctrl/slot.c
index 51de1eecdb26..094c7df454fc 100644
--- a/drivers/pci/pwrctrl/slot.c
+++ b/drivers/pci/pwrctrl/slot.c
@@ -17,13 +17,40 @@ struct slot_pwrctrl {
struct pci_pwrctrl pwrctrl;
struct regulator_bulk_data *supplies;
int num_supplies;
+ struct clk *clk;
};
-static void devm_slot_pwrctrl_power_off(void *data)
+static int slot_pwrctrl_power_on(struct pci_pwrctrl *pwrctrl)
{
- struct slot_pwrctrl *slot = data;
+ struct slot_pwrctrl *slot = container_of(pwrctrl,
+ struct slot_pwrctrl, 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 slot_pwrctrl_power_off(struct pci_pwrctrl *pwrctrl)
+{
+ struct slot_pwrctrl *slot = container_of(pwrctrl,
+ struct slot_pwrctrl, pwrctrl);
regulator_bulk_disable(slot->num_supplies, slot->supplies);
+ clk_disable_unprepare(slot->clk);
+
+ return 0;
+}
+
+static void devm_slot_pwrctrl_release(void *data)
+{
+ struct slot_pwrctrl *slot = data;
+
+ slot_pwrctrl_power_off(&slot->pwrctrl);
regulator_bulk_free(slot->num_supplies, slot->supplies);
}
@@ -31,7 +58,6 @@ static int slot_pwrctrl_probe(struct platform_device *pdev)
{
struct slot_pwrctrl *slot;
struct device *dev = &pdev->dev;
- struct clk *clk;
int ret;
slot = devm_kzalloc(dev, sizeof(*slot), GFP_KERNEL);
@@ -46,24 +72,19 @@ static int slot_pwrctrl_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_slot_pwrctrl_power_off,
- slot);
+ ret = devm_add_action_or_reset(dev, devm_slot_pwrctrl_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");
}
+ slot_pwrctrl_power_on(&slot->pwrctrl);
+
pci_pwrctrl_init(&slot->pwrctrl, dev);
ret = devm_pci_pwrctrl_device_set_ready(dev, &slot->pwrctrl);