mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Patrik Dahlström" <risca@dalakolonin.se>
To: linux-iio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, letux-kernel@openphoenux.org,
	kernel@pyra-handheld.com, pgoudagunta@nvidia.com,
	hns@goldelico.com, jic23@kernel.org, lars@metafoo.de,
	linux-omap@vger.kernel.org,
	"Patrik Dahlström" <risca@dalakolonin.se>
Subject: [PATCH v3 3/7] iio: adc: palmas: use iio_event_direction for threshold polarity
Date: Wed,  5 Apr 2023 23:22:29 +0200	[thread overview]
Message-ID: <20230405212233.4167986-4-risca@dalakolonin.se> (raw)
In-Reply-To: <20230405212233.4167986-1-risca@dalakolonin.se>

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: Patrik Dahlström <risca@dalakolonin.se>
---
 drivers/iio/adc/palmas_gpadc.c | 36 ++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
index 55fdf59ef711..205a7628b235 100644
--- a/drivers/iio/adc/palmas_gpadc.c
+++ b/drivers/iio/adc/palmas_gpadc.c
@@ -77,9 +77,9 @@ static struct palmas_gpadc_info palmas_gpadc_info[] = {
 };
 
 struct palmas_adc_event {
-	int adc_channel_number;
-	int adc_high_threshold;
-	int adc_low_threshold;
+	int channel;
+	int raw_thresh;
+	enum iio_event_direction direction;
 };
 
 /*
@@ -618,16 +618,21 @@ static int palmas_adc_configure_events(struct palmas_gpadc *adc)
 
 	conv = 0;
 	if (adc->event0_enable) {
+		struct palmas_adc_event *ev = &adc->event0;
 		int polarity;
 
-		ch0 = adc->event0.adc_channel_number;
+		ch0 = ev->channel;
+		thres = ev->raw_thresh;
 		conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV0_EN;
-		if (adc->event0.adc_high_threshold > 0) {
-			thres = adc->event0.adc_high_threshold;
+		switch (ev->direction) {
+		case IIO_EV_DIR_RISING:
 			polarity = 0;
-		} else {
-			thres = adc->event0.adc_low_threshold;
+			break;
+		case IIO_EV_DIR_FALLING:
 			polarity = PALMAS_GPADC_THRES_CONV0_MSB_THRES_CONV0_POL;
+			break;
+		default:
+			return -EINVAL;
 		}
 
 		ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE,
@@ -649,16 +654,21 @@ static int palmas_adc_configure_events(struct palmas_gpadc *adc)
 	}
 
 	if (adc->event1_enable) {
+		struct palmas_adc_event *ev = &adc->event1;
 		int polarity;
 
-		ch1 = adc->event1.adc_channel_number;
+		ch1 = ev->channel;
+		thres = ev->raw_thresh;
 		conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV1_EN;
-		if (adc->event1.adc_high_threshold > 0) {
-			thres = adc->event1.adc_high_threshold;
+		switch (ev->direction) {
+		case IIO_EV_DIR_RISING:
 			polarity = 0;
-		} else {
-			thres = adc->event1.adc_low_threshold;
+			break;
+		case IIO_EV_DIR_FALLING:
 			polarity = PALMAS_GPADC_THRES_CONV1_MSB_THRES_CONV1_POL;
+			break;
+		default:
+			return -EINVAL;
 		}
 
 		ret = palmas_write(adc->palmas, PALMAS_GPADC_BASE,
-- 
2.25.1


  parent reply	other threads:[~2023-04-05 21:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-05 21:22 [PATCH v3 0/7] iio: adc: palmas_gpadc: add iio events Patrik Dahlström
2023-04-05 21:22 ` [PATCH v3 1/7] iio: adc: palmas: remove adc_wakeupX_data Patrik Dahlström
2023-04-05 21:22 ` [PATCH v3 2/7] iio: adc: palmas: replace "wakeup" with "event" Patrik Dahlström
2023-04-05 21:22 ` Patrik Dahlström [this message]
2023-04-05 21:22 ` [PATCH v3 4/7] iio: adc: palmas: move eventX_enable into palmas_adc_event Patrik Dahlström
2023-04-05 21:22 ` [PATCH v3 5/7] iio: adc: palmas: always reset events on unload Patrik Dahlström
2023-04-05 21:22 ` [PATCH v3 6/7] iio: adc: palmas: add support for iio threshold events Patrik Dahlström
2023-04-07 17:19   ` Jonathan Cameron
2023-04-08 11:31     ` Patrik Dahlström
2023-04-05 21:22 ` [PATCH v3 7/7] iio: adc: palmas: don't alter event config on suspend/resume Patrik Dahlström
2023-04-07 17:22   ` Jonathan Cameron
2023-04-07 17:04 ` [PATCH v3 0/7] iio: adc: palmas_gpadc: add iio events Jonathan Cameron
2023-04-07 17:09   ` Jonathan Cameron
2023-04-08 10:51     ` Patrik Dahlström
2023-04-08 11:46 Patrik Dahlström
2023-04-08 11:46 ` [PATCH v3 3/7] iio: adc: palmas: use iio_event_direction for threshold polarity Patrik Dahlström

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230405212233.4167986-4-risca@dalakolonin.se \
    --to=risca@dalakolonin.se \
    --cc=hns@goldelico.com \
    --cc=jic23@kernel.org \
    --cc=kernel@pyra-handheld.com \
    --cc=lars@metafoo.de \
    --cc=letux-kernel@openphoenux.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=pgoudagunta@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®