cvb.c (e5451c8f8330e03ad3cfa16048b4daf961af434f) | cvb.c (e8f6a68c508b5d1cc4612ada028d87c74ab279d5) |
---|---|
1/* 2 * Utility functions for parsing Tegra CVB voltage tables 3 * 4 * Copyright (C) 2012-2014 NVIDIA Corporation. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. --- 47 unchanged lines hidden (view full) --- 56 57 uv = max(mv * 1000, align->offset_uv) - align->offset_uv; 58 uv = (uv + (up ? align->step_uv - 1 : 0)) / align->step_uv; 59 return (uv * align->step_uv + align->offset_uv) / 1000; 60 } 61 return mv; 62} 63 | 1/* 2 * Utility functions for parsing Tegra CVB voltage tables 3 * 4 * Copyright (C) 2012-2014 NVIDIA Corporation. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. --- 47 unchanged lines hidden (view full) --- 56 57 uv = max(mv * 1000, align->offset_uv) - align->offset_uv; 58 uv = (uv + (up ? align->step_uv - 1 : 0)) / align->step_uv; 59 return (uv * align->step_uv + align->offset_uv) / 1000; 60 } 61 return mv; 62} 63 |
64static int build_opp_table(const struct cvb_table *d, 65 int speedo_value, 66 unsigned long max_freq, 67 struct device *opp_dev) | 64static int build_opp_table(struct device *dev, const struct cvb_table *table, 65 int speedo_value, unsigned long max_freq) |
68{ | 66{ |
67 const struct rail_alignment *align = &table->alignment; |
|
69 int i, ret, dfll_mv, min_mv, max_mv; | 68 int i, ret, dfll_mv, min_mv, max_mv; |
70 const struct cvb_table_freq_entry *table = NULL; 71 const struct rail_alignment *align = &d->alignment; | |
72 | 69 |
73 min_mv = round_voltage(d->min_millivolts, align, UP); 74 max_mv = round_voltage(d->max_millivolts, align, DOWN); | 70 min_mv = round_voltage(table->min_millivolts, align, UP); 71 max_mv = round_voltage(table->max_millivolts, align, DOWN); |
75 76 for (i = 0; i < MAX_DVFS_FREQS; i++) { | 72 73 for (i = 0; i < MAX_DVFS_FREQS; i++) { |
77 table = &d->cvb_table[i]; 78 if (!table->freq || (table->freq > max_freq)) | 74 const struct cvb_table_freq_entry *entry = &table->entries[i]; 75 76 if (!entry->freq || (entry->freq > max_freq)) |
79 break; 80 | 77 break; 78 |
81 dfll_mv = get_cvb_voltage( 82 speedo_value, d->speedo_scale, &table->coefficients); 83 dfll_mv = round_cvb_voltage(dfll_mv, d->voltage_scale, align); | 79 dfll_mv = get_cvb_voltage(speedo_value, table->speedo_scale, 80 &entry->coefficients); 81 dfll_mv = round_cvb_voltage(dfll_mv, table->voltage_scale, 82 align); |
84 dfll_mv = clamp(dfll_mv, min_mv, max_mv); 85 | 83 dfll_mv = clamp(dfll_mv, min_mv, max_mv); 84 |
86 ret = dev_pm_opp_add(opp_dev, table->freq, dfll_mv * 1000); | 85 ret = dev_pm_opp_add(dev, entry->freq, dfll_mv * 1000); |
87 if (ret) 88 return ret; 89 } 90 91 return 0; 92} 93 94/** | 86 if (ret) 87 return ret; 88 } 89 90 return 0; 91} 92 93/** |
95 * tegra_cvb_build_opp_table - build OPP table from Tegra CVB tables | 94 * tegra_cvb_add_opp_table - build OPP table from Tegra CVB tables |
96 * @cvb_tables: array of CVB tables 97 * @sz: size of the previously mentioned array 98 * @process_id: process id of the HW module 99 * @speedo_id: speedo id of the HW module 100 * @speedo_value: speedo value of the HW module 101 * @max_rate: highest safe clock rate 102 * @opp_dev: the struct device * for which the OPP table is built 103 * 104 * On Tegra, a CVB table encodes the relationship between operating voltage 105 * and safe maximal frequency for a given module (e.g. GPU or CPU). This 106 * function calculates the optimal voltage-frequency operating points 107 * for the given arguments and exports them via the OPP library for the 108 * given @opp_dev. Returns a pointer to the struct cvb_table that matched 109 * or an ERR_PTR on failure. 110 */ | 95 * @cvb_tables: array of CVB tables 96 * @sz: size of the previously mentioned array 97 * @process_id: process id of the HW module 98 * @speedo_id: speedo id of the HW module 99 * @speedo_value: speedo value of the HW module 100 * @max_rate: highest safe clock rate 101 * @opp_dev: the struct device * for which the OPP table is built 102 * 103 * On Tegra, a CVB table encodes the relationship between operating voltage 104 * and safe maximal frequency for a given module (e.g. GPU or CPU). This 105 * function calculates the optimal voltage-frequency operating points 106 * for the given arguments and exports them via the OPP library for the 107 * given @opp_dev. Returns a pointer to the struct cvb_table that matched 108 * or an ERR_PTR on failure. 109 */ |
111const struct cvb_table *tegra_cvb_build_opp_table( 112 const struct cvb_table *cvb_tables, 113 size_t sz, int process_id, 114 int speedo_id, int speedo_value, 115 unsigned long max_rate, 116 struct device *opp_dev) | 110const struct cvb_table * 111tegra_cvb_add_opp_table(struct device *dev, const struct cvb_table *tables, 112 size_t count, int process_id, int speedo_id, 113 int speedo_value, unsigned long max_freq) |
117{ | 114{ |
118 int i, ret; | 115 size_t i; 116 int ret; |
119 | 117 |
120 for (i = 0; i < sz; i++) { 121 const struct cvb_table *d = &cvb_tables[i]; | 118 for (i = 0; i < count; i++) { 119 const struct cvb_table *table = &tables[i]; |
122 | 120 |
123 if (d->speedo_id != -1 && d->speedo_id != speedo_id) | 121 if (table->speedo_id != -1 && table->speedo_id != speedo_id) |
124 continue; | 122 continue; |
125 if (d->process_id != -1 && d->process_id != process_id) | 123 124 if (table->process_id != -1 && table->process_id != process_id) |
126 continue; 127 | 125 continue; 126 |
128 ret = build_opp_table(d, speedo_value, max_rate, opp_dev); 129 return ret ? ERR_PTR(ret) : d; | 127 ret = build_opp_table(dev, table, speedo_value, max_freq); 128 return ret ? ERR_PTR(ret) : table; |
130 } 131 132 return ERR_PTR(-EINVAL); 133} | 129 } 130 131 return ERR_PTR(-EINVAL); 132} |