Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / include / linux / linear_range.h
blob2e4f4c3539c075a6caa69f6ae750a556f41fce5d
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (C) 2020 ROHM Semiconductors */
4 #ifndef LINEAR_RANGE_H
5 #define LINEAR_RANGE_H
7 #include <linux/types.h>
9 /**
10 * struct linear_range - table of selector - value pairs
12 * Define a lookup-table for range of values. Intended to help when looking
13 * for a register value matching certaing physical measure (like voltage).
14 * Usable when increment of one in register always results a constant increment
15 * of the physical measure (like voltage).
17 * @min: Lowest value in range
18 * @min_sel: Lowest selector for range
19 * @max_sel: Highest selector for range
20 * @step: Value step size
22 struct linear_range {
23 unsigned int min;
24 unsigned int min_sel;
25 unsigned int max_sel;
26 unsigned int step;
29 #define LINEAR_RANGE(_min, _min_sel, _max_sel, _step) \
30 { \
31 .min = _min, \
32 .min_sel = _min_sel, \
33 .max_sel = _max_sel, \
34 .step = _step, \
37 #define LINEAR_RANGE_IDX(_idx, _min, _min_sel, _max_sel, _step) \
38 [_idx] = LINEAR_RANGE(_min, _min_sel, _max_sel, _step)
40 unsigned int linear_range_values_in_range(const struct linear_range *r);
41 unsigned int linear_range_values_in_range_array(const struct linear_range *r,
42 int ranges);
43 unsigned int linear_range_get_max_value(const struct linear_range *r);
45 int linear_range_get_value(const struct linear_range *r, unsigned int selector,
46 unsigned int *val);
47 int linear_range_get_value_array(const struct linear_range *r, int ranges,
48 unsigned int selector, unsigned int *val);
49 int linear_range_get_selector_low(const struct linear_range *r,
50 unsigned int val, unsigned int *selector,
51 bool *found);
52 int linear_range_get_selector_high(const struct linear_range *r,
53 unsigned int val, unsigned int *selector,
54 bool *found);
55 void linear_range_get_selector_within(const struct linear_range *r,
56 unsigned int val, unsigned int *selector);
57 int linear_range_get_selector_low_array(const struct linear_range *r,
58 int ranges, unsigned int val,
59 unsigned int *selector, bool *found);
61 #endif