@@ -337,6 +337,17 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts)
337
337
return ret ;
338
338
}
339
339
340
+ static void iio_gts_us_to_int_micro (int * time_us , int * int_micro_times ,
341
+ int num_times )
342
+ {
343
+ int i ;
344
+
345
+ for (i = 0 ; i < num_times ; i ++ ) {
346
+ int_micro_times [i * 2 ] = time_us [i ] / 1000000 ;
347
+ int_micro_times [i * 2 + 1 ] = time_us [i ] % 1000000 ;
348
+ }
349
+ }
350
+
340
351
/**
341
352
* iio_gts_build_avail_time_table - build table of available integration times
342
353
* @gts: Gain time scale descriptor
@@ -351,7 +362,7 @@ static int iio_gts_build_avail_scale_table(struct iio_gts *gts)
351
362
*/
352
363
static int iio_gts_build_avail_time_table (struct iio_gts * gts )
353
364
{
354
- int * times , i , j , idx = 0 ;
365
+ int * times , i , j , idx = 0 , * int_micro_times ;
355
366
356
367
if (!gts -> num_itime )
357
368
return 0 ;
@@ -378,13 +389,24 @@ static int iio_gts_build_avail_time_table(struct iio_gts *gts)
378
389
}
379
390
}
380
391
}
381
- gts -> avail_time_tables = times ;
382
- /*
383
- * This is just to survive a unlikely corner-case where times in the
384
- * given time table were not unique. Else we could just trust the
385
- * gts->num_itime.
386
- */
387
- gts -> num_avail_time_tables = idx ;
392
+
393
+ /* create a list of times formatted as list of IIO_VAL_INT_PLUS_MICRO */
394
+ int_micro_times = kcalloc (idx , sizeof (int ) * 2 , GFP_KERNEL );
395
+ if (int_micro_times ) {
396
+ /*
397
+ * This is just to survive a unlikely corner-case where times in
398
+ * the given time table were not unique. Else we could just
399
+ * trust the gts->num_itime.
400
+ */
401
+ gts -> num_avail_time_tables = idx ;
402
+ iio_gts_us_to_int_micro (times , int_micro_times , idx );
403
+ }
404
+
405
+ gts -> avail_time_tables = int_micro_times ;
406
+ kfree (times );
407
+
408
+ if (!int_micro_times )
409
+ return - ENOMEM ;
388
410
389
411
return 0 ;
390
412
}
@@ -683,8 +705,8 @@ int iio_gts_avail_times(struct iio_gts *gts, const int **vals, int *type,
683
705
return - EINVAL ;
684
706
685
707
* vals = gts -> avail_time_tables ;
686
- * type = IIO_VAL_INT ;
687
- * length = gts -> num_avail_time_tables ;
708
+ * type = IIO_VAL_INT_PLUS_MICRO ;
709
+ * length = gts -> num_avail_time_tables * 2 ;
688
710
689
711
return IIO_AVAIL_LIST ;
690
712
}
0 commit comments