From patchwork Sat Apr 8 11:46:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Patrik_Dahlstr=C3=B6m?= X-Patchwork-Id: 81178 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp840800vqo; Sat, 8 Apr 2023 05:20:31 -0700 (PDT) X-Google-Smtp-Source: AKy350YkPkMk+4KUS515PkO0njrNkEiV9ZvhdhGlHsfbdHwiFYD8eOLQOKFJck1IF14gD0Z152Gx X-Received: by 2002:a17:90b:4d0f:b0:23d:1143:c664 with SMTP id mw15-20020a17090b4d0f00b0023d1143c664mr6074553pjb.31.1680956431440; Sat, 08 Apr 2023 05:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680956431; cv=none; d=google.com; s=arc-20160816; b=gkpfDTZw8wNN0vRck97ijLcpexJ2/ElgmHby1pIIk1+R7Zn4S1KSaFuQsOwpUNKyJK oPr9nfWCeZG7AtL24oviuluGl8OHaVNIlMUsDLfGgpVv/oLRH2200H9CM4oYnYWJvys0 Co4ET0qtKrr0PyWK6mXF3ASinqbqxmpU2W/Tpk1xQ6Tr9NwLTZsINVzS1XDoBNaoXnoc w3vZ2pYYEB7z0C0egU7SFt4qV1TUJs4AYD/z0+jtlt6n9UyNnqJjSOWkskNYo+Ksj2HH NeqaIM+ytIXufCHBsQkjU9yi2uPPcwdA39HQ48peyNwovOHjVwfsnHxlyfbyV2D5z7rz lf9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=8oCsKoWj+OT4dqdz4wKUl0ESprUGM0ZozVBAf1AeyA0=; b=tleakynjNFD8seIFhPV4aR2ACXgqm6WK91zn4cFmzlaM6lVg//l7YeR9L0mCKUKi+v NRGMvxpB7HPzzCbj/bOmwajWwi4XhRx+EPkO4lkfeW3ZhjnGt+SU1QUNW1bhgnpdAcHm hZAR3i/U9ANIU1zFDJGxchEJxnsjg245UIF/9XRjNc/UckJEQC1PcawAkIJovfXchXKK NIbeJmIa0sgV9Q88xiHz62vXgNr8y/bhD4Q6CgO8BaDtOaG6anUfHxBSeyJAW9foIsgl rRHxq9gd14+21ox8O595kWlN4of3AKt36yPLwek3sQ/SaovNri8CBlgSJgcoiPBP5L6k Y2gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b=nDIG0lmB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=dalakolonin.se Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf19-20020a17090b0b1300b00237413f8c6esi8249263pjb.154.2023.04.08.05.20.19; Sat, 08 Apr 2023 05:20:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b=nDIG0lmB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=dalakolonin.se Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230296AbjDHLrQ (ORCPT + 99 others); Sat, 8 Apr 2023 07:47:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbjDHLrN (ORCPT ); Sat, 8 Apr 2023 07:47:13 -0400 Received: from pio-pvt-msa3.bahnhof.se (pio-pvt-msa3.bahnhof.se [79.136.2.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B05B7FF37; Sat, 8 Apr 2023 04:46:59 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa3.bahnhof.se (Postfix) with ESMTP id 9FD0B3F6DD; Sat, 8 Apr 2023 13:46:57 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at bahnhof.se X-Spam-Score: -2.1 X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Authentication-Results: pio-pvt-msa3.bahnhof.se (amavisd-new); dkim=pass (2048-bit key) header.d=dalakolonin.se Received: from pio-pvt-msa3.bahnhof.se ([127.0.0.1]) by localhost (pio-pvt-msa3.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TV1ARSLbVha0; Sat, 8 Apr 2023 13:46:56 +0200 (CEST) Received: by pio-pvt-msa3.bahnhof.se (Postfix) with ESMTPA id A8FF03F645; Sat, 8 Apr 2023 13:46:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 4C64095F46; Sat, 8 Apr 2023 11:46:56 +0000 (UTC) Received: from zimbra.dalakolonin.se ([127.0.0.1]) by localhost (zimbra.dalakolonin.se [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id TXAn8zRf6FVy; Sat, 8 Apr 2023 11:46:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id CF6BD95F42; Sat, 8 Apr 2023 11:46:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra.dalakolonin.se CF6BD95F42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalakolonin.se; s=D374B428-D0A7-11ED-A657-75977B426508; t=1680954413; bh=8oCsKoWj+OT4dqdz4wKUl0ESprUGM0ZozVBAf1AeyA0=; h=From:To:Date:Message-Id:MIME-Version; b=nDIG0lmBvcF8jmEvZZF4zN/YChcDQWKTGKZxmoUU5VlV3iwKWGmTlkhr/QHgBkOsr 3qp2Uq8to6NteGqWK4NuXUBg4pDpLmkn/KtUUcYFISboofE9D4LTODCTRXYtgShxgM 3rSRUGBFpw1QN8YV29YCpueTAVqQPLSwLmsHMIju3oVCndb4L+WQOLCaXdpbKUMWIX ZQgMQWWN1kXcuZ4TBUQ94R/aUV+F2Kj4MUXx/JXn2UzDq6x0HMzcypM2PNlt3ZSos4 1sUq3DhqcNe78ehfEXNqGAVX/Vk3lMDI0Dc+WMlXxn4f0O64yZPd9cY8MwvPuMy9Qo 7lNxh4gG6YCPw== X-Virus-Scanned: amavisd-new at dalakolonin.se Received: from zimbra.dalakolonin.se ([127.0.0.1]) by localhost (zimbra.dalakolonin.se [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id s7CCfjFJXs7L; Sat, 8 Apr 2023 11:46:53 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id 35F6A95F3F; Sat, 8 Apr 2023 11:46:53 +0000 (UTC) From: =?utf-8?q?Patrik_Dahlstr=C3=B6m?= 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, =?utf-8?q?Pa?= =?utf-8?q?trik_Dahlstr=C3=B6m?= Subject: [PATCH v3 3/7] iio: adc: palmas: use iio_event_direction for threshold polarity Date: Sat, 8 Apr 2023 13:46:20 +0200 Message-Id: <20230408114624.824144-4-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230408114624.824144-1-risca@dalakolonin.se> References: <20230408114624.824144-1-risca@dalakolonin.se> MIME-Version: 1.0 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762610571024712822?= X-GMAIL-MSGID: =?utf-8?q?1762610571024712822?= 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 --- 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,