~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/iio/iio-gts-helper.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/iio/iio-gts-helper.h (Version linux-6.12-rc7) and /include/linux/iio/iio-gts-helper.h (Version linux-4.10.17)


  1 /* SPDX-License-Identifier: GPL-2.0-only */         1 
  2 /* gain-time-scale conversion helpers for IIO     
  3  *                                                
  4  * Copyright (c) 2023 Matti Vaittinen <mazzies    
  5  */                                               
  6                                                   
  7 #ifndef __IIO_GTS_HELPER__                        
  8 #define __IIO_GTS_HELPER__                        
  9                                                   
 10 #include <linux/types.h>                          
 11                                                   
 12 struct device;                                    
 13                                                   
 14 /**                                               
 15  * struct iio_gain_sel_pair - gain - selector     
 16  *                                                
 17  * In many cases devices like light sensors al    
 18  * (gain) using a register interface. This str    
 19  * and corresponding selector (register value)    
 20  *                                                
 21  * @gain:       Gain (multiplication) value. G    
 22  *              values are reserved for error     
 23  * @sel:        Selector (usually register val    
 24  *              NOTE: Only selectors >= 0 supp    
 25  */                                               
 26 struct iio_gain_sel_pair {                        
 27         int gain;                                 
 28         int sel;                                  
 29 };                                                
 30                                                   
 31 /**                                               
 32  * struct iio_itime_sel_mul - integration time    
 33  *                                                
 34  * In many cases devices like light sensors al    
 35  * collecting data. Typically this duration ha    
 36  * of measured values (gain). This structure d    
 37  * integration time and amplification as well     
 38  * (register value).                              
 39  *                                                
 40  * An example could be a sensor allowing 50, 1    
 41  * respective multiplication values could be 5    
 42  * 200 mS => 4 and 400 mS => 8 assuming the im    
 43  * linear in a way that when collecting data f    
 44  * the data collection time caused value 2X et    
 45  *                                                
 46  * @time_us:    Integration time in microsecon    
 47  *              negative values are reserved f    
 48  * @sel:        Selector (usually register val    
 49  *              NOTE: Only selectors >= 0 supp    
 50  * @mul:        Multiplication to the values c    
 51  *              NOTE: Only multipliers > 0 sup    
 52  */                                               
 53 struct iio_itime_sel_mul {                        
 54         int time_us;                              
 55         int sel;                                  
 56         int mul;                                  
 57 };                                                
 58                                                   
 59 struct iio_gts {                                  
 60         u64 max_scale;                            
 61         const struct iio_gain_sel_pair *hwgain    
 62         int num_hwgain;                           
 63         const struct iio_itime_sel_mul *itime_    
 64         int num_itime;                            
 65         int **per_time_avail_scale_tables;        
 66         int *avail_all_scales_table;              
 67         int num_avail_all_scales;                 
 68         int *avail_time_tables;                   
 69         int num_avail_time_tables;                
 70 };                                                
 71                                                   
 72 #define GAIN_SCALE_GAIN(_gain, _sel)              
 73 {                                                 
 74         .gain = (_gain),                          
 75         .sel = (_sel),                            
 76 }                                                 
 77                                                   
 78 #define GAIN_SCALE_ITIME_US(_itime, _sel, _mul    
 79 {                                                 
 80         .time_us = (_itime),                      
 81         .sel = (_sel),                            
 82         .mul = (_mul),                            
 83 }                                                 
 84                                                   
 85 static inline const struct iio_itime_sel_mul *    
 86 iio_gts_find_itime_by_time(struct iio_gts *gts    
 87 {                                                 
 88         int i;                                    
 89                                                   
 90         if (!gts->num_itime)                      
 91                 return NULL;                      
 92                                                   
 93         for (i = 0; i < gts->num_itime; i++)      
 94                 if (gts->itime_table[i].time_u    
 95                         return &gts->itime_tab    
 96                                                   
 97         return NULL;                              
 98 }                                                 
 99                                                   
100 static inline const struct iio_itime_sel_mul *    
101 iio_gts_find_itime_by_sel(struct iio_gts *gts,    
102 {                                                 
103         int i;                                    
104                                                   
105         for (i = 0; i < gts->num_itime; i++)      
106                 if (gts->itime_table[i].sel ==    
107                         return &gts->itime_tab    
108                                                   
109         return NULL;                              
110 }                                                 
111                                                   
112 int devm_iio_init_iio_gts(struct device *dev,     
113                           const struct iio_gai    
114                           const struct iio_iti    
115                           struct iio_gts *gts)    
116 /**                                               
117  * iio_gts_find_int_time_by_sel - find integra    
118  * @gts:        Gain time scale descriptor        
119  * @sel:        selector for which matching in    
120  *                                                
121  * Return:      integration time matching give    
122  *              integration time was not found    
123  */                                               
124 static inline int iio_gts_find_int_time_by_sel    
125 {                                                 
126         const struct iio_itime_sel_mul *itime;    
127                                                   
128         itime = iio_gts_find_itime_by_sel(gts,    
129         if (!itime)                               
130                 return -EINVAL;                   
131                                                   
132         return itime->time_us;                    
133 }                                                 
134                                                   
135 /**                                               
136  * iio_gts_find_sel_by_int_time - find selecto    
137  * @gts:        Gain time scale descriptor        
138  * @time:       Integration time for which mat    
139  *                                                
140  * Return:      a selector matching given inte    
141  *              selector was not found.           
142  */                                               
143 static inline int iio_gts_find_sel_by_int_time    
144 {                                                 
145         const struct iio_itime_sel_mul *itime;    
146                                                   
147         itime = iio_gts_find_itime_by_time(gts    
148         if (!itime)                               
149                 return -EINVAL;                   
150                                                   
151         return itime->sel;                        
152 }                                                 
153                                                   
154 /**                                               
155  * iio_gts_valid_time - check if given integra    
156  * @gts:        Gain time scale descriptor        
157  * @time_us:    Integration time to check         
158  *                                                
159  * Return:      True if given time is supporte    
160  */                                               
161 static inline bool iio_gts_valid_time(struct i    
162 {                                                 
163         return iio_gts_find_itime_by_time(gts,    
164 }                                                 
165                                                   
166 int iio_gts_find_sel_by_gain(struct iio_gts *g    
167                                                   
168 /**                                               
169  * iio_gts_valid_gain - check if given HW-gain    
170  * @gts:        Gain time scale descriptor        
171  * @gain:       HW-gain to check                  
172  *                                                
173  * Return:      True if given time is supporte    
174  */                                               
175 static inline bool iio_gts_valid_gain(struct i    
176 {                                                 
177         return iio_gts_find_sel_by_gain(gts, g    
178 }                                                 
179                                                   
180 int iio_find_closest_gain_low(struct iio_gts *    
181 int iio_gts_find_gain_by_sel(struct iio_gts *g    
182 int iio_gts_get_min_gain(struct iio_gts *gts);    
183 int iio_gts_find_int_time_by_sel(struct iio_gt    
184 int iio_gts_find_sel_by_int_time(struct iio_gt    
185                                                   
186 int iio_gts_total_gain_to_scale(struct iio_gts    
187                                 int *scale_int    
188 int iio_gts_find_gain_sel_for_scale_using_time    
189                                                   
190                                                   
191 int iio_gts_get_scale(struct iio_gts *gts, int    
192                       int *scale_nano);           
193 int iio_gts_find_new_gain_sel_by_old_gain_time    
194                                                   
195                                                   
196 int iio_gts_find_new_gain_by_old_gain_time(str    
197                                            int    
198                                            int    
199 int iio_gts_avail_times(struct iio_gts *gts,      
200                         int *length);             
201 int iio_gts_all_avail_scales(struct iio_gts *g    
202                              int *length);        
203 int iio_gts_avail_scales_for_time(struct iio_g    
204                                   const int **    
205                                                   
206 #endif                                            
207                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php