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

PM / Domains: Add new helper functions for device-tree

Ideally, if we are returning a reference to a PM domain via a call to
of_genpd_get_from_provider(), then we should keep track of such
references via a reference count. The reference count could then be used
to determine if a PM domain can be safely removed. Alternatively, it is
possible to avoid such external references by providing APIs to access
the PM domain and hence, eliminate any calls to
of_genpd_get_from_provider().

Add new helper functions for adding a device and a subdomain to a PM
domain when using device-tree, so that external calls to
of_genpd_get_from_provider() can be removed.

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Jon Hunter and committed by
Rafael J. Wysocki
ec69572b 8b0510b5

+62
+46
drivers/base/power/domain.c
··· 1502 1502 EXPORT_SYMBOL_GPL(of_genpd_get_from_provider); 1503 1503 1504 1504 /** 1505 + * of_genpd_add_device() - Add a device to an I/O PM domain 1506 + * @genpdspec: OF phandle args to use for look-up PM domain 1507 + * @dev: Device to be added. 1508 + * 1509 + * Looks-up an I/O PM domain based upon phandle args provided and adds 1510 + * the device to the PM domain. Returns a negative error code on failure. 1511 + */ 1512 + int of_genpd_add_device(struct of_phandle_args *genpdspec, struct device *dev) 1513 + { 1514 + struct generic_pm_domain *genpd; 1515 + 1516 + genpd = of_genpd_get_from_provider(genpdspec); 1517 + if (IS_ERR(genpd)) 1518 + return PTR_ERR(genpd); 1519 + 1520 + return pm_genpd_add_device(genpd, dev); 1521 + } 1522 + EXPORT_SYMBOL_GPL(of_genpd_add_device); 1523 + 1524 + /** 1525 + * of_genpd_add_subdomain - Add a subdomain to an I/O PM domain. 1526 + * @parent_spec: OF phandle args to use for parent PM domain look-up 1527 + * @subdomain_spec: OF phandle args to use for subdomain look-up 1528 + * 1529 + * Looks-up a parent PM domain and subdomain based upon phandle args 1530 + * provided and adds the subdomain to the parent PM domain. Returns a 1531 + * negative error code on failure. 1532 + */ 1533 + int of_genpd_add_subdomain(struct of_phandle_args *parent_spec, 1534 + struct of_phandle_args *subdomain_spec) 1535 + { 1536 + struct generic_pm_domain *parent, *subdomain; 1537 + 1538 + parent = of_genpd_get_from_provider(parent_spec); 1539 + if (IS_ERR(parent)) 1540 + return PTR_ERR(parent); 1541 + 1542 + subdomain = of_genpd_get_from_provider(subdomain_spec); 1543 + if (IS_ERR(subdomain)) 1544 + return PTR_ERR(subdomain); 1545 + 1546 + return pm_genpd_add_subdomain(parent, subdomain); 1547 + } 1548 + EXPORT_SYMBOL_GPL(of_genpd_add_subdomain); 1549 + 1550 + /** 1505 1551 * genpd_dev_pm_detach - Detach a device from its PM domain. 1506 1552 * @dev: Device to detach. 1507 1553 * @power_off: Currently not used
+16
include/linux/pm_domain.h
··· 208 208 struct generic_pm_domain *__of_genpd_xlate_onecell( 209 209 struct of_phandle_args *genpdspec, 210 210 void *data); 211 + extern int of_genpd_add_device(struct of_phandle_args *args, 212 + struct device *dev); 213 + extern int of_genpd_add_subdomain(struct of_phandle_args *parent, 214 + struct of_phandle_args *new_subdomain); 211 215 212 216 int genpd_dev_pm_attach(struct device *dev); 213 217 #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ ··· 230 226 231 227 #define __of_genpd_xlate_simple NULL 232 228 #define __of_genpd_xlate_onecell NULL 229 + 230 + static inline int of_genpd_add_device(struct of_phandle_args *args, 231 + struct device *dev) 232 + { 233 + return -ENODEV; 234 + } 235 + 236 + static inline int of_genpd_add_subdomain(struct of_phandle_args *parent, 237 + struct of_phandle_args *new_subdomain) 238 + { 239 + return -ENODEV; 240 + } 233 241 234 242 static inline int genpd_dev_pm_attach(struct device *dev) 235 243 {