^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * helpers to map values in a linear range to range index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Original idea borrowed from regulator framework
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * It might be useful if we could support also inversely proportional ranges?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright 2020 ROHM Semiconductors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/linear_range.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * linear_range_values_in_range - return the amount of values in a range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * @r: pointer to linear range where values are counted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Compute the amount of values in range pointed by @r. Note, values can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * be all equal - range with selectors 0,...,2 with step 0 still contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * 3 values even though they are all equal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * Return: the amount of values in range pointed by @r
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) unsigned int linear_range_values_in_range(const struct linear_range *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (!r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return r->max_sel - r->min_sel + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) EXPORT_SYMBOL_GPL(linear_range_values_in_range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * linear_range_values_in_range_array - return the amount of values in ranges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * @r: pointer to array of linear ranges where values are counted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * @ranges: amount of ranges we include in computation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * Compute the amount of values in ranges pointed by @r. Note, values can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * be all equal - range with selectors 0,...,2 with step 0 still contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * 3 values even though they are all equal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * Return: the amount of values in first @ranges ranges pointed by @r
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned int linear_range_values_in_range_array(const struct linear_range *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int ranges)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int i, values_in_range = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) for (i = 0; i < ranges; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) int values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) values = linear_range_values_in_range(&r[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (!values)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) values_in_range += values;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return values_in_range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) EXPORT_SYMBOL_GPL(linear_range_values_in_range_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * linear_range_get_max_value - return the largest value in a range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * @r: pointer to linear range where value is looked from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * Return: the largest value in the given range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned int linear_range_get_max_value(const struct linear_range *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return r->min + (r->max_sel - r->min_sel) * r->step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) EXPORT_SYMBOL_GPL(linear_range_get_max_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * linear_range_get_value - fetch a value from given range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * @r: pointer to linear range where value is looked from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * @selector: selector for which the value is searched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * @val: address where found value is updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * Search given ranges for value which matches given selector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * Return: 0 on success, -EINVAL given selector is not found from any of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * ranges.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int linear_range_get_value(const struct linear_range *r, unsigned int selector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) unsigned int *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (r->min_sel > selector || r->max_sel < selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *val = r->min + (selector - r->min_sel) * r->step;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) EXPORT_SYMBOL_GPL(linear_range_get_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * linear_range_get_value_array - fetch a value from array of ranges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * @r: pointer to array of linear ranges where value is looked from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * @ranges: amount of ranges in an array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * @selector: selector for which the value is searched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * @val: address where found value is updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * Search through an array of ranges for value which matches given selector.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * Return: 0 on success, -EINVAL given selector is not found from any of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * ranges.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) int linear_range_get_value_array(const struct linear_range *r, int ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) unsigned int selector, unsigned int *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) for (i = 0; i < ranges; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (r[i].min_sel <= selector && r[i].max_sel >= selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return linear_range_get_value(&r[i], selector, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) EXPORT_SYMBOL_GPL(linear_range_get_value_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * linear_range_get_selector_low - return linear range selector for value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * @r: pointer to linear range where selector is looked from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * @val: value for which the selector is searched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * @selector: address where found selector value is updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * @found: flag to indicate that given value was in the range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * Return selector which which range value is closest match for given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * input value. Value is matching if it is equal or smaller than given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * value. If given value is in the range, then @found is set true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * Return: 0 on success, -EINVAL if range is invalid or does not contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * value smaller or equal to given value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int linear_range_get_selector_low(const struct linear_range *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned int val, unsigned int *selector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) bool *found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) *found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (r->min > val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (linear_range_get_max_value(r) < val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) *selector = r->max_sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) *found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (r->step == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) *selector = r->min_sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *selector = (val - r->min) / r->step + r->min_sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) EXPORT_SYMBOL_GPL(linear_range_get_selector_low);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * linear_range_get_selector_low_array - return linear range selector for value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * @r: pointer to array of linear ranges where selector is looked from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * @ranges: amount of ranges to scan from array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * @val: value for which the selector is searched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * @selector: address where found selector value is updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * @found: flag to indicate that given value was in the range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * Scan array of ranges for selector which which range value matches given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * input value. Value is matching if it is equal or smaller than given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * value. If given value is found to be in a range scanning is stopped and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * @found is set true. If a range with values smaller than given value is found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * but the range max is being smaller than given value, then the ranges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * biggest selector is updated to @selector but scanning ranges is continued
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * and @found is set to false.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * Return: 0 on success, -EINVAL if range array is invalid or does not contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * range with a value smaller or equal to given value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int linear_range_get_selector_low_array(const struct linear_range *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int ranges, unsigned int val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) unsigned int *selector, bool *found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) for (i = 0; i < ranges; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) int tmpret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) tmpret = linear_range_get_selector_low(&r[i], val, selector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (!tmpret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (*found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) EXPORT_SYMBOL_GPL(linear_range_get_selector_low_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * linear_range_get_selector_high - return linear range selector for value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * @r: pointer to linear range where selector is looked from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * @val: value for which the selector is searched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * @selector: address where found selector value is updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * @found: flag to indicate that given value was in the range
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * Return selector which which range value is closest match for given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * input value. Value is matching if it is equal or higher than given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * value. If given value is in the range, then @found is set true.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * Return: 0 on success, -EINVAL if range is invalid or does not contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * value greater or equal to given value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) int linear_range_get_selector_high(const struct linear_range *r,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) unsigned int val, unsigned int *selector,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) bool *found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) *found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (linear_range_get_max_value(r) < val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (r->min > val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) *selector = r->min_sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) *found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (r->step == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) *selector = r->max_sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) *selector = DIV_ROUND_UP(val - r->min, r->step) + r->min_sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) EXPORT_SYMBOL_GPL(linear_range_get_selector_high);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) MODULE_DESCRIPTION("linear-ranges helper");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) MODULE_LICENSE("GPL");