diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-05-06 16:05:16 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-05-06 16:05:16 -0400 |
commit | c8541203a680a63ba7dcc4e50cd25d40e9a13dff (patch) | |
tree | e33573ab6d220be72986bde903fef61a8fa304e3 /drivers/base/power/opp/core.c | |
parent | 21f8a99ce61b2d4b74bd425a5bf7e9efbe162788 (diff) | |
parent | f47b72a15a9679dd4dc1af681d4d2f1ca2815552 (diff) |
Merge back new material for v4.7.
Diffstat (limited to 'drivers/base/power/opp/core.c')
-rw-r--r-- | drivers/base/power/opp/core.c | 440 |
1 files changed, 21 insertions, 419 deletions
diff --git a/drivers/base/power/opp/core.c b/drivers/base/power/opp/core.c index d8f4cc22856c..7c04c87738a6 100644 --- a/drivers/base/power/opp/core.c +++ b/drivers/base/power/opp/core.c | |||
@@ -18,7 +18,6 @@ | |||
18 | #include <linux/err.h> | 18 | #include <linux/err.h> |
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include <linux/device.h> | 20 | #include <linux/device.h> |
21 | #include <linux/of.h> | ||
22 | #include <linux/export.h> | 21 | #include <linux/export.h> |
23 | #include <linux/regulator/consumer.h> | 22 | #include <linux/regulator/consumer.h> |
24 | 23 | ||
@@ -29,7 +28,7 @@ | |||
29 | * from here, with each opp_table containing the list of opps it supports in | 28 | * from here, with each opp_table containing the list of opps it supports in |
30 | * various states of availability. | 29 | * various states of availability. |
31 | */ | 30 | */ |
32 | static LIST_HEAD(opp_tables); | 31 | LIST_HEAD(opp_tables); |
33 | /* Lock to allow exclusive modification to the device and opp lists */ | 32 | /* Lock to allow exclusive modification to the device and opp lists */ |
34 | DEFINE_MUTEX(opp_table_lock); | 33 | DEFINE_MUTEX(opp_table_lock); |
35 | 34 | ||
@@ -53,26 +52,6 @@ static struct opp_device *_find_opp_dev(const struct device *dev, | |||
53 | return NULL; | 52 | return NULL; |
54 | } | 53 | } |
55 | 54 | ||
56 | static struct opp_table *_managed_opp(const struct device_node *np) | ||
57 | { | ||
58 | struct opp_table *opp_table; | ||
59 | |||
60 | list_for_each_entry_rcu(opp_table, &opp_tables, node) { | ||
61 | if (opp_table->np == np) { | ||
62 | /* | ||
63 | * Multiple devices can point to the same OPP table and | ||
64 | * so will have same node-pointer, np. | ||
65 | * | ||
66 | * But the OPPs will be considered as shared only if the | ||
67 | * OPP table contains a "opp-shared" property. | ||
68 | */ | ||
69 | return opp_table->shared_opp ? opp_table : NULL; | ||
70 | } | ||
71 | } | ||
72 | |||
73 | return NULL; | ||
74 | } | ||
75 | |||
76 | /** | 55 | /** |
77 | * _find_opp_table() - find opp_table struct using device pointer | 56 | * _find_opp_table() - find opp_table struct using device pointer |
78 | * @dev: device pointer used to lookup OPP table | 57 | * @dev: device pointer used to lookup OPP table |
@@ -757,7 +736,6 @@ static struct opp_table *_add_opp_table(struct device *dev) | |||
757 | { | 736 | { |
758 | struct opp_table *opp_table; | 737 | struct opp_table *opp_table; |
759 | struct opp_device *opp_dev; | 738 | struct opp_device *opp_dev; |
760 | struct device_node *np; | ||
761 | int ret; | 739 | int ret; |
762 | 740 | ||
763 | /* Check for existing table for 'dev' first */ | 741 | /* Check for existing table for 'dev' first */ |
@@ -781,20 +759,7 @@ static struct opp_table *_add_opp_table(struct device *dev) | |||
781 | return NULL; | 759 | return NULL; |
782 | } | 760 | } |
783 | 761 | ||
784 | /* | 762 | _of_init_opp_table(opp_table, dev); |
785 | * Only required for backward compatibility with v1 bindings, but isn't | ||
786 | * harmful for other cases. And so we do it unconditionally. | ||
787 | */ | ||
788 | np = of_node_get(dev->of_node); | ||
789 | if (np) { | ||
790 | u32 val; | ||
791 | |||
792 | if (!of_property_read_u32(np, "clock-latency", &val)) | ||
793 | opp_table->clock_latency_ns_max = val; | ||
794 | of_property_read_u32(np, "voltage-tolerance", | ||
795 | &opp_table->voltage_tolerance_v1); | ||
796 | of_node_put(np); | ||
797 | } | ||
798 | 763 | ||
799 | /* Set regulator to a non-NULL error value */ | 764 | /* Set regulator to a non-NULL error value */ |
800 | opp_table->regulator = ERR_PTR(-ENXIO); | 765 | opp_table->regulator = ERR_PTR(-ENXIO); |
@@ -890,8 +855,8 @@ static void _kfree_opp_rcu(struct rcu_head *head) | |||
890 | * It is assumed that the caller holds required mutex for an RCU updater | 855 | * It is assumed that the caller holds required mutex for an RCU updater |
891 | * strategy. | 856 | * strategy. |
892 | */ | 857 | */ |
893 | static void _opp_remove(struct opp_table *opp_table, | 858 | void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp, |
894 | struct dev_pm_opp *opp, bool notify) | 859 | bool notify) |
895 | { | 860 | { |
896 | /* | 861 | /* |
897 | * Notify the changes in the availability of the operable | 862 | * Notify the changes in the availability of the operable |
@@ -952,8 +917,8 @@ unlock: | |||
952 | } | 917 | } |
953 | EXPORT_SYMBOL_GPL(dev_pm_opp_remove); | 918 | EXPORT_SYMBOL_GPL(dev_pm_opp_remove); |
954 | 919 | ||
955 | static struct dev_pm_opp *_allocate_opp(struct device *dev, | 920 | struct dev_pm_opp *_allocate_opp(struct device *dev, |
956 | struct opp_table **opp_table) | 921 | struct opp_table **opp_table) |
957 | { | 922 | { |
958 | struct dev_pm_opp *opp; | 923 | struct dev_pm_opp *opp; |
959 | 924 | ||
@@ -989,8 +954,8 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp, | |||
989 | return true; | 954 | return true; |
990 | } | 955 | } |
991 | 956 | ||
992 | static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, | 957 | int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, |
993 | struct opp_table *opp_table) | 958 | struct opp_table *opp_table) |
994 | { | 959 | { |
995 | struct dev_pm_opp *opp; | 960 | struct dev_pm_opp *opp; |
996 | struct list_head *head = &opp_table->opp_list; | 961 | struct list_head *head = &opp_table->opp_list; |
@@ -1066,8 +1031,8 @@ static int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, | |||
1066 | * Duplicate OPPs (both freq and volt are same) and !opp->available | 1031 | * Duplicate OPPs (both freq and volt are same) and !opp->available |
1067 | * -ENOMEM Memory allocation failure | 1032 | * -ENOMEM Memory allocation failure |
1068 | */ | 1033 | */ |
1069 | static int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt, | 1034 | int _opp_add_v1(struct device *dev, unsigned long freq, long u_volt, |
1070 | bool dynamic) | 1035 | bool dynamic) |
1071 | { | 1036 | { |
1072 | struct opp_table *opp_table; | 1037 | struct opp_table *opp_table; |
1073 | struct dev_pm_opp *new_opp; | 1038 | struct dev_pm_opp *new_opp; |
@@ -1112,83 +1077,6 @@ unlock: | |||
1112 | return ret; | 1077 | return ret; |
1113 | } | 1078 | } |
1114 | 1079 | ||
1115 | /* TODO: Support multiple regulators */ | ||
1116 | static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, | ||
1117 | struct opp_table *opp_table) | ||
1118 | { | ||
1119 | u32 microvolt[3] = {0}; | ||
1120 | u32 val; | ||
1121 | int count, ret; | ||
1122 | struct property *prop = NULL; | ||
1123 | char name[NAME_MAX]; | ||
1124 | |||
1125 | /* Search for "opp-microvolt-<name>" */ | ||
1126 | if (opp_table->prop_name) { | ||
1127 | snprintf(name, sizeof(name), "opp-microvolt-%s", | ||
1128 | opp_table->prop_name); | ||
1129 | prop = of_find_property(opp->np, name, NULL); | ||
1130 | } | ||
1131 | |||
1132 | if (!prop) { | ||
1133 | /* Search for "opp-microvolt" */ | ||
1134 | sprintf(name, "opp-microvolt"); | ||
1135 | prop = of_find_property(opp->np, name, NULL); | ||
1136 | |||
1137 | /* Missing property isn't a problem, but an invalid entry is */ | ||
1138 | if (!prop) | ||
1139 | return 0; | ||
1140 | } | ||
1141 | |||
1142 | count = of_property_count_u32_elems(opp->np, name); | ||
1143 | if (count < 0) { | ||
1144 | dev_err(dev, "%s: Invalid %s property (%d)\n", | ||
1145 | __func__, name, count); | ||
1146 | return count; | ||
1147 | } | ||
1148 | |||
1149 | /* There can be one or three elements here */ | ||
1150 | if (count != 1 && count != 3) { | ||
1151 | dev_err(dev, "%s: Invalid number of elements in %s property (%d)\n", | ||
1152 | __func__, name, count); | ||
1153 | return -EINVAL; | ||
1154 | } | ||
1155 | |||
1156 | ret = of_property_read_u32_array(opp->np, name, microvolt, count); | ||
1157 | if (ret) { | ||
1158 | dev_err(dev, "%s: error parsing %s: %d\n", __func__, name, ret); | ||
1159 | return -EINVAL; | ||
1160 | } | ||
1161 | |||
1162 | opp->u_volt = microvolt[0]; | ||
1163 | |||
1164 | if (count == 1) { | ||
1165 | opp->u_volt_min = opp->u_volt; | ||
1166 | opp->u_volt_max = opp->u_volt; | ||
1167 | } else { | ||
1168 | opp->u_volt_min = microvolt[1]; | ||
1169 | opp->u_volt_max = microvolt[2]; | ||
1170 | } | ||
1171 | |||
1172 | /* Search for "opp-microamp-<name>" */ | ||
1173 | prop = NULL; | ||
1174 | if (opp_table->prop_name) { | ||
1175 | snprintf(name, sizeof(name), "opp-microamp-%s", | ||
1176 | opp_table->prop_name); | ||
1177 | prop = of_find_property(opp->np, name, NULL); | ||
1178 | } | ||
1179 | |||
1180 | if (!prop) { | ||
1181 | /* Search for "opp-microamp" */ | ||
1182 | sprintf(name, "opp-microamp"); | ||
1183 | prop = of_find_property(opp->np, name, NULL); | ||
1184 | } | ||
1185 | |||
1186 | if (prop && !of_property_read_u32(opp->np, name, &val)) | ||
1187 | opp->u_amp = val; | ||
1188 | |||
1189 | return 0; | ||
1190 | } | ||
1191 | |||
1192 | /** | 1080 | /** |
1193 | * dev_pm_opp_set_supported_hw() - Set supported platforms | 1081 | * dev_pm_opp_set_supported_hw() - Set supported platforms |
1194 | * @dev: Device for which supported-hw has to be set. | 1082 | * @dev: Device for which supported-hw has to be set. |
@@ -1517,144 +1405,6 @@ unlock: | |||
1517 | } | 1405 | } |
1518 | EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulator); | 1406 | EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulator); |
1519 | 1407 | ||
1520 | static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table, | ||
1521 | struct device_node *np) | ||
1522 | { | ||
1523 | unsigned int count = opp_table->supported_hw_count; | ||
1524 | u32 version; | ||
1525 | int ret; | ||
1526 | |||
1527 | if (!opp_table->supported_hw) | ||
1528 | return true; | ||
1529 | |||
1530 | while (count--) { | ||
1531 | ret = of_property_read_u32_index(np, "opp-supported-hw", count, | ||
1532 | &version); | ||
1533 | if (ret) { | ||
1534 | dev_warn(dev, "%s: failed to read opp-supported-hw property at index %d: %d\n", | ||
1535 | __func__, count, ret); | ||
1536 | return false; | ||
1537 | } | ||
1538 | |||
1539 | /* Both of these are bitwise masks of the versions */ | ||
1540 | if (!(version & opp_table->supported_hw[count])) | ||
1541 | return false; | ||
1542 | } | ||
1543 | |||
1544 | return true; | ||
1545 | } | ||
1546 | |||
1547 | /** | ||
1548 | * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings) | ||
1549 | * @dev: device for which we do this operation | ||
1550 | * @np: device node | ||
1551 | * | ||
1552 | * This function adds an opp definition to the opp table and returns status. The | ||
1553 | * opp can be controlled using dev_pm_opp_enable/disable functions and may be | ||
1554 | * removed by dev_pm_opp_remove. | ||
1555 | * | ||
1556 | * Locking: The internal opp_table and opp structures are RCU protected. | ||
1557 | * Hence this function internally uses RCU updater strategy with mutex locks | ||
1558 | * to keep the integrity of the internal data structures. Callers should ensure | ||
1559 | * that this function is *NOT* called under RCU protection or in contexts where | ||
1560 | * mutex cannot be locked. | ||
1561 | * | ||
1562 | * Return: | ||
1563 | * 0 On success OR | ||
1564 | * Duplicate OPPs (both freq and volt are same) and opp->available | ||
1565 | * -EEXIST Freq are same and volt are different OR | ||
1566 | * Duplicate OPPs (both freq and volt are same) and !opp->available | ||
1567 | * -ENOMEM Memory allocation failure | ||
1568 | * -EINVAL Failed parsing the OPP node | ||
1569 | */ | ||
1570 | static int _opp_add_static_v2(struct device *dev, struct device_node *np) | ||
1571 | { | ||
1572 | struct opp_table *opp_table; | ||
1573 | struct dev_pm_opp *new_opp; | ||
1574 | u64 rate; | ||
1575 | u32 val; | ||
1576 | int ret; | ||
1577 | |||
1578 | /* Hold our table modification lock here */ | ||
1579 | mutex_lock(&opp_table_lock); | ||
1580 | |||
1581 | new_opp = _allocate_opp(dev, &opp_table); | ||
1582 | if (!new_opp) { | ||
1583 | ret = -ENOMEM; | ||
1584 | goto unlock; | ||
1585 | } | ||
1586 | |||
1587 | ret = of_property_read_u64(np, "opp-hz", &rate); | ||
1588 | if (ret < 0) { | ||
1589 | dev_err(dev, "%s: opp-hz not found\n", __func__); | ||
1590 | goto free_opp; | ||
1591 | } | ||
1592 | |||
1593 | /* Check if the OPP supports hardware's hierarchy of versions or not */ | ||
1594 | if (!_opp_is_supported(dev, opp_table, np)) { | ||
1595 | dev_dbg(dev, "OPP not supported by hardware: %llu\n", rate); | ||
1596 | goto free_opp; | ||
1597 | } | ||
1598 | |||
1599 | /* | ||
1600 | * Rate is defined as an unsigned long in clk API, and so casting | ||
1601 | * explicitly to its type. Must be fixed once rate is 64 bit | ||
1602 | * guaranteed in clk API. | ||
1603 | */ | ||
1604 | new_opp->rate = (unsigned long)rate; | ||
1605 | new_opp->turbo = of_property_read_bool(np, "turbo-mode"); | ||
1606 | |||
1607 | new_opp->np = np; | ||
1608 | new_opp->dynamic = false; | ||
1609 | new_opp->available = true; | ||
1610 | |||
1611 | if (!of_property_read_u32(np, "clock-latency-ns", &val)) | ||
1612 | new_opp->clock_latency_ns = val; | ||
1613 | |||
1614 | ret = opp_parse_supplies(new_opp, dev, opp_table); | ||
1615 | if (ret) | ||
1616 | goto free_opp; | ||
1617 | |||
1618 | ret = _opp_add(dev, new_opp, opp_table); | ||
1619 | if (ret) | ||
1620 | goto free_opp; | ||
1621 | |||
1622 | /* OPP to select on device suspend */ | ||
1623 | if (of_property_read_bool(np, "opp-suspend")) { | ||
1624 | if (opp_table->suspend_opp) { | ||
1625 | dev_warn(dev, "%s: Multiple suspend OPPs found (%lu %lu)\n", | ||
1626 | __func__, opp_table->suspend_opp->rate, | ||
1627 | new_opp->rate); | ||
1628 | } else { | ||
1629 | new_opp->suspend = true; | ||
1630 | opp_table->suspend_opp = new_opp; | ||
1631 | } | ||
1632 | } | ||
1633 | |||
1634 | if (new_opp->clock_latency_ns > opp_table->clock_latency_ns_max) | ||
1635 | opp_table->clock_latency_ns_max = new_opp->clock_latency_ns; | ||
1636 | |||
1637 | mutex_unlock(&opp_table_lock); | ||
1638 | |||
1639 | pr_debug("%s: turbo:%d rate:%lu uv:%lu uvmin:%lu uvmax:%lu latency:%lu\n", | ||
1640 | __func__, new_opp->turbo, new_opp->rate, new_opp->u_volt, | ||
1641 | new_opp->u_volt_min, new_opp->u_volt_max, | ||
1642 | new_opp->clock_latency_ns); | ||
1643 | |||
1644 | /* | ||
1645 | * Notify the changes in the availability of the operable | ||
1646 | * frequency/voltage list. | ||
1647 | */ | ||
1648 | srcu_notifier_call_chain(&opp_table->srcu_head, OPP_EVENT_ADD, new_opp); | ||
1649 | return 0; | ||
1650 | |||
1651 | free_opp: | ||
1652 | _opp_remove(opp_table, new_opp, false); | ||
1653 | unlock: | ||
1654 | mutex_unlock(&opp_table_lock); | ||
1655 | return ret; | ||
1656 | } | ||
1657 | |||
1658 | /** | 1408 | /** |
1659 | * dev_pm_opp_add() - Add an OPP table from a table definitions | 1409 | * dev_pm_opp_add() - Add an OPP table from a table definitions |
1660 | * @dev: device for which we do this operation | 1410 | * @dev: device for which we do this operation |
@@ -1842,21 +1592,11 @@ struct srcu_notifier_head *dev_pm_opp_get_notifier(struct device *dev) | |||
1842 | } | 1592 | } |
1843 | EXPORT_SYMBOL_GPL(dev_pm_opp_get_notifier); | 1593 | EXPORT_SYMBOL_GPL(dev_pm_opp_get_notifier); |
1844 | 1594 | ||
1845 | #ifdef CONFIG_OF | 1595 | /* |
1846 | /** | 1596 | * Free OPPs either created using static entries present in DT or even the |
1847 | * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT | 1597 | * dynamically added entries based on remove_all param. |
1848 | * entries | ||
1849 | * @dev: device pointer used to lookup OPP table. | ||
1850 | * | ||
1851 | * Free OPPs created using static entries present in DT. | ||
1852 | * | ||
1853 | * Locking: The internal opp_table and opp structures are RCU protected. | ||
1854 | * Hence this function indirectly uses RCU updater strategy with mutex locks | ||
1855 | * to keep the integrity of the internal data structures. Callers should ensure | ||
1856 | * that this function is *NOT* called under RCU protection or in contexts where | ||
1857 | * mutex cannot be locked. | ||
1858 | */ | 1598 | */ |
1859 | void dev_pm_opp_of_remove_table(struct device *dev) | 1599 | void _dev_pm_opp_remove_table(struct device *dev, bool remove_all) |
1860 | { | 1600 | { |
1861 | struct opp_table *opp_table; | 1601 | struct opp_table *opp_table; |
1862 | struct dev_pm_opp *opp, *tmp; | 1602 | struct dev_pm_opp *opp, *tmp; |
@@ -1881,7 +1621,7 @@ void dev_pm_opp_of_remove_table(struct device *dev) | |||
1881 | if (list_is_singular(&opp_table->dev_list)) { | 1621 | if (list_is_singular(&opp_table->dev_list)) { |
1882 | /* Free static OPPs */ | 1622 | /* Free static OPPs */ |
1883 | list_for_each_entry_safe(opp, tmp, &opp_table->opp_list, node) { | 1623 | list_for_each_entry_safe(opp, tmp, &opp_table->opp_list, node) { |
1884 | if (!opp->dynamic) | 1624 | if (remove_all || !opp->dynamic) |
1885 | _opp_remove(opp_table, opp, true); | 1625 | _opp_remove(opp_table, opp, true); |
1886 | } | 1626 | } |
1887 | } else { | 1627 | } else { |
@@ -1891,160 +1631,22 @@ void dev_pm_opp_of_remove_table(struct device *dev) | |||
1891 | unlock: | 1631 | unlock: |
1892 | mutex_unlock(&opp_table_lock); | 1632 | mutex_unlock(&opp_table_lock); |
1893 | } | 1633 | } |
1894 | EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table); | ||
1895 | |||
1896 | /* Returns opp descriptor node for a device, caller must do of_node_put() */ | ||
1897 | struct device_node *_of_get_opp_desc_node(struct device *dev) | ||
1898 | { | ||
1899 | /* | ||
1900 | * TODO: Support for multiple OPP tables. | ||
1901 | * | ||
1902 | * There should be only ONE phandle present in "operating-points-v2" | ||
1903 | * property. | ||
1904 | */ | ||
1905 | |||
1906 | return of_parse_phandle(dev->of_node, "operating-points-v2", 0); | ||
1907 | } | ||
1908 | |||
1909 | /* Initializes OPP tables based on new bindings */ | ||
1910 | static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np) | ||
1911 | { | ||
1912 | struct device_node *np; | ||
1913 | struct opp_table *opp_table; | ||
1914 | int ret = 0, count = 0; | ||
1915 | |||
1916 | mutex_lock(&opp_table_lock); | ||
1917 | |||
1918 | opp_table = _managed_opp(opp_np); | ||
1919 | if (opp_table) { | ||
1920 | /* OPPs are already managed */ | ||
1921 | if (!_add_opp_dev(dev, opp_table)) | ||
1922 | ret = -ENOMEM; | ||
1923 | mutex_unlock(&opp_table_lock); | ||
1924 | return ret; | ||
1925 | } | ||
1926 | mutex_unlock(&opp_table_lock); | ||
1927 | |||
1928 | /* We have opp-table node now, iterate over it and add OPPs */ | ||
1929 | for_each_available_child_of_node(opp_np, np) { | ||
1930 | count++; | ||
1931 | |||
1932 | ret = _opp_add_static_v2(dev, np); | ||
1933 | if (ret) { | ||
1934 | dev_err(dev, "%s: Failed to add OPP, %d\n", __func__, | ||
1935 | ret); | ||
1936 | goto free_table; | ||
1937 | } | ||
1938 | } | ||
1939 | |||
1940 | /* There should be one of more OPP defined */ | ||
1941 | if (WARN_ON(!count)) | ||
1942 | return -ENOENT; | ||
1943 | |||
1944 | mutex_lock(&opp_table_lock); | ||
1945 | |||
1946 | opp_table = _find_opp_table(dev); | ||
1947 | if (WARN_ON(IS_ERR(opp_table))) { | ||
1948 | ret = PTR_ERR(opp_table); | ||
1949 | mutex_unlock(&opp_table_lock); | ||
1950 | goto free_table; | ||
1951 | } | ||
1952 | |||
1953 | opp_table->np = opp_np; | ||
1954 | opp_table->shared_opp = of_property_read_bool(opp_np, "opp-shared"); | ||
1955 | |||
1956 | mutex_unlock(&opp_table_lock); | ||
1957 | |||
1958 | return 0; | ||
1959 | |||
1960 | free_table: | ||
1961 | dev_pm_opp_of_remove_table(dev); | ||
1962 | |||
1963 | return ret; | ||
1964 | } | ||
1965 | |||
1966 | /* Initializes OPP tables based on old-deprecated bindings */ | ||
1967 | static int _of_add_opp_table_v1(struct device *dev) | ||
1968 | { | ||
1969 | const struct property *prop; | ||
1970 | const __be32 *val; | ||
1971 | int nr; | ||
1972 | |||
1973 | prop = of_find_property(dev->of_node, "operating-points", NULL); | ||
1974 | if (!prop) | ||
1975 | return -ENODEV; | ||
1976 | if (!prop->value) | ||
1977 | return -ENODATA; | ||
1978 | |||
1979 | /* | ||
1980 | * Each OPP is a set of tuples consisting of frequency and | ||
1981 | * voltage like <freq-kHz vol-uV>. | ||
1982 | */ | ||
1983 | nr = prop->length / sizeof(u32); | ||
1984 | if (nr % 2) { | ||
1985 | dev_err(dev, "%s: Invalid OPP table\n", __func__); | ||
1986 | return -EINVAL; | ||
1987 | } | ||
1988 | |||
1989 | val = prop->value; | ||
1990 | while (nr) { | ||
1991 | unsigned long freq = be32_to_cpup(val++) * 1000; | ||
1992 | unsigned long volt = be32_to_cpup(val++); | ||
1993 | |||
1994 | if (_opp_add_v1(dev, freq, volt, false)) | ||
1995 | dev_warn(dev, "%s: Failed to add OPP %ld\n", | ||
1996 | __func__, freq); | ||
1997 | nr -= 2; | ||
1998 | } | ||
1999 | |||
2000 | return 0; | ||
2001 | } | ||
2002 | 1634 | ||
2003 | /** | 1635 | /** |
2004 | * dev_pm_opp_of_add_table() - Initialize opp table from device tree | 1636 | * dev_pm_opp_remove_table() - Free all OPPs associated with the device |
2005 | * @dev: device pointer used to lookup OPP table. | 1637 | * @dev: device pointer used to lookup OPP table. |
2006 | * | 1638 | * |
2007 | * Register the initial OPP table with the OPP library for given device. | 1639 | * Free both OPPs created using static entries present in DT and the |
1640 | * dynamically added entries. | ||
2008 | * | 1641 | * |
2009 | * Locking: The internal opp_table and opp structures are RCU protected. | 1642 | * Locking: The internal opp_table and opp structures are RCU protected. |
2010 | * Hence this function indirectly uses RCU updater strategy with mutex locks | 1643 | * Hence this function indirectly uses RCU updater strategy with mutex locks |
2011 | * to keep the integrity of the internal data structures. Callers should ensure | 1644 | * to keep the integrity of the internal data structures. Callers should ensure |
2012 | * that this function is *NOT* called under RCU protection or in contexts where | 1645 | * that this function is *NOT* called under RCU protection or in contexts where |
2013 | * mutex cannot be locked. | 1646 | * mutex cannot be locked. |
2014 | * | ||
2015 | * Return: | ||
2016 | * 0 On success OR | ||
2017 | * Duplicate OPPs (both freq and volt are same) and opp->available | ||
2018 | * -EEXIST Freq are same and volt are different OR | ||
2019 | * Duplicate OPPs (both freq and volt are same) and !opp->available | ||
2020 | * -ENOMEM Memory allocation failure | ||
2021 | * -ENODEV when 'operating-points' property is not found or is invalid data | ||
2022 | * in device node. | ||
2023 | * -ENODATA when empty 'operating-points' property is found | ||
2024 | * -EINVAL when invalid entries are found in opp-v2 table | ||
2025 | */ | 1647 | */ |
2026 | int dev_pm_opp_of_add_table(struct device *dev) | 1648 | void dev_pm_opp_remove_table(struct device *dev) |
2027 | { | 1649 | { |
2028 | struct device_node *opp_np; | 1650 | _dev_pm_opp_remove_table(dev, true); |
2029 | int ret; | ||
2030 | |||
2031 | /* | ||
2032 | * OPPs have two version of bindings now. The older one is deprecated, | ||
2033 | * try for the new binding first. | ||
2034 | */ | ||
2035 | opp_np = _of_get_opp_desc_node(dev); | ||
2036 | if (!opp_np) { | ||
2037 | /* | ||
2038 | * Try old-deprecated bindings for backward compatibility with | ||
2039 | * older dtbs. | ||
2040 | */ | ||
2041 | return _of_add_opp_table_v1(dev); | ||
2042 | } | ||
2043 | |||
2044 | ret = _of_add_opp_table_v2(dev, opp_np); | ||
2045 | of_node_put(opp_np); | ||
2046 | |||
2047 | return ret; | ||
2048 | } | 1651 | } |
2049 | EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); | 1652 | EXPORT_SYMBOL_GPL(dev_pm_opp_remove_table); |
2050 | #endif | ||