Skip to content

Commit 26c17a1

Browse files
Beomho Seojic23
authored andcommitted
iio: cm36651: Fix read/write integration time function.
This patch is fixed [read/write] integration time function. cm36651 have integration time from 1 to 640 milliseconds. But, print more then the thousand second. when call *_integration_time attribute. Because read_integration_time function return IIO_VAL_INT. read integration time function is changed return IIO_VAL_INT_PLUS_MICRO; And then .write_raw_get_fmt callback function for parse a fixed-point number from a string. Some description is revised milliseconds unit. v2: cm36651_write_int_time function fixed as it was. Signed-off-by: Beomho Seo <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 55b40d3 commit 26c17a1

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

drivers/iio/light/cm36651.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
#define CM36651_CS_CONF2_DEFAULT_BIT 0x08
5151

5252
/* CS_CONF3 channel integration time */
53-
#define CM36651_CS_IT1 0x00 /* Integration time 80000 usec */
54-
#define CM36651_CS_IT2 0x40 /* Integration time 160000 usec */
55-
#define CM36651_CS_IT3 0x80 /* Integration time 320000 usec */
56-
#define CM36651_CS_IT4 0xC0 /* Integration time 640000 usec */
53+
#define CM36651_CS_IT1 0x00 /* Integration time 80 msec */
54+
#define CM36651_CS_IT2 0x40 /* Integration time 160 msec */
55+
#define CM36651_CS_IT3 0x80 /* Integration time 320 msec */
56+
#define CM36651_CS_IT4 0xC0 /* Integration time 640 msec */
5757

5858
/* PS_CONF1 command code */
5959
#define CM36651_PS_ENABLE 0x00
@@ -64,10 +64,10 @@
6464
#define CM36651_PS_PERS4 0x0C
6565

6666
/* PS_CONF1 command code: integration time */
67-
#define CM36651_PS_IT1 0x00 /* Integration time 320 usec */
68-
#define CM36651_PS_IT2 0x10 /* Integration time 420 usec */
69-
#define CM36651_PS_IT3 0x20 /* Integration time 520 usec */
70-
#define CM36651_PS_IT4 0x30 /* Integration time 640 usec */
67+
#define CM36651_PS_IT1 0x00 /* Integration time 0.32 msec */
68+
#define CM36651_PS_IT2 0x10 /* Integration time 0.42 msec */
69+
#define CM36651_PS_IT3 0x20 /* Integration time 0.52 msec */
70+
#define CM36651_PS_IT4 0x30 /* Integration time 0.64 msec */
7171

7272
/* PS_CONF1 command code: duty ratio */
7373
#define CM36651_PS_DR1 0x00 /* Duty ratio 1/80 */
@@ -93,8 +93,8 @@
9393
#define CM36651_CLOSE_PROXIMITY 0x32
9494
#define CM36651_FAR_PROXIMITY 0x33
9595

96-
#define CM36651_CS_INT_TIME_AVAIL "80000 160000 320000 640000"
97-
#define CM36651_PS_INT_TIME_AVAIL "320 420 520 640"
96+
#define CM36651_CS_INT_TIME_AVAIL "0.08 0.16 0.32 0.64"
97+
#define CM36651_PS_INT_TIME_AVAIL "0.000320 0.000420 0.000520 0.000640"
9898

9999
enum cm36651_operation_mode {
100100
CM36651_LIGHT_EN,
@@ -356,38 +356,38 @@ static int cm36651_read_channel(struct cm36651_data *cm36651,
356356
}
357357

358358
static int cm36651_read_int_time(struct cm36651_data *cm36651,
359-
struct iio_chan_spec const *chan, int *val)
359+
struct iio_chan_spec const *chan, int *val2)
360360
{
361361
switch (chan->type) {
362362
case IIO_LIGHT:
363363
if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT1)
364-
*val = 80000;
364+
*val2 = 80000;
365365
else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT2)
366-
*val = 160000;
366+
*val2 = 160000;
367367
else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT3)
368-
*val = 320000;
368+
*val2 = 320000;
369369
else if (cm36651->cs_int_time[chan->address] == CM36651_CS_IT4)
370-
*val = 640000;
370+
*val2 = 640000;
371371
else
372372
return -EINVAL;
373373
break;
374374
case IIO_PROXIMITY:
375375
if (cm36651->ps_int_time == CM36651_PS_IT1)
376-
*val = 320;
376+
*val2 = 320;
377377
else if (cm36651->ps_int_time == CM36651_PS_IT2)
378-
*val = 420;
378+
*val2 = 420;
379379
else if (cm36651->ps_int_time == CM36651_PS_IT3)
380-
*val = 520;
380+
*val2 = 520;
381381
else if (cm36651->ps_int_time == CM36651_PS_IT4)
382-
*val = 640;
382+
*val2 = 640;
383383
else
384384
return -EINVAL;
385385
break;
386386
default:
387387
return -EINVAL;
388388
}
389389

390-
return IIO_VAL_INT;
390+
return IIO_VAL_INT_PLUS_MICRO;
391391
}
392392

393393
static int cm36651_write_int_time(struct cm36651_data *cm36651,
@@ -459,7 +459,8 @@ static int cm36651_read_raw(struct iio_dev *indio_dev,
459459
ret = cm36651_read_channel(cm36651, chan, val);
460460
break;
461461
case IIO_CHAN_INFO_INT_TIME:
462-
ret = cm36651_read_int_time(cm36651, chan, val);
462+
*val = 0;
463+
ret = cm36651_read_int_time(cm36651, chan, val2);
463464
break;
464465
default:
465466
ret = -EINVAL;
@@ -479,7 +480,7 @@ static int cm36651_write_raw(struct iio_dev *indio_dev,
479480
int ret = -EINVAL;
480481

481482
if (mask == IIO_CHAN_INFO_INT_TIME) {
482-
ret = cm36651_write_int_time(cm36651, chan, val);
483+
ret = cm36651_write_int_time(cm36651, chan, val2);
483484
if (ret < 0)
484485
dev_err(&client->dev, "Integration time write failed\n");
485486
}

0 commit comments

Comments
 (0)