diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2024-07-15 17:34:31 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2024-07-15 17:34:31 -0700 |
commit | e763c9ec71dd462337d0b671ec5014b737c5342e (patch) | |
tree | cb077cc4599fb10db856d74ff7ac8a7508c1ca8d /include | |
parent | cdf471c348c1200ca243775b4b8d6eaa6d7f3979 (diff) | |
parent | 50b040ef373293b4ae2ecdc5873daa4656724868 (diff) |
Merge tag 'pwrseq-updates-for-v6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Pull power sequencing updates from Bartosz Golaszewski:
"This has been in development since last year's Linux Plumbers
Conference and was inspired by the need to enable support upstream for
Bluetooth/WLAN chips on Qualcomm platforms.
The main problem we're fixing is powering up devices which are
represented as separate objects in the kernel (binding to different
drivers) but which share parts of the power-up sequence and thus need
some kind of a mediator who knows the possible interactions and can
assure they don't interfere with neither device's bring up. An example
of such an inter-driver interaction is the WCN family of BT/WLAN chips
from Qualcomm of which some models require the user to observe a
certain delay between driving the bt-enable and wlan-enable GPIOs.
This is not a new problem but up to this point all attempts at
addressing it ended up hitting one wall or another and being dropped.
The main obstacle was the fact that most these attempts tried to
introduce the concept of a "power sequence" into the device-tree
bindings which breaks the main DT rule: describe the hardware, not its
behavior. The solution I proposed focuses on making the power
sequencer drivers interpret the actual HW description flexibly. More
details on that are in the linked cover letter.
The second problem fixed here is powering up PCI devices before they
are detected on the bus. This is achieved by creating special platform
devices for device-tree nodes describing hard-wired PCI devices which
bind to the so-called PCI power control drivers which enable required
resources and trigger a bus rescan once the controlled device is up
then setup the correct devlink hierarchy for power-management.
By combining the two new frameworks we implemented the power
sequencing PCI power control driver which is capable of powering up
the WLAN modules of the QCom WCN family of chipsets.
All this has spent a significant amount of time in linux-next and
enabled WLAN/BT support on several Qualcomm platforms. To further
prove that this is useful and needed: right after this was picked up
into next, I was sent a series using the subsystem for a similar
use-case on Amlogic platforms.
This contains the core power sequencing framework, the first driver,
PCI changes using the pwrseq library (blessed by Bjorn Helgaas) and
some fixes that came later"
* tag 'pwrseq-updates-for-v6.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux:
PCI/pwrctl: only call of_platform_populate() if CONFIG_OF is enabled
power: sequencing: simplify returning pointer without cleanup
PCI/pwrctl: Add a PCI power control driver for power sequenced devices
PCI/pwrctl: Add PCI power control core code
PCI/pwrctl: Create platform devices for child OF nodes of the port node
PCI/pwrctl: Reuse the OF node for power controlled devices
PCI: Hold the rescan mutex when scanning for the first time
power: pwrseq: add a driver for the PMU module on the QCom WCN chipsets
power: sequencing: implement the pwrseq core
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/pci-pwrctl.h | 51 | ||||
-rw-r--r-- | include/linux/pwrseq/consumer.h | 56 | ||||
-rw-r--r-- | include/linux/pwrseq/provider.h | 75 |
3 files changed, 182 insertions, 0 deletions
diff --git a/include/linux/pci-pwrctl.h b/include/linux/pci-pwrctl.h new file mode 100644 index 000000000000..45e9cfe740e4 --- /dev/null +++ b/include/linux/pci-pwrctl.h @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Linaro Ltd. + */ + +#ifndef __PCI_PWRCTL_H__ +#define __PCI_PWRCTL_H__ + +#include <linux/notifier.h> + +struct device; +struct device_link; + +/* + * This is a simple framework for solving the issue of PCI devices that require + * certain resources (regulators, GPIOs, clocks) to be enabled before the + * device can actually be detected on the PCI bus. + * + * The idea is to reuse the platform bus to populate OF nodes describing the + * PCI device and its resources, let these platform devices probe and enable + * relevant resources and then trigger a rescan of the PCI bus allowing for the + * same device (with a second associated struct device) to be registered with + * the PCI subsystem. + * + * To preserve a correct hierarchy for PCI power management and device reset, + * we create a device link between the power control platform device (parent) + * and the supplied PCI device (child). + */ + +/** + * struct pci_pwrctl - PCI device power control context. + * @dev: Address of the power controlling device. + * + * An object of this type must be allocated by the PCI power control device and + * passed to the pwrctl subsystem to trigger a bus rescan and setup a device + * link with the device once it's up. + */ +struct pci_pwrctl { + struct device *dev; + + /* Private: don't use. */ + struct notifier_block nb; + struct device_link *link; +}; + +int pci_pwrctl_device_set_ready(struct pci_pwrctl *pwrctl); +void pci_pwrctl_device_unset_ready(struct pci_pwrctl *pwrctl); +int devm_pci_pwrctl_device_set_ready(struct device *dev, + struct pci_pwrctl *pwrctl); + +#endif /* __PCI_PWRCTL_H__ */ diff --git a/include/linux/pwrseq/consumer.h b/include/linux/pwrseq/consumer.h new file mode 100644 index 000000000000..7d583b4f266e --- /dev/null +++ b/include/linux/pwrseq/consumer.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Linaro Ltd. + */ + +#ifndef __POWER_SEQUENCING_CONSUMER_H__ +#define __POWER_SEQUENCING_CONSUMER_H__ + +#include <linux/err.h> + +struct device; +struct pwrseq_desc; + +#if IS_ENABLED(CONFIG_POWER_SEQUENCING) + +struct pwrseq_desc * __must_check +pwrseq_get(struct device *dev, const char *target); +void pwrseq_put(struct pwrseq_desc *desc); + +struct pwrseq_desc * __must_check +devm_pwrseq_get(struct device *dev, const char *target); + +int pwrseq_power_on(struct pwrseq_desc *desc); +int pwrseq_power_off(struct pwrseq_desc *desc); + +#else /* CONFIG_POWER_SEQUENCING */ + +static inline struct pwrseq_desc * __must_check +pwrseq_get(struct device *dev, const char *target) +{ + return ERR_PTR(-ENOSYS); +} + +static inline void pwrseq_put(struct pwrseq_desc *desc) +{ +} + +static inline struct pwrseq_desc * __must_check +devm_pwrseq_get(struct device *dev, const char *target) +{ + return ERR_PTR(-ENOSYS); +} + +static inline int pwrseq_power_on(struct pwrseq_desc *desc) +{ + return -ENOSYS; +} + +static inline int pwrseq_power_off(struct pwrseq_desc *desc) +{ + return -ENOSYS; +} + +#endif /* CONFIG_POWER_SEQUENCING */ + +#endif /* __POWER_SEQUENCING_CONSUMER_H__ */ diff --git a/include/linux/pwrseq/provider.h b/include/linux/pwrseq/provider.h new file mode 100644 index 000000000000..cbc3607cbfcf --- /dev/null +++ b/include/linux/pwrseq/provider.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2024 Linaro Ltd. + */ + +#ifndef __POWER_SEQUENCING_PROVIDER_H__ +#define __POWER_SEQUENCING_PROVIDER_H__ + +struct device; +struct module; +struct pwrseq_device; + +typedef int (*pwrseq_power_state_func)(struct pwrseq_device *); +typedef int (*pwrseq_match_func)(struct pwrseq_device *, struct device *); + +/** + * struct pwrseq_unit_data - Configuration of a single power sequencing + * unit. + * @name: Name of the unit. + * @deps: Units that must be enabled before this one and disabled after it + * in the order they come in this array. Must be NULL-terminated. + * @enable: Callback running the part of the power-on sequence provided by + * this unit. + * @disable: Callback running the part of the power-off sequence provided + * by this unit. + */ +struct pwrseq_unit_data { + const char *name; + const struct pwrseq_unit_data **deps; + pwrseq_power_state_func enable; + pwrseq_power_state_func disable; +}; + +/** + * struct pwrseq_target_data - Configuration of a power sequencing target. + * @name: Name of the target. + * @unit: Final unit that this target must reach in order to be considered + * enabled. + * @post_enable: Callback run after the target unit has been enabled, *after* + * the state lock has been released. It's useful for implementing + * boot-up delays without blocking other users from powering up + * using the same power sequencer. + */ +struct pwrseq_target_data { + const char *name; + const struct pwrseq_unit_data *unit; + pwrseq_power_state_func post_enable; +}; + +/** + * struct pwrseq_config - Configuration used for registering a new provider. + * @parent: Parent device for the sequencer. Must be set. + * @owner: Module providing this device. + * @drvdata: Private driver data. + * @match: Provider callback used to match the consumer device to the sequencer. + * @targets: Array of targets for this power sequencer. Must be NULL-terminated. + */ +struct pwrseq_config { + struct device *parent; + struct module *owner; + void *drvdata; + pwrseq_match_func match; + const struct pwrseq_target_data **targets; +}; + +struct pwrseq_device * +pwrseq_device_register(const struct pwrseq_config *config); +void pwrseq_device_unregister(struct pwrseq_device *pwrseq); +struct pwrseq_device * +devm_pwrseq_device_register(struct device *dev, + const struct pwrseq_config *config); + +void *pwrseq_device_get_drvdata(struct pwrseq_device *pwrseq); + +#endif /* __POWER_SEQUENCING_PROVIDER_H__ */ |