Commit 0afc90ce authored by Manivannan Sadhasivam's avatar Manivannan Sadhasivam Committed by Bjorn Helgaas
Browse files

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: default avatarManivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Reviewed-by: default avatarBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Link: https://patch.msgid.link/20260115-pci-pwrctrl-rework-v5-7-9d26da3ce903@oss.qualcomm.com
parent 370d2de0
Loading
Loading
Loading
Loading
+35 −14
Original line number Diff line number Diff line
@@ -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);