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

OPP: Migrate set-supported-hw API to use set-config helpers

Now that we have a central API to handle all OPP table configurations,
migrate the set-supported-hw family of helpers to use the new
infrastructure.

The return type and parameter to the APIs change a bit due to this,
update the current users as well in the same commit in order to avoid
breaking builds.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

+66 -105
+6 -6
drivers/cpufreq/imx-cpufreq-dt.c
··· 31 31 32 32 /* cpufreq-dt device registered by imx-cpufreq-dt */ 33 33 static struct platform_device *cpufreq_dt_pdev; 34 - static struct opp_table *cpufreq_opp_table; 35 34 static struct device *cpu_dev; 35 + static int cpufreq_opp_token; 36 36 37 37 enum IMX7ULP_CPUFREQ_CLKS { 38 38 ARM, ··· 153 153 dev_info(&pdev->dev, "cpu speed grade %d mkt segment %d supported-hw %#x %#x\n", 154 154 speed_grade, mkt_segment, supported_hw[0], supported_hw[1]); 155 155 156 - cpufreq_opp_table = dev_pm_opp_set_supported_hw(cpu_dev, supported_hw, 2); 157 - if (IS_ERR(cpufreq_opp_table)) { 158 - ret = PTR_ERR(cpufreq_opp_table); 156 + cpufreq_opp_token = dev_pm_opp_set_supported_hw(cpu_dev, supported_hw, 2); 157 + if (cpufreq_opp_token < 0) { 158 + ret = cpufreq_opp_token; 159 159 dev_err(&pdev->dev, "Failed to set supported opp: %d\n", ret); 160 160 return ret; 161 161 } ··· 163 163 cpufreq_dt_pdev = platform_device_register_data( 164 164 &pdev->dev, "cpufreq-dt", -1, NULL, 0); 165 165 if (IS_ERR(cpufreq_dt_pdev)) { 166 - dev_pm_opp_put_supported_hw(cpufreq_opp_table); 166 + dev_pm_opp_put_supported_hw(cpufreq_opp_token); 167 167 ret = PTR_ERR(cpufreq_dt_pdev); 168 168 dev_err(&pdev->dev, "Failed to register cpufreq-dt: %d\n", ret); 169 169 return ret; ··· 176 176 { 177 177 platform_device_unregister(cpufreq_dt_pdev); 178 178 if (!of_machine_is_compatible("fsl,imx7ulp")) 179 - dev_pm_opp_put_supported_hw(cpufreq_opp_table); 179 + dev_pm_opp_put_supported_hw(cpufreq_opp_token); 180 180 else 181 181 clk_bulk_put(ARRAY_SIZE(imx7ulp_clks), imx7ulp_clks); 182 182
+5 -7
drivers/cpufreq/tegra20-cpufreq.c
··· 32 32 return ret; 33 33 } 34 34 35 - static void tegra20_cpufreq_put_supported_hw(void *opp_table) 35 + static void tegra20_cpufreq_put_supported_hw(void *opp_token) 36 36 { 37 - dev_pm_opp_put_supported_hw(opp_table); 37 + dev_pm_opp_put_supported_hw((unsigned long) opp_token); 38 38 } 39 39 40 40 static void tegra20_cpufreq_dt_unregister(void *cpufreq_dt) ··· 45 45 static int tegra20_cpufreq_probe(struct platform_device *pdev) 46 46 { 47 47 struct platform_device *cpufreq_dt; 48 - struct opp_table *opp_table; 49 48 struct device *cpu_dev; 50 49 u32 versions[2]; 51 50 int err; ··· 70 71 if (WARN_ON(!cpu_dev)) 71 72 return -ENODEV; 72 73 73 - opp_table = dev_pm_opp_set_supported_hw(cpu_dev, versions, 2); 74 - err = PTR_ERR_OR_ZERO(opp_table); 75 - if (err) { 74 + err = dev_pm_opp_set_supported_hw(cpu_dev, versions, 2); 75 + if (err < 0) { 76 76 dev_err(&pdev->dev, "failed to set supported hw: %d\n", err); 77 77 return err; 78 78 } 79 79 80 80 err = devm_add_action_or_reset(&pdev->dev, 81 81 tegra20_cpufreq_put_supported_hw, 82 - opp_table); 82 + (void *)((unsigned long) err)); 83 83 if (err) 84 84 return err; 85 85
+5 -6
drivers/memory/tegra/tegra124-emc.c
··· 1395 1395 static int tegra_emc_opp_table_init(struct tegra_emc *emc) 1396 1396 { 1397 1397 u32 hw_version = BIT(tegra_sku_info.soc_speedo_id); 1398 - struct opp_table *hw_opp_table; 1399 - int err; 1398 + int opp_token, err; 1400 1399 1401 - hw_opp_table = dev_pm_opp_set_supported_hw(emc->dev, &hw_version, 1); 1402 - err = PTR_ERR_OR_ZERO(hw_opp_table); 1403 - if (err) { 1400 + err = dev_pm_opp_set_supported_hw(emc->dev, &hw_version, 1); 1401 + if (err < 0) { 1404 1402 dev_err(emc->dev, "failed to set OPP supported HW: %d\n", err); 1405 1403 return err; 1406 1404 } 1405 + opp_token = err; 1407 1406 1408 1407 err = dev_pm_opp_of_add_table(emc->dev); 1409 1408 if (err) { ··· 1429 1430 remove_table: 1430 1431 dev_pm_opp_of_remove_table(emc->dev); 1431 1432 put_hw_table: 1432 - dev_pm_opp_put_supported_hw(hw_opp_table); 1433 + dev_pm_opp_put_supported_hw(opp_token); 1433 1434 1434 1435 return err; 1435 1436 }
+20 -67
drivers/opp/core.c
··· 1952 1952 } 1953 1953 1954 1954 /** 1955 - * dev_pm_opp_set_supported_hw() - Set supported platforms 1955 + * _opp_set_supported_hw() - Set supported platforms 1956 1956 * @dev: Device for which supported-hw has to be set. 1957 1957 * @versions: Array of hierarchy of versions to match. 1958 1958 * @count: Number of elements in the array. ··· 1962 1962 * OPPs, which are available for those versions, based on its 'opp-supported-hw' 1963 1963 * property. 1964 1964 */ 1965 - struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, 1966 - const u32 *versions, unsigned int count) 1965 + static int _opp_set_supported_hw(struct opp_table *opp_table, 1966 + const u32 *versions, unsigned int count) 1967 1967 { 1968 - struct opp_table *opp_table; 1969 - 1970 - opp_table = _add_opp_table(dev, false); 1971 - if (IS_ERR(opp_table)) 1972 - return opp_table; 1973 - 1974 - /* Make sure there are no concurrent readers while updating opp_table */ 1975 - WARN_ON(!list_empty(&opp_table->opp_list)); 1976 - 1977 1968 /* Another CPU that shares the OPP table has set the property ? */ 1978 1969 if (opp_table->supported_hw) 1979 - return opp_table; 1970 + return 0; 1980 1971 1981 1972 opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions), 1982 1973 GFP_KERNEL); 1983 - if (!opp_table->supported_hw) { 1984 - dev_pm_opp_put_opp_table(opp_table); 1985 - return ERR_PTR(-ENOMEM); 1986 - } 1974 + if (!opp_table->supported_hw) 1975 + return -ENOMEM; 1987 1976 1988 1977 opp_table->supported_hw_count = count; 1989 1978 1990 - return opp_table; 1979 + return 0; 1991 1980 } 1992 - EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw); 1993 1981 1994 1982 /** 1995 - * dev_pm_opp_put_supported_hw() - Releases resources blocked for supported hw 1996 - * @opp_table: OPP table returned by dev_pm_opp_set_supported_hw(). 1983 + * _opp_put_supported_hw() - Releases resources blocked for supported hw 1984 + * @opp_table: OPP table returned by _opp_set_supported_hw(). 1997 1985 * 1998 1986 * This is required only for the V2 bindings, and is called for a matching 1999 - * dev_pm_opp_set_supported_hw(). Until this is called, the opp_table structure 1987 + * _opp_set_supported_hw(). Until this is called, the opp_table structure 2000 1988 * will not be freed. 2001 1989 */ 2002 - void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) 1990 + static void _opp_put_supported_hw(struct opp_table *opp_table) 2003 1991 { 2004 - if (unlikely(!opp_table)) 2005 - return; 2006 - 2007 - kfree(opp_table->supported_hw); 2008 - opp_table->supported_hw = NULL; 2009 - opp_table->supported_hw_count = 0; 2010 - 2011 - dev_pm_opp_put_opp_table(opp_table); 1992 + if (opp_table->supported_hw) { 1993 + kfree(opp_table->supported_hw); 1994 + opp_table->supported_hw = NULL; 1995 + opp_table->supported_hw_count = 0; 1996 + } 2012 1997 } 2013 - EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw); 2014 - 2015 - static void devm_pm_opp_supported_hw_release(void *data) 2016 - { 2017 - dev_pm_opp_put_supported_hw(data); 2018 - } 2019 - 2020 - /** 2021 - * devm_pm_opp_set_supported_hw() - Set supported platforms 2022 - * @dev: Device for which supported-hw has to be set. 2023 - * @versions: Array of hierarchy of versions to match. 2024 - * @count: Number of elements in the array. 2025 - * 2026 - * This is a resource-managed variant of dev_pm_opp_set_supported_hw(). 2027 - * 2028 - * Return: 0 on success and errorno otherwise. 2029 - */ 2030 - int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, 2031 - unsigned int count) 2032 - { 2033 - struct opp_table *opp_table; 2034 - 2035 - opp_table = dev_pm_opp_set_supported_hw(dev, versions, count); 2036 - if (IS_ERR(opp_table)) 2037 - return PTR_ERR(opp_table); 2038 - 2039 - return devm_add_action_or_reset(dev, devm_pm_opp_supported_hw_release, 2040 - opp_table); 2041 - } 2042 - EXPORT_SYMBOL_GPL(devm_pm_opp_set_supported_hw); 2043 1998 2044 1999 /** 2045 2000 * dev_pm_opp_set_prop_name() - Set prop-extn name ··· 2538 2583 if (data->flags & OPP_CONFIG_REGULATOR) 2539 2584 _opp_put_regulators(data->opp_table); 2540 2585 if (data->flags & OPP_CONFIG_SUPPORTED_HW) 2541 - dev_pm_opp_put_supported_hw(data->opp_table); 2586 + _opp_put_supported_hw(data->opp_table); 2542 2587 if (data->flags & OPP_CONFIG_REGULATOR_HELPER) 2543 2588 dev_pm_opp_unregister_set_opp_helper(data->opp_table); 2544 2589 if (data->flags & OPP_CONFIG_PROP_NAME) ··· 2649 2694 2650 2695 /* Configure supported hardware */ 2651 2696 if (config->supported_hw) { 2652 - err = dev_pm_opp_set_supported_hw(dev, config->supported_hw, 2653 - config->supported_hw_count); 2654 - if (IS_ERR(err)) { 2655 - ret = PTR_ERR(err); 2697 + ret = _opp_set_supported_hw(opp_table, config->supported_hw, 2698 + config->supported_hw_count); 2699 + if (ret) 2656 2700 goto err; 2657 - } 2658 2701 2659 2702 data->flags |= OPP_CONFIG_SUPPORTED_HW; 2660 2703 }
+30 -19
include/linux/pm_opp.h
··· 184 184 int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config); 185 185 void dev_pm_opp_clear_config(int token); 186 186 187 - struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count); 188 - void dev_pm_opp_put_supported_hw(struct opp_table *opp_table); 189 - int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count); 190 187 struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name); 191 188 void dev_pm_opp_put_prop_name(struct opp_table *opp_table); 192 189 struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name); ··· 362 365 } 363 366 364 367 static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb) 365 - { 366 - return -EOPNOTSUPP; 367 - } 368 - 369 - static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, 370 - const u32 *versions, 371 - unsigned int count) 372 - { 373 - return ERR_PTR(-EOPNOTSUPP); 374 - } 375 - 376 - static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {} 377 - 378 - static inline int devm_pm_opp_set_supported_hw(struct device *dev, 379 - const u32 *versions, 380 - unsigned int count) 381 368 { 382 369 return -EOPNOTSUPP; 383 370 } ··· 594 613 { 595 614 struct dev_pm_opp_config config = { 596 615 .regulator_names = names, 616 + }; 617 + 618 + return devm_pm_opp_set_config(dev, &config); 619 + } 620 + 621 + /* Supported-hw helpers */ 622 + static inline int dev_pm_opp_set_supported_hw(struct device *dev, 623 + const u32 *versions, 624 + unsigned int count) 625 + { 626 + struct dev_pm_opp_config config = { 627 + .supported_hw = versions, 628 + .supported_hw_count = count, 629 + }; 630 + 631 + return dev_pm_opp_set_config(dev, &config); 632 + } 633 + 634 + static inline void dev_pm_opp_put_supported_hw(int token) 635 + { 636 + dev_pm_opp_clear_config(token); 637 + } 638 + 639 + static inline int devm_pm_opp_set_supported_hw(struct device *dev, 640 + const u32 *versions, 641 + unsigned int count) 642 + { 643 + struct dev_pm_opp_config config = { 644 + .supported_hw = versions, 645 + .supported_hw_count = count, 597 646 }; 598 647 599 648 return devm_pm_opp_set_config(dev, &config);