]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI/pwrctrl: slot: Factor out power on/off code to helpers
authorManivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Fri, 16 Jan 2026 18:14:55 +0000 (12:14 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 16 Jan 2026 19:23:37 +0000 (13:23 -0600)
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
drivers/pci/pwrctrl/slot.c

index 51de1eecdb26b404d6e09cd71578abe359f79be9..094c7df454fcdc4f56422cefd286c133bf68c535 100644 (file)
@@ -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);