From ff124bbbca1d3a07fa1392ffdbbdeece71f68ece Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Wed, 18 Mar 2026 12:10:10 -0500 Subject: PCI/pwrctrl: generic: Rename pci-pwrctrl-slot as generic The driver is pretty generic and would fit for either PCI Slots or endpoints connected to PCI ports, so rename the driver and module as pci-pwrctrl-generic. Suggested-by: Manivannan Sadhasivam Signed-off-by: Neil Armstrong Signed-off-by: Bjorn Helgaas Reviewed-by: Manivannan Sadhasivam Reviewed-by: Bartosz Golaszewski Link: https://patch.msgid.link/20260220-topic-sm8650-ayaneo-pocket-s2-base-v5-3-1ad79caa1efa@linaro.org --- drivers/pci/controller/dwc/Kconfig | 4 +- drivers/pci/pwrctrl/Kconfig | 13 ++-- drivers/pci/pwrctrl/Makefile | 4 +- drivers/pci/pwrctrl/generic.c | 140 +++++++++++++++++++++++++++++++++++++ drivers/pci/pwrctrl/slot.c | 140 ------------------------------------- 5 files changed, 151 insertions(+), 150 deletions(-) create mode 100644 drivers/pci/pwrctrl/generic.c delete mode 100644 drivers/pci/pwrctrl/slot.c (limited to 'drivers') diff --git a/drivers/pci/controller/dwc/Kconfig b/drivers/pci/controller/dwc/Kconfig index d0aa031397fa..4bd36e133ca6 100644 --- a/drivers/pci/controller/dwc/Kconfig +++ b/drivers/pci/controller/dwc/Kconfig @@ -309,7 +309,7 @@ config PCIE_QCOM select CRC8 select PCIE_QCOM_COMMON select PCI_HOST_COMMON - select PCI_PWRCTRL_SLOT + select PCI_PWRCTRL_GENERIC help Say Y here to enable PCIe controller support on Qualcomm SoCs. The PCIe controller uses the DesignWare core plus Qualcomm-specific @@ -431,7 +431,7 @@ config PCIE_SPACEMIT_K1 depends on ARCH_SPACEMIT || COMPILE_TEST depends on HAS_IOMEM select PCIE_DW_HOST - select PCI_PWRCTRL_SLOT + select PCI_PWRCTRL_GENERIC default ARCH_SPACEMIT help Enables support for the DesignWare based PCIe controller in diff --git a/drivers/pci/pwrctrl/Kconfig b/drivers/pci/pwrctrl/Kconfig index cd3aa15bad00..9eec767cda86 100644 --- a/drivers/pci/pwrctrl/Kconfig +++ b/drivers/pci/pwrctrl/Kconfig @@ -11,17 +11,18 @@ config PCI_PWRCTRL_PWRSEQ select POWER_SEQUENCING select PCI_PWRCTRL -config PCI_PWRCTRL_SLOT - tristate "PCI Power Control driver for PCI slots" +config PCI_PWRCTRL_GENERIC + tristate "Generic PCI Power Control driver for PCI slots and endpoints" select POWER_SEQUENCING select PCI_PWRCTRL help - Say Y here to enable the PCI Power Control driver to control the power - state of PCI slots. + Say Y here to enable the generic PCI Power Control driver to control + the power state of PCI slots and endpoints. This is a generic driver that controls the power state of different - PCI slots. The voltage regulators powering the rails of the PCI slots - are expected to be defined in the devicetree node of the PCI bridge. + PCI slots and endpoints. The voltage regulators powering the rails + of the PCI slots or endpoints are expected to be defined in the + devicetree node of the PCI bridge or endpoint. config PCI_PWRCTRL_TC9563 tristate "PCI Power Control driver for TC9563 PCIe switch" diff --git a/drivers/pci/pwrctrl/Makefile b/drivers/pci/pwrctrl/Makefile index 13b02282106c..f6bb4fb9a410 100644 --- a/drivers/pci/pwrctrl/Makefile +++ b/drivers/pci/pwrctrl/Makefile @@ -5,7 +5,7 @@ pci-pwrctrl-core-y := core.o obj-$(CONFIG_PCI_PWRCTRL_PWRSEQ) += pci-pwrctrl-pwrseq.o -obj-$(CONFIG_PCI_PWRCTRL_SLOT) += pci-pwrctrl-slot.o -pci-pwrctrl-slot-y := slot.o +obj-$(CONFIG_PCI_PWRCTRL_GENERIC) += pci-pwrctrl-generic.o +pci-pwrctrl-generic-y := generic.o obj-$(CONFIG_PCI_PWRCTRL_TC9563) += pci-pwrctrl-tc9563.o diff --git a/drivers/pci/pwrctrl/generic.c b/drivers/pci/pwrctrl/generic.c new file mode 100644 index 000000000000..082af81efe25 --- /dev/null +++ b/drivers/pci/pwrctrl/generic.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024 Linaro Ltd. + * Author: Manivannan Sadhasivam + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct slot_pwrctrl { + struct pci_pwrctrl pwrctrl; + struct regulator_bulk_data *supplies; + int num_supplies; + struct clk *clk; + struct pwrseq_desc *pwrseq; +}; + +static int slot_pwrctrl_power_on(struct pci_pwrctrl *pwrctrl) +{ + struct slot_pwrctrl *slot = container_of(pwrctrl, + struct slot_pwrctrl, pwrctrl); + int ret; + + if (slot->pwrseq) { + pwrseq_power_on(slot->pwrseq); + return 0; + } + + 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); + + if (slot->pwrseq) { + pwrseq_power_off(slot->pwrseq); + return 0; + } + + 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); +} + +static int slot_pwrctrl_probe(struct platform_device *pdev) +{ + struct slot_pwrctrl *slot; + struct device *dev = &pdev->dev; + int ret; + + slot = devm_kzalloc(dev, sizeof(*slot), GFP_KERNEL); + if (!slot) + return -ENOMEM; + + if (of_graph_is_present(dev_of_node(dev))) { + slot->pwrseq = devm_pwrseq_get(dev, "pcie"); + if (IS_ERR(slot->pwrseq)) + return dev_err_probe(dev, PTR_ERR(slot->pwrseq), + "Failed to get the power sequencer\n"); + + goto skip_resources; + } + + ret = of_regulator_bulk_get_all(dev, dev_of_node(dev), + &slot->supplies); + if (ret < 0) { + dev_err_probe(dev, ret, "Failed to get slot regulators\n"); + return ret; + } + + slot->num_supplies = ret; + + 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"); + } + +skip_resources: + slot->pwrctrl.power_on = slot_pwrctrl_power_on; + slot->pwrctrl.power_off = slot_pwrctrl_power_off; + + ret = devm_add_action_or_reset(dev, devm_slot_pwrctrl_release, slot); + if (ret) + return ret; + + pci_pwrctrl_init(&slot->pwrctrl, dev); + + ret = devm_pci_pwrctrl_device_set_ready(dev, &slot->pwrctrl); + if (ret) + return dev_err_probe(dev, ret, "Failed to register pwrctrl driver\n"); + + return 0; +} + +static const struct of_device_id slot_pwrctrl_of_match[] = { + { + .compatible = "pciclass,0604", + }, + { } +}; +MODULE_DEVICE_TABLE(of, slot_pwrctrl_of_match); + +static struct platform_driver slot_pwrctrl_driver = { + .driver = { + .name = "pci-pwrctrl-slot", + .of_match_table = slot_pwrctrl_of_match, + }, + .probe = slot_pwrctrl_probe, +}; +module_platform_driver(slot_pwrctrl_driver); + +MODULE_AUTHOR("Manivannan Sadhasivam "); +MODULE_DESCRIPTION("Generic PCI Power Control driver for PCI Slots"); +MODULE_LICENSE("GPL"); diff --git a/drivers/pci/pwrctrl/slot.c b/drivers/pci/pwrctrl/slot.c deleted file mode 100644 index 082af81efe25..000000000000 --- a/drivers/pci/pwrctrl/slot.c +++ /dev/null @@ -1,140 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2024 Linaro Ltd. - * Author: Manivannan Sadhasivam - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct slot_pwrctrl { - struct pci_pwrctrl pwrctrl; - struct regulator_bulk_data *supplies; - int num_supplies; - struct clk *clk; - struct pwrseq_desc *pwrseq; -}; - -static int slot_pwrctrl_power_on(struct pci_pwrctrl *pwrctrl) -{ - struct slot_pwrctrl *slot = container_of(pwrctrl, - struct slot_pwrctrl, pwrctrl); - int ret; - - if (slot->pwrseq) { - pwrseq_power_on(slot->pwrseq); - return 0; - } - - 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); - - if (slot->pwrseq) { - pwrseq_power_off(slot->pwrseq); - return 0; - } - - 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); -} - -static int slot_pwrctrl_probe(struct platform_device *pdev) -{ - struct slot_pwrctrl *slot; - struct device *dev = &pdev->dev; - int ret; - - slot = devm_kzalloc(dev, sizeof(*slot), GFP_KERNEL); - if (!slot) - return -ENOMEM; - - if (of_graph_is_present(dev_of_node(dev))) { - slot->pwrseq = devm_pwrseq_get(dev, "pcie"); - if (IS_ERR(slot->pwrseq)) - return dev_err_probe(dev, PTR_ERR(slot->pwrseq), - "Failed to get the power sequencer\n"); - - goto skip_resources; - } - - ret = of_regulator_bulk_get_all(dev, dev_of_node(dev), - &slot->supplies); - if (ret < 0) { - dev_err_probe(dev, ret, "Failed to get slot regulators\n"); - return ret; - } - - slot->num_supplies = ret; - - 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"); - } - -skip_resources: - slot->pwrctrl.power_on = slot_pwrctrl_power_on; - slot->pwrctrl.power_off = slot_pwrctrl_power_off; - - ret = devm_add_action_or_reset(dev, devm_slot_pwrctrl_release, slot); - if (ret) - return ret; - - pci_pwrctrl_init(&slot->pwrctrl, dev); - - ret = devm_pci_pwrctrl_device_set_ready(dev, &slot->pwrctrl); - if (ret) - return dev_err_probe(dev, ret, "Failed to register pwrctrl driver\n"); - - return 0; -} - -static const struct of_device_id slot_pwrctrl_of_match[] = { - { - .compatible = "pciclass,0604", - }, - { } -}; -MODULE_DEVICE_TABLE(of, slot_pwrctrl_of_match); - -static struct platform_driver slot_pwrctrl_driver = { - .driver = { - .name = "pci-pwrctrl-slot", - .of_match_table = slot_pwrctrl_of_match, - }, - .probe = slot_pwrctrl_probe, -}; -module_platform_driver(slot_pwrctrl_driver); - -MODULE_AUTHOR("Manivannan Sadhasivam "); -MODULE_DESCRIPTION("Generic PCI Power Control driver for PCI Slots"); -MODULE_LICENSE("GPL"); -- cgit v1.2.3