Lines Matching +full:clk +full:- +full:freq +full:- +full:optimized

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2016-2017 Texas Instruments Incorporated - https://www.ti.com/
5 * Dave Gerlach <d-gerlach@ti.com>
11 #include <linux/clk.h>
26 * struct ti_opp_supply_optimum_voltage_table - optimized voltage table
28 * @optimized_uv: Optimized voltage from efuse
36 * struct ti_opp_supply_data - OMAP specific opp supply data
37 * @vdd_table: Optimized voltage mapping table
54 * struct ti_opp_supply_of_data - device tree match data
57 * @efuse_voltage_uv: Are the efuse entries in micro-volts? if not, assume
58 * milli-volts.
69 * _store_optimized_voltages() - store optimized voltages
73 * Picks up efuse based optimized voltages for VDD unique per device and
94 ret = -ENODEV; in _store_optimized_voltages()
98 base = ioremap(res->start, resource_size(res)); in _store_optimized_voltages()
101 ret = -ENOMEM; in _store_optimized_voltages()
105 /* Fetch efuse-settings. */ in _store_optimized_voltages()
106 prop = of_find_property(dev->of_node, "ti,efuse-settings", NULL); in _store_optimized_voltages()
108 dev_err(dev, "No 'ti,efuse-settings' property found\n"); in _store_optimized_voltages()
109 ret = -EINVAL; in _store_optimized_voltages()
113 proplen = prop->length / sizeof(int); in _store_optimized_voltages()
114 data->num_vdd_table = proplen / 2; in _store_optimized_voltages()
116 if (data->num_vdd_table * 2 * sizeof(int) != prop->length) { in _store_optimized_voltages()
117 dev_err(dev, "Invalid 'ti,efuse-settings'\n"); in _store_optimized_voltages()
118 ret = -EINVAL; in _store_optimized_voltages()
122 ret = of_property_read_u32(dev->of_node, "ti,absolute-max-voltage-uv", in _store_optimized_voltages()
123 &data->vdd_absolute_max_voltage_uv); in _store_optimized_voltages()
125 dev_err(dev, "ti,absolute-max-voltage-uv is missing\n"); in _store_optimized_voltages()
126 ret = -EINVAL; in _store_optimized_voltages()
130 table = kcalloc(data->num_vdd_table, sizeof(*data->vdd_table), in _store_optimized_voltages()
133 ret = -ENOMEM; in _store_optimized_voltages()
136 data->vdd_table = table; in _store_optimized_voltages()
138 val = prop->value; in _store_optimized_voltages()
139 for (i = 0; i < data->num_vdd_table; i++, table++) { in _store_optimized_voltages()
143 table->reference_uv = be32_to_cpup(val++); in _store_optimized_voltages()
147 tmp &= of_data->efuse_voltage_mask; in _store_optimized_voltages()
148 tmp >>= __ffs(of_data->efuse_voltage_mask); in _store_optimized_voltages()
150 table->optimized_uv = of_data->efuse_voltage_uv ? tmp : in _store_optimized_voltages()
154 i, efuse_offset, table->reference_uv, in _store_optimized_voltages()
155 table->optimized_uv); in _store_optimized_voltages()
158 * Some older samples might not have optimized efuse in _store_optimized_voltages()
159 * Use reference voltage for those - just add debug message in _store_optimized_voltages()
162 if (!table->optimized_uv) { in _store_optimized_voltages()
164 i, efuse_offset, table->reference_uv); in _store_optimized_voltages()
165 table->optimized_uv = table->reference_uv; in _store_optimized_voltages()
175 * _free_optimized_voltages() - free resources for optvoltages
182 kfree(data->vdd_table); in _free_optimized_voltages()
183 data->vdd_table = NULL; in _free_optimized_voltages()
184 data->num_vdd_table = 0; in _free_optimized_voltages()
188 * _get_optimal_vdd_voltage() - Finds optimal voltage for the supply
193 * Return: if a match is found, return optimized voltage, else return
203 if (!data->num_vdd_table) in _get_optimal_vdd_voltage()
206 table = data->vdd_table; in _get_optimal_vdd_voltage()
208 return -EINVAL; in _get_optimal_vdd_voltage()
210 /* Find a exact match - this list is usually very small */ in _get_optimal_vdd_voltage()
211 for (i = 0; i < data->num_vdd_table; i++, table++) in _get_optimal_vdd_voltage()
212 if (table->reference_uv == reference_uv) in _get_optimal_vdd_voltage()
213 return table->optimized_uv; in _get_optimal_vdd_voltage()
216 dev_err_ratelimited(dev, "%s: Failed optimized voltage match for %d\n", in _get_optimal_vdd_voltage()
232 vdd_uv = supply->u_volt; in _opp_set_voltage()
245 uv_max = supply->u_volt_max; in _opp_set_voltage()
248 vdd_uv < supply->u_volt_min || in _opp_set_voltage()
249 supply->u_volt_min > uv_max) { in _opp_set_voltage()
252 supply->u_volt_min, vdd_uv, uv_max); in _opp_set_voltage()
253 return -EINVAL; in _opp_set_voltage()
257 vdd_uv, supply->u_volt_min, in _opp_set_voltage()
261 supply->u_volt_min, in _opp_set_voltage()
266 reg_name, vdd_uv, supply->u_volt_min, in _opp_set_voltage()
285 unsigned long old_freq, freq; in ti_opp_config_regulators() local
292 /* Fetch supplies and freq information from OPP core */ in ti_opp_config_regulators()
297 freq = dev_pm_opp_get_freq(new_opp); in ti_opp_config_regulators()
298 WARN_ON(!old_freq || !freq); in ti_opp_config_regulators()
301 new_supply_vdd->u_volt); in ti_opp_config_regulators()
303 if (new_supply_vdd->u_volt_min < vdd_uv) in ti_opp_config_regulators()
304 new_supply_vdd->u_volt_min = vdd_uv; in ti_opp_config_regulators()
307 if (freq > old_freq) { in ti_opp_config_regulators()
335 if (old_supply_vdd->u_volt) { in ti_opp_config_regulators()
365 {.compatible = "ti,omap-opp-supply", .data = &omap_generic_of_data},
366 {.compatible = "ti,omap5-opp-supply", .data = &omap_omap5_of_data},
367 {.compatible = "ti,omap5-core-opp-supply",
375 struct device *dev = &pdev->dev; in ti_opp_supply_probe()
384 return -EINVAL; in ti_opp_supply_probe()
388 /* If we need optimized voltage */ in ti_opp_supply_probe()
389 if (of_data->flags & OPPDM_EFUSE_CLASS0_OPTIMIZED_VOLTAGE) { in ti_opp_supply_probe()