From patchwork Sun Mar 19 22:39:08 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: 71913 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp904667wrt; Sun, 19 Mar 2023 15:40:33 -0700 (PDT) X-Google-Smtp-Source: AK7set+6pPoxBDkLvXFtGlVZkH0ChL71/59yfKd69yBEV3an5QgOYd+fYtPo+m3F0PB7KWLM1XI/ X-Received: by 2002:a05:6a00:27ab:b0:627:e180:ac04 with SMTP id bd43-20020a056a0027ab00b00627e180ac04mr5625885pfb.0.1679265633120; Sun, 19 Mar 2023 15:40:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679265633; cv=none; d=google.com; s=arc-20160816; b=GXwHZxF2/9K9M5VZjdfKftAOuQ4zuILQT9Phgsg0cZMtO3p3nar+Ob0xDKNIcUFpdP sht+EMgCl+iaHE1QQ+kcAa3cIih6xBnwbf9vtcXmP4BbifJAGKTzdLv9VDlLBLQOeJUG BYLLwfNv30hlisXD8PeHkITdvxj1Z7mpo0/s1ADmEKnqq309x5nvPcDmBSW56innbfqZ trvrbgZ8cvfLcJxbV2dkuARFacIL1W5KGn4NnjjYV5K4FQpCnGQJCHl8GVfe9CaedD4I 2YvweXiwsBBjzN1gkERHypAPtkvdyBMF/R9WVSVNTv+Rx7gx+JCLumyL48SSMucmr5xi 8ucA== 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; bh=EGvUd5FSPICOseoHVxE6edAehxAPDRwXNJr3XIh2+y4=; b=jK1220V8u98rKNOHZgA41MVicmtu3EPaaPzJ1/9H09dIunyPC9EpUPJJtcVa9bywMc m21wXvqzTB0TVhbpWIe/TYInAx7+HNEwdmAZhH/GALBQS4qAgATLS0Xy4J+Q3EzPUmqX aw8k0gpmIVBnNVFG7XWiCHe3in/tD4oayh0mCpfmul3zhQopwIgc3rGSt/LqlarYYuMf fsFSP+06u3V0yF9zi10SqTI5w5klEyQaYSFvVSSeKrv/q0e1XJdRXT2wsk800Q6fJNl9 W6rR1Io11QfFjeSM6HDrAdjvQd+ojHcM2f2XrAD7NsaImTHTm01FV+5fBlI+fdE+9eBU y0Tw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a056a00170200b00623b50eb7d0si9859773pfc.214.2023.03.19.15.40.17; Sun, 19 Mar 2023 15:40:33 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbjCSWjq convert rfc822-to-8bit (ORCPT + 99 others); Sun, 19 Mar 2023 18:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229779AbjCSWjk (ORCPT ); Sun, 19 Mar 2023 18:39:40 -0400 Received: from pio-pvt-msa1.bahnhof.se (pio-pvt-msa1.bahnhof.se [79.136.2.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D28E21B542; Sun, 19 Mar 2023 15:39:37 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa1.bahnhof.se (Postfix) with ESMTP id 8C3A23F683; Sun, 19 Mar 2023 23:39:35 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at bahnhof.se X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_FAIL,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 Received: from pio-pvt-msa1.bahnhof.se ([127.0.0.1]) by localhost (pio-pvt-msa1.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OYmxcAaU6aKO; Sun, 19 Mar 2023 23:39:34 +0100 (CET) Received: by pio-pvt-msa1.bahnhof.se (Postfix) with ESMTPA id 6840F3F55C; Sun, 19 Mar 2023 23:39:34 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 9FEE88EBD6; Sun, 19 Mar 2023 22:39:27 +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 WrE8dZEpIUYh; Sun, 19 Mar 2023 22:39:22 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 133008EBCF; Sun, 19 Mar 2023 22:39:22 +0000 (UTC) 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 crPBhBBIioQm; Sun, 19 Mar 2023 22:39:22 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id A9E248EBC8; Sun, 19 Mar 2023 22:39:21 +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, =?utf-8?q?Patrik_Dahlstr=C3=B6m?= Subject: [PATCH 3/3] iio: adc: palmas_gpadc: remove palmas_adc_wakeup_property Date: Sun, 19 Mar 2023 23:39:08 +0100 Message-Id: <20230319223908.108540-4-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230319223908.108540-1-risca@dalakolonin.se> References: <20230319223908.108540-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?1760837640590262141?= X-GMAIL-MSGID: =?utf-8?q?1760837640590262141?= This struct contain essentially the same information as palmas_adc_event and palmas_gpadc_thresholds combined, but with more ambiguity: the code decided whether to trigger on rising or falling edge based on the high threshold being non-zero. Since its use in platform data has now been removed, we can remove it entirely. Lastly, the use case for waking up the cpu from sleep mode when a threshold has been passed is no longer the primary use for events so all code is changed to say "event" instead of "wakeup". Signed-off-by: Patrik Dahlström --- drivers/iio/adc/palmas_gpadc.c | 94 +++++++++++++--------------------- include/linux/mfd/palmas.h | 6 --- 2 files changed, 36 insertions(+), 64 deletions(-) diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index 419d7db51345..042b68f29444 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -122,10 +122,8 @@ struct palmas_gpadc { int irq_auto_1; struct palmas_gpadc_info *adc_info; struct completion conv_completion; - struct palmas_adc_wakeup_property wakeup1_data; - struct palmas_adc_wakeup_property wakeup2_data; - bool wakeup1_enable; - bool wakeup2_enable; + bool event0_enable; + bool event1_enable; int auto_conversion_period; struct mutex lock; struct palmas_adc_event event0; @@ -592,50 +590,26 @@ static int palmas_gpadc_read_event_config(struct iio_dev *indio_dev, return ret; } -static void palmas_adc_event_to_wakeup(struct palmas_gpadc *adc, - struct palmas_adc_event *ev, - struct palmas_adc_wakeup_property *wakeup) -{ - wakeup->adc_channel_number = ev->channel; - if (ev->direction == IIO_EV_DIR_RISING) { - wakeup->adc_low_threshold = 0; - wakeup->adc_high_threshold = - palmas_gpadc_get_high_threshold_raw(adc, &adc->event0); - } - else { - wakeup->adc_low_threshold = - palmas_gpadc_get_low_threshold_raw(adc, &adc->event0); - wakeup->adc_high_threshold = 0; - } -} - -static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc); -static int palmas_adc_wakeup_reset(struct palmas_gpadc *adc); +static int palmas_adc_events_configure(struct palmas_gpadc *adc); +static int palmas_adc_events_reset(struct palmas_gpadc *adc); static int palmas_gpadc_reconfigure_event_channels(struct palmas_gpadc *adc) { - bool was_enabled = adc->wakeup1_enable || adc->wakeup2_enable; + bool was_enabled = adc->event0_enable || adc->event1_enable; bool enable; - adc->wakeup1_enable = adc->event0.channel == -1 ? false : true; - adc->wakeup2_enable = adc->event1.channel == -1 ? false : true; + adc->event0_enable = adc->event0.channel == -1 ? false : true; + adc->event1_enable = adc->event1.channel == -1 ? false : true; - enable = adc->wakeup1_enable || adc->wakeup2_enable; + enable = adc->event0_enable || adc->event1_enable; if (!was_enabled && enable) device_wakeup_enable(adc->dev); else if (was_enabled && !enable) device_wakeup_disable(adc->dev); - if (!enable) - return palmas_adc_wakeup_reset(adc); - - // adjust levels - if (adc->wakeup1_enable) - palmas_adc_event_to_wakeup(adc, &adc->event0, &adc->wakeup1_data); - if (adc->wakeup2_enable) - palmas_adc_event_to_wakeup(adc, &adc->event1, &adc->wakeup2_data); - - return palmas_adc_wakeup_configure(adc); + return enable ? + palmas_adc_events_configure(adc) : + palmas_adc_events_reset(adc); } static int palmas_gpadc_enable_event_config(struct palmas_gpadc *adc, @@ -864,12 +838,14 @@ static int palmas_gpadc_get_adc_dt_data(struct platform_device *pdev, return 0; } -static void palmas_disable_wakeup(void *data) +static void palmas_disable_events(void *data) { struct palmas_gpadc *adc = data; - if (adc->wakeup1_enable || adc->wakeup2_enable) + if (adc->event0_enable || adc->event1_enable) { + palmas_adc_events_reset(adc); device_wakeup_disable(adc->dev); + } } static int palmas_gpadc_probe(struct platform_device *pdev) @@ -993,7 +969,7 @@ static int palmas_gpadc_probe(struct platform_device *pdev) device_set_wakeup_capable(&pdev->dev, 1); ret = devm_add_action_or_reset(&pdev->dev, - palmas_disable_wakeup, + palmas_disable_events, adc); if (ret) return ret; @@ -1001,7 +977,7 @@ static int palmas_gpadc_probe(struct platform_device *pdev) return 0; } -static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc) +static int palmas_adc_events_configure(struct palmas_gpadc *adc) { int adc_period, conv; int i; @@ -1027,16 +1003,18 @@ static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc) } conv = 0; - if (adc->wakeup1_enable) { + if (adc->event0_enable) { + struct palmas_adc_event *ev = &adc->event0; int polarity; - ch0 = adc->wakeup1_data.adc_channel_number; + ch0 = ev->channel; conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV0_EN; - if (adc->wakeup1_data.adc_high_threshold > 0) { - thres = adc->wakeup1_data.adc_high_threshold; + + if (ev->direction == IIO_EV_DIR_RISING) { + thres = palmas_gpadc_get_high_threshold_raw(adc, ev); polarity = 0; } else { - thres = adc->wakeup1_data.adc_low_threshold; + thres = palmas_gpadc_get_low_threshold_raw(adc, ev); polarity = PALMAS_GPADC_THRES_CONV0_MSB_THRES_CONV0_POL; } @@ -1058,16 +1036,18 @@ static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc) } } - if (adc->wakeup2_enable) { + if (adc->event1_enable) { + struct palmas_adc_event *ev = &adc->event1; int polarity; - ch1 = adc->wakeup2_data.adc_channel_number; + ch1 = ev->channel; conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV1_EN; - if (adc->wakeup2_data.adc_high_threshold > 0) { - thres = adc->wakeup2_data.adc_high_threshold; + + if (ev->direction == IIO_EV_DIR_RISING) { + thres = palmas_gpadc_get_high_threshold_raw(adc, ev); polarity = 0; } else { - thres = adc->wakeup2_data.adc_low_threshold; + thres = palmas_gpadc_get_low_threshold_raw(adc, ev); polarity = PALMAS_GPADC_THRES_CONV1_MSB_THRES_CONV1_POL; } @@ -1106,7 +1086,7 @@ static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc) return ret; } -static int palmas_adc_wakeup_reset(struct palmas_gpadc *adc) +static int palmas_adc_events_reset(struct palmas_gpadc *adc) { int ret; @@ -1128,15 +1108,14 @@ static int palmas_gpadc_suspend(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct palmas_gpadc *adc = iio_priv(indio_dev); - int ret; if (!device_may_wakeup(dev)) return 0; - if (adc->wakeup1_enable) + if (adc->event0_enable) enable_irq_wake(adc->irq_auto_0); - if (adc->wakeup2_enable) + if (adc->event1_enable) enable_irq_wake(adc->irq_auto_1); return 0; @@ -1146,15 +1125,14 @@ static int palmas_gpadc_resume(struct device *dev) { struct iio_dev *indio_dev = dev_get_drvdata(dev); struct palmas_gpadc *adc = iio_priv(indio_dev); - int ret; if (!device_may_wakeup(dev)) return 0; - if (adc->wakeup1_enable) + if (adc->event0_enable) disable_irq_wake(adc->irq_auto_0); - if (adc->wakeup2_enable) + if (adc->event1_enable) disable_irq_wake(adc->irq_auto_1); return 0; diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h index dc79d5e2d680..55f22adb1a9e 100644 --- a/include/linux/mfd/palmas.h +++ b/include/linux/mfd/palmas.h @@ -129,12 +129,6 @@ struct palmas_pmic_driver_data { struct regulator_config config); }; -struct palmas_adc_wakeup_property { - int adc_channel_number; - int adc_high_threshold; - int adc_low_threshold; -}; - struct palmas_gpadc_platform_data { /* Channel 3 current source is only enabled during conversion */ int ch3_current; /* 0: off; 1: 10uA; 2: 400uA; 3: 800 uA */