@@ -192,6 +192,24 @@ static const int tsl2591_calibscale_available[] = {
192192 1 , 25 , 428 , 9876 ,
193193};
194194
195+ static const u8 tsl2591_persist_table [] = {
196+ [TSL2591_PRST_ALS_INT_CYCLE_ANY ] = 1 ,
197+ [TSL2591_PRST_ALS_INT_CYCLE_2 ] = 2 ,
198+ [TSL2591_PRST_ALS_INT_CYCLE_3 ] = 3 ,
199+ [TSL2591_PRST_ALS_INT_CYCLE_5 ] = 5 ,
200+ [TSL2591_PRST_ALS_INT_CYCLE_10 ] = 10 ,
201+ [TSL2591_PRST_ALS_INT_CYCLE_15 ] = 15 ,
202+ [TSL2591_PRST_ALS_INT_CYCLE_20 ] = 20 ,
203+ [TSL2591_PRST_ALS_INT_CYCLE_25 ] = 25 ,
204+ [TSL2591_PRST_ALS_INT_CYCLE_30 ] = 30 ,
205+ [TSL2591_PRST_ALS_INT_CYCLE_35 ] = 35 ,
206+ [TSL2591_PRST_ALS_INT_CYCLE_40 ] = 40 ,
207+ [TSL2591_PRST_ALS_INT_CYCLE_45 ] = 45 ,
208+ [TSL2591_PRST_ALS_INT_CYCLE_50 ] = 50 ,
209+ [TSL2591_PRST_ALS_INT_CYCLE_55 ] = 55 ,
210+ [TSL2591_PRST_ALS_INT_CYCLE_60 ] = 60 ,
211+ };
212+
195213static int tsl2591_set_als_lower_threshold (struct tsl2591_chip * chip ,
196214 u16 als_lower_threshold );
197215static int tsl2591_set_als_upper_threshold (struct tsl2591_chip * chip ,
@@ -231,78 +249,22 @@ static int tsl2591_multiplier_to_gain(const u32 multiplier)
231249
232250static int tsl2591_persist_cycle_to_lit (const u8 als_persist )
233251{
234- switch (als_persist ) {
235- case TSL2591_PRST_ALS_INT_CYCLE_ANY :
236- return 1 ;
237- case TSL2591_PRST_ALS_INT_CYCLE_2 :
238- return 2 ;
239- case TSL2591_PRST_ALS_INT_CYCLE_3 :
240- return 3 ;
241- case TSL2591_PRST_ALS_INT_CYCLE_5 :
242- return 5 ;
243- case TSL2591_PRST_ALS_INT_CYCLE_10 :
244- return 10 ;
245- case TSL2591_PRST_ALS_INT_CYCLE_15 :
246- return 15 ;
247- case TSL2591_PRST_ALS_INT_CYCLE_20 :
248- return 20 ;
249- case TSL2591_PRST_ALS_INT_CYCLE_25 :
250- return 25 ;
251- case TSL2591_PRST_ALS_INT_CYCLE_30 :
252- return 30 ;
253- case TSL2591_PRST_ALS_INT_CYCLE_35 :
254- return 35 ;
255- case TSL2591_PRST_ALS_INT_CYCLE_40 :
256- return 40 ;
257- case TSL2591_PRST_ALS_INT_CYCLE_45 :
258- return 45 ;
259- case TSL2591_PRST_ALS_INT_CYCLE_50 :
260- return 50 ;
261- case TSL2591_PRST_ALS_INT_CYCLE_55 :
262- return 55 ;
263- case TSL2591_PRST_ALS_INT_CYCLE_60 :
264- return 60 ;
265- default :
252+ if (als_persist >= ARRAY_SIZE (tsl2591_persist_table ) ||
253+ !tsl2591_persist_table [als_persist ])
266254 return - EINVAL ;
267- }
255+
256+ return tsl2591_persist_table [als_persist ];
268257}
269258
270259static int tsl2591_persist_lit_to_cycle (const u8 als_persist )
271260{
272- switch (als_persist ) {
273- case 1 :
274- return TSL2591_PRST_ALS_INT_CYCLE_ANY ;
275- case 2 :
276- return TSL2591_PRST_ALS_INT_CYCLE_2 ;
277- case 3 :
278- return TSL2591_PRST_ALS_INT_CYCLE_3 ;
279- case 5 :
280- return TSL2591_PRST_ALS_INT_CYCLE_5 ;
281- case 10 :
282- return TSL2591_PRST_ALS_INT_CYCLE_10 ;
283- case 15 :
284- return TSL2591_PRST_ALS_INT_CYCLE_15 ;
285- case 20 :
286- return TSL2591_PRST_ALS_INT_CYCLE_20 ;
287- case 25 :
288- return TSL2591_PRST_ALS_INT_CYCLE_25 ;
289- case 30 :
290- return TSL2591_PRST_ALS_INT_CYCLE_30 ;
291- case 35 :
292- return TSL2591_PRST_ALS_INT_CYCLE_35 ;
293- case 40 :
294- return TSL2591_PRST_ALS_INT_CYCLE_40 ;
295- case 45 :
296- return TSL2591_PRST_ALS_INT_CYCLE_45 ;
297- case 50 :
298- return TSL2591_PRST_ALS_INT_CYCLE_50 ;
299- case 55 :
300- return TSL2591_PRST_ALS_INT_CYCLE_55 ;
301- case 60 :
302- return TSL2591_PRST_ALS_INT_CYCLE_60 ;
303- default :
304- return - EINVAL ;
261+ for (unsigned int i = TSL2591_PRST_ALS_INT_CYCLE_ANY ;
262+ i < ARRAY_SIZE (tsl2591_persist_table ); i ++ ) {
263+ if (als_persist == tsl2591_persist_table [i ])
264+ return i ;
305265 }
266+
267+ return - EINVAL ;
306268}
307269
308270static int tsl2591_compatible_int_time (struct tsl2591_chip * chip ,
0 commit comments