Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) 2020 ROHM Semiconductors */
0003 
0004 #ifndef LINEAR_RANGE_H
0005 #define LINEAR_RANGE_H
0006 
0007 #include <linux/types.h>
0008 
0009 /**
0010  * struct linear_range - table of selector - value pairs
0011  *
0012  * Define a lookup-table for range of values. Intended to help when looking
0013  * for a register value matching certaing physical measure (like voltage).
0014  * Usable when increment of one in register always results a constant increment
0015  * of the physical measure (like voltage).
0016  *
0017  * @min:  Lowest value in range
0018  * @min_sel: Lowest selector for range
0019  * @max_sel: Highest selector for range
0020  * @step: Value step size
0021  */
0022 struct linear_range {
0023     unsigned int min;
0024     unsigned int min_sel;
0025     unsigned int max_sel;
0026     unsigned int step;
0027 };
0028 
0029 unsigned int linear_range_values_in_range(const struct linear_range *r);
0030 unsigned int linear_range_values_in_range_array(const struct linear_range *r,
0031                         int ranges);
0032 unsigned int linear_range_get_max_value(const struct linear_range *r);
0033 
0034 int linear_range_get_value(const struct linear_range *r, unsigned int selector,
0035                unsigned int *val);
0036 int linear_range_get_value_array(const struct linear_range *r, int ranges,
0037                  unsigned int selector, unsigned int *val);
0038 int linear_range_get_selector_low(const struct linear_range *r,
0039                   unsigned int val, unsigned int *selector,
0040                   bool *found);
0041 int linear_range_get_selector_high(const struct linear_range *r,
0042                    unsigned int val, unsigned int *selector,
0043                    bool *found);
0044 void linear_range_get_selector_within(const struct linear_range *r,
0045                       unsigned int val, unsigned int *selector);
0046 int linear_range_get_selector_low_array(const struct linear_range *r,
0047                     int ranges, unsigned int val,
0048                     unsigned int *selector, bool *found);
0049 
0050 #endif