Commit 7501a3a9 authored by Patrik Dahlström's avatar Patrik Dahlström Committed by Jonathan Cameron

iio: adc: palmas: use iio_event_direction for threshold polarity

Instead of having high_threshold > 0 as an indicator for upper threshold
event and lower threshold event otherwise, use enum iio_event_direction
instead. This is hopefully less ambiguous.
Signed-off-by: default avatarPatrik Dahlström <risca@dalakolonin.se>
Link: https://lore.kernel.org/r/20230408114825.824505-6-risca@dalakolonin.seSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent d2ab4eea
...@@ -77,9 +77,9 @@ static struct palmas_gpadc_info palmas_gpadc_info[] = { ...@@ -77,9 +77,9 @@ static struct palmas_gpadc_info palmas_gpadc_info[] = {
}; };
struct palmas_adc_event { struct palmas_adc_event {
int adc_channel_number; int channel;
int adc_high_threshold; int raw_thresh;
int adc_low_threshold; enum iio_event_direction direction;
}; };
/* /*
...@@ -618,16 +618,21 @@ static int palmas_adc_configure_events(struct palmas_gpadc *adc) ...@@ -618,16 +618,21 @@ static int palmas_adc_configure_events(struct palmas_gpadc *adc)
conv = 0; conv = 0;
if (adc->event0_enable) { if (adc->event0_enable) {
struct palmas_adc_event *ev = &adc->event0;
int polarity; int polarity;
ch0 = adc->event0.adc_channel_number; ch0 = ev->channel;
thres = ev->raw_thresh;
conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV0_EN; conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV0_EN;
if (adc->event0.adc_high_threshold > 0) { switch (ev->direction) {
thres = adc->event0.adc_high_threshold; case IIO_EV_DIR_RISING:
polarity = 0; polarity = 0;
} else { break;
thres = adc->event0.adc_low_threshold; case IIO_EV_DIR_FALLING:
polarity = PALMAS_GPADC_THRES_CONV0_MSB_THRES_CONV0_POL; polarity = PALMAS_GPADC_THRES_CONV0_MSB_THRES_CONV0_POL;
break;
default:
return -EINVAL;
} }
ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE,
...@@ -649,16 +654,21 @@ static int palmas_adc_configure_events(struct palmas_gpadc *adc) ...@@ -649,16 +654,21 @@ static int palmas_adc_configure_events(struct palmas_gpadc *adc)
} }
if (adc->event1_enable) { if (adc->event1_enable) {
struct palmas_adc_event *ev = &adc->event1;
int polarity; int polarity;
ch1 = adc->event1.adc_channel_number; ch1 = ev->channel;
thres = ev->raw_thresh;
conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV1_EN; conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV1_EN;
if (adc->event1.adc_high_threshold > 0) { switch (ev->direction) {
thres = adc->event1.adc_high_threshold; case IIO_EV_DIR_RISING:
polarity = 0; polarity = 0;
} else { break;
thres = adc->event1.adc_low_threshold; case IIO_EV_DIR_FALLING:
polarity = PALMAS_GPADC_THRES_CONV1_MSB_THRES_CONV1_POL; polarity = PALMAS_GPADC_THRES_CONV1_MSB_THRES_CONV1_POL;
break;
default:
return -EINVAL;
} }
ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE, ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment