Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'pci/pwrctrl'

- Rename pwrseq, tc9563, and slot driver structs, variables, and functions
for consistency (Bjorn Helgaas)

- Add power_on/off callbacks with generic signature to pwrseq, tc9563, and
slot drivers so they can be used by pwrctrl core (Manivannan Sadhasivam)

- Add interfaces to create and destroy pwrctrl devices (Krishna Chaitanya
Chundru)

- Add interfaces to power devices on and off (Manivannan Sadhasivam)

- Switch to pwrctrl interfaces to create, destroy, and power on/off
devices, calling them from host controller drivers instead of the PCI
core (Manivannan Sadhasivam)

- Drop qcom .assert_perst() callbacks since this is now done by the
controller driver instead of the pwrctrl driver (Manivannan Sadhasivam)

- Add PCIe M.2 connector support to the slot pwrctrl driver (Manivannan
Sadhasivam)

- Create pwrctrl devices for devicetree PCIe M.2 connector nodes
(Manivannan Sadhasivam)

* pci/pwrctrl:
PCI/pwrctrl: Create pwrctrl device if graph port is found
PCI/pwrctrl: Add PCIe M.2 connector support
PCI: Drop the assert_perst() callback
PCI: qcom: Drop the assert_perst() callbacks
PCI/pwrctrl: Switch to pwrctrl create, power on/off, destroy APIs
PCI/pwrctrl: Add APIs to power on/off pwrctrl devices
PCI/pwrctrl: Add APIs to create, destroy pwrctrl devices
PCI/pwrctrl: Add 'struct pci_pwrctrl::power_{on/off}' callbacks
PCI/pwrctrl: pwrseq: Factor out power on/off code to helpers
PCI/pwrctrl: slot: Factor out power on/off code to helpers
PCI/pwrctrl: tc9563: Rename private struct and pointers for consistency
PCI/pwrctrl: tc9563: Add local variables to reduce repetition
PCI/pwrctrl: tc9563: Clean up whitespace
PCI/pwrctrl: tc9563: Use put_device() instead of i2c_put_adapter()
PCI/pwrctrl: slot: Rename private struct and pointers for consistency
PCI/pwrctrl: pwrseq: Rename private struct and pointers for consistency

# Conflicts:
# drivers/pci/bus.c

+527 -318
-19
drivers/pci/bus.c
··· 345 345 void pci_bus_add_device(struct pci_dev *dev) 346 346 { 347 347 struct device_node *dn = dev->dev.of_node; 348 - struct platform_device *pdev; 349 348 350 349 /* 351 350 * Can not put in pci_device_add yet because resources ··· 360 361 361 362 /* Save config space for error recoverability */ 362 363 pci_save_state(dev); 363 - 364 - /* 365 - * If the PCI device is associated with a pwrctrl device with a 366 - * power supply, create a device link between the PCI device and 367 - * pwrctrl device. This ensures that pwrctrl drivers are probed 368 - * before PCI client drivers. 369 - */ 370 - pdev = of_find_device_by_node(dn); 371 - if (pdev) { 372 - if (of_pci_supply_present(dn)) { 373 - if (!device_link_add(&dev->dev, &pdev->dev, 374 - DL_FLAG_AUTOREMOVE_CONSUMER)) { 375 - pci_err(dev, "failed to add device link to power control device %s\n", 376 - pdev->name); 377 - } 378 - } 379 - put_device(&pdev->dev); 380 - } 381 364 382 365 /* 383 366 * Enable runtime PM, which potentially allows the device to
-9
drivers/pci/controller/dwc/pcie-designware-host.c
··· 857 857 return pci->dbi_base + where; 858 858 } 859 859 860 - static int dw_pcie_op_assert_perst(struct pci_bus *bus, bool assert) 861 - { 862 - struct dw_pcie_rp *pp = bus->sysdata; 863 - struct dw_pcie *pci = to_dw_pcie_from_pp(pp); 864 - 865 - return dw_pcie_assert_perst(pci, assert); 866 - } 867 - 868 860 static struct pci_ops dw_pcie_ops = { 869 861 .map_bus = dw_pcie_own_conf_map_bus, 870 862 .read = pci_generic_config_read, 871 863 .write = pci_generic_config_write, 872 - .assert_perst = dw_pcie_op_assert_perst, 873 864 }; 874 865 875 866 static struct pci_ops dw_pcie_ecam_ops = {
-9
drivers/pci/controller/dwc/pcie-designware.h
··· 493 493 enum dw_pcie_ltssm (*get_ltssm)(struct dw_pcie *pcie); 494 494 int (*start_link)(struct dw_pcie *pcie); 495 495 void (*stop_link)(struct dw_pcie *pcie); 496 - int (*assert_perst)(struct dw_pcie *pcie, bool assert); 497 496 }; 498 497 499 498 struct debugfs_info { ··· 795 796 { 796 797 if (pci->ops && pci->ops->stop_link) 797 798 pci->ops->stop_link(pci); 798 - } 799 - 800 - static inline int dw_pcie_assert_perst(struct dw_pcie *pci, bool assert) 801 - { 802 - if (pci->ops && pci->ops->assert_perst) 803 - return pci->ops->assert_perst(pci, assert); 804 - 805 - return 0; 806 799 } 807 800 808 801 static inline enum dw_pcie_ltssm dw_pcie_get_ltssm(struct dw_pcie *pci)
+22 -15
drivers/pci/controller/dwc/pcie-qcom.c
··· 24 24 #include <linux/of_pci.h> 25 25 #include <linux/pci.h> 26 26 #include <linux/pci-ecam.h> 27 + #include <linux/pci-pwrctrl.h> 27 28 #include <linux/pm_opp.h> 28 29 #include <linux/pm_runtime.h> 29 30 #include <linux/platform_device.h> ··· 638 637 } 639 638 640 639 qcom_pcie_clear_hpc(pcie->pci); 641 - 642 - return 0; 643 - } 644 - 645 - static int qcom_pcie_assert_perst(struct dw_pcie *pci, bool assert) 646 - { 647 - struct qcom_pcie *pcie = to_qcom_pcie(pci); 648 - 649 - if (assert) 650 - qcom_ep_reset_assert(pcie); 651 - else 652 - qcom_ep_reset_deassert(pcie); 653 640 654 641 return 0; 655 642 } ··· 1299 1310 if (ret) 1300 1311 goto err_deinit; 1301 1312 1313 + ret = pci_pwrctrl_create_devices(pci->dev); 1314 + if (ret) 1315 + goto err_disable_phy; 1316 + 1317 + ret = pci_pwrctrl_power_on_devices(pci->dev); 1318 + if (ret) 1319 + goto err_pwrctrl_destroy; 1320 + 1302 1321 if (pcie->cfg->ops->post_init) { 1303 1322 ret = pcie->cfg->ops->post_init(pcie); 1304 1323 if (ret) 1305 - goto err_disable_phy; 1324 + goto err_pwrctrl_power_off; 1306 1325 } 1307 1326 1308 1327 qcom_ep_reset_deassert(pcie); ··· 1325 1328 1326 1329 err_assert_reset: 1327 1330 qcom_ep_reset_assert(pcie); 1331 + err_pwrctrl_power_off: 1332 + pci_pwrctrl_power_off_devices(pci->dev); 1333 + err_pwrctrl_destroy: 1334 + if (ret != -EPROBE_DEFER) 1335 + pci_pwrctrl_destroy_devices(pci->dev); 1328 1336 err_disable_phy: 1329 1337 qcom_pcie_phy_power_off(pcie); 1330 1338 err_deinit: ··· 1344 1342 struct qcom_pcie *pcie = to_qcom_pcie(pci); 1345 1343 1346 1344 qcom_ep_reset_assert(pcie); 1345 + 1346 + /* 1347 + * No need to destroy pwrctrl devices as this function only gets called 1348 + * during system suspend as of now. 1349 + */ 1350 + pci_pwrctrl_power_off_devices(pci->dev); 1347 1351 qcom_pcie_phy_power_off(pcie); 1348 1352 pcie->cfg->ops->deinit(pcie); 1349 1353 } ··· 1502 1494 static const struct dw_pcie_ops dw_pcie_ops = { 1503 1495 .link_up = qcom_pcie_link_up, 1504 1496 .start_link = qcom_pcie_start_link, 1505 - .assert_perst = qcom_pcie_assert_perst, 1506 1497 }; 1507 1498 1508 1499 static int qcom_pcie_icc_init(struct qcom_pcie *pcie) ··· 1968 1961 1969 1962 ret = dw_pcie_host_init(pp); 1970 1963 if (ret) { 1971 - dev_err(dev, "cannot initialize host\n"); 1964 + dev_err_probe(dev, ret, "cannot initialize host\n"); 1972 1965 goto err_phy_exit; 1973 1966 } 1974 1967
+1
drivers/pci/of.c
··· 867 867 868 868 return false; 869 869 } 870 + EXPORT_SYMBOL_GPL(of_pci_supply_present); 870 871 871 872 #endif /* CONFIG_PCI */ 872 873
-59
drivers/pci/probe.c
··· 2596 2596 } 2597 2597 EXPORT_SYMBOL(pci_bus_read_dev_vendor_id); 2598 2598 2599 - #if IS_ENABLED(CONFIG_PCI_PWRCTRL) 2600 - static struct platform_device *pci_pwrctrl_create_device(struct pci_bus *bus, int devfn) 2601 - { 2602 - struct pci_host_bridge *host = pci_find_host_bridge(bus); 2603 - struct platform_device *pdev; 2604 - struct device_node *np; 2605 - 2606 - np = of_pci_find_child_device(dev_of_node(&bus->dev), devfn); 2607 - if (!np) 2608 - return NULL; 2609 - 2610 - pdev = of_find_device_by_node(np); 2611 - if (pdev) { 2612 - put_device(&pdev->dev); 2613 - goto err_put_of_node; 2614 - } 2615 - 2616 - /* 2617 - * First check whether the pwrctrl device really needs to be created or 2618 - * not. This is decided based on at least one of the power supplies 2619 - * being defined in the devicetree node of the device. 2620 - */ 2621 - if (!of_pci_supply_present(np)) { 2622 - pr_debug("PCI/pwrctrl: Skipping OF node: %s\n", np->name); 2623 - goto err_put_of_node; 2624 - } 2625 - 2626 - /* Now create the pwrctrl device */ 2627 - pdev = of_platform_device_create(np, NULL, &host->dev); 2628 - if (!pdev) { 2629 - pr_err("PCI/pwrctrl: Failed to create pwrctrl device for node: %s\n", np->name); 2630 - goto err_put_of_node; 2631 - } 2632 - 2633 - of_node_put(np); 2634 - 2635 - return pdev; 2636 - 2637 - err_put_of_node: 2638 - of_node_put(np); 2639 - 2640 - return NULL; 2641 - } 2642 - #else 2643 - static struct platform_device *pci_pwrctrl_create_device(struct pci_bus *bus, int devfn) 2644 - { 2645 - return NULL; 2646 - } 2647 - #endif 2648 - 2649 2599 /* 2650 2600 * Read the config data for a PCI device, sanity-check it, 2651 2601 * and fill in the dev structure. ··· 2604 2654 { 2605 2655 struct pci_dev *dev; 2606 2656 u32 l; 2607 - 2608 - /* 2609 - * Create pwrctrl device (if required) for the PCI device to handle the 2610 - * power state. If the pwrctrl device is created, then skip scanning 2611 - * further as the pwrctrl core will rescan the bus after powering on 2612 - * the device. 2613 - */ 2614 - if (pci_pwrctrl_create_device(bus, devfn)) 2615 - return NULL; 2616 2657 2617 2658 if (!pci_bus_read_dev_vendor_id(bus, devfn, &l, 60*1000)) 2618 2659 return NULL;
+1
drivers/pci/pwrctrl/Kconfig
··· 13 13 14 14 config PCI_PWRCTRL_SLOT 15 15 tristate "PCI Power Control driver for PCI slots" 16 + select POWER_SEQUENCING 16 17 select PCI_PWRCTRL 17 18 help 18 19 Say Y here to enable the PCI Power Control driver to control the power
+245 -15
drivers/pci/pwrctrl/core.c
··· 3 3 * Copyright (C) 2024 Linaro Ltd. 4 4 */ 5 5 6 + #define dev_fmt(fmt) "pwrctrl: " fmt 7 + 6 8 #include <linux/device.h> 7 9 #include <linux/export.h> 8 10 #include <linux/kernel.h> 11 + #include <linux/of.h> 12 + #include <linux/of_graph.h> 13 + #include <linux/of_platform.h> 9 14 #include <linux/pci.h> 10 15 #include <linux/pci-pwrctrl.h> 16 + #include <linux/platform_device.h> 11 17 #include <linux/property.h> 12 18 #include <linux/slab.h> 19 + 20 + #include "../pci.h" 13 21 14 22 static int pci_pwrctrl_notify(struct notifier_block *nb, unsigned long action, 15 23 void *data) ··· 46 38 return NOTIFY_DONE; 47 39 } 48 40 49 - static void rescan_work_func(struct work_struct *work) 50 - { 51 - struct pci_pwrctrl *pwrctrl = container_of(work, 52 - struct pci_pwrctrl, work); 53 - 54 - pci_lock_rescan_remove(); 55 - pci_rescan_bus(to_pci_host_bridge(pwrctrl->dev->parent)->bus); 56 - pci_unlock_rescan_remove(); 57 - } 58 - 59 41 /** 60 42 * pci_pwrctrl_init() - Initialize the PCI power control context struct 61 43 * ··· 55 57 void pci_pwrctrl_init(struct pci_pwrctrl *pwrctrl, struct device *dev) 56 58 { 57 59 pwrctrl->dev = dev; 58 - INIT_WORK(&pwrctrl->work, rescan_work_func); 60 + dev_set_drvdata(dev, pwrctrl); 59 61 } 60 62 EXPORT_SYMBOL_GPL(pci_pwrctrl_init); 61 63 ··· 85 87 if (ret) 86 88 return ret; 87 89 88 - schedule_work(&pwrctrl->work); 89 - 90 90 return 0; 91 91 } 92 92 EXPORT_SYMBOL_GPL(pci_pwrctrl_device_set_ready); ··· 97 101 */ 98 102 void pci_pwrctrl_device_unset_ready(struct pci_pwrctrl *pwrctrl) 99 103 { 100 - cancel_work_sync(&pwrctrl->work); 101 - 102 104 /* 103 105 * We don't have to delete the link here. Typically, this function 104 106 * is only called when the power control device is being detached. If ··· 138 144 pwrctrl); 139 145 } 140 146 EXPORT_SYMBOL_GPL(devm_pci_pwrctrl_device_set_ready); 147 + 148 + static int __pci_pwrctrl_power_off_device(struct device *dev) 149 + { 150 + struct pci_pwrctrl *pwrctrl = dev_get_drvdata(dev); 151 + 152 + if (!pwrctrl) 153 + return 0; 154 + 155 + return pwrctrl->power_off(pwrctrl); 156 + } 157 + 158 + static void pci_pwrctrl_power_off_device(struct device_node *np) 159 + { 160 + struct platform_device *pdev; 161 + int ret; 162 + 163 + for_each_available_child_of_node_scoped(np, child) 164 + pci_pwrctrl_power_off_device(child); 165 + 166 + pdev = of_find_device_by_node(np); 167 + if (!pdev) 168 + return; 169 + 170 + if (device_is_bound(&pdev->dev)) { 171 + ret = __pci_pwrctrl_power_off_device(&pdev->dev); 172 + if (ret) 173 + dev_err(&pdev->dev, "Failed to power off device: %d", ret); 174 + } 175 + 176 + platform_device_put(pdev); 177 + } 178 + 179 + /** 180 + * pci_pwrctrl_power_off_devices - Power off pwrctrl devices 181 + * 182 + * @parent: PCI host controller device 183 + * 184 + * Recursively traverse all pwrctrl devices for the devicetree hierarchy 185 + * below the specified PCI host controller and power them off in a depth 186 + * first manner. 187 + */ 188 + void pci_pwrctrl_power_off_devices(struct device *parent) 189 + { 190 + struct device_node *np = parent->of_node; 191 + 192 + for_each_available_child_of_node_scoped(np, child) 193 + pci_pwrctrl_power_off_device(child); 194 + } 195 + EXPORT_SYMBOL_GPL(pci_pwrctrl_power_off_devices); 196 + 197 + static int __pci_pwrctrl_power_on_device(struct device *dev) 198 + { 199 + struct pci_pwrctrl *pwrctrl = dev_get_drvdata(dev); 200 + 201 + if (!pwrctrl) 202 + return 0; 203 + 204 + return pwrctrl->power_on(pwrctrl); 205 + } 206 + 207 + /* 208 + * Power on the devices in a depth first manner. Before powering on the device, 209 + * make sure its driver is bound. 210 + */ 211 + static int pci_pwrctrl_power_on_device(struct device_node *np) 212 + { 213 + struct platform_device *pdev; 214 + int ret; 215 + 216 + for_each_available_child_of_node_scoped(np, child) { 217 + ret = pci_pwrctrl_power_on_device(child); 218 + if (ret) 219 + return ret; 220 + } 221 + 222 + pdev = of_find_device_by_node(np); 223 + if (!pdev) 224 + return 0; 225 + 226 + if (device_is_bound(&pdev->dev)) { 227 + ret = __pci_pwrctrl_power_on_device(&pdev->dev); 228 + } else { 229 + /* FIXME: Use blocking wait instead of probe deferral */ 230 + dev_dbg(&pdev->dev, "driver is not bound\n"); 231 + ret = -EPROBE_DEFER; 232 + } 233 + 234 + platform_device_put(pdev); 235 + 236 + return ret; 237 + } 238 + 239 + /** 240 + * pci_pwrctrl_power_on_devices - Power on pwrctrl devices 241 + * 242 + * @parent: PCI host controller device 243 + * 244 + * Recursively traverse all pwrctrl devices for the devicetree hierarchy 245 + * below the specified PCI host controller and power them on in a depth 246 + * first manner. On error, all powered on devices will be powered off. 247 + * 248 + * Return: 0 on success, -EPROBE_DEFER if any pwrctrl driver is not bound, an 249 + * appropriate error code otherwise. 250 + */ 251 + int pci_pwrctrl_power_on_devices(struct device *parent) 252 + { 253 + struct device_node *np = parent->of_node; 254 + struct device_node *child = NULL; 255 + int ret; 256 + 257 + for_each_available_child_of_node(np, child) { 258 + ret = pci_pwrctrl_power_on_device(child); 259 + if (ret) 260 + goto err_power_off; 261 + } 262 + 263 + return 0; 264 + 265 + err_power_off: 266 + for_each_available_child_of_node_scoped(np, tmp) { 267 + if (tmp == child) 268 + break; 269 + pci_pwrctrl_power_off_device(tmp); 270 + } 271 + of_node_put(child); 272 + 273 + return ret; 274 + } 275 + EXPORT_SYMBOL_GPL(pci_pwrctrl_power_on_devices); 276 + 277 + static int pci_pwrctrl_create_device(struct device_node *np, 278 + struct device *parent) 279 + { 280 + struct platform_device *pdev; 281 + int ret; 282 + 283 + for_each_available_child_of_node_scoped(np, child) { 284 + ret = pci_pwrctrl_create_device(child, parent); 285 + if (ret) 286 + return ret; 287 + } 288 + 289 + /* Bail out if the platform device is already available for the node */ 290 + pdev = of_find_device_by_node(np); 291 + if (pdev) { 292 + platform_device_put(pdev); 293 + return 0; 294 + } 295 + 296 + /* 297 + * Sanity check to make sure that the node has the compatible property 298 + * to allow driver binding. 299 + */ 300 + if (!of_property_present(np, "compatible")) 301 + return 0; 302 + 303 + /* 304 + * Check whether the pwrctrl device really needs to be created or not. 305 + * This is decided based on at least one of the power supplies defined 306 + * in the devicetree node of the device or the graph property. 307 + */ 308 + if (!of_pci_supply_present(np) && !of_graph_is_present(np)) { 309 + dev_dbg(parent, "Skipping OF node: %s\n", np->name); 310 + return 0; 311 + } 312 + 313 + /* Now create the pwrctrl device */ 314 + pdev = of_platform_device_create(np, NULL, parent); 315 + if (!pdev) { 316 + dev_err(parent, "Failed to create pwrctrl device for node: %s\n", np->name); 317 + return -EINVAL; 318 + } 319 + 320 + return 0; 321 + } 322 + 323 + /** 324 + * pci_pwrctrl_create_devices - Create pwrctrl devices 325 + * 326 + * @parent: PCI host controller device 327 + * 328 + * Recursively create pwrctrl devices for the devicetree hierarchy below 329 + * the specified PCI host controller in a depth first manner. On error, all 330 + * created devices will be destroyed. 331 + * 332 + * Return: 0 on success, negative error number on error. 333 + */ 334 + int pci_pwrctrl_create_devices(struct device *parent) 335 + { 336 + int ret; 337 + 338 + for_each_available_child_of_node_scoped(parent->of_node, child) { 339 + ret = pci_pwrctrl_create_device(child, parent); 340 + if (ret) { 341 + pci_pwrctrl_destroy_devices(parent); 342 + return ret; 343 + } 344 + } 345 + 346 + return 0; 347 + } 348 + EXPORT_SYMBOL_GPL(pci_pwrctrl_create_devices); 349 + 350 + static void pci_pwrctrl_destroy_device(struct device_node *np) 351 + { 352 + struct platform_device *pdev; 353 + 354 + for_each_available_child_of_node_scoped(np, child) 355 + pci_pwrctrl_destroy_device(child); 356 + 357 + pdev = of_find_device_by_node(np); 358 + if (!pdev) 359 + return; 360 + 361 + of_device_unregister(pdev); 362 + platform_device_put(pdev); 363 + 364 + of_node_clear_flag(np, OF_POPULATED); 365 + } 366 + 367 + /** 368 + * pci_pwrctrl_destroy_devices - Destroy pwrctrl devices 369 + * 370 + * @parent: PCI host controller device 371 + * 372 + * Recursively destroy pwrctrl devices for the devicetree hierarchy below 373 + * the specified PCI host controller in a depth first manner. 374 + */ 375 + void pci_pwrctrl_destroy_devices(struct device *parent) 376 + { 377 + struct device_node *np = parent->of_node; 378 + 379 + for_each_available_child_of_node_scoped(np, child) 380 + pci_pwrctrl_destroy_device(child); 381 + } 382 + EXPORT_SYMBOL_GPL(pci_pwrctrl_destroy_devices); 141 383 142 384 MODULE_AUTHOR("Bartosz Golaszewski <bartosz.golaszewski@linaro.org>"); 143 385 MODULE_DESCRIPTION("PCI Device Power Control core driver");
+49 -35
drivers/pci/pwrctrl/pci-pwrctrl-pwrseq.c
··· 13 13 #include <linux/slab.h> 14 14 #include <linux/types.h> 15 15 16 - struct pci_pwrctrl_pwrseq_data { 17 - struct pci_pwrctrl ctx; 16 + struct pwrseq_pwrctrl { 17 + struct pci_pwrctrl pwrctrl; 18 18 struct pwrseq_desc *pwrseq; 19 19 }; 20 20 21 - struct pci_pwrctrl_pwrseq_pdata { 21 + struct pwrseq_pwrctrl_pdata { 22 22 const char *target; 23 23 /* 24 24 * Called before doing anything else to perform device-specific ··· 27 27 int (*validate_device)(struct device *dev); 28 28 }; 29 29 30 - static int pci_pwrctrl_pwrseq_qcm_wcn_validate_device(struct device *dev) 30 + static int pwrseq_pwrctrl_qcm_wcn_validate_device(struct device *dev) 31 31 { 32 32 /* 33 33 * Old device trees for some platforms already define wifi nodes for ··· 47 47 return 0; 48 48 } 49 49 50 - static const struct pci_pwrctrl_pwrseq_pdata pci_pwrctrl_pwrseq_qcom_wcn_pdata = { 50 + static const struct pwrseq_pwrctrl_pdata pwrseq_pwrctrl_qcom_wcn_pdata = { 51 51 .target = "wlan", 52 - .validate_device = pci_pwrctrl_pwrseq_qcm_wcn_validate_device, 52 + .validate_device = pwrseq_pwrctrl_qcm_wcn_validate_device, 53 53 }; 54 54 55 - static void devm_pci_pwrctrl_pwrseq_power_off(void *data) 55 + static int pwrseq_pwrctrl_power_on(struct pci_pwrctrl *pwrctrl) 56 56 { 57 - struct pwrseq_desc *pwrseq = data; 57 + struct pwrseq_pwrctrl *pwrseq = container_of(pwrctrl, 58 + struct pwrseq_pwrctrl, pwrctrl); 58 59 59 - pwrseq_power_off(pwrseq); 60 + return pwrseq_power_on(pwrseq->pwrseq); 60 61 } 61 62 62 - static int pci_pwrctrl_pwrseq_probe(struct platform_device *pdev) 63 + static int pwrseq_pwrctrl_power_off(struct pci_pwrctrl *pwrctrl) 63 64 { 64 - const struct pci_pwrctrl_pwrseq_pdata *pdata; 65 - struct pci_pwrctrl_pwrseq_data *data; 65 + struct pwrseq_pwrctrl *pwrseq = container_of(pwrctrl, 66 + struct pwrseq_pwrctrl, pwrctrl); 67 + 68 + return pwrseq_power_off(pwrseq->pwrseq); 69 + } 70 + 71 + static void devm_pwrseq_pwrctrl_power_off(void *data) 72 + { 73 + struct pwrseq_pwrctrl *pwrseq = data; 74 + 75 + pwrseq_pwrctrl_power_off(&pwrseq->pwrctrl); 76 + } 77 + 78 + static int pwrseq_pwrctrl_probe(struct platform_device *pdev) 79 + { 80 + const struct pwrseq_pwrctrl_pdata *pdata; 81 + struct pwrseq_pwrctrl *pwrseq; 66 82 struct device *dev = &pdev->dev; 67 83 int ret; 68 84 ··· 92 76 return ret; 93 77 } 94 78 95 - data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 96 - if (!data) 79 + pwrseq = devm_kzalloc(dev, sizeof(*pwrseq), GFP_KERNEL); 80 + if (!pwrseq) 97 81 return -ENOMEM; 98 82 99 - data->pwrseq = devm_pwrseq_get(dev, pdata->target); 100 - if (IS_ERR(data->pwrseq)) 101 - return dev_err_probe(dev, PTR_ERR(data->pwrseq), 83 + pwrseq->pwrseq = devm_pwrseq_get(dev, pdata->target); 84 + if (IS_ERR(pwrseq->pwrseq)) 85 + return dev_err_probe(dev, PTR_ERR(pwrseq->pwrseq), 102 86 "Failed to get the power sequencer\n"); 103 87 104 - ret = pwrseq_power_on(data->pwrseq); 105 - if (ret) 106 - return dev_err_probe(dev, ret, 107 - "Failed to power-on the device\n"); 108 - 109 - ret = devm_add_action_or_reset(dev, devm_pci_pwrctrl_pwrseq_power_off, 110 - data->pwrseq); 88 + ret = devm_add_action_or_reset(dev, devm_pwrseq_pwrctrl_power_off, 89 + pwrseq); 111 90 if (ret) 112 91 return ret; 113 92 114 - pci_pwrctrl_init(&data->ctx, dev); 93 + pwrseq->pwrctrl.power_on = pwrseq_pwrctrl_power_on; 94 + pwrseq->pwrctrl.power_off = pwrseq_pwrctrl_power_off; 115 95 116 - ret = devm_pci_pwrctrl_device_set_ready(dev, &data->ctx); 96 + pci_pwrctrl_init(&pwrseq->pwrctrl, dev); 97 + 98 + ret = devm_pci_pwrctrl_device_set_ready(dev, &pwrseq->pwrctrl); 117 99 if (ret) 118 100 return dev_err_probe(dev, ret, 119 101 "Failed to register the pwrctrl wrapper\n"); ··· 119 105 return 0; 120 106 } 121 107 122 - static const struct of_device_id pci_pwrctrl_pwrseq_of_match[] = { 108 + static const struct of_device_id pwrseq_pwrctrl_of_match[] = { 123 109 { 124 110 /* ATH11K in QCA6390 package. */ 125 111 .compatible = "pci17cb,1101", 126 - .data = &pci_pwrctrl_pwrseq_qcom_wcn_pdata, 112 + .data = &pwrseq_pwrctrl_qcom_wcn_pdata, 127 113 }, 128 114 { 129 115 /* ATH11K in WCN6855 package. */ 130 116 .compatible = "pci17cb,1103", 131 - .data = &pci_pwrctrl_pwrseq_qcom_wcn_pdata, 117 + .data = &pwrseq_pwrctrl_qcom_wcn_pdata, 132 118 }, 133 119 { 134 120 /* ATH12K in WCN7850 package. */ 135 121 .compatible = "pci17cb,1107", 136 - .data = &pci_pwrctrl_pwrseq_qcom_wcn_pdata, 122 + .data = &pwrseq_pwrctrl_qcom_wcn_pdata, 137 123 }, 138 124 { } 139 125 }; 140 - MODULE_DEVICE_TABLE(of, pci_pwrctrl_pwrseq_of_match); 126 + MODULE_DEVICE_TABLE(of, pwrseq_pwrctrl_of_match); 141 127 142 - static struct platform_driver pci_pwrctrl_pwrseq_driver = { 128 + static struct platform_driver pwrseq_pwrctrl_driver = { 143 129 .driver = { 144 130 .name = "pci-pwrctrl-pwrseq", 145 - .of_match_table = pci_pwrctrl_pwrseq_of_match, 131 + .of_match_table = pwrseq_pwrctrl_of_match, 146 132 }, 147 - .probe = pci_pwrctrl_pwrseq_probe, 133 + .probe = pwrseq_pwrctrl_probe, 148 134 }; 149 - module_platform_driver(pci_pwrctrl_pwrseq_driver); 135 + module_platform_driver(pwrseq_pwrctrl_driver); 150 136 151 137 MODULE_AUTHOR("Bartosz Golaszewski <bartosz.golaszewski@linaro.org>"); 152 138 MODULE_DESCRIPTION("Generic PCI Power Control module for power sequenced devices");
+120 -106
drivers/pci/pwrctrl/pci-pwrctrl-tc9563.c
··· 59 59 #define TC9563_POWER_CONTROL_OVREN 0x82b2c8 60 60 61 61 #define TC9563_GPIO_MASK 0xfffffff3 62 - #define TC9563_GPIO_DEASSERT_BITS 0xc /* Bits to clear for GPIO deassert */ 62 + #define TC9563_GPIO_DEASSERT_BITS 0xc /* Clear to deassert GPIO */ 63 63 64 64 #define TC9563_TX_MARGIN_MIN_UA 400000 65 65 ··· 69 69 */ 70 70 #define TC9563_OSC_STAB_DELAY_US (10 * USEC_PER_MSEC) 71 71 72 - #define TC9563_L0S_L1_DELAY_UNIT_NS 256 /* Each unit represents 256 nanoseconds */ 72 + #define TC9563_L0S_L1_DELAY_UNIT_NS 256 /* Each unit represents 256 ns */ 73 73 74 74 struct tc9563_pwrctrl_reg_setting { 75 75 unsigned int offset; ··· 105 105 "vddio18", 106 106 }; 107 107 108 - struct tc9563_pwrctrl_ctx { 108 + struct tc9563_pwrctrl { 109 + struct pci_pwrctrl pwrctrl; 109 110 struct regulator_bulk_data supplies[TC9563_PWRCTL_MAX_SUPPLY]; 110 111 struct tc9563_pwrctrl_cfg cfg[TC9563_MAX]; 111 112 struct gpio_desc *reset_gpio; 112 113 struct i2c_adapter *adapter; 113 114 struct i2c_client *client; 114 - struct pci_pwrctrl pwrctrl; 115 115 }; 116 116 117 117 /* ··· 217 217 } 218 218 219 219 static int tc9563_pwrctrl_i2c_bulk_write(struct i2c_client *client, 220 - const struct tc9563_pwrctrl_reg_setting *seq, int len) 220 + const struct tc9563_pwrctrl_reg_setting *seq, 221 + int len) 221 222 { 222 223 int ret, i; 223 224 ··· 231 230 return 0; 232 231 } 233 232 234 - static int tc9563_pwrctrl_disable_port(struct tc9563_pwrctrl_ctx *ctx, 233 + static int tc9563_pwrctrl_disable_port(struct tc9563_pwrctrl *tc9563, 235 234 enum tc9563_pwrctrl_ports port) 236 235 { 237 - struct tc9563_pwrctrl_cfg *cfg = &ctx->cfg[port]; 236 + struct tc9563_pwrctrl_cfg *cfg = &tc9563->cfg[port]; 238 237 const struct tc9563_pwrctrl_reg_setting *seq; 239 238 int ret, len; 240 239 ··· 249 248 len = ARRAY_SIZE(dsp2_pwroff_seq); 250 249 } 251 250 252 - ret = tc9563_pwrctrl_i2c_bulk_write(ctx->client, seq, len); 251 + ret = tc9563_pwrctrl_i2c_bulk_write(tc9563->client, seq, len); 253 252 if (ret) 254 253 return ret; 255 254 256 - return tc9563_pwrctrl_i2c_bulk_write(ctx->client, 257 - common_pwroff_seq, ARRAY_SIZE(common_pwroff_seq)); 255 + return tc9563_pwrctrl_i2c_bulk_write(tc9563->client, common_pwroff_seq, 256 + ARRAY_SIZE(common_pwroff_seq)); 258 257 } 259 258 260 - static int tc9563_pwrctrl_set_l0s_l1_entry_delay(struct tc9563_pwrctrl_ctx *ctx, 261 - enum tc9563_pwrctrl_ports port, bool is_l1, u32 ns) 259 + static int tc9563_pwrctrl_set_l0s_l1_entry_delay(struct tc9563_pwrctrl *tc9563, 260 + enum tc9563_pwrctrl_ports port, 261 + bool is_l1, u32 ns) 262 262 { 263 263 u32 rd_val, units; 264 264 int ret; ··· 271 269 units = ns / TC9563_L0S_L1_DELAY_UNIT_NS; 272 270 273 271 if (port == TC9563_ETHERNET) { 274 - ret = tc9563_pwrctrl_i2c_read(ctx->client, TC9563_EMBEDDED_ETH_DELAY, &rd_val); 272 + ret = tc9563_pwrctrl_i2c_read(tc9563->client, 273 + TC9563_EMBEDDED_ETH_DELAY, 274 + &rd_val); 275 275 if (ret) 276 276 return ret; 277 277 278 278 if (is_l1) 279 - rd_val = u32_replace_bits(rd_val, units, TC9563_ETH_L1_DELAY_MASK); 279 + rd_val = u32_replace_bits(rd_val, units, 280 + TC9563_ETH_L1_DELAY_MASK); 280 281 else 281 - rd_val = u32_replace_bits(rd_val, units, TC9563_ETH_L0S_DELAY_MASK); 282 + rd_val = u32_replace_bits(rd_val, units, 283 + TC9563_ETH_L0S_DELAY_MASK); 282 284 283 - return tc9563_pwrctrl_i2c_write(ctx->client, TC9563_EMBEDDED_ETH_DELAY, rd_val); 285 + return tc9563_pwrctrl_i2c_write(tc9563->client, 286 + TC9563_EMBEDDED_ETH_DELAY, 287 + rd_val); 284 288 } 285 289 286 - ret = tc9563_pwrctrl_i2c_write(ctx->client, TC9563_PORT_SELECT, BIT(port)); 290 + ret = tc9563_pwrctrl_i2c_write(tc9563->client, TC9563_PORT_SELECT, 291 + BIT(port)); 287 292 if (ret) 288 293 return ret; 289 294 290 - return tc9563_pwrctrl_i2c_write(ctx->client, 291 - is_l1 ? TC9563_PORT_L1_DELAY : TC9563_PORT_L0S_DELAY, units); 295 + return tc9563_pwrctrl_i2c_write(tc9563->client, 296 + is_l1 ? TC9563_PORT_L1_DELAY : TC9563_PORT_L0S_DELAY, 297 + units); 292 298 } 293 299 294 - static int tc9563_pwrctrl_set_tx_amplitude(struct tc9563_pwrctrl_ctx *ctx, 300 + static int tc9563_pwrctrl_set_tx_amplitude(struct tc9563_pwrctrl *tc9563, 295 301 enum tc9563_pwrctrl_ports port) 296 302 { 297 - u32 amp = ctx->cfg[port].tx_amp; 303 + u32 amp = tc9563->cfg[port].tx_amp; 298 304 int port_access; 299 305 300 306 if (amp < TC9563_TX_MARGIN_MIN_UA) ··· 331 321 {TC9563_TX_MARGIN, amp}, 332 322 }; 333 323 334 - return tc9563_pwrctrl_i2c_bulk_write(ctx->client, tx_amp_seq, ARRAY_SIZE(tx_amp_seq)); 324 + return tc9563_pwrctrl_i2c_bulk_write(tc9563->client, tx_amp_seq, 325 + ARRAY_SIZE(tx_amp_seq)); 335 326 } 336 327 337 - static int tc9563_pwrctrl_disable_dfe(struct tc9563_pwrctrl_ctx *ctx, 328 + static int tc9563_pwrctrl_disable_dfe(struct tc9563_pwrctrl *tc9563, 338 329 enum tc9563_pwrctrl_ports port) 339 330 { 340 - struct tc9563_pwrctrl_cfg *cfg = &ctx->cfg[port]; 331 + struct tc9563_pwrctrl_cfg *cfg = &tc9563->cfg[port]; 341 332 int port_access, lane_access = 0x3; 342 333 u32 phy_rate = 0x21; 343 334 ··· 375 364 {TC9563_PHY_RATE_CHANGE_OVERRIDE, 0x0}, 376 365 }; 377 366 378 - return tc9563_pwrctrl_i2c_bulk_write(ctx->client, 379 - disable_dfe_seq, ARRAY_SIZE(disable_dfe_seq)); 367 + return tc9563_pwrctrl_i2c_bulk_write(tc9563->client, disable_dfe_seq, 368 + ARRAY_SIZE(disable_dfe_seq)); 380 369 } 381 370 382 - static int tc9563_pwrctrl_set_nfts(struct tc9563_pwrctrl_ctx *ctx, 371 + static int tc9563_pwrctrl_set_nfts(struct tc9563_pwrctrl *tc9563, 383 372 enum tc9563_pwrctrl_ports port) 384 373 { 385 - u8 *nfts = ctx->cfg[port].nfts; 374 + u8 *nfts = tc9563->cfg[port].nfts; 386 375 struct tc9563_pwrctrl_reg_setting nfts_seq[] = { 387 376 {TC9563_NFTS_2_5_GT, nfts[0]}, 388 377 {TC9563_NFTS_5_GT, nfts[1]}, ··· 392 381 if (!nfts[0]) 393 382 return 0; 394 383 395 - ret = tc9563_pwrctrl_i2c_write(ctx->client, TC9563_PORT_SELECT, BIT(port)); 384 + ret = tc9563_pwrctrl_i2c_write(tc9563->client, TC9563_PORT_SELECT, 385 + BIT(port)); 396 386 if (ret) 397 387 return ret; 398 388 399 - return tc9563_pwrctrl_i2c_bulk_write(ctx->client, nfts_seq, ARRAY_SIZE(nfts_seq)); 389 + return tc9563_pwrctrl_i2c_bulk_write(tc9563->client, nfts_seq, 390 + ARRAY_SIZE(nfts_seq)); 400 391 } 401 392 402 - static int tc9563_pwrctrl_assert_deassert_reset(struct tc9563_pwrctrl_ctx *ctx, bool deassert) 393 + static int tc9563_pwrctrl_assert_deassert_reset(struct tc9563_pwrctrl *tc9563, 394 + bool deassert) 403 395 { 404 396 int ret, val; 405 397 406 - ret = tc9563_pwrctrl_i2c_write(ctx->client, TC9563_GPIO_CONFIG, TC9563_GPIO_MASK); 398 + ret = tc9563_pwrctrl_i2c_write(tc9563->client, TC9563_GPIO_CONFIG, 399 + TC9563_GPIO_MASK); 407 400 if (ret) 408 401 return ret; 409 402 410 403 val = deassert ? TC9563_GPIO_DEASSERT_BITS : 0; 411 404 412 - return tc9563_pwrctrl_i2c_write(ctx->client, TC9563_RESET_GPIO, val); 405 + return tc9563_pwrctrl_i2c_write(tc9563->client, TC9563_RESET_GPIO, val); 413 406 } 414 407 415 - static int tc9563_pwrctrl_parse_device_dt(struct tc9563_pwrctrl_ctx *ctx, struct device_node *node, 408 + static int tc9563_pwrctrl_parse_device_dt(struct tc9563_pwrctrl *tc9563, 409 + struct device_node *node, 416 410 enum tc9563_pwrctrl_ports port) 417 411 { 418 - struct tc9563_pwrctrl_cfg *cfg = &ctx->cfg[port]; 412 + struct tc9563_pwrctrl_cfg *cfg = &tc9563->cfg[port]; 419 413 int ret; 420 414 421 415 /* Disable port if the status of the port is disabled. */ ··· 450 434 return 0; 451 435 } 452 436 453 - static void tc9563_pwrctrl_power_off(struct tc9563_pwrctrl_ctx *ctx) 437 + static int tc9563_pwrctrl_power_off(struct pci_pwrctrl *pwrctrl) 454 438 { 455 - gpiod_set_value(ctx->reset_gpio, 1); 439 + struct tc9563_pwrctrl *tc9563 = container_of(pwrctrl, 440 + struct tc9563_pwrctrl, pwrctrl); 456 441 457 - regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies); 442 + gpiod_set_value(tc9563->reset_gpio, 1); 443 + 444 + regulator_bulk_disable(ARRAY_SIZE(tc9563->supplies), tc9563->supplies); 445 + 446 + return 0; 458 447 } 459 448 460 - static int tc9563_pwrctrl_bring_up(struct tc9563_pwrctrl_ctx *ctx) 449 + static int tc9563_pwrctrl_power_on(struct pci_pwrctrl *pwrctrl) 461 450 { 451 + struct tc9563_pwrctrl *tc9563 = container_of(pwrctrl, 452 + struct tc9563_pwrctrl, pwrctrl); 453 + struct device *dev = tc9563->pwrctrl.dev; 462 454 struct tc9563_pwrctrl_cfg *cfg; 463 455 int ret, i; 464 456 465 - ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies); 457 + ret = regulator_bulk_enable(ARRAY_SIZE(tc9563->supplies), 458 + tc9563->supplies); 466 459 if (ret < 0) 467 - return dev_err_probe(ctx->pwrctrl.dev, ret, "cannot enable regulators\n"); 460 + return dev_err_probe(dev, ret, "cannot enable regulators\n"); 468 461 469 - gpiod_set_value(ctx->reset_gpio, 0); 462 + gpiod_set_value(tc9563->reset_gpio, 0); 470 463 471 464 fsleep(TC9563_OSC_STAB_DELAY_US); 472 465 473 - ret = tc9563_pwrctrl_assert_deassert_reset(ctx, false); 466 + ret = tc9563_pwrctrl_assert_deassert_reset(tc9563, false); 474 467 if (ret) 475 468 goto power_off; 476 469 477 470 for (i = 0; i < TC9563_MAX; i++) { 478 - cfg = &ctx->cfg[i]; 479 - ret = tc9563_pwrctrl_disable_port(ctx, i); 471 + cfg = &tc9563->cfg[i]; 472 + ret = tc9563_pwrctrl_disable_port(tc9563, i); 480 473 if (ret) { 481 - dev_err(ctx->pwrctrl.dev, "Disabling port failed\n"); 474 + dev_err(dev, "Disabling port failed\n"); 482 475 goto power_off; 483 476 } 484 477 485 - ret = tc9563_pwrctrl_set_l0s_l1_entry_delay(ctx, i, false, cfg->l0s_delay); 478 + ret = tc9563_pwrctrl_set_l0s_l1_entry_delay(tc9563, i, false, cfg->l0s_delay); 486 479 if (ret) { 487 - dev_err(ctx->pwrctrl.dev, "Setting L0s entry delay failed\n"); 480 + dev_err(dev, "Setting L0s entry delay failed\n"); 488 481 goto power_off; 489 482 } 490 483 491 - ret = tc9563_pwrctrl_set_l0s_l1_entry_delay(ctx, i, true, cfg->l1_delay); 484 + ret = tc9563_pwrctrl_set_l0s_l1_entry_delay(tc9563, i, true, cfg->l1_delay); 492 485 if (ret) { 493 - dev_err(ctx->pwrctrl.dev, "Setting L1 entry delay failed\n"); 486 + dev_err(dev, "Setting L1 entry delay failed\n"); 494 487 goto power_off; 495 488 } 496 489 497 - ret = tc9563_pwrctrl_set_tx_amplitude(ctx, i); 490 + ret = tc9563_pwrctrl_set_tx_amplitude(tc9563, i); 498 491 if (ret) { 499 - dev_err(ctx->pwrctrl.dev, "Setting Tx amplitude failed\n"); 492 + dev_err(dev, "Setting Tx amplitude failed\n"); 500 493 goto power_off; 501 494 } 502 495 503 - ret = tc9563_pwrctrl_set_nfts(ctx, i); 496 + ret = tc9563_pwrctrl_set_nfts(tc9563, i); 504 497 if (ret) { 505 - dev_err(ctx->pwrctrl.dev, "Setting N_FTS failed\n"); 498 + dev_err(dev, "Setting N_FTS failed\n"); 506 499 goto power_off; 507 500 } 508 501 509 - ret = tc9563_pwrctrl_disable_dfe(ctx, i); 502 + ret = tc9563_pwrctrl_disable_dfe(tc9563, i); 510 503 if (ret) { 511 - dev_err(ctx->pwrctrl.dev, "Disabling DFE failed\n"); 504 + dev_err(dev, "Disabling DFE failed\n"); 512 505 goto power_off; 513 506 } 514 507 } 515 508 516 - ret = tc9563_pwrctrl_assert_deassert_reset(ctx, true); 509 + ret = tc9563_pwrctrl_assert_deassert_reset(tc9563, true); 517 510 if (!ret) 518 511 return 0; 519 512 520 513 power_off: 521 - tc9563_pwrctrl_power_off(ctx); 514 + tc9563_pwrctrl_power_off(&tc9563->pwrctrl); 522 515 return ret; 523 516 } 524 517 525 518 static int tc9563_pwrctrl_probe(struct platform_device *pdev) 526 519 { 527 - struct pci_host_bridge *bridge = to_pci_host_bridge(pdev->dev.parent); 528 - struct pci_bus *bus = bridge->bus; 520 + struct device_node *node = pdev->dev.of_node; 529 521 struct device *dev = &pdev->dev; 530 522 enum tc9563_pwrctrl_ports port; 531 - struct tc9563_pwrctrl_ctx *ctx; 523 + struct tc9563_pwrctrl *tc9563; 532 524 struct device_node *i2c_node; 533 525 int ret, addr; 534 526 535 - ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); 536 - if (!ctx) 527 + tc9563 = devm_kzalloc(dev, sizeof(*tc9563), GFP_KERNEL); 528 + if (!tc9563) 537 529 return -ENOMEM; 538 530 539 - ret = of_property_read_u32_index(pdev->dev.of_node, "i2c-parent", 1, &addr); 531 + ret = of_property_read_u32_index(node, "i2c-parent", 1, &addr); 540 532 if (ret) 541 533 return dev_err_probe(dev, ret, "Failed to read i2c-parent property\n"); 542 534 543 535 i2c_node = of_parse_phandle(dev->of_node, "i2c-parent", 0); 544 - ctx->adapter = of_find_i2c_adapter_by_node(i2c_node); 536 + tc9563->adapter = of_find_i2c_adapter_by_node(i2c_node); 545 537 of_node_put(i2c_node); 546 - if (!ctx->adapter) 538 + if (!tc9563->adapter) 547 539 return dev_err_probe(dev, -EPROBE_DEFER, "Failed to find I2C adapter\n"); 548 540 549 - ctx->client = i2c_new_dummy_device(ctx->adapter, addr); 550 - if (IS_ERR(ctx->client)) { 541 + tc9563->client = i2c_new_dummy_device(tc9563->adapter, addr); 542 + if (IS_ERR(tc9563->client)) { 551 543 dev_err(dev, "Failed to create I2C client\n"); 552 - i2c_put_adapter(ctx->adapter); 553 - return PTR_ERR(ctx->client); 544 + put_device(&tc9563->adapter->dev); 545 + return PTR_ERR(tc9563->client); 554 546 } 555 547 556 548 for (int i = 0; i < ARRAY_SIZE(tc9563_supply_names); i++) 557 - ctx->supplies[i].supply = tc9563_supply_names[i]; 549 + tc9563->supplies[i].supply = tc9563_supply_names[i]; 558 550 559 - ret = devm_regulator_bulk_get(dev, TC9563_PWRCTL_MAX_SUPPLY, ctx->supplies); 551 + ret = devm_regulator_bulk_get(dev, TC9563_PWRCTL_MAX_SUPPLY, 552 + tc9563->supplies); 560 553 if (ret) { 561 554 dev_err_probe(dev, ret, "failed to get supply regulator\n"); 562 555 goto remove_i2c; 563 556 } 564 557 565 - ctx->reset_gpio = devm_gpiod_get(dev, "resx", GPIOD_OUT_HIGH); 566 - if (IS_ERR(ctx->reset_gpio)) { 567 - ret = dev_err_probe(dev, PTR_ERR(ctx->reset_gpio), "failed to get resx GPIO\n"); 558 + tc9563->reset_gpio = devm_gpiod_get(dev, "resx", GPIOD_OUT_HIGH); 559 + if (IS_ERR(tc9563->reset_gpio)) { 560 + ret = dev_err_probe(dev, PTR_ERR(tc9563->reset_gpio), "failed to get resx GPIO\n"); 568 561 goto remove_i2c; 569 562 } 570 563 571 - pci_pwrctrl_init(&ctx->pwrctrl, dev); 564 + pci_pwrctrl_init(&tc9563->pwrctrl, dev); 572 565 573 566 port = TC9563_USP; 574 - ret = tc9563_pwrctrl_parse_device_dt(ctx, pdev->dev.of_node, port); 567 + ret = tc9563_pwrctrl_parse_device_dt(tc9563, node, port); 575 568 if (ret) { 576 569 dev_err(dev, "failed to parse device tree properties: %d\n", ret); 577 570 goto remove_i2c; ··· 588 563 589 564 /* 590 565 * Downstream ports are always children of the upstream port. 591 - * The first node represents DSP1, the second node represents DSP2, and so on. 566 + * The first node represents DSP1, the second node represents DSP2, 567 + * and so on. 592 568 */ 593 - for_each_child_of_node_scoped(pdev->dev.of_node, child) { 569 + for_each_child_of_node_scoped(node, child) { 594 570 port++; 595 - ret = tc9563_pwrctrl_parse_device_dt(ctx, child, port); 571 + ret = tc9563_pwrctrl_parse_device_dt(tc9563, child, port); 596 572 if (ret) 597 573 break; 598 574 /* Embedded ethernet device are under DSP3 */ 599 575 if (port == TC9563_DSP3) { 600 576 for_each_child_of_node_scoped(child, child1) { 601 577 port++; 602 - ret = tc9563_pwrctrl_parse_device_dt(ctx, child1, port); 578 + ret = tc9563_pwrctrl_parse_device_dt(tc9563, 579 + child1, port); 603 580 if (ret) 604 581 break; 605 582 } ··· 612 585 goto remove_i2c; 613 586 } 614 587 615 - if (bridge->ops->assert_perst) { 616 - ret = bridge->ops->assert_perst(bus, true); 617 - if (ret) 618 - goto remove_i2c; 619 - } 588 + tc9563->pwrctrl.power_on = tc9563_pwrctrl_power_on; 589 + tc9563->pwrctrl.power_off = tc9563_pwrctrl_power_off; 620 590 621 - ret = tc9563_pwrctrl_bring_up(ctx); 622 - if (ret) 623 - goto remove_i2c; 624 - 625 - if (bridge->ops->assert_perst) { 626 - ret = bridge->ops->assert_perst(bus, false); 627 - if (ret) 628 - goto power_off; 629 - } 630 - 631 - ret = devm_pci_pwrctrl_device_set_ready(dev, &ctx->pwrctrl); 591 + ret = devm_pci_pwrctrl_device_set_ready(dev, &tc9563->pwrctrl); 632 592 if (ret) 633 593 goto power_off; 634 - 635 - platform_set_drvdata(pdev, ctx); 636 594 637 595 return 0; 638 596 639 597 power_off: 640 - tc9563_pwrctrl_power_off(ctx); 598 + tc9563_pwrctrl_power_off(&tc9563->pwrctrl); 641 599 remove_i2c: 642 - i2c_unregister_device(ctx->client); 643 - i2c_put_adapter(ctx->adapter); 600 + i2c_unregister_device(tc9563->client); 601 + put_device(&tc9563->adapter->dev); 644 602 return ret; 645 603 } 646 604 647 605 static void tc9563_pwrctrl_remove(struct platform_device *pdev) 648 606 { 649 - struct tc9563_pwrctrl_ctx *ctx = platform_get_drvdata(pdev); 607 + struct pci_pwrctrl *pwrctrl = dev_get_drvdata(&pdev->dev); 608 + struct tc9563_pwrctrl *tc9563 = container_of(pwrctrl, 609 + struct tc9563_pwrctrl, pwrctrl); 650 610 651 - tc9563_pwrctrl_power_off(ctx); 652 - i2c_unregister_device(ctx->client); 653 - i2c_put_adapter(ctx->adapter); 611 + tc9563_pwrctrl_power_off(&tc9563->pwrctrl); 612 + i2c_unregister_device(tc9563->client); 613 + put_device(&tc9563->adapter->dev); 654 614 } 655 615 656 616 static const struct of_device_id tc9563_pwrctrl_of_match[] = {
+74 -29
drivers/pci/pwrctrl/slot.c
··· 8 8 #include <linux/device.h> 9 9 #include <linux/mod_devicetable.h> 10 10 #include <linux/module.h> 11 + #include <linux/of_graph.h> 11 12 #include <linux/pci-pwrctrl.h> 12 13 #include <linux/platform_device.h> 14 + #include <linux/pwrseq/consumer.h> 13 15 #include <linux/regulator/consumer.h> 14 16 #include <linux/slab.h> 15 17 16 - struct pci_pwrctrl_slot_data { 17 - struct pci_pwrctrl ctx; 18 + struct slot_pwrctrl { 19 + struct pci_pwrctrl pwrctrl; 18 20 struct regulator_bulk_data *supplies; 19 21 int num_supplies; 22 + struct clk *clk; 23 + struct pwrseq_desc *pwrseq; 20 24 }; 21 25 22 - static void devm_pci_pwrctrl_slot_power_off(void *data) 26 + static int slot_pwrctrl_power_on(struct pci_pwrctrl *pwrctrl) 23 27 { 24 - struct pci_pwrctrl_slot_data *slot = data; 28 + struct slot_pwrctrl *slot = container_of(pwrctrl, 29 + struct slot_pwrctrl, pwrctrl); 30 + int ret; 31 + 32 + if (slot->pwrseq) { 33 + pwrseq_power_on(slot->pwrseq); 34 + return 0; 35 + } 36 + 37 + ret = regulator_bulk_enable(slot->num_supplies, slot->supplies); 38 + if (ret < 0) { 39 + dev_err(slot->pwrctrl.dev, "Failed to enable slot regulators\n"); 40 + return ret; 41 + } 42 + 43 + return clk_prepare_enable(slot->clk); 44 + } 45 + 46 + static int slot_pwrctrl_power_off(struct pci_pwrctrl *pwrctrl) 47 + { 48 + struct slot_pwrctrl *slot = container_of(pwrctrl, 49 + struct slot_pwrctrl, pwrctrl); 50 + 51 + if (slot->pwrseq) { 52 + pwrseq_power_off(slot->pwrseq); 53 + return 0; 54 + } 25 55 26 56 regulator_bulk_disable(slot->num_supplies, slot->supplies); 57 + clk_disable_unprepare(slot->clk); 58 + 59 + return 0; 60 + } 61 + 62 + static void devm_slot_pwrctrl_release(void *data) 63 + { 64 + struct slot_pwrctrl *slot = data; 65 + 66 + slot_pwrctrl_power_off(&slot->pwrctrl); 27 67 regulator_bulk_free(slot->num_supplies, slot->supplies); 28 68 } 29 69 30 - static int pci_pwrctrl_slot_probe(struct platform_device *pdev) 70 + static int slot_pwrctrl_probe(struct platform_device *pdev) 31 71 { 32 - struct pci_pwrctrl_slot_data *slot; 72 + struct slot_pwrctrl *slot; 33 73 struct device *dev = &pdev->dev; 34 - struct clk *clk; 35 74 int ret; 36 75 37 76 slot = devm_kzalloc(dev, sizeof(*slot), GFP_KERNEL); 38 77 if (!slot) 39 78 return -ENOMEM; 79 + 80 + if (of_graph_is_present(dev_of_node(dev))) { 81 + slot->pwrseq = devm_pwrseq_get(dev, "pcie"); 82 + if (IS_ERR(slot->pwrseq)) 83 + return dev_err_probe(dev, PTR_ERR(slot->pwrseq), 84 + "Failed to get the power sequencer\n"); 85 + 86 + goto skip_resources; 87 + } 40 88 41 89 ret = of_regulator_bulk_get_all(dev, dev_of_node(dev), 42 90 &slot->supplies); ··· 94 46 } 95 47 96 48 slot->num_supplies = ret; 97 - ret = regulator_bulk_enable(slot->num_supplies, slot->supplies); 98 - if (ret < 0) { 99 - dev_err_probe(dev, ret, "Failed to enable slot regulators\n"); 100 - regulator_bulk_free(slot->num_supplies, slot->supplies); 101 - return ret; 102 - } 103 49 104 - ret = devm_add_action_or_reset(dev, devm_pci_pwrctrl_slot_power_off, 105 - slot); 106 - if (ret) 107 - return ret; 108 - 109 - clk = devm_clk_get_optional_enabled(dev, NULL); 110 - if (IS_ERR(clk)) { 111 - return dev_err_probe(dev, PTR_ERR(clk), 50 + slot->clk = devm_clk_get_optional(dev, NULL); 51 + if (IS_ERR(slot->clk)) { 52 + return dev_err_probe(dev, PTR_ERR(slot->clk), 112 53 "Failed to enable slot clock\n"); 113 54 } 114 55 115 - pci_pwrctrl_init(&slot->ctx, dev); 56 + skip_resources: 57 + slot->pwrctrl.power_on = slot_pwrctrl_power_on; 58 + slot->pwrctrl.power_off = slot_pwrctrl_power_off; 116 59 117 - ret = devm_pci_pwrctrl_device_set_ready(dev, &slot->ctx); 60 + ret = devm_add_action_or_reset(dev, devm_slot_pwrctrl_release, slot); 61 + if (ret) 62 + return ret; 63 + 64 + pci_pwrctrl_init(&slot->pwrctrl, dev); 65 + 66 + ret = devm_pci_pwrctrl_device_set_ready(dev, &slot->pwrctrl); 118 67 if (ret) 119 68 return dev_err_probe(dev, ret, "Failed to register pwrctrl driver\n"); 120 69 121 70 return 0; 122 71 } 123 72 124 - static const struct of_device_id pci_pwrctrl_slot_of_match[] = { 73 + static const struct of_device_id slot_pwrctrl_of_match[] = { 125 74 { 126 75 .compatible = "pciclass,0604", 127 76 }, 128 77 { } 129 78 }; 130 - MODULE_DEVICE_TABLE(of, pci_pwrctrl_slot_of_match); 79 + MODULE_DEVICE_TABLE(of, slot_pwrctrl_of_match); 131 80 132 - static struct platform_driver pci_pwrctrl_slot_driver = { 81 + static struct platform_driver slot_pwrctrl_driver = { 133 82 .driver = { 134 83 .name = "pci-pwrctrl-slot", 135 - .of_match_table = pci_pwrctrl_slot_of_match, 84 + .of_match_table = slot_pwrctrl_of_match, 136 85 }, 137 - .probe = pci_pwrctrl_slot_probe, 86 + .probe = slot_pwrctrl_probe, 138 87 }; 139 - module_platform_driver(pci_pwrctrl_slot_driver); 88 + module_platform_driver(slot_pwrctrl_driver); 140 89 141 90 MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>"); 142 91 MODULE_DESCRIPTION("Generic PCI Power Control driver for PCI Slots");
-20
drivers/pci/remove.c
··· 17 17 } 18 18 } 19 19 20 - static void pci_pwrctrl_unregister(struct device *dev) 21 - { 22 - struct device_node *np; 23 - struct platform_device *pdev; 24 - 25 - np = dev_of_node(dev); 26 - if (!np) 27 - return; 28 - 29 - pdev = of_find_device_by_node(np); 30 - if (!pdev) 31 - return; 32 - 33 - of_device_unregister(pdev); 34 - put_device(&pdev->dev); 35 - 36 - of_node_clear_flag(np, OF_POPULATED); 37 - } 38 - 39 20 static void pci_stop_dev(struct pci_dev *dev) 40 21 { 41 22 pci_pme_active(dev, false); ··· 54 73 pci_ide_destroy(dev); 55 74 pcie_aspm_exit_link_state(dev); 56 75 pci_bridge_d3_update(dev); 57 - pci_pwrctrl_unregister(&dev->dev); 58 76 pci_free_resources(dev); 59 77 put_device(&dev->dev); 60 78 }
+15 -1
include/linux/pci-pwrctrl.h
··· 31 31 /** 32 32 * struct pci_pwrctrl - PCI device power control context. 33 33 * @dev: Address of the power controlling device. 34 + * @power_on: Callback to power on the power controlling device. 35 + * @power_off: Callback to power off the power controlling device. 34 36 * 35 37 * An object of this type must be allocated by the PCI power control device and 36 38 * passed to the pwrctrl subsystem to trigger a bus rescan and setup a device ··· 40 38 */ 41 39 struct pci_pwrctrl { 42 40 struct device *dev; 41 + int (*power_on)(struct pci_pwrctrl *pwrctrl); 42 + int (*power_off)(struct pci_pwrctrl *pwrctrl); 43 43 44 44 /* private: internal use only */ 45 45 struct notifier_block nb; ··· 54 50 void pci_pwrctrl_device_unset_ready(struct pci_pwrctrl *pwrctrl); 55 51 int devm_pci_pwrctrl_device_set_ready(struct device *dev, 56 52 struct pci_pwrctrl *pwrctrl); 57 - 53 + #if IS_ENABLED(CONFIG_PCI_PWRCTRL) 54 + int pci_pwrctrl_create_devices(struct device *parent); 55 + void pci_pwrctrl_destroy_devices(struct device *parent); 56 + int pci_pwrctrl_power_on_devices(struct device *parent); 57 + void pci_pwrctrl_power_off_devices(struct device *parent); 58 + #else 59 + static inline int pci_pwrctrl_create_devices(struct device *parent) { return 0; } 60 + static void pci_pwrctrl_destroy_devices(struct device *parent) { } 61 + static inline int pci_pwrctrl_power_on_devices(struct device *parent) { return 0; } 62 + static void pci_pwrctrl_power_off_devices(struct device *parent) { } 63 + #endif 58 64 #endif /* __PCI_PWRCTRL_H__ */
-1
include/linux/pci.h
··· 860 860 void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where); 861 861 int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val); 862 862 int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val); 863 - int (*assert_perst)(struct pci_bus *bus, bool assert); 864 863 }; 865 864 866 865 /*