Message ID | 20240117160748.37682-5-brgl@bgdev.pl |
---|---|
State | New |
Headers | show |
Series | PCI: introduce the concept of power sequencing of PCIe devices | expand |
On Fri, Feb 2, 2024 at 11:02 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > On Fri, Feb 2, 2024 at 1:03 AM Bjorn Andersson <andersson@kernel.org> wrote: > > > > [snip] > > > > > > > > > I believe I missed this part of the discussion, why does this need to be > > > > a platform_device? What does the platform_bus bring that can't be > > > > provided by some other bus? > > > > > > > > > > Does it need to be a platform_device? No, of course not. Does it make > > > sense for it to be one? Yes, for two reasons: > > > > > > 1. The ATH11K WLAN module is represented on the device tree like a > > > platform device, we know it's always there and it consumes regulators > > > from another platform device. The fact it uses PCIe doesn't change the > > > fact that it is logically a platform device. > > > > Are you referring to the ath11k SNOC (firmware running on co-processor > > in the SoC) variant? > > > > Afaict the PCIe-attached ath11k is not represented as a platform_device > > in DeviceTree. > > > > My bad. In RB5 it isn't (yet - I want to add it in the power > sequencing series). It is in X13s though[1]. > > > Said platform_device is also not a child under the PCIe bus, so this > > would be a different platform_device... > > > > It's the child of the PCIe port node but there's a reason for it to > have the `compatible` property. It's because it's an entity of whose > existence we are aware before the system boots. > > > > 2. The platform bus already provides us with the entire infrastructure > > > that we'd now need to duplicate (possibly adding bugs) in order to > > > introduce a "power sequencing bus". > > > > > > > This is a perfectly reasonable desire. Look at our PMICs, they are full > > of platform_devices. But through the years it's been said many times, > > that this is not a valid or good reason for using platform_devices, and > > as a result we have e.g. auxiliary bus. > > > > Ok, so I cannot find this information anywhere (nor any example). Do > you happen to know if the auxiliary bus offers any software node > integration so that the `compatible` property from DT can get > seamlessly mapped to auxiliary device IDs? > So I was just trying to port this to using the auxiliary bus, only to find myself literally reimplementing functions from drivers/of/device.c. I have a feeling that this is simply wrong. If we're instantiating devices well defined on the device-tree then IMO we *should* make them platform devices. Anything else and we'll be reimplementing drivers/of/ because we will need to parse the device nodes, check the compatible, match it against drivers etc. Things that are already implemented for the platform bus and of_* APIs. Greg: Could you chime in and confirm that it's alright to use the platform bus here? Or maybe there is some infrastructure to create auxiliary devices from software nodes? Bartosz > > Anyway, (please) don't claim that "we need to", when it actually is "we > > want to use platform_device because that's more convenient"! > > Bart > > [snip] > > [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/boot/dts/qcom/sc8280xp-lenovo-thinkpad-x13s.dts#n744
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 9c2137dae429..8ab07f711834 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -12,6 +12,7 @@ #include <linux/errno.h> #include <linux/ioport.h> #include <linux/of.h> +#include <linux/of_platform.h> #include <linux/proc_fs.h> #include <linux/slab.h> @@ -342,8 +343,14 @@ void pci_bus_add_device(struct pci_dev *dev) */ pcibios_bus_add_device(dev); pci_fixup_device(pci_fixup_final, dev); - if (pci_is_bridge(dev)) + if (pci_is_bridge(dev)) { of_pci_make_dev_node(dev); + retval = of_platform_populate(dev->dev.of_node, NULL, NULL, + &dev->dev); + if (retval) + pci_err(dev, "failed to populate child OF nodes (%d)\n", + retval); + } pci_create_sysfs_dev_files(dev); pci_proc_attach_device(dev); pci_bridge_d3_update(dev); diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index d749ea8250d6..77be0630b7b3 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include <linux/pci.h> #include <linux/module.h> +#include <linux/of_platform.h> #include "pci.h" static void pci_free_resources(struct pci_dev *dev) @@ -18,11 +19,11 @@ static void pci_stop_dev(struct pci_dev *dev) pci_pme_active(dev, false); if (pci_dev_is_added(dev)) { - device_release_driver(&dev->dev); pci_proc_detach_device(dev); pci_remove_sysfs_dev_files(dev); of_pci_remove_node(dev); + of_platform_depopulate(&dev->dev); pci_dev_assign_added(dev, false); }