pmdomain: core: Add genpd_dev_pm_attach_by_node()
Subsystems (5)
PATCH 1/1 pmdomain: core: Add genpd_dev_pm_attach_by_node()
genpd_dev_pm_attach_by_id() and genpd_dev_pm_attach_by_name() attach a virtual device to a PM domain listed in the OF node of the passed device.
Some hardware blocks are described in a child node of a main device. They have no device of their own, but they do have a PM domain of their own. Neither function can attach that domain, as both parse only the OF node of the device.
An example case is TI's display subsystem and its OLDI (LVDS) transmitters:
dss@30200000 {
power-domains = <...>;
oldi-transmitters {
oldi@0 {
power-domains = <...>;
};
oldi@1 {
power-domains = <...>;
};
};
};The OLDI TX blocks are not part of the DSS IP, but they are not quite real devices either as they don't have registers of their own, and are instead controlled via DSS registers.
Add genpd_dev_pm_attach_by_node(), which is similar to genpd_dev_pm_attach_by_id() but instead of looking for the power-domains from the passed device's DT node, the DT node is passed explicitly. Also add a matching wrapper function dev_pm_domain_attach_by_node().
---
This is a new try for managing the OLDI power domains. Previously I tried using auxiliary device/driver for OLDIs, and handling the PDs the normal way:
https://lore.kernel.org/all/20260529-beagley-ai-display-v3-12-7fefdc5d1adf%40ideasonboard.com/
Then I realized an issue, mentioned in Documentation/driver-api/driver-model/driver.rst: "-EPROBE_DEFER must not be returned if probe() has already created child devices".
The PD virtual devices used in this patch's approach do not hit the issue as they don't get a driver, so they are not probed. The tidss driver's OLDI part can then use normal pm_runtime_get/put functions to manage the OLDI PDs.
--- drivers/base/power/common.c | 27 +++++++++++++ drivers/pmdomain/core.c | 97 +++++++++++++++++++++++++++++++++------------ include/linux/pm_domain.h | 19 +++++++++ 3 files changed, 117 insertions(+), 26 deletions(-)
drivers/base/power/common.c +27 -0
@@ -171,6 +171,33 @@ struct device *dev_pm_domain_attach_by_name(struct device *dev, }EXPORT_SYMBOL_GPL (dev_pm_domain_attach_by_name); +/** +* dev_pm_domain_attach_by_node - Associate a device with a PM domain of a DT +* node. +* @dev: The device that uses the PM domain. +* @np: The DT node with the PM domain. +* @index: The index of the PM domain in @np. +* +* Like dev_pm_domain_attach_by_id(), but the PM domain is looked up +* in @np instead of the OF node of @dev. +* +* Unlike dev_pm_domain_attach_by_id(), @dev may already be attached to a PM +* domain of its own. The driver controls the power to the PM domain through +* runtime PM of the returned virtual device, or through a device link to it. +* +* Returns the virtual created device when successfully attached to its PM +* domain, NULL in case @np has no PM domain at @index, else an ERR_PTR(). +* Note that, to detach the returned virtual device, the driver shall call +* dev_pm_domain_detach() on it, typically during the remove phase. +*/ +struct device *dev_pm_domain_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +return genpd_dev_pm_attach_by_node (dev, np, index); +} +EXPORT_SYMBOL_GPL (dev_pm_domain_attach_by_node); +/** * dev_pm_domain_attach_list - Associate a device with its PM domains. * @dev: The device used to lookup the PM domains for.
drivers/pmdomain/core.c +71 -26
131 lines not on this page · raw message
include/linux/pm_domain.h +19 -0
@@ -477,6 +477,9 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev, unsigned int index);struct device *genpd_dev_pm_attach_by_name (struct device *dev,const char *name); +struct device *genpd_dev_pm_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index);#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ static inline int of_genpd_add_provider_simple (struct device_node *np,struct generic_pm_domain *genpd)
@@ -535,6 +538,13 @@ static inline struct device *genpd_dev_pm_attach_by_name(struct device *dev,return NULL ; } +static inline struct device *genpd_dev_pm_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +return NULL ; +} +static inline struct generic_pm_domain *of_genpd_remove_last (struct device_node *np) {
@@ -560,6 +570,9 @@ struct device *dev_pm_domain_attach_by_id(struct device *dev, unsigned int index);struct device *dev_pm_domain_attach_by_name (struct device *dev,const char *name); +struct device *dev_pm_domain_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index);int dev_pm_domain_attach_list (struct device *dev,const struct dev_pm_domain_attach_data *data,struct dev_pm_domain_list **list);
@@ -586,6 +599,12 @@ static inline struct device *dev_pm_domain_attach_by_name(struct device *dev, {return NULL ; } +static inline struct device *dev_pm_domain_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +return NULL ; +}static inline int dev_pm_domain_attach_list (struct device *dev,const struct dev_pm_domain_attach_data *data,struct dev_pm_domain_list **list)
---
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261023-pm_attach_by_node-13788662f3a1
Best regards,
Signature · 1 line
Tomi Valkeinen <[email protected]>
Hi,
Quoted 26 lines · Tomi Valkeinen
genpd_dev_pm_attach_by_id()andgenpd_dev_pm_attach_by_name()attach a virtual device to a PM domain listed in the OF node of the passed device.Some hardware blocks are described in a child node of a main device. They have no device of their own, but they do have a PM domain of their own. Neither function can attach that domain, as both parse only the OF node of the device.
An example case is TI's display subsystem and its OLDI (LVDS) transmitters:
dss@30200000 { power-domains = <...>; oldi-transmitters { oldi@0 { power-domains = <...>; }; oldi@1 { power-domains = <...>; }; }; };
Quoted 8 lines
The OLDI TX blocks are not part of the DSS IP, but they are not quite real devices either as they don't have registers of their own, and are instead controlled via DSS registers.
Add
genpd_dev_pm_attach_by_node(), which is similar togenpd_dev_pm_attach_by_id()but instead of looking for the power-domains from the passed device's DT node, the DT node is passed explicitly. Also add a matching wrapper functiondev_pm_domain_attach_by_node().
Ping, any thoughts on this?
Tomi
Quoted 259 lines
Signed-off-by Tomi Valkeinen <[email protected]>---
This is a new try for managing the OLDI power domains. Previously I tried using auxiliary device/driver for OLDIs, and handling the PDs the normal way:https://lore.kernel.org/all/20260529-beagley-ai-display-v3-12-7fefdc5d1adf%40ideasonboard.com/
Then I realized an issue, mentioned in
Documentation/driver-api/driver-model/driver.rst: "-EPROBE_DEFER must not be returned ifprobe()has already created child devices".The PD virtual devices used in this patch's approach do not hit the issue as they don't get a driver, so they are not probed. The tidss driver's OLDI part can then use normal pm_runtime_get/put functions to manage the OLDI PDs.
--- drivers/base/power/common.c | 27 +++++++++++++ drivers/pmdomain/core.c | 97 +++++++++++++++++++++++++++++++++------------ include/linux/pm_domain.h | 19 +++++++++ 3 files changed, 117 insertions(+), 26 deletions(-)drivers/base/power/common.c +27
-0@@ -171,6 +171,33 @@ struct device *dev_pm_domain_attach_by_name(struct device *dev, }EXPORT_SYMBOL_GPL (dev_pm_domain_attach_by_name); +/** +* dev_pm_domain_attach_by_node - Associate a device with a PM domain of a DT +* node. +* @dev: The device that uses the PM domain. +* @np: The DT node with the PM domain. +* @index: The index of the PM domain in @np. +* +* Like dev_pm_domain_attach_by_id(), but the PM domain is looked up +* in @np instead of the OF node of @dev. +* +* Unlike dev_pm_domain_attach_by_id(), @dev may already be attached to a PM +* domain of its own. The driver controls the power to the PM domain through +* runtime PM of the returned virtual device, or through a device link to it. +* +* Returns the virtual created device when successfully attached to its PM +* domain, NULL in case @np has no PM domain at @index, else an ERR_PTR(). +* Note that, to detach the returned virtual device, the driver shall call +* dev_pm_domain_detach() on it, typically during the remove phase. +*/ +struct device *dev_pm_domain_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +return genpd_dev_pm_attach_by_node (dev, np, index); +} +EXPORT_SYMBOL_GPL (dev_pm_domain_attach_by_node); +/** * dev_pm_domain_attach_list - Associate a device with its PM domains. * @dev: The device used to lookup the PM domains for. drivers/pmdomain/core.c +71
-26@@ -3462,34 +3462,16 @@ int genpd_dev_pm_attach(struct device *dev) }EXPORT_SYMBOL_GPL (genpd_dev_pm_attach); -/** -* genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains. -* @dev: The device used to lookup the PM domain. -* @index: The index of the PM domain. -* -* Parse device's OF node to find a PM domain specifier at the provided @index. -* If such is found, creates a virtual device and attaches it to the retrieved -* pm_domain ops. To deal with detaching of the virtual device, the ->detach() -* callback in the struct dev_pm_domain are assigned to genpd_dev_pm_detach(). -* -* Returns the created virtual device if successfully attached PM domain, NULL -* when the device don't need a PM domain, else an ERR_PTR() in case of -* failures. If a power-domain exists for the device, but cannot be found or -* turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device -* is not probed and to re-try again later. -*/ -struct device *genpd_dev_pm_attach_by_id (struct device *dev, -unsigned int index) +static struct device *genpd_dev_pm_attach_virt (struct device *dev, +struct device_node *np, +unsigned int index) {struct device *virt_dev;int num_domains;int ret; -if (!dev->of_node) -return NULL ; -/* Verify that the index is within a valid range. */ - num_domains =of_count_phandle_with_args (dev->of_node,"power-domains" , + num_domains =of_count_phandle_with_args (np,"power-domains" ,"#power-domain-cells" );if (num_domains <0 || index >= num_domains)return NULL ;@@ -3502,10 +3484,14 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,if (!virt_dev)return ERR_PTR (-ENOMEM ); -dev_set_name (virt_dev,"genpd:%u:%s" , index,dev_name (dev)); +if (np == dev->of_node) +dev_set_name (virt_dev,"genpd:%u:%s" , index,dev_name (dev)); +else +dev_set_name (virt_dev,"genpd:%u:%s:%pOFP" , index, +dev_name (dev), np); virt_dev->bus = &genpd_bus_type; virt_dev->release = genpd_release_dev; - virt_dev->of_node =of_node_get (dev->of_node); + virt_dev->of_node =of_node_get (np); ret =device_register (virt_dev);if (ret) {@@ -3513,8 +3499,13 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,return ERR_PTR (ret); } -/* Try to attach the device to the PM domain at the specified index. */ - ret =__genpd_dev_pm_attach (virt_dev, dev, index, num_domains, false); +/* +* Try to attach the device to the PM domain at the specified index. +* Pass 0 as the num_domains when np != dev->of_node, so that the dev's +* required OPPs are not used for the PD. +*/ + ret =__genpd_dev_pm_attach (virt_dev, dev, index, + np == dev->of_node ? num_domains :0 , false);if (ret <1 ) {device_unregister (virt_dev);return ret ?ERR_PTR (ret) :NULL ;@@ -3525,8 +3516,62 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,return virt_dev; } + +/** +* genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains. +* @dev: The device used to lookup the PM domain. +* @index: The index of the PM domain. +* +* Parse device's OF node to find a PM domain specifier at the provided @index. +* If such is found, creates a virtual device and attaches it to the retrieved +* pm_domain ops. To deal with detaching of the virtual device, the ->detach() +* callback in the struct dev_pm_domain are assigned to genpd_dev_pm_detach(). +* +* Returns the created virtual device if successfully attached PM domain, NULL +* when the device don't need a PM domain, else an ERR_PTR() in case of +* failures. If a power-domain exists for the device, but cannot be found or +* turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device +* is not probed and to re-try again later. +*/ +struct device *genpd_dev_pm_attach_by_id (struct device *dev, +unsigned int index) +{ +if (!dev->of_node) +return NULL ; + +return genpd_dev_pm_attach_virt (dev, dev->of_node, index); +}EXPORT_SYMBOL_GPL (genpd_dev_pm_attach_by_id); +/** +* genpd_dev_pm_attach_by_node - Associate a device with a PM domain of a DT +* node. +* @dev: The device that uses the PM domain. +* @np: The DT node with the PM domain. +* @index: The index of the PM domain in @np. +* +* Like genpd_dev_pm_attach_by_id(), but the PM domain is looked up in +* @np instead of the OF node of @dev. +* +* The virtual device is named after @dev and @np. The required OPPs of @dev are +* not linked to the PM domain. +* +* Returns the created virtual device if successfully attached PM domain, NULL +* when @np has no PM domain at @index, else an ERR_PTR() in case of failures. +* If the PM domain exists, but cannot be found or turned on, then +* ERR_PTR(-EPROBE_DEFER) is returned. +*/ +struct device *genpd_dev_pm_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +if (!np) +return NULL ; + +return genpd_dev_pm_attach_virt (dev, np, index); +} +EXPORT_SYMBOL_GPL (genpd_dev_pm_attach_by_node); +/** * genpd_dev_pm_attach_by_name - Associate a device with one of its PM domains. * @dev: The device used to lookup the PM domain. include/linux/pm_domain.h +19
-1@@ -477,6 +477,9 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev, unsigned int index);struct device *genpd_dev_pm_attach_by_name (struct device *dev,const char *name); +struct device *genpd_dev_pm_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index);#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ static inline int of_genpd_add_provider_simple (struct device_node *np,struct generic_pm_domain *genpd)@@ -535,6 +538,13 @@ static inline struct device *genpd_dev_pm_attach_by_name(struct device *dev,return NULL ; } +static inline struct device *genpd_dev_pm_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +return NULL ; +} +static inline struct generic_pm_domain *of_genpd_remove_last (struct device_node *np) {@@ -560,6 +570,9 @@ struct device *dev_pm_domain_attach_by_id(struct device *dev, unsigned int index);struct device *dev_pm_domain_attach_by_name (struct device *dev,const char *name); +struct device *dev_pm_domain_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index);int dev_pm_domain_attach_list (struct device *dev,const struct dev_pm_domain_attach_data *data,struct dev_pm_domain_list **list);@@ -586,6 +599,12 @@ static inline struct device *dev_pm_domain_attach_by_name(struct device *dev, {return NULL ; } +static inline struct device *dev_pm_domain_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +return NULL ; +}static inline int dev_pm_domain_attach_list (struct device *dev,const struct dev_pm_domain_attach_data *data,struct dev_pm_domain_list **list) ---base-commit:
c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261023-pm_attach_by_node-13788662f3a1Best regards,
--
Tomi Valkeinen <[email protected]>
Hi again,
Quoted 33 lines · Tomi Valkeinen
Hi,
Quoted 30 lines · Tomi Valkeinen
genpd_dev_pm_attach_by_id()andgenpd_dev_pm_attach_by_name()attach a virtual device to a PM domain listed in the OF node of the passed device.Some hardware blocks are described in a child node of a main device. They have no device of their own, but they do have a PM domain of their own. Neither function can attach that domain, as both parse only the OF node of the device.
An example case is TI's display subsystem and its OLDI (LVDS) transmitters:
dss@30200000 {
power-domains = <...>;oldi-transmitters {
oldi@0 {
power-domains = <...>;
};oldi@1 {
power-domains = <...>;
};
};
};The OLDI TX blocks are not part of the DSS IP, but they are not quite real devices either as they don't have registers of their own, and are instead controlled via DSS registers.
Quoted 6 lines
Quoted 4 lines
Add
genpd_dev_pm_attach_by_node(), which is similar togenpd_dev_pm_attach_by_id()but instead of looking for the power-domains from the passed device's DT node, the DT node is passed explicitly. Also add a matching wrapper functiondev_pm_domain_attach_by_node().Ping, any thoughts on this?
One more thing, if this change is ok, I'd like to somehow synchronize merging this with the display side patches, as it's a compile time dependency.
The easiest, at least to me, would be to merge this (with an ack from the relevant maintainers) along the display patches, via drm-misc-next.
Tomi
Quoted 296 lines
Tomi
Quoted 292 lines
Signed-off-by Tomi Valkeinen <[email protected]>---
This is a new try for managing the OLDI power domains. Previously I tried using auxiliary device/driver for OLDIs, and handling the PDs the normal way:https://lore.kernel.org/all/20260529-beagley-ai-display- v3-12-7fefdc5d1adf%40ideasonboard.com/
Then I realized an issue, mentioned in
Documentation/driver-api/driver-model/driver.rst: "-EPROBE_DEFER must not be returned ifprobe()has already created child devices".The PD virtual devices used in this patch's approach do not hit the issue as they don't get a driver, so they are not probed. The tidss driver's OLDI part can then use normal pm_runtime_get/put functions to manage the OLDI PDs.
---
drivers/base/power/common.c| 27 +++++++++++++ drivers/pmdomain/core.c | 97 +++++++++++++++++++++++++++++++++------------ include/linux/pm_domain.h | 19 +++++++++ 3 files changed, 117 insertions(+), 26 deletions(-)drivers/base/power/common.c +2
-0@@ -171,6 +171,33 @@ struct device *dev_pm_domain_attach_by_name(struct device *dev, } EXPORT_SYMBOL_GPL(dev_pm_domain_attach_by_name); +/** +* dev_pm_domain_attach_by_node - Associate a device with a PM domain of a DT
+ * node.
+ * @dev: The device that uses the PM domain.
+ * @np: The DT node with the PM domain.
+ * @index: The index of the PM domain in @np.
+ *
+ * Likedev_pm_domain_attach_by_id(), but the PM domain is looked up
+ * in @np instead of the OF node of @dev.
+ *
+ * Unlikedev_pm_domain_attach_by_id(), @dev may already be attached to a PM
+ * domain of its own. The driver controls the power to the PM domain through
+ * runtime PM of the returned virtual device, or through a device link to it.
+ *
+ * Returns the virtual created device when successfully attached to its PM
+ * domain, NULL in case @np has no PM domain at @index, else anERR_PTR().
+ * Note that, to detach the returned virtual device, the driver shall call
+ *dev_pm_domain_detach()on it, typically during the remove phase.
+ */drivers/base/power/common.c +8
-0+struct device *dev_pm_domain_attach_by_node (struct device *dev, + struct device_node *np, + unsigned int index) +{ + return genpd_dev_pm_attach_by_node(dev, np, index); +} +EXPORT_SYMBOL_GPL (dev_pm_domain_attach_by_node); +/**
*dev_pm_domain_attach_list- Associate a device with its PM domains.
* @dev: The device used to lookup the PM domains for.drivers/pmdomain/core.c +0
-2@@ -3462,34 +3462,16 @@ int genpd_dev_pm_attach(struct device *dev) } EXPORT_SYMBOL_GPL(genpd_dev_pm_attach); -/** -* genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains.
- * @dev: The device used to lookup the PM domain.
- * @index: The index of the PM domain.
- *
- * Parse device's OF node to find a PM domain specifier at the provided @index.
- * If such is found, creates a virtual device and attaches it to the retrieved
- *pm_domainops. To deal with detaching of the virtual device, the -Quoted 1 line
detach()- * callback in the struct
dev_pm_domainare assigned togenpd_dev_pm_detach().
- *
- * Returns the created virtual device if successfully attached PM domain, NULL
- * when the device don't need a PM domain, else anERR_PTR()in case of
- * failures. If a power-domain exists for the device, but cannot be found or
- * turned on, thenERR_PTR(-EPROBE_DEFER)is returned to ensure that the device
- * is not probed and to re-try again later.
- */drivers/pmdomain/core.c +3
-2-struct device *genpd_dev_pm_attach_by_id (struct device *dev, - unsigned int index) +static struct device *genpd_dev_pm_attach_virt (struct device *dev, + struct device_node *np, + unsigned int index){
struct device*virt_dev;
intnum_domains;
int ret;
- if (!dev->of_node)
- return NULL;
-
/* Verify that the index is within a valid range. */ -num_domains= of_count_phandle_with_args(dev->of_node, "power- domains",
+num_domains=of_count_phandle_with_args(np, "power-domains", "#power-domain-cells");
if (num_domains< 0 || index >=num_domains) return NULL;drivers/pmdomain/core.c +6
-3@@ -3502,10 +3484,14 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev, if (!virt_dev) return ERR_PTR(-ENOMEM); - dev_set_name(virt_dev, "genpd:%u:%s", index, dev_name(dev)); + if (np == dev->of_node) + dev_set_name(virt_dev, "genpd:%u:%s", index, dev_name(dev)); + else + dev_set_name(virt_dev, "genpd:%u:%s:%pOFP", index, + dev_name(dev), np); virt_dev->bus = &genpd_bus_type; virt_dev->release = genpd_release_dev; - virt_dev->of_node = of_node_get(dev->of_node); + virt_dev->of_node = of_node_get(np); ret = device_register(virt_dev); if (ret) {@@ -3513,8 +3499,13 @@ struct device *genpd_dev_pm_attach_by_id(structdevice *dev, return ERR_PTR(ret); } - /* Try to attach the device to the PM domain at the specifiedindex. */
- ret =__genpd_dev_pm_attach(virt_dev, dev, index, num_domains, false);
+ /*
+ * Try to attach the device to the PM domain at the specified index. + * Pass 0 as thenum_domainswhen np !=dev->of_node, so that the dev's
+ * required OPPs are not used for the PD.
+ */
+ ret = __genpd_dev_pm_attach(virt_dev, dev, index,
+ np ==dev->of_node?num_domains: 0, false); if (ret < 1) {
device_unregister(virt_dev);
return ret ?ERR_PTR(ret): NULL;drivers/pmdomain/core.c +3
-0@@ -3525,8 +3516,62 @@ struct device *genpd_dev_pm_attach_by_id(structdevice *dev, return virt_dev; } + +/** +* genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains.
+ * @dev: The device used to lookup the PM domain.
+ * @index: The index of the PM domain.
+ *
+ * Parse device's OF node to find a PM domain specifier at the provided @index.
+ * If such is found, creates a virtual device and attaches it to the retrieved
+ *pm_domainops. To deal with detaching of the virtual device, the -Quoted 1 line
detach()+ * callback in the struct
dev_pm_domainare assigned togenpd_dev_pm_detach().
+ *
+ * Returns the created virtual device if successfully attached PM domain, NULL
+ * when the device don't need a PM domain, else anERR_PTR()in case of
+ * failures. If a power-domain exists for the device, but cannot be found or
+ * turned on, thenERR_PTR(-EPROBE_DEFER)is returned to ensure that the device
+ * is not probed and to re-try again later.
+ */drivers/pmdomain/core.c +8
-0+struct device *genpd_dev_pm_attach_by_id (struct device *dev, + unsigned int index) +{ + if (!dev->of_node) + return NULL; + + return genpd_dev_pm_attach_virt(dev, dev->of_node, index); +}
EXPORT_SYMBOL_GPL(genpd_dev_pm_attach_by_id);
+/**
+ *genpd_dev_pm_attach_by_node- Associate a device with a PM domain of a DT
+ * node.
+ * @dev: The device that uses the PM domain.
+ * @np: The DT node with the PM domain.
+ * @index: The index of the PM domain in @np.
+ *
+ * Likegenpd_dev_pm_attach_by_id(), but the PM domain is looked up in
+ * @np instead of the OF node of @dev.
+ *
+ * The virtual device is named after @dev and @np. The required OPPs of @dev are
+ * not linked to the PM domain.
+ *
+ * Returns the created virtual device if successfully attached PM domain, NULL
+ * when @np has no PM domain at @index, else anERR_PTR()in case of failures.
+ * If the PM domain exists, but cannot be found or turned on, then
+ *ERR_PTR(-EPROBE_DEFER)is returned.
+ */drivers/pmdomain/core.c +11
-0+struct device *genpd_dev_pm_attach_by_node (struct device *dev, + struct device_node *np, + unsigned int index) +{ + if (!np) + return NULL; + + return genpd_dev_pm_attach_virt(dev, np, index); +} +EXPORT_SYMBOL_GPL (genpd_dev_pm_attach_by_node); +/**
*genpd_dev_pm_attach_by_name- Associate a device with one of its PM domains.
* @dev: The device used to lookup the PM domain.include/linux/pm_domain.h +3
-0@@ -477,6 +477,9 @@ struct device *genpd_dev_pm_attach_by_id(structdevice *dev, unsigned int index); struct device *genpd_dev_pm_attach_by_name(struct device *dev, const char *name); +struct device *genpd_dev_pm_attach_by_node (struct device *dev, + struct device_node *np, + unsigned int index); #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ static inline int of_genpd_add_provider_simple(struct device_node *np,struct
generic_pm_domain*genpd)include/linux/pm_domain.h +7
-0@@ -535,6 +538,13 @@ static inline struct device *genpd_dev_pm_attach_by_name(struct device *dev, return NULL; } +static inline struct device *genpd_dev_pm_attach_by_node(struct device *dev, + struct device_node *np, + unsigned int index) +{ + return NULL; +} +static inline
structgeneric_pm_domain*of_genpd_remove_last(structdevice_node*np) {include/linux/pm_domain.h +3
-0@@ -560,6 +570,9 @@ struct device *dev_pm_domain_attach_by_id(structdevice *dev, unsigned int index); struct device *dev_pm_domain_attach_by_name(struct device *dev, const char *name); +struct device *dev_pm_domain_attach_by_node (struct device *dev, + struct device_node *np, + unsigned int index); int dev_pm_domain_attach_list(struct device *dev, const struct dev_pm_domain_attach_data *data,struct
dev_pm_domain_list**list);include/linux/pm_domain.h +6
-0@@ -586,6 +599,12 @@ static inline struct device *dev_pm_domain_attach_by_name(struct device *dev, { return NULL; } +static inline struct device *dev_pm_domain_attach_by_node(struct device *dev, + struct device_node *np, + unsigned int index) +{ + return NULL; +} static inline int dev_pm_domain_attach_list(struct device *dev,const struct
dev_pm_domain_attach_data*data, structdev_pm_domain_list**list)---
base-commit:c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261023-pm_attach_by_node-13788662f3a1Best regards,
Signature · 1 line
Tomi Valkeinen <[email protected]>
Quoted 42 lines · Tomi Valkeinen
genpd_dev_pm_attach_by_id()andgenpd_dev_pm_attach_by_name()attach a virtual device to a PM domain listed in the OF node of the passed device.Some hardware blocks are described in a child node of a main device. They have no device of their own, but they do have a PM domain of their own. Neither function can attach that domain, as both parse only the OF node of the device.
An example case is TI's display subsystem and its OLDI (LVDS) transmitters:
dss@30200000 { power-domains = <...>; oldi-transmitters { oldi@0 { power-domains = <...>; }; oldi@1 { power-domains = <...>; }; }; };The OLDI TX blocks are not part of the DSS IP, but they are not quite real devices either as they don't have registers of their own, and are instead controlled via DSS registers.
Add
genpd_dev_pm_attach_by_node(), which is similar togenpd_dev_pm_attach_by_id()but instead of looking for the power-domains from the passed device's DT node, the DT node is passed explicitly. Also add a matching wrapper functiondev_pm_domain_attach_by_node().Signed-off-by Tomi Valkeinen <[email protected]>---
This is a new try for managing the OLDI power domains. Previously I tried using auxiliary device/driver for OLDIs, and handling the PDs the normal way:
Quoted 5 lines
https://lore.kernel.org/all/20260529-beagley-ai-display-v3-12-7fefdc5d1adf%40ideasonboard.com/
Then I realized an issue, mentioned in
Documentation/driver-api/driver-model/driver.rst: "-EPROBE_DEFER must not be returned ifprobe()has already created child devices".
I don't follow. How is this a problem? Why not create the child devices at a later point?
Quoted 5 lines
The PD virtual devices used in this patch's approach do not hit the issue as they don't get a driver, so they are not probed. The tidss driver's OLDI part can then use normal pm_runtime_get/put functions to manage the OLDI PDs.
Sorry, but this makes no sense to me. Considering the above statement about -EPROBE_DEFER and child devices, it sounds like we need to manage some kind of cleanup in both solutions, right?
Perhaps if you provide a user of dev_pm_domain_attach_by_node() this becomes more clear.
Kind regards
Uffe
Quoted 243 lines
--- drivers/base/power/common.c | 27 +++++++++++++ drivers/pmdomain/core.c | 97 +++++++++++++++++++++++++++++++++------------ include/linux/pm_domain.h | 19 +++++++++ 3 files changed, 117 insertions(+), 26 deletions(-)drivers/base/power/common.c +27
-0@@ -171,6 +171,33 @@ struct device *dev_pm_domain_attach_by_name(struct device *dev, }EXPORT_SYMBOL_GPL (dev_pm_domain_attach_by_name); +/** +* dev_pm_domain_attach_by_node - Associate a device with a PM domain of a DT +* node. +* @dev: The device that uses the PM domain. +* @np: The DT node with the PM domain. +* @index: The index of the PM domain in @np. +* +* Like dev_pm_domain_attach_by_id(), but the PM domain is looked up +* in @np instead of the OF node of @dev. +* +* Unlike dev_pm_domain_attach_by_id(), @dev may already be attached to a PM +* domain of its own. The driver controls the power to the PM domain through +* runtime PM of the returned virtual device, or through a device link to it. +* +* Returns the virtual created device when successfully attached to its PM +* domain, NULL in case @np has no PM domain at @index, else an ERR_PTR(). +* Note that, to detach the returned virtual device, the driver shall call +* dev_pm_domain_detach() on it, typically during the remove phase. +*/ +struct device *dev_pm_domain_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +return genpd_dev_pm_attach_by_node (dev, np, index); +} +EXPORT_SYMBOL_GPL (dev_pm_domain_attach_by_node); +/** * dev_pm_domain_attach_list - Associate a device with its PM domains. * @dev: The device used to lookup the PM domains for. drivers/pmdomain/core.c +71
-26@@ -3462,34 +3462,16 @@ int genpd_dev_pm_attach(struct device *dev) }EXPORT_SYMBOL_GPL (genpd_dev_pm_attach); -/** -* genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains. -* @dev: The device used to lookup the PM domain. -* @index: The index of the PM domain. -* -* Parse device's OF node to find a PM domain specifier at the provided @index. -* If such is found, creates a virtual device and attaches it to the retrieved -* pm_domain ops. To deal with detaching of the virtual device, the ->detach() -* callback in the struct dev_pm_domain are assigned to genpd_dev_pm_detach(). -* -* Returns the created virtual device if successfully attached PM domain, NULL -* when the device don't need a PM domain, else an ERR_PTR() in case of -* failures. If a power-domain exists for the device, but cannot be found or -* turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device -* is not probed and to re-try again later. -*/ -struct device *genpd_dev_pm_attach_by_id (struct device *dev, -unsigned int index) +static struct device *genpd_dev_pm_attach_virt (struct device *dev, +struct device_node *np, +unsigned int index) {struct device *virt_dev;int num_domains;int ret; -if (!dev->of_node) -return NULL ; -/* Verify that the index is within a valid range. */ - num_domains =of_count_phandle_with_args (dev->of_node,"power-domains" , + num_domains =of_count_phandle_with_args (np,"power-domains" ,"#power-domain-cells" );if (num_domains <0 || index >= num_domains)return NULL ;@@ -3502,10 +3484,14 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,if (!virt_dev)return ERR_PTR (-ENOMEM ); -dev_set_name (virt_dev,"genpd:%u:%s" , index,dev_name (dev)); +if (np == dev->of_node) +dev_set_name (virt_dev,"genpd:%u:%s" , index,dev_name (dev)); +else +dev_set_name (virt_dev,"genpd:%u:%s:%pOFP" , index, +dev_name (dev), np); virt_dev->bus = &genpd_bus_type; virt_dev->release = genpd_release_dev; - virt_dev->of_node =of_node_get (dev->of_node); + virt_dev->of_node =of_node_get (np); ret =device_register (virt_dev);if (ret) {@@ -3513,8 +3499,13 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,return ERR_PTR (ret); } -/* Try to attach the device to the PM domain at the specified index. */ - ret =__genpd_dev_pm_attach (virt_dev, dev, index, num_domains, false); +/* +* Try to attach the device to the PM domain at the specified index. +* Pass 0 as the num_domains when np != dev->of_node, so that the dev's +* required OPPs are not used for the PD. +*/ + ret =__genpd_dev_pm_attach (virt_dev, dev, index, + np == dev->of_node ? num_domains :0 , false);if (ret <1 ) {device_unregister (virt_dev);return ret ?ERR_PTR (ret) :NULL ;@@ -3525,8 +3516,62 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,return virt_dev; } + +/** +* genpd_dev_pm_attach_by_id - Associate a device with one of its PM domains. +* @dev: The device used to lookup the PM domain. +* @index: The index of the PM domain. +* +* Parse device's OF node to find a PM domain specifier at the provided @index. +* If such is found, creates a virtual device and attaches it to the retrieved +* pm_domain ops. To deal with detaching of the virtual device, the ->detach() +* callback in the struct dev_pm_domain are assigned to genpd_dev_pm_detach(). +* +* Returns the created virtual device if successfully attached PM domain, NULL +* when the device don't need a PM domain, else an ERR_PTR() in case of +* failures. If a power-domain exists for the device, but cannot be found or +* turned on, then ERR_PTR(-EPROBE_DEFER) is returned to ensure that the device +* is not probed and to re-try again later. +*/ +struct device *genpd_dev_pm_attach_by_id (struct device *dev, +unsigned int index) +{ +if (!dev->of_node) +return NULL ; + +return genpd_dev_pm_attach_virt (dev, dev->of_node, index); +}EXPORT_SYMBOL_GPL (genpd_dev_pm_attach_by_id); +/** +* genpd_dev_pm_attach_by_node - Associate a device with a PM domain of a DT +* node. +* @dev: The device that uses the PM domain. +* @np: The DT node with the PM domain. +* @index: The index of the PM domain in @np. +* +* Like genpd_dev_pm_attach_by_id(), but the PM domain is looked up in +* @np instead of the OF node of @dev. +* +* The virtual device is named after @dev and @np. The required OPPs of @dev are +* not linked to the PM domain. +* +* Returns the created virtual device if successfully attached PM domain, NULL +* when @np has no PM domain at @index, else an ERR_PTR() in case of failures. +* If the PM domain exists, but cannot be found or turned on, then +* ERR_PTR(-EPROBE_DEFER) is returned. +*/ +struct device *genpd_dev_pm_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +if (!np) +return NULL ; + +return genpd_dev_pm_attach_virt (dev, np, index); +} +EXPORT_SYMBOL_GPL (genpd_dev_pm_attach_by_node); +/** * genpd_dev_pm_attach_by_name - Associate a device with one of its PM domains. * @dev: The device used to lookup the PM domain. include/linux/pm_domain.h +19
-1@@ -477,6 +477,9 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev, unsigned int index);struct device *genpd_dev_pm_attach_by_name (struct device *dev,const char *name); +struct device *genpd_dev_pm_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index);#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ static inline int of_genpd_add_provider_simple (struct device_node *np,struct generic_pm_domain *genpd)@@ -535,6 +538,13 @@ static inline struct device *genpd_dev_pm_attach_by_name(struct device *dev,return NULL ; } +static inline struct device *genpd_dev_pm_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +return NULL ; +} +static inline struct generic_pm_domain *of_genpd_remove_last (struct device_node *np) {@@ -560,6 +570,9 @@ struct device *dev_pm_domain_attach_by_id(struct device *dev, unsigned int index);struct device *dev_pm_domain_attach_by_name (struct device *dev,const char *name); +struct device *dev_pm_domain_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index);int dev_pm_domain_attach_list (struct device *dev,const struct dev_pm_domain_attach_data *data,struct dev_pm_domain_list **list);@@ -586,6 +599,12 @@ static inline struct device *dev_pm_domain_attach_by_name(struct device *dev, {return NULL ; } +static inline struct device *dev_pm_domain_attach_by_node (struct device *dev, +struct device_node *np, +unsigned int index) +{ +return NULL ; +}static inline int dev_pm_domain_attach_list (struct device *dev,const struct dev_pm_domain_attach_data *data,struct dev_pm_domain_list **list) ---base-commit:
c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261023-pm_attach_by_node-13788662f3a1Best regards,
--
Tomi Valkeinen <[email protected]>
Hi,
Quoted 44 lines · Ulf Hansson
Quoted 42 lines · Tomi Valkeinen
genpd_dev_pm_attach_by_id()andgenpd_dev_pm_attach_by_name()attach a virtual device to a PM domain listed in the OF node of the passed device.Some hardware blocks are described in a child node of a main device. They have no device of their own, but they do have a PM domain of their own. Neither function can attach that domain, as both parse only the OF node of the device.
An example case is TI's display subsystem and its OLDI (LVDS) transmitters:
dss@30200000 { power-domains = <...>; oldi-transmitters { oldi@0 { power-domains = <...>; }; oldi@1 { power-domains = <...>; }; }; };The OLDI TX blocks are not part of the DSS IP, but they are not quite real devices either as they don't have registers of their own, and are instead controlled via DSS registers.
Add
genpd_dev_pm_attach_by_node(), which is similar togenpd_dev_pm_attach_by_id()but instead of looking for the power-domains from the passed device's DT node, the DT node is passed explicitly. Also add a matching wrapper functiondev_pm_domain_attach_by_node().Signed-off-by Tomi Valkeinen <[email protected]>---
This is a new try for managing the OLDI power domains. Previously I tried using auxiliary device/driver for OLDIs, and handling the PDs the normal way:
Quoted 8 lines
Quoted 5 lines
https://lore.kernel.org/all/20260529-beagley-ai-display-v3-12-7fefdc5d1adf%40ideasonboard.com/
Then I realized an issue, mentioned in
Documentation/driver-api/driver-model/driver.rst: "-EPROBE_DEFER must not be returned ifprobe()has already created child devices".I don't follow. How is this a problem? Why not create the child devices at a later point?
The problem the above text refers to is (as far as I understand):
The main driver probes, and creates a child device, which probes successfully. That causes the flag for "run deferred probes again" to be set. The main driver then continues its probe, but, for some reason, must return -EPROBE_DEFER. But as the above-mentioned flag is set, so probes are ran again, resulting in the same sequence, again and again.
Creating the child device later is difficult. We have display pipelines which contain multiple independent devices. All those devices must have probed and their bridges/panels registered to the DRM framework so that the main DRM driver can finish its probe. If parts of the pipeline are missing, we return -EPROBE_DEFER and wait for the missing parts to appear.
And the OLDIs here are not really independent devices. They don't have register space, and OLDI configuration is done via DSS registers. Yet they don't fit very well inside the DSS either, as they are clearly an outside IP, an external encoder. So the aim has been to represent them as separates child DT nodes, which allows setting OLDI properties and the media graph, but there's no compatible string and it's the tidss driver that fully manages the creation/cleanup.
Here a simple pipeline could be:
DSS -> OLDI -> panel
If the panel hasn't been registered, tidss will defer. But tidss needs OLDI to be there too, when it binds the display pipeline, otherwise it could never finish.
It is possible to create the DRM bridge entity for the OLDI without any OLDI device/driver, which allows creating the display pipeline. But the OLDI bridge code has to be able to enable the OLDI power domain, and I think the only way to use PDs currently is via devices.
So if we created the OLDI DRM bridge as mentioned above, then later in tidss probe we could create a device for OLDI, which probes and binds. That can then be used to control the PD, but there would be no other use for it. And the sequence feels like doing it backwards.
Quoted 8 lines
Quoted 4 lines
The PD virtual devices used in this patch's approach do not hit the issue as they don't get a driver, so they are not probed. The tidss driver's OLDI part can then use normal pm_runtime_get/put functions to manage the OLDI PDs.
Sorry, but this makes no sense to me. Considering the above statement about -EPROBE_DEFER and child devices, it sounds like we need to manage some kind of cleanup in both solutions, right?
Yes, but with PD virtual devices there's no probe, so they don't cause the "do deferred probes again" flag to be set. It's not the cleanup as such that causes the problem.
In some ways this does feel a bit like a work-around to the framework limitation. Representing OLDI with the aux-bus feels quite correct, I think. But then, all that plumbing just to enable/disable the PD...
So, what I'm basically trying to do in this patch is to provide an API that allows enabling/disabling a PD that's not in a DT node managed by a Linux device.
Quoted 2 lines
Perhaps if you provide a user of
dev_pm_domain_attach_by_node()this becomes more clear.
I have pushed my branch to korg:
https://git.kernel.org/pub/scm/linux/kernel/git/tomba/linux.git/log/?h=b4/beagley-ai-display
The commit that uses this patch is:
"drm/tidss: oldi: Add power domain support"
And the dts file that has the OLDI nodes is:
"arm64: dts: ti: k3-am62p-j722s-common-main: Add support for DSS"
Tomi
Quoted 65 lines · Tomi Valkeinen
Hi,
Quoted 44 lines · Ulf Hansson
Quoted 42 lines · Tomi Valkeinen
genpd_dev_pm_attach_by_id()andgenpd_dev_pm_attach_by_name()attach a virtual device to a PM domain listed in the OF node of the passed device.Some hardware blocks are described in a child node of a main device. They have no device of their own, but they do have a PM domain of their own. Neither function can attach that domain, as both parse only the OF node of the device.
An example case is TI's display subsystem and its OLDI (LVDS) transmitters:
dss@30200000 { power-domains = <...>; oldi-transmitters { oldi@0 { power-domains = <...>; }; oldi@1 { power-domains = <...>; }; }; };The OLDI TX blocks are not part of the DSS IP, but they are not quite real devices either as they don't have registers of their own, and are instead controlled via DSS registers.
Add
genpd_dev_pm_attach_by_node(), which is similar togenpd_dev_pm_attach_by_id()but instead of looking for the power-domains from the passed device's DT node, the DT node is passed explicitly. Also add a matching wrapper functiondev_pm_domain_attach_by_node().Signed-off-by Tomi Valkeinen <[email protected]>---
This is a new try for managing the OLDI power domains. Previously I tried using auxiliary device/driver for OLDIs, and handling the PDs the normal way:Quoted 8 lines
Quoted 5 lines
https://lore.kernel.org/all/20260529-beagley-ai-display-v3-12-7fefdc5d1adf%40ideasonboard.com/
Then I realized an issue, mentioned in
Documentation/driver-api/driver-model/driver.rst: "-EPROBE_DEFER must not be returned ifprobe()has already created child devices".I don't follow. How is this a problem? Why not create the child devices at a later point?
The problem the above text refers to is (as far as I understand):
The main driver probes, and creates a child device, which probes successfully. That causes the flag for "run deferred probes again" to be set. The main driver then continues its probe, but, for some reason, must return -EPROBE_DEFER. But as the above-mentioned flag is set, so probes are ran again, resulting in the same sequence, again and again.
Quoted 5 lines
Creating the child device later is difficult. We have display pipelines which contain multiple independent devices. All those devices must have probed and their bridges/panels registered to the DRM framework so that the main DRM driver can finish its probe. If parts of the pipeline are missing, we return -EPROBE_DEFER and wait for the missing parts to appear.
Well, I still don't see why creating the child devices later is a problem. In fact, the opposite seems to be the reason for these churns.
Usually what we do to solve this kind of problem is to make sure the main driver for the parent device has completed its operations for the probe and then it populates the child devices. If that doesn't work for some reason, the main driver simply needs to remove the child devices in the error path in the probe.
If the main driver requires the child devices to complete their probe, an additional synchronization mechanism needs to be added to allow them to inform the parent.
Quoted 8 lines
And the OLDIs here are not really independent devices. They don't have register space, and OLDI configuration is done via DSS registers. Yet they don't fit very well inside the DSS either, as they are clearly an outside IP, an external encoder. So the aim has been to represent them as separates child DT nodes, which allows setting OLDI properties and the media graph, but there's no compatible string and it's the tidss driver that fully manages the creation/cleanup.
I don't see how this is a problem. It's perfectly fine at ->remove() that the parent should be responsible for removing its children, right?
Quoted 8 lines
Here a simple pipeline could be:
DSS -> OLDI -> panel
If the panel hasn't been registered, tidss will defer. But tidss needs OLDI to be there too, when it binds the display pipeline, otherwise it could never finish.
I guess "finish" is the important word here. Finish doesn't necessarily need to be the same thing as that probe completed. This is what it seems to boil down to.
Quoted 5 lines
It is possible to create the DRM bridge entity for the OLDI without any OLDI device/driver, which allows creating the display pipeline. But the OLDI bridge code has to be able to enable the OLDI power domain, and I think the only way to use PDs currently is via devices.
Correct and there are good reasons for that.
Quoted 5 lines
So if we created the OLDI DRM bridge as mentioned above, then later in tidss probe we could create a device for OLDI, which probes and binds. That can then be used to control the PD, but there would be no other use for it. And the sequence feels like doing it backwards.
I am not sure this is backwards, at least if we compare with how many other subsystems/drivers are doing it.
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
The PD virtual devices used in this patch's approach do not hit the issue as they don't get a driver, so they are not probed. The tidss driver's OLDI part can then use normal pm_runtime_get/put functions to manage the OLDI PDs.
Sorry, but this makes no sense to me. Considering the above statement about -EPROBE_DEFER and child devices, it sounds like we need to manage some kind of cleanup in both solutions, right?
Quoted 7 lines
Yes, but with PD virtual devices there's no probe, so they don't cause the "do deferred probes again" flag to be set. It's not the cleanup as such that causes the problem.
In some ways this does feel a bit like a work-around to the framework limitation. Representing OLDI with the aux-bus feels quite correct, I think. But then, all that plumbing just to enable/disable the PD...
Right, but the plumbing sounds quite straightforward, especially since the auxiliary bus would solve most of the problem for us.
More importantly, I really want to avoid introducing another API for attaching to power domains.
To solve this I suggest to re-visit the auxiliary device/driver. It's also important that the created auxiliary device gets its fwnode assigned to the corresponding child node as in this way, the child node will also be properly considered for "sync_state" for the power-domain provider. In regards to the synchronization with the parent, I suggest providing a platform data for the auxiliary device, that the auxiliary driver can use to notify the driver for the parent that it's ready.
Quoted 13 lines
So, what I'm basically trying to do in this patch is to provide an API that allows enabling/disabling a PD that's not in a DT node managed by a Linux device.
Quoted 2 lines
Perhaps if you provide a user of
dev_pm_domain_attach_by_node()this becomes more clear.I have pushed my branch to korg:
https://git.kernel.org/pub/scm/linux/kernel/git/tomba/linux.git/log/?h=b4/beagley-ai-display
The commit that uses this patch is:
Quoted 8 lines
"drm/tidss: oldi: Add power domain support"
And the dts file that has the OLDI nodes is:
"arm64: dts: ti: k3-am62p-j722s-common-main: Add support for DSS"
Tomi
Kind regards
Uffe
Hi Ulf,
Quoted 77 lines · Ulf Hansson
Quoted 65 lines · Tomi Valkeinen
Hi,
Quoted 44 lines · Ulf Hansson
Quoted 42 lines · Tomi Valkeinen
genpd_dev_pm_attach_by_id()andgenpd_dev_pm_attach_by_name()attach a virtual device to a PM domain listed in the OF node of the passed device.Some hardware blocks are described in a child node of a main device. They have no device of their own, but they do have a PM domain of their own. Neither function can attach that domain, as both parse only the OF node of the device.
An example case is TI's display subsystem and its OLDI (LVDS) transmitters:
dss@30200000 { power-domains = <...>; oldi-transmitters { oldi@0 { power-domains = <...>; }; oldi@1 { power-domains = <...>; }; }; };The OLDI TX blocks are not part of the DSS IP, but they are not quite real devices either as they don't have registers of their own, and are instead controlled via DSS registers.
Add
genpd_dev_pm_attach_by_node(), which is similar togenpd_dev_pm_attach_by_id()but instead of looking for the power-domains from the passed device's DT node, the DT node is passed explicitly. Also add a matching wrapper functiondev_pm_domain_attach_by_node().Signed-off-by Tomi Valkeinen <[email protected]>---
This is a new try for managing the OLDI power domains. Previously I tried using auxiliary device/driver for OLDIs, and handling the PDs the normal way:Quoted 8 lines
Quoted 5 lines
https://lore.kernel.org/all/20260529-beagley-ai-display-v3-12-7fefdc5d1adf%40ideasonboard.com/
Then I realized an issue, mentioned in
Documentation/driver-api/driver-model/driver.rst: "-EPROBE_DEFER must not be returned ifprobe()has already created child devices".I don't follow. How is this a problem? Why not create the child devices at a later point?
The problem the above text refers to is (as far as I understand):
The main driver probes, and creates a child device, which probes successfully. That causes the flag for "run deferred probes again" to be set. The main driver then continues its probe, but, for some reason, must return -EPROBE_DEFER. But as the above-mentioned flag is set, so probes are ran again, resulting in the same sequence, again and again.
Quoted 5 lines
Creating the child device later is difficult. We have display pipelines which contain multiple independent devices. All those devices must have probed and their bridges/panels registered to the DRM framework so that the main DRM driver can finish its probe. If parts of the pipeline are missing, we return -EPROBE_DEFER and wait for the missing parts to appear.
Well, I still don't see why creating the child devices later is a problem. In fact, the opposite seems to be the reason for these churns.
Quoted 5 lines
Usually what we do to solve this kind of problem is to make sure the main driver for the parent device has completed its operations for the probe and then it populates the child devices. If that doesn't work for some reason, the main driver simply needs to remove the child devices in the error path in the probe.
Yes. And this works fine, unless something can cause EDEFE_PROBE after a child device has been created.
Quoted 3 lines
If the main driver requires the child devices to complete their probe, an additional synchronization mechanism needs to be added to allow them to inform the parent.
Yes, I think the component system can be used here. It just adds a bit more complications for a seemingly simple case.
Quoted 11 lines
Quoted 7 lines
And the OLDIs here are not really independent devices. They don't have register space, and OLDI configuration is done via DSS registers. Yet they don't fit very well inside the DSS either, as they are clearly an outside IP, an external encoder. So the aim has been to represent them as separates child DT nodes, which allows setting OLDI properties and the media graph, but there's no compatible string and it's the tidss driver that fully manages the creation/cleanup.
I don't see how this is a problem. It's perfectly fine at ->remove() that the parent should be responsible for removing its children, right?
Yes, my point was just that the OLDI is very much tied to the DSS, and can't act as a separate device. But I have to say it's a bit unclear to me what is a "device" and what is not =).
Quoted 11 lines
Quoted 7 lines
Here a simple pipeline could be:
DSS -> OLDI -> panel
If the panel hasn't been registered, tidss will defer. But tidss needs OLDI to be there too, when it binds the display pipeline, otherwise it could never finish.
I guess "finish" is the important word here. Finish doesn't necessarily need to be the same thing as that probe completed. This is what it seems to boil down to.
True. I am quite keen on keeping it simple, and managing the DSS and OLDI as one "thing", so tidss probe handles OLDI and when tidss probe is done, so is OLDI, and so is the display pipeline.
The alternatives, e.g. with component model, are always more complex to write and maintain.
Quoted 8 lines
Quoted 4 lines
It is possible to create the DRM bridge entity for the OLDI without any OLDI device/driver, which allows creating the display pipeline. But the OLDI bridge code has to be able to enable the OLDI power domain, and I think the only way to use PDs currently is via devices.
Correct and there are good reasons for that.
Quoted 1 line
Quoted 7 lines
Quoted 4 lines
So if we created the OLDI DRM bridge as mentioned above, then later in tidss probe we could create a device for OLDI, which probes and binds. That can then be used to control the PD, but there would be no other use for it. And the sequence feels like doing it backwards.
I am not sure this is backwards, at least if we compare with how many other subsystems/drivers are doing it.
What do you mean? Usually the driver probe registers to some kind of a subystem/framework. Here we would first register OLDI to the DRM subsystem, and afterwards create the OLDI device and its probe would be called. That feels backwards to me...
Or are we talking about different things?
Quoted 13 lines
Quoted 13 lines
Quoted 8 lines
Quoted 4 lines
The PD virtual devices used in this patch's approach do not hit the issue as they don't get a driver, so they are not probed. The tidss driver's OLDI part can then use normal pm_runtime_get/put functions to manage the OLDI PDs.
Sorry, but this makes no sense to me. Considering the above statement about -EPROBE_DEFER and child devices, it sounds like we need to manage some kind of cleanup in both solutions, right?
Yes, but with PD virtual devices there's no probe, so they don't cause the "do deferred probes again" flag to be set. It's not the cleanup as such that causes the problem.
Quoted 6 lines
Quoted 3 lines
In some ways this does feel a bit like a work-around to the framework limitation. Representing OLDI with the aux-bus feels quite correct, I think. But then, all that plumbing just to enable/disable the PD...
Right, but the plumbing sounds quite straightforward, especially since the auxiliary bus would solve most of the problem for us.
It doesn't feel straightforward to me... We have two ways:
- Essentially a single driver and device (tidss) which supports OLDI. Probing, removing, life-cycle management is simple and clear.
- tidss as a parent device, oldi as a child device. Separate probing/removal, life-cycle management tied together but still not the same, setup needs to be done in stages instead of doing it all in probe.
It's not rocket science, but it's still non-trivial, and only to be able to enable/disable a PD.
Quoted 2 lines
More importantly, I really want to avoid introducing another API for attaching to power domains.
Fair enough, I'll look at the aux-bus again.
Btw, this can be done without new APIs, without aux-bus. Afaik the same thing that the code added in this patch will do can also be done in the driver. So tidss would just create a minimal device for the OLDI, without a driver, point it to the OLDI DT node, etc. But it feel a bit like cheating... =)
Quoted 8 lines
To solve this I suggest to re-visit the auxiliary device/driver. It's also important that the created auxiliary device gets its fwnode assigned to the corresponding child node as in this way, the child node will also be properly considered for "
sync_state" for the power-domain provider. In regards to the synchronization with the parent, I suggest providing a platform data for the auxiliary device, that the auxiliary driver can use to notify the driver for the parent that it's ready.
Yep, I'll try to come up with something. And, indeed, perhaps the platform data can be used instead of the component model, maybe it's a bit lighter.
Tomi