From patchwork Sat Apr 8 11:48:17 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: 81173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp838944vqo; Sat, 8 Apr 2023 05:16:39 -0700 (PDT) X-Google-Smtp-Source: AKy350bkNuHXiVOsshUI5Sbyq6Qh7WYoaA++9IZ8eZzDX9QFZ5VbLMZkuYasPWr6cxOMGCFraDye X-Received: by 2002:a17:902:f543:b0:19c:ff5d:1fd2 with SMTP id h3-20020a170902f54300b0019cff5d1fd2mr5308747plf.8.1680956199486; Sat, 08 Apr 2023 05:16:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680956199; cv=none; d=google.com; s=arc-20160816; b=EF6yzYYv4Bg1mLzYfMTz9OirZ52463CVaUfCgGBbu/HbEq/bmhrPvrjbB22dQoAFQ8 cSTcKYtqxioUfZQRFwj+SFy6I/PvsLR/Cp0N6J/WAYR67UTnjvVliywKW8IMU97mbM6F WmLQnmoWesUsdbiLEAJEixh8w5QAlAvKG4aMF3A9HYaIIpXb2k6WJw5xepxgW/jz6oZ/ 0NEihCwnjz0MCBhVrD5TKx25+67k37AT2cx4C3Qeppe2BQuELexbhppAsqNkrn3wuBcy PCLGIMhjnF8irpjE27k1PhWaNDNgaPiXNd3ytK4I+Y1sGicINpv49BUQAC7O8OpJyvMo QeQQ== 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=XhROZXPSXckR4cXo6YbuNE8r4xKHu7TnEgvgxqLTtlg=; b=UCHbIaaAxpi/WEcQ3SRdSxR/DORWkSAjJwT2Abq8MMDdIpI9J8/LCKomd3BIrl9k0d 7mldL86BL3j69jkDKSYFChRKBM9c00HLSCNAAh2iyaKo37mqKS4LmEHjFCdTFT4yxz/O 9+pBGmFSqLwE+PjbegxEjfFcp8G+He7enPCSUASi5sUhCyaReeswxfjiHreQqsoIhd8f 9ha1yB1LftkpLrC1L3t8an32awhjjBFqDScR+0GC2puJj2GouvloWBcBVR0RdGaMRsQa iDv5YR4KWIXnFvi7k+1MTJNoErnsvQS8IfcGrhnUBsS4kly9653CfIXDX23E7lnpB1yh hU+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b=VtHTbDOy; 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 bc6-20020a170902930600b001a1defc30cbsi5883533plb.479.2023.04.08.05.16.27; Sat, 08 Apr 2023 05:16:39 -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=VtHTbDOy; 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 S229708AbjDHLtL (ORCPT + 99 others); Sat, 8 Apr 2023 07:49:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230443AbjDHLtJ (ORCPT ); Sat, 8 Apr 2023 07:49:09 -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 87E2CD532; Sat, 8 Apr 2023 04:49:06 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa1.bahnhof.se (Postfix) with ESMTP id 177C23F586; Sat, 8 Apr 2023 13:49:05 +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.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Authentication-Results: pio-pvt-msa1.bahnhof.se (amavisd-new); dkim=pass (2048-bit key) header.d=dalakolonin.se 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 g1tQhCcjjgA0; Sat, 8 Apr 2023 13:49:03 +0200 (CEST) Received: by pio-pvt-msa1.bahnhof.se (Postfix) with ESMTPA id A5C2D3F3E8; Sat, 8 Apr 2023 13:49:03 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 782F295F9F; Sat, 8 Apr 2023 11:49:03 +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 3Sd9tTVk3Z73; Sat, 8 Apr 2023 11:49:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id AD9C395F9B; Sat, 8 Apr 2023 11:49:01 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra.dalakolonin.se AD9C395F9B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalakolonin.se; s=D374B428-D0A7-11ED-A657-75977B426508; t=1680954541; bh=XhROZXPSXckR4cXo6YbuNE8r4xKHu7TnEgvgxqLTtlg=; h=From:To:Date:Message-Id:MIME-Version; b=VtHTbDOyyeXmmfAj5jl8fG5gWoJkSCXcfss5kbCtRzZ8UDyvJ2HfyGlGqu0nnEODe 6jXv6febDkSi6CXjfR3fDi62idqowsDCCMtcBfmXBTQTYLB/iESXr6INH89nKkR4gD ip+xvpzmDERj8YbQZS/2OJY6ltrr0Y7l9S09At8DR5i0gegEClWg+z+/tOFHZln4xc w5NXwuVHZaDY7ou83QbK4nBP77lxXw8t2ecX1v9n8IlDUngHdbhYqKiDeM3LxzU7/6 SBM+pewcUyJtXsZp0MnGGkfwBAgKSG1IjbNuNQMVaDI1djgWQp7IBe2YlFRynDbV7C Ia+0wYNAcrDxw== 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 Ye8JcNTTR-Wm; Sat, 8 Apr 2023 11:49:01 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id 84AD595F98; Sat, 8 Apr 2023 11:49:01 +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?= , Jonathan Cameron Subject: [PATCH v4 1/9] iio: adc: palmas_gpadc: fix NULL dereference on rmmod Date: Sat, 8 Apr 2023 13:48:17 +0200 Message-Id: <20230408114825.824505-2-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230408114825.824505-1-risca@dalakolonin.se> References: <20230408114825.824505-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?1762610327873299738?= X-GMAIL-MSGID: =?utf-8?q?1762610327873299738?= Calling dev_to_iio_dev() on a platform device pointer is undefined and will make adc NULL. Signed-off-by: Patrik Dahlström Link: https://lore.kernel.org/r/20230313205029.1881745-1-risca@dalakolonin.se Signed-off-by: Jonathan Cameron --- drivers/iio/adc/palmas_gpadc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index fd000345ec5c..849a697a467e 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -639,7 +639,7 @@ static int palmas_gpadc_probe(struct platform_device *pdev) static int palmas_gpadc_remove(struct platform_device *pdev) { - struct iio_dev *indio_dev = dev_to_iio_dev(&pdev->dev); + struct iio_dev *indio_dev = dev_get_drvdata(&pdev->dev); struct palmas_gpadc *adc = iio_priv(indio_dev); if (adc->wakeup1_enable || adc->wakeup2_enable) From patchwork Sat Apr 8 11:48:18 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: 81167 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp837654vqo; Sat, 8 Apr 2023 05:14:03 -0700 (PDT) X-Google-Smtp-Source: AKy350Z8dzh2pYrp16qrELMWcfk3B55uN3R34k45HazpP0+CMyn1pccHLUkxeaTKqagM2S0kMvMg X-Received: by 2002:a17:90b:3b47:b0:23f:a4da:1208 with SMTP id ot7-20020a17090b3b4700b0023fa4da1208mr2402960pjb.39.1680956043673; Sat, 08 Apr 2023 05:14:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680956043; cv=none; d=google.com; s=arc-20160816; b=pm83VIOX/rIHY0baFy8lhFIl/CAzIgGEkMfkpDlFPXxpdmij4rT0U8KTwLDfb3ybiW VlMKgZk2GtPRxxZEq727hoR4+0ZLrt9J9h4tnYyh3T9kHqdzhtI8rv9vwmWCJCHIPRm6 j1WG75tDOmVMPppU6enxoh2Mc/3kW4smAHZHrP0Hn+LYV9tQMmwjGENCL3oLbzmWcO/W RGElbPyABeBenC4Fc7lSMzM4ko++QRRLq1+SmWQYIKxmXo8qhzBCmAp/rDTf823QWifV q9/lfish4TfFMPXDi7igtN6ZOCZnFTguOE/LPQqWD2BhxT7y3uSOXHLxNOyhypK0ZnVE ZXHQ== 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=MIvS60g+N7evk2zc658kkSPiJ+/wC4UJjKm/8zr3l5w=; b=m9tp7D5EADLn+51VoXpYEjexyy/IqmTIkeuq6y+fvfeQ0Fzfg/XPTrSaHKYZxCqN7d al3ZrkTR3/MJuvzmprFvNlRA5iGE4NZepJdZsociUpIgjXS/MVT6clnTqe/OfKRoe234 EkBqE44cD4wTGEmo+u6jiJhUcpYinwPKGlSxwHljBG+Fug5IRRYMfykDR39jYcT/KOjB 5e/3Oe4ZT4W4HXuAwZ/iYb6pyE4ij521x4+L2q4xvnUlztHHt198plkUcSLwJEbLgSX/ e0WaCji3RsewsoM17ZBS79TdwvY6E8M/W/DQWJ3PGNLlCZKi+A2+yLyXnPgnIMqSWRAH onCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b=oV71UjeB; 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 ez7-20020a17090ae14700b0024681cc291csi479962pjb.88.2023.04.08.05.13.51; Sat, 08 Apr 2023 05:14:03 -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=oV71UjeB; 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 S230216AbjDHLt0 (ORCPT + 99 others); Sat, 8 Apr 2023 07:49:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230463AbjDHLtX (ORCPT ); Sat, 8 Apr 2023 07:49:23 -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 C23D0EF9C; Sat, 8 Apr 2023 04:49:17 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa3.bahnhof.se (Postfix) with ESMTP id 264763F6DD; Sat, 8 Apr 2023 13:49:16 +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 QCGD13k5_3nC; Sat, 8 Apr 2023 13:49:14 +0200 (CEST) Received: by pio-pvt-msa3.bahnhof.se (Postfix) with ESMTPA id 9F89F3F645; Sat, 8 Apr 2023 13:49:14 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 2EAE295FBB; Sat, 8 Apr 2023 11:49:14 +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 0Y_c_wLMcn1K; Sat, 8 Apr 2023 11:49:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 5204A95FB5; Sat, 8 Apr 2023 11:49:12 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra.dalakolonin.se 5204A95FB5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalakolonin.se; s=D374B428-D0A7-11ED-A657-75977B426508; t=1680954552; bh=MIvS60g+N7evk2zc658kkSPiJ+/wC4UJjKm/8zr3l5w=; h=From:To:Date:Message-Id:MIME-Version; b=oV71UjeBQ7Ms4z3Kyu+C7Qs9pLhUwD5uf2ZyxYDYm6I5N/U0q8xEQP5kr+K4KMvWI /+GyAir1aDnHLB0rJ1vlcQMR2QidmLIMZlIQN24QarDtmwqjDZRtxd/AFglQ6D8OR5 D+aSFPto761ugy5rrNyU2PU+NE9kAAJkEq14EhI4f0hIqlmntUlfKp+EX98ufBgr8w OpPQ74ekrwoJM3IePv1KlYSsvCSdntkI+hWjjAKIWb85vShkC3E1VgDzPblWWrRYIh N/YyRKguYrIbdb/4PloSidOM1hY1DhVe4/0xRmklT9nJnx1yG7TuDsmQClxTafTvVn eMUCB3G0D/5kQ== 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 vhAdopkyiOka; Sat, 8 Apr 2023 11:49:11 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id 3289E95FAF; Sat, 8 Apr 2023 11:49:11 +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, Jonathan Cameron , =?utf-8?q?Signed-off-by_=3A?= =?utf-8?q?_Patrik_Dahlstr=C3=B6m?= Subject: [PATCH v4 2/9] iio: adc: palmas: Take probe fully device managed. Date: Sat, 8 Apr 2023 13:48:18 +0200 Message-Id: <20230408114825.824505-3-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230408114825.824505-1-risca@dalakolonin.se> References: <20230408114825.824505-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?1762610164554791515?= X-GMAIL-MSGID: =?utf-8?q?1762610164554791515?= From: Jonathan Cameron Review of a recent fix highlighted that this driver could be trivially converted to be entirely devm managed. That fix should be applied to resolve the fix in a fashion easy to back port even though this change removes the relevant code. [1] https://patchwork.kernel.org/project/linux-iio/patch/20230313205029.1881745-1-risca@dalakolonin.se/ Signed-off-by: Jonathan Cameron Cc: Signed-off-by: Patrik Dahlström --- drivers/iio/adc/palmas_gpadc.c | 110 +++++++++++++-------------------- 1 file changed, 42 insertions(+), 68 deletions(-) diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index 849a697a467e..2921186458e0 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -493,6 +493,11 @@ static int palmas_gpadc_get_adc_dt_data(struct platform_device *pdev, return 0; } +static void palmas_disable_wakeup(void *dev) +{ + device_wakeup_disable(dev); +} + static int palmas_gpadc_probe(struct platform_device *pdev) { struct palmas_gpadc *adc; @@ -532,36 +537,30 @@ static int palmas_gpadc_probe(struct platform_device *pdev) adc->auto_conversion_period = gpadc_pdata->auto_conversion_period_ms; adc->irq = palmas_irq_get_virq(adc->palmas, PALMAS_GPADC_EOC_SW_IRQ); - if (adc->irq < 0) { - dev_err(adc->dev, - "get virq failed: %d\n", adc->irq); - ret = adc->irq; - goto out; - } - ret = request_threaded_irq(adc->irq, NULL, - palmas_gpadc_irq, - IRQF_ONESHOT, dev_name(adc->dev), - adc); - if (ret < 0) { - dev_err(adc->dev, - "request irq %d failed: %d\n", adc->irq, ret); - goto out; - } + if (adc->irq < 0) + return dev_err_probe(adc->dev, adc->irq, "get virq failed\n"); + + ret = devm_request_threaded_irq(&pdev->dev, adc->irq, NULL, + palmas_gpadc_irq, + IRQF_ONESHOT, dev_name(adc->dev), + adc); + if (ret < 0) + return dev_err_probe(adc->dev, ret, + "request irq %d failed\n", adc->irq); if (gpadc_pdata->adc_wakeup1_data) { memcpy(&adc->wakeup1_data, gpadc_pdata->adc_wakeup1_data, sizeof(adc->wakeup1_data)); adc->wakeup1_enable = true; adc->irq_auto_0 = platform_get_irq(pdev, 1); - ret = request_threaded_irq(adc->irq_auto_0, NULL, - palmas_gpadc_irq_auto, - IRQF_ONESHOT, - "palmas-adc-auto-0", adc); - if (ret < 0) { - dev_err(adc->dev, "request auto0 irq %d failed: %d\n", - adc->irq_auto_0, ret); - goto out_irq_free; - } + ret = devm_request_threaded_irq(&pdev->dev, adc->irq_auto_0, + NULL, palmas_gpadc_irq_auto, + IRQF_ONESHOT, + "palmas-adc-auto-0", adc); + if (ret < 0) + return dev_err_probe(adc->dev, ret, + "request auto0 irq %d failed\n", + adc->irq_auto_0); } if (gpadc_pdata->adc_wakeup2_data) { @@ -569,15 +568,14 @@ static int palmas_gpadc_probe(struct platform_device *pdev) sizeof(adc->wakeup2_data)); adc->wakeup2_enable = true; adc->irq_auto_1 = platform_get_irq(pdev, 2); - ret = request_threaded_irq(adc->irq_auto_1, NULL, - palmas_gpadc_irq_auto, - IRQF_ONESHOT, - "palmas-adc-auto-1", adc); - if (ret < 0) { - dev_err(adc->dev, "request auto1 irq %d failed: %d\n", - adc->irq_auto_1, ret); - goto out_irq_auto0_free; - } + ret = devm_request_threaded_irq(&pdev->dev, adc->irq_auto_1, + NULL, palmas_gpadc_irq_auto, + IRQF_ONESHOT, + "palmas-adc-auto-1", adc); + if (ret < 0) + return dev_err_probe(adc->dev, ret, + "request auto1 irq %d failed\n", + adc->irq_auto_1); } /* set the current source 0 (value 0/5/15/20 uA => 0..3) */ @@ -608,11 +606,10 @@ static int palmas_gpadc_probe(struct platform_device *pdev) indio_dev->channels = palmas_gpadc_iio_channel; indio_dev->num_channels = ARRAY_SIZE(palmas_gpadc_iio_channel); - ret = iio_device_register(indio_dev); - if (ret < 0) { - dev_err(adc->dev, "iio_device_register() failed: %d\n", ret); - goto out_irq_auto1_free; - } + ret = devm_iio_device_register(&pdev->dev, indio_dev); + if (ret < 0) + return dev_err_probe(adc->dev, ret, + "iio_device_register() failed\n"); device_set_wakeup_capable(&pdev->dev, 1); for (i = 0; i < PALMAS_ADC_CH_MAX; i++) { @@ -620,36 +617,14 @@ static int palmas_gpadc_probe(struct platform_device *pdev) palmas_gpadc_calibrate(adc, i); } - if (adc->wakeup1_enable || adc->wakeup2_enable) + if (adc->wakeup1_enable || adc->wakeup2_enable) { device_wakeup_enable(&pdev->dev); - - return 0; - -out_irq_auto1_free: - if (gpadc_pdata->adc_wakeup2_data) - free_irq(adc->irq_auto_1, adc); -out_irq_auto0_free: - if (gpadc_pdata->adc_wakeup1_data) - free_irq(adc->irq_auto_0, adc); -out_irq_free: - free_irq(adc->irq, adc); -out: - return ret; -} - -static int palmas_gpadc_remove(struct platform_device *pdev) -{ - struct iio_dev *indio_dev = dev_get_drvdata(&pdev->dev); - struct palmas_gpadc *adc = iio_priv(indio_dev); - - if (adc->wakeup1_enable || adc->wakeup2_enable) - device_wakeup_disable(&pdev->dev); - iio_device_unregister(indio_dev); - free_irq(adc->irq, adc); - if (adc->wakeup1_enable) - free_irq(adc->irq_auto_0, adc); - if (adc->wakeup2_enable) - free_irq(adc->irq_auto_1, adc); + ret = devm_add_action_or_reset(&pdev->dev, + palmas_disable_wakeup, + &pdev->dev); + if (ret) + return ret; + } return 0; } @@ -834,7 +809,6 @@ MODULE_DEVICE_TABLE(of, of_palmas_gpadc_match_tbl); static struct platform_driver palmas_gpadc_driver = { .probe = palmas_gpadc_probe, - .remove = palmas_gpadc_remove, .driver = { .name = MOD_NAME, .pm = pm_sleep_ptr(&palmas_pm_ops), From patchwork Sat Apr 8 11:48:19 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: 81176 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp840479vqo; Sat, 8 Apr 2023 05:19:52 -0700 (PDT) X-Google-Smtp-Source: AKy350bsPDSlQFj3iSaD7SFb9vgCoj9zj9kK8Ug1Fds+RkZJYWQgGZW7iSsvyOH8hoq/ObWwsVer X-Received: by 2002:a17:90b:384d:b0:23d:29c7:916f with SMTP id nl13-20020a17090b384d00b0023d29c7916fmr5899477pjb.32.1680956392292; Sat, 08 Apr 2023 05:19:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680956392; cv=none; d=google.com; s=arc-20160816; b=G10olFtLoV+4+ZYPo/Lm+Jjc5trvcu6UjIDSvWenDbGho3l7bq3swJTWppBD/F7Jh9 ZmOjJMe7pQYDsaR4MCBlzxQ0pwoCF7r1YBrJpc2ffgmjJJlzee2ZcpA0kpCML/3UyzIg DJnIe2bby2NbasBgLCEMbHwja5eMYxDlVm9dRA4h1T8ONsgVjkEWBLDw7j5Lk5oikbaC mmzaUe9yEgdMT4WgYaFY75/i0j5MFO0VbonSowk7Z5LH9TCMRzOED6PIbn8HM9BQw5D6 DrTsBvPoqvQJHY/bvp1yTxOQ3JeauRN+81EOh0E9l6vUMXt4cW39S6k1BF3xQWjwg8Bl /8cw== 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=QpAkz8NzyhCd80cX7C/EMbSMfNw/jsM+n+BufT6T6ZU=; b=U4ejgWs/jpWYLV3FKnjfBwykIiOjztqHnczZ314UoYVgmKaSQHZguAk2racOEh5k1S C+GPa1n6lXDl0aFf8lGsQF3hu0F24Q4JQqojohhSCr7TcRZimqSu+CJNQ3tjcEhPbdEr z+Sd7Y25dfyuU5+j6ayJUK+ZdbE1Tlj0EW0D6kdqfssAyeRjdC4HfWcgJsZ5AsrTtl7P V8DMntDeKqXUyzSBqu67Cu0/Mg2BJKPJV5R9jZliqzMvEjcmV2zva+0rNy5OLnVgUPz1 rdi81J3NdIGbrHhDeczBcgOW/WJ37n4oowsgLc2Wgi9COzVabWE5hWgHMQ0feS4i05cP sY9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b=cxyyknrj; 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 q18-20020a17090ad39200b0024046d91263si8262210pju.51.2023.04.08.05.19.40; Sat, 08 Apr 2023 05:19:52 -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=cxyyknrj; 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 S230469AbjDHLtj (ORCPT + 99 others); Sat, 8 Apr 2023 07:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230463AbjDHLtc (ORCPT ); Sat, 8 Apr 2023 07:49:32 -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 E662110243; Sat, 8 Apr 2023 04:49:19 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa3.bahnhof.se (Postfix) with ESMTP id 814D03F703; Sat, 8 Apr 2023 13:49:18 +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 9PCjORLLcL0a; Sat, 8 Apr 2023 13:49:17 +0200 (CEST) Received: by pio-pvt-msa3.bahnhof.se (Postfix) with ESMTPA id 8C4FB3F645; Sat, 8 Apr 2023 13:49:17 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 4EACC95FCB; Sat, 8 Apr 2023 11:49:17 +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 z3kSxSC3AhDS; Sat, 8 Apr 2023 11:49:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 0CCCA95FC0; Sat, 8 Apr 2023 11:49:16 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra.dalakolonin.se 0CCCA95FC0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalakolonin.se; s=D374B428-D0A7-11ED-A657-75977B426508; t=1680954556; bh=QpAkz8NzyhCd80cX7C/EMbSMfNw/jsM+n+BufT6T6ZU=; h=From:To:Date:Message-Id:MIME-Version; b=cxyyknrj95FW92fCs3jDBc55NbqQHb6Q7TvXf5q1uc6dKelPPIyiOdVG/RggWhv2M bQgZKWI2tdl5Yk0ZkyaBbhp06H+6xDGqR0wE++7U7izx0GA8R6+5zkQGJS5TggFt2u g7neprvTyl7pG0NU/xglgHtHflaOojp78hJ6BgwJlBaa/UpdblQxn1KDt2K3sJ74Cs jilJ+KehzIdDZl+Rtl6h7WxCMWNus1Sa0TTb0FSpRSRYt3apTIRG2by/7GpQ2Kicic 3ID/dJENyp1cx1hEi9wp738eqWRRDAkDffIo9UrDQgthVr9h9WSRrTxtizZAYgzYs1 v0HWCGnqjV/9g== 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 KsIYKCglIhS7; Sat, 8 Apr 2023 11:49:15 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id D489895FBD; Sat, 8 Apr 2023 11:49:15 +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 v4 3/9] iio: adc: palmas: remove adc_wakeupX_data Date: Sat, 8 Apr 2023 13:48:19 +0200 Message-Id: <20230408114825.824505-4-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230408114825.824505-1-risca@dalakolonin.se> References: <20230408114825.824505-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?1762610530166821338?= X-GMAIL-MSGID: =?utf-8?q?1762610530166821338?= It does not seem to be used by anyone and later patches in this series are made simpler by first removing this. There is now a lot of dead code that cannot be reached, until later patches revive it. Arguably, this is preferred over removing the code only to add it again. Signed-off-by: Patrik Dahlström --- drivers/iio/adc/palmas_gpadc.c | 50 ++++------------------------------ include/linux/mfd/palmas.h | 8 ------ 2 files changed, 6 insertions(+), 52 deletions(-) diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index 2921186458e0..03af6cd73ec8 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -76,6 +76,12 @@ static struct palmas_gpadc_info palmas_gpadc_info[] = { PALMAS_ADC_INFO(IN15, 0, 0, 0, 0, INVALID, INVALID, true), }; +struct palmas_adc_wakeup_property { + int adc_channel_number; + int adc_high_threshold; + int adc_low_threshold; +}; + /* * struct palmas_gpadc - the palmas_gpadc structure * @ch0_current: channel 0 current source setting @@ -493,11 +499,6 @@ static int palmas_gpadc_get_adc_dt_data(struct platform_device *pdev, return 0; } -static void palmas_disable_wakeup(void *dev) -{ - device_wakeup_disable(dev); -} - static int palmas_gpadc_probe(struct platform_device *pdev) { struct palmas_gpadc *adc; @@ -548,36 +549,6 @@ static int palmas_gpadc_probe(struct platform_device *pdev) return dev_err_probe(adc->dev, ret, "request irq %d failed\n", adc->irq); - if (gpadc_pdata->adc_wakeup1_data) { - memcpy(&adc->wakeup1_data, gpadc_pdata->adc_wakeup1_data, - sizeof(adc->wakeup1_data)); - adc->wakeup1_enable = true; - adc->irq_auto_0 = platform_get_irq(pdev, 1); - ret = devm_request_threaded_irq(&pdev->dev, adc->irq_auto_0, - NULL, palmas_gpadc_irq_auto, - IRQF_ONESHOT, - "palmas-adc-auto-0", adc); - if (ret < 0) - return dev_err_probe(adc->dev, ret, - "request auto0 irq %d failed\n", - adc->irq_auto_0); - } - - if (gpadc_pdata->adc_wakeup2_data) { - memcpy(&adc->wakeup2_data, gpadc_pdata->adc_wakeup2_data, - sizeof(adc->wakeup2_data)); - adc->wakeup2_enable = true; - adc->irq_auto_1 = platform_get_irq(pdev, 2); - ret = devm_request_threaded_irq(&pdev->dev, adc->irq_auto_1, - NULL, palmas_gpadc_irq_auto, - IRQF_ONESHOT, - "palmas-adc-auto-1", adc); - if (ret < 0) - return dev_err_probe(adc->dev, ret, - "request auto1 irq %d failed\n", - adc->irq_auto_1); - } - /* set the current source 0 (value 0/5/15/20 uA => 0..3) */ if (gpadc_pdata->ch0_current <= 1) adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_0; @@ -617,15 +588,6 @@ static int palmas_gpadc_probe(struct platform_device *pdev) palmas_gpadc_calibrate(adc, i); } - if (adc->wakeup1_enable || adc->wakeup2_enable) { - device_wakeup_enable(&pdev->dev); - ret = devm_add_action_or_reset(&pdev->dev, - palmas_disable_wakeup, - &pdev->dev); - if (ret) - return ret; - } - return 0; } diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h index 117d02708439..eda1ffd99c1a 100644 --- a/include/linux/mfd/palmas.h +++ b/include/linux/mfd/palmas.h @@ -128,12 +128,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 */ @@ -152,8 +146,6 @@ struct palmas_gpadc_platform_data { int start_polarity; int auto_conversion_period_ms; - struct palmas_adc_wakeup_property *adc_wakeup1_data; - struct palmas_adc_wakeup_property *adc_wakeup2_data; }; struct palmas_reg_init { From patchwork Sat Apr 8 11:48: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: 81165 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp825924vqo; Sat, 8 Apr 2023 04:51:18 -0700 (PDT) X-Google-Smtp-Source: AKy350azHym0DwOY4NEpgNEgMm2Y1gn9rAXptBvfOJrtE3w7k4SVPdKyGxXbJ//RSKTJpW3pt+6P X-Received: by 2002:a17:906:c085:b0:949:7c05:71b6 with SMTP id f5-20020a170906c08500b009497c0571b6mr2386881ejz.44.1680954678061; Sat, 08 Apr 2023 04:51:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680954678; cv=none; d=google.com; s=arc-20160816; b=Hk0T+A/kDVIJQq+r54hvjtIQlT5z6Y3DlpwRyGHrnouMXnyr0UFRCp8z6YlSL3RHNb wQ0JDeMmwgl6IAUwWlJ6NKgBtGcnDcLs4nWkg3vdYnm6QOdN+SFdHgaGXzw+4iKJiXnC ail3Liu0b6NnWG8DPo1iDiVbV6ceNxgZIBybUGa076cAt7wyR8/q4tjq9H5J/pEWh4+6 rX7gOQdnobvB+CdWcA/A3vQhaFOhVin3CayKGtCTLCT3PehwYSvBzWOpHMjVo3Y1tE9g NoBYYhKwTUW2pMUYYyyuBC5oKcHdqH4BE3Kwddpj8c/3JfhLWgluMjXkkYapIQTmKXWY dXHQ== 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=WEa42btgt5YoGy4wRFO15STm/DxrasoQ4xEIrCOV4as=; b=TIkEJ+X9jjlX75iUaR8Ysugi4faFbwK9n1qwpaH8EZuc41eI0eaEO6WzDp3cAi4OBG OYvc45OK6s+paHm0Zt6pZi5T9srvRXZT9+HQqve5HAAfw+5eTbpS4YQV0sOOlTZ9fUcW Y5oDvjqEhfeOqaL8BZjaUEmiFPegQ90ZMa8YZDL30psZUSo9GXQ9jOD085f8+7HrO0TS h5D1lTguJafb7pDvlxdJCVrTs2cVl42vY6w2BJB3bV1dB8yLC5tmHA6PBGthpbK5dPNm lgDdj1NfBEu4/+0aTXq2tpE41LxaNgkLxPHkdtksBT2OovZUoxDVOS4ntpgk/BPIqhG9 8n2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b=TKmdjN4v; 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 n22-20020a1709061d1600b00939c395018esi4828489ejh.474.2023.04.08.04.50.53; Sat, 08 Apr 2023 04:51:18 -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=TKmdjN4v; 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 S231139AbjDHLts (ORCPT + 99 others); Sat, 8 Apr 2023 07:49:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230484AbjDHLtj (ORCPT ); Sat, 8 Apr 2023 07:49:39 -0400 Received: from ste-pvt-msa2.bahnhof.se (ste-pvt-msa2.bahnhof.se [213.80.101.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C5C1E04A; Sat, 8 Apr 2023 04:49:25 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTP id C47EC3FF56; Sat, 8 Apr 2023 13:49:23 +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.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Authentication-Results: ste-ftg-msa2.bahnhof.se (amavisd-new); dkim=pass (2048-bit key) header.d=dalakolonin.se Received: from ste-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (ste-ftg-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N1OTarnPJooQ; Sat, 8 Apr 2023 13:49:22 +0200 (CEST) Received: by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id BC6853FF15; Sat, 8 Apr 2023 13:49:22 +0200 (CEST) Authentication-Results: ste-pvt-msa2.bahnhof.se; dkim=pass (2048-bit key; unprotected) header.d=dalakolonin.se header.i=@dalakolonin.se header.b="TKmdjN4v"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 9711E95FD6; Sat, 8 Apr 2023 11:49:22 +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 BFSjQLZm2sym; Sat, 8 Apr 2023 11:49:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 2DBBB95FD2; Sat, 8 Apr 2023 11:49:21 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra.dalakolonin.se 2DBBB95FD2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalakolonin.se; s=D374B428-D0A7-11ED-A657-75977B426508; t=1680954561; bh=WEa42btgt5YoGy4wRFO15STm/DxrasoQ4xEIrCOV4as=; h=From:To:Date:Message-Id:MIME-Version; b=TKmdjN4vkt1ewu/qAkt4lJOUICYuBsbiK/7RkUjLvKCswsGN5NwL/gO73TjEMedGz H8hI3sOmqsfUhg+oB2JCSvMkbmmGJdxKXuNXL57HxxDGMIosVaMUzF1Bax97pbKcTC QvXNXpMC2NUn/Ry7sk0mZIfKg127OXYMpnT3sAY7SUNDez6eMmc7BktfTg9LklOnPT 9lkxWHP16fbzqHMIoqz9kS44o7v3UpYd63xzKzBQdzSGVCEWXDehEzREYRnN0jcgdM ORAV2e9d3vaewgFYH51bvWBNTb7NAYyA5WDFNuXDWnzHyvzaraFLK/fZZVOwRccrfu 23BZCGP26SGMQ== 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 21EgUHyuaVpE; Sat, 8 Apr 2023 11:49:21 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id 0196895FCF; Sat, 8 Apr 2023 11:49: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, linux-omap@vger.kernel.org, =?utf-8?q?Pa?= =?utf-8?q?trik_Dahlstr=C3=B6m?= Subject: [PATCH v4 4/9] iio: adc: palmas: replace "wakeup" with "event" Date: Sat, 8 Apr 2023 13:48:20 +0200 Message-Id: <20230408114825.824505-5-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230408114825.824505-1-risca@dalakolonin.se> References: <20230408114825.824505-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?1762608732359452791?= X-GMAIL-MSGID: =?utf-8?q?1762608732359452791?= The palmas gpadc block has support for monitoring up to 2 ADC channels and issue an interrupt if they reach past a set threshold. This is currently used to wake up the system from sleep, but the functionality is more generic than that. As such, change the naming of functions and variables to refer to it as events instead, except during suspend and resume where wakeup still make sense. Signed-off-by: Patrik Dahlström --- drivers/iio/adc/palmas_gpadc.c | 50 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index 03af6cd73ec8..55fdf59ef711 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -76,7 +76,7 @@ static struct palmas_gpadc_info palmas_gpadc_info[] = { PALMAS_ADC_INFO(IN15, 0, 0, 0, 0, INVALID, INVALID, true), }; -struct palmas_adc_wakeup_property { +struct palmas_adc_event { int adc_channel_number; int adc_high_threshold; int adc_low_threshold; @@ -117,10 +117,10 @@ 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; + struct palmas_adc_event event0; + struct palmas_adc_event event1; + bool event0_enable; + bool event1_enable; int auto_conversion_period; struct mutex lock; }; @@ -591,7 +591,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_configure_events(struct palmas_gpadc *adc) { int adc_period, conv; int i; @@ -617,16 +617,16 @@ static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc) } conv = 0; - if (adc->wakeup1_enable) { + if (adc->event0_enable) { int polarity; - ch0 = adc->wakeup1_data.adc_channel_number; + ch0 = adc->event0.adc_channel_number; conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV0_EN; - if (adc->wakeup1_data.adc_high_threshold > 0) { - thres = adc->wakeup1_data.adc_high_threshold; + if (adc->event0.adc_high_threshold > 0) { + thres = adc->event0.adc_high_threshold; polarity = 0; } else { - thres = adc->wakeup1_data.adc_low_threshold; + thres = adc->event0.adc_low_threshold; polarity = PALMAS_GPADC_THRES_CONV0_MSB_THRES_CONV0_POL; } @@ -648,16 +648,16 @@ static int palmas_adc_wakeup_configure(struct palmas_gpadc *adc) } } - if (adc->wakeup2_enable) { + if (adc->event1_enable) { int polarity; - ch1 = adc->wakeup2_data.adc_channel_number; + ch1 = adc->event1.adc_channel_number; conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV1_EN; - if (adc->wakeup2_data.adc_high_threshold > 0) { - thres = adc->wakeup2_data.adc_high_threshold; + if (adc->event1.adc_high_threshold > 0) { + thres = adc->event1.adc_high_threshold; polarity = 0; } else { - thres = adc->wakeup2_data.adc_low_threshold; + thres = adc->event1.adc_low_threshold; polarity = PALMAS_GPADC_THRES_CONV1_MSB_THRES_CONV1_POL; } @@ -696,7 +696,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_reset_events(struct palmas_gpadc *adc) { int ret; @@ -718,20 +718,20 @@ 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 wakeup = adc->wakeup1_enable || adc->wakeup2_enable; + int wakeup = adc->event0_enable || adc->event1_enable; int ret; if (!device_may_wakeup(dev) || !wakeup) return 0; - ret = palmas_adc_wakeup_configure(adc); + ret = palmas_adc_configure_events(adc); if (ret < 0) return ret; - 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; @@ -741,20 +741,20 @@ 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 wakeup = adc->wakeup1_enable || adc->wakeup2_enable; + int wakeup = adc->event0_enable || adc->event1_enable; int ret; if (!device_may_wakeup(dev) || !wakeup) return 0; - ret = palmas_adc_wakeup_reset(adc); + ret = palmas_adc_reset_events(adc); if (ret < 0) return ret; - 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; From patchwork Sat Apr 8 11:48:21 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: 81171 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp838687vqo; Sat, 8 Apr 2023 05:16:09 -0700 (PDT) X-Google-Smtp-Source: AKy350ZnKk7lWBTUUmLx1Ok0evFz2v7HKwPvuMmquCDy1NiyTMWL48M1dYJee0M9LBm+qtxv67U2 X-Received: by 2002:a62:5e41:0:b0:626:2ae6:31f6 with SMTP id s62-20020a625e41000000b006262ae631f6mr5894800pfb.7.1680956169488; Sat, 08 Apr 2023 05:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680956169; cv=none; d=google.com; s=arc-20160816; b=WwuQByRF7kv8ZXJnn+Xuu7W76aIx0jFqdq7LIXBsArI2eFD9BXcGnIeD1lKZQkFcwI bJmN+xqtp0Ltbf01SNvJuiF6wV7pmhvZEq/5CfcjTVyx6C/L4W5ypi4VR12yDtwsAgzz CCy50pT/suWKvrmCJ8x94bt8sgwX//0+meM11HAEL2uYvEFCTOdF1Gy3Kq09JoIqZN5/ oDD/f7j12GNWYHnFk4qtsHF94/ZwmYHwGrT6odHXhlqprq2j4ovRtU3/jaBBsSLwSbms MwVRKeblpCbygfngWEHg0lloZbT903e+fXHXG7O1LA22hKvzJhdgJFkD9W2qQZYCGSyy zFdg== 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=1KXqS6uPQfbvE2zn8Vvi97+Iuqb+bXr9hi9vBHy3yN5TFYYOeaXMiCnFugLx77HF6P NaAaH8IrONcYe38jTsIvqVKLh7BsfPeNaEhMxB3Gra1vuntaquZRfG8Z7xK7By1UusJo XovGhK8IGrVQAcjo3hDvx3Mq2XnbjidSgDaRct49QE1GeTbzobZiIoHzMrE7kCGmB95x lkqVbo6FLMhhocesbVSC7ECBwSdbgH+CWb0AkeYViXzEGTpZp7+lcNUm7H1NSCR24g/r CfnN0C9O9lwH3OxS33zOGIB1O4UaTw1dFd7DquUQvIeoXgZYRsCRETgNDLy5oQJE6vF9 KLVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b=WprrFeiQ; 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 y10-20020aa793ca000000b0062d7d3c6cc8si5899299pff.375.2023.04.08.05.15.54; Sat, 08 Apr 2023 05:16:09 -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=WprrFeiQ; 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 S230525AbjDHLuI (ORCPT + 99 others); Sat, 8 Apr 2023 07:50:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230492AbjDHLt7 (ORCPT ); Sat, 8 Apr 2023 07:49:59 -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 E9ED3D53C; Sat, 8 Apr 2023 04:49:38 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa1.bahnhof.se (Postfix) with ESMTP id 5C4E43F586; Sat, 8 Apr 2023 13:49:37 +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.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Authentication-Results: pio-pvt-msa1.bahnhof.se (amavisd-new); dkim=pass (2048-bit key) header.d=dalakolonin.se 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 3s1CL0GkR64w; Sat, 8 Apr 2023 13:49:36 +0200 (CEST) Received: by pio-pvt-msa1.bahnhof.se (Postfix) with ESMTPA id 8E9283F3E8; Sat, 8 Apr 2023 13:49:36 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 2DE6A95FF6; Sat, 8 Apr 2023 11:49:36 +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 FW_byLenNJss; Sat, 8 Apr 2023 11:49:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 2DD7495FF1; Sat, 8 Apr 2023 11:49:34 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra.dalakolonin.se 2DD7495FF1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalakolonin.se; s=D374B428-D0A7-11ED-A657-75977B426508; t=1680954574; bh=8oCsKoWj+OT4dqdz4wKUl0ESprUGM0ZozVBAf1AeyA0=; h=From:To:Date:Message-Id:MIME-Version; b=WprrFeiQXvda/qT4FLUi29yq9bAiy1/ukHbOt5F4PHe88Fd1aoCXUM/Ps7043ehdh DvcMefgaoO3iJ3zi5w8ihvDfgzZ7ddpqNJAbVFQoSDGo7nYNb2yk9Oo59kd8prl9aA WFVMr1CBug41FEBmv8xUV+jGEnJsQqfzPoe5GmdA5D2ZJL3ZT0x7U/DvJqYns8e1oF JDiM5BAl/l91ESmxgW+EerHs1l675SL38O7fwgzi+dXzRCYsLshvto6yhykmnFpvk1 c8DeQjZxxMVIN0+xT26p/9g7NnEhITDAdWrGErY6bTGeK64XClVLyUgDRcV9nPnGFk kHXBXa+iZC9pg== 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 TScB6t6Lrm2a; Sat, 8 Apr 2023 11:49:34 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id C50E295FEE; Sat, 8 Apr 2023 11:49:33 +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 v4 5/9] iio: adc: palmas: use iio_event_direction for threshold polarity Date: Sat, 8 Apr 2023 13:48:21 +0200 Message-Id: <20230408114825.824505-6-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230408114825.824505-1-risca@dalakolonin.se> References: <20230408114825.824505-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?1762610296410409394?= X-GMAIL-MSGID: =?utf-8?q?1762610296410409394?= 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, From patchwork Sat Apr 8 11:48:22 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: 81174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp839839vqo; Sat, 8 Apr 2023 05:18:30 -0700 (PDT) X-Google-Smtp-Source: AKy350ZrqtZ4CZekSQtEBxofaHm2dO+Df+d5YM6MDvPSF+9jsQqLwfet0q+6I1f28u47Hs/zE0g/ X-Received: by 2002:a17:902:e84f:b0:1a1:953b:9559 with SMTP id t15-20020a170902e84f00b001a1953b9559mr8305665plg.3.1680956310579; Sat, 08 Apr 2023 05:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680956310; cv=none; d=google.com; s=arc-20160816; b=l+WSykuTgQlskU292vSQzWD1mhbLzS5d2mTpgJ52q1ze5qTqzMayEr9hR3maPKjkKh k3hfoHPjp88MBbn/O1K0yUa7uV8UOZJeVOnf90AhRZL5cofCgbRYBOo2J2x7uoNhJY4P ulMfO7WgAXCAru/PTeTMr5aFz/DETbT+r0xim0m+3yMkEIOcNMCc4ZbGactLrwYldE5/ SEJ/nQD7Ti28hcEEyCugiF4IvgJTE8ugHdrYyZfXT+EedTlRnxNQxAh7q/B+AsQVeGvn h37zVEQU0pU2k7qq0SzmnrJH1Bf9+8INocVMZKeh1AbHrmkZCPsndHinpqDZThBNEnr0 PAXA== 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=TmuWTPcVR6kjhWZxrkfB1qR/xKdRysUauxZUpzZtF7k=; b=SR5eqXrMwR0FIKf92o4YQ1UgRhj9ivqDRd8fcLm8UeWjUScvRSLzNgiwQVmJxXRPOn EBmQ23ipW9Dae5ZAHbwdw+roccz6bYoJRhVbV4R6+43F9Qk/HxBk+OPQ3A5nSbTt4sdh +vj+projuFPjMzgwqEPo812qMKFNwO7Unsl/mSGajh7vP3jHa5pPM3sfdHzgUd31Ni1X JaEPCUteWM9eyq92rGA3b9Eku0V439JEitZLAMoKegOa9eRtW3B1yu56A/wnOCLVPt4d FjT/hHx0F91hA30xCsC1r3IjuiKvstLjvRNEYv+tZWdK13BcBblxOWKVPBBFyFCz3uIj epbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b="cOZ/90wz"; 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 d6-20020a170903230600b0019e9e57f92esi6577622plh.571.2023.04.08.05.18.17; Sat, 08 Apr 2023 05:18:30 -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="cOZ/90wz"; 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 S230484AbjDHLuL (ORCPT + 99 others); Sat, 8 Apr 2023 07:50:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231144AbjDHLuF (ORCPT ); Sat, 8 Apr 2023 07:50:05 -0400 Received: from ste-pvt-msa1.bahnhof.se (ste-pvt-msa1.bahnhof.se [213.80.101.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60137D530; Sat, 8 Apr 2023 04:49:45 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTP id 1EA213FB0D; Sat, 8 Apr 2023 13:49:44 +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.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Authentication-Results: ste-pvt-msa1.bahnhof.se (amavisd-new); dkim=pass (2048-bit key) header.d=dalakolonin.se Received: from ste-pvt-msa1.bahnhof.se ([127.0.0.1]) by localhost (ste-pvt-msa1.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id idWU9n_NZ-g1; Sat, 8 Apr 2023 13:49:43 +0200 (CEST) Received: by ste-pvt-msa1.bahnhof.se (Postfix) with ESMTPA id 39CF13F303; Sat, 8 Apr 2023 13:49:43 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 90B699600D; Sat, 8 Apr 2023 11:49:42 +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 w7sA9IdZ3AdJ; Sat, 8 Apr 2023 11:49:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 32BBC95FFB; Sat, 8 Apr 2023 11:49:39 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra.dalakolonin.se 32BBC95FFB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalakolonin.se; s=D374B428-D0A7-11ED-A657-75977B426508; t=1680954579; bh=TmuWTPcVR6kjhWZxrkfB1qR/xKdRysUauxZUpzZtF7k=; h=From:To:Date:Message-Id:MIME-Version; b=cOZ/90wzYhMz8Ttzcn7Nh1k2vh28gBqbF7Ss6XABkvuZslgwuImItTzOVoHgzJmt5 /AUaFreU2PAuM8cg96R/WDwupKk3biDWJaI3+r89pJo/rTv6l4qw6j1CHUE1O+Iggr ouLCVRd6UP+waSVUmMf+6IDHljlL3TJcrF7Q5JlbZKQw1R09ShrOUyfrzguymf1FYV iue/RAt2buRBtROPRnqhR1jRb7X85tae9LM+nls3V/OwSiYSLyuvY9GDOpLLWugC55 Fpm354/35vyrLw3NgMipRzrK5wUyEf/IAG7RHXjSVeKecCNDU9Hjys8r7XQ1mHFY1t wVMTbx0GhTO/A== 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 ZoWYMzudRtI8; Sat, 8 Apr 2023 11:49:39 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id 6767895FF8; Sat, 8 Apr 2023 11:49:38 +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 v4 6/9] iio: adc: palmas: move eventX_enable into palmas_adc_event Date: Sat, 8 Apr 2023 13:48:22 +0200 Message-Id: <20230408114825.824505-7-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230408114825.824505-1-risca@dalakolonin.se> References: <20230408114825.824505-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?1762610444548656291?= X-GMAIL-MSGID: =?utf-8?q?1762610444548656291?= It just makes more sense to have all information regarding adc events in one place. Signed-off-by: Patrik Dahlström --- drivers/iio/adc/palmas_gpadc.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index 205a7628b235..8c6ea4a3cd2e 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -77,6 +77,7 @@ static struct palmas_gpadc_info palmas_gpadc_info[] = { }; struct palmas_adc_event { + bool enabled; int channel; int raw_thresh; enum iio_event_direction direction; @@ -119,8 +120,6 @@ struct palmas_gpadc { struct completion conv_completion; struct palmas_adc_event event0; struct palmas_adc_event event1; - bool event0_enable; - bool event1_enable; int auto_conversion_period; struct mutex lock; }; @@ -617,7 +616,7 @@ static int palmas_adc_configure_events(struct palmas_gpadc *adc) } conv = 0; - if (adc->event0_enable) { + if (adc->event0.enabled) { struct palmas_adc_event *ev = &adc->event0; int polarity; @@ -653,7 +652,7 @@ static int palmas_adc_configure_events(struct palmas_gpadc *adc) } } - if (adc->event1_enable) { + if (adc->event1.enabled) { struct palmas_adc_event *ev = &adc->event1; int polarity; @@ -728,7 +727,7 @@ 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 wakeup = adc->event0_enable || adc->event1_enable; + int wakeup = adc->event0.enabled || adc->event1.enabled; int ret; if (!device_may_wakeup(dev) || !wakeup) @@ -738,10 +737,10 @@ static int palmas_gpadc_suspend(struct device *dev) if (ret < 0) return ret; - if (adc->event0_enable) + if (adc->event0.enabled) enable_irq_wake(adc->irq_auto_0); - if (adc->event1_enable) + if (adc->event1.enabled) enable_irq_wake(adc->irq_auto_1); return 0; @@ -751,7 +750,7 @@ 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 wakeup = adc->event0_enable || adc->event1_enable; + int wakeup = adc->event0.enabled || adc->event1.enabled; int ret; if (!device_may_wakeup(dev) || !wakeup) @@ -761,10 +760,10 @@ static int palmas_gpadc_resume(struct device *dev) if (ret < 0) return ret; - if (adc->event0_enable) + if (adc->event0.enabled) disable_irq_wake(adc->irq_auto_0); - if (adc->event1_enable) + if (adc->event1.enabled) disable_irq_wake(adc->irq_auto_1); return 0; From patchwork Sat Apr 8 11:48:23 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: 81166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp829816vqo; Sat, 8 Apr 2023 05:01:17 -0700 (PDT) X-Google-Smtp-Source: AKy350aWEcscnonUx7PCflVe54NmqaxCMdTf+RwUsyuzAVtAk80Y4FEyLZXbq1WGV5IaYhP+nHhj X-Received: by 2002:a05:6a20:2da:b0:df:5e73:d78a with SMTP id 26-20020a056a2002da00b000df5e73d78amr4824107pzb.49.1680955277042; Sat, 08 Apr 2023 05:01:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680955277; cv=none; d=google.com; s=arc-20160816; b=fT7MPV5fHizgG+uobpEPL2jKC78oDxb1fwQVYVjXk1w53sq/+DD4R18k6suAYrpWMX ANQb7rEYO35bREwvf+m5HEvxnwM6A4VD11O31NfbdV7ZIYbr8NlN0El7OxMadUuIDnL6 qk3VHTs2qRfYg8xXs8nOA7leL3Hl9mxQSxjT1ommqGU55NbWmj3BiULO8fYke6tXJS5Y E0nGcEnZADbnFZB4a+2oPNUjJ7eoc4ahbvHoZiZxloMVULJjZZKzTBJWk8c7QZUCAAGb P93QnGP5TTV55H9fy89QC9i8ftHcCq9cC2kE2pBlquKY5MMm/in7xhDNiQMCCXHn5LQu V+6w== 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=46bAIQhprw5uAV/CIe/YRgQOYjSd553x4RWwfAtfJJI=; b=Waos5AkSlbGQoRdloIqt1fIy5oBmMF6PFYtOUyyffr/XhAA1ZzY7ZmSNqtWCuXSI8n GC7TUDtDcFtjwZeU/DBdql7IjsiFyiJHYsM7RO4kSC+wMx0mq8tWnhxuPA+sQtDQaFlF vFpNnexYsQNuFaPH82PJ+i1bqmhzhRi2kE8mjLtJ/KpUm/I768B36r2kFM0N8/NPkx0y FiwjbD7u+/GtVq7dFNFOYNjrPmI32hujLdGoi3x/PGJI/pXtL5ZvXBcTPN7Yc8O1fyqv bxXtBjdgr3lFDczGyVbeBLvN8Ixhing7cqUA4e3JHTxXg5ofHICumd0wHRYMDKb7NJNb Sc9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b=YojNMbdt; 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 j33-20020a635521000000b0050be5b718ebsi5588312pgb.272.2023.04.08.05.01.01; Sat, 08 Apr 2023 05:01:17 -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=YojNMbdt; 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 S230477AbjDHLu2 (ORCPT + 99 others); Sat, 8 Apr 2023 07:50:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230466AbjDHLuR (ORCPT ); Sat, 8 Apr 2023 07:50:17 -0400 Received: from ste-pvt-msa2.bahnhof.se (ste-pvt-msa2.bahnhof.se [213.80.101.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1DE2FF33; Sat, 8 Apr 2023 04:49:54 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTP id 071AC3FF56; Sat, 8 Apr 2023 13:49:51 +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.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Authentication-Results: ste-ftg-msa2.bahnhof.se (amavisd-new); dkim=pass (2048-bit key) header.d=dalakolonin.se Received: from ste-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (ste-ftg-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qG3G_D5UE7Hc; Sat, 8 Apr 2023 13:49:50 +0200 (CEST) Received: by ste-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id 317083FF15; Sat, 8 Apr 2023 13:49:50 +0200 (CEST) Authentication-Results: ste-pvt-msa2.bahnhof.se; dkim=pass (2048-bit key; unprotected) header.d=dalakolonin.se header.i=@dalakolonin.se header.b="YojNMbdt"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 413E696022; Sat, 8 Apr 2023 11:49:49 +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 w4m7C-XTXzVi; Sat, 8 Apr 2023 11:49:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 7A6479601D; Sat, 8 Apr 2023 11:49:46 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra.dalakolonin.se 7A6479601D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalakolonin.se; s=D374B428-D0A7-11ED-A657-75977B426508; t=1680954586; bh=46bAIQhprw5uAV/CIe/YRgQOYjSd553x4RWwfAtfJJI=; h=From:To:Date:Message-Id:MIME-Version; b=YojNMbdtND9v8ITXzm4Tt2IlR6p1LvEnQauRLpBqzHOq7yLK0xmsdB2QbN9ogJVsL jXwKsWvV3k2i3mu5UE8mmqpm3XHqGvZg/NjYrvGragEelR6MFVWAC9i4Igc0SyJI/L 7CfjPHtm/enCvTqkFV3fiQ/NdkmgEd8PdZxF6os3LMqxw5VDKlpMiXtNYX41YP82kE EEPkShlDbLtU11P9QlqIUBRGNdKoMtGTBfEqGvBlKwVtyfFc41fk9tySiaUrkCtjux 09y7MU0u9JWFFdgJZCL0M1P90tHb8UFpTtOr8ie2fGwPg71N/3cyZ8Ay9wsqQ4aVnW BSo7APa2igLag== 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 AakoBU_a_1zt; Sat, 8 Apr 2023 11:49:46 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id D0C409601A; Sat, 8 Apr 2023 11:49:45 +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 v4 7/9] iio: adc: palmas: always reset events on unload Date: Sat, 8 Apr 2023 13:48:23 +0200 Message-Id: <20230408114825.824505-8-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230408114825.824505-1-risca@dalakolonin.se> References: <20230408114825.824505-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?1762609360506437161?= X-GMAIL-MSGID: =?utf-8?q?1762609360506437161?= This prevents leaving the adc in freerunning mode when removing the driver. Signed-off-by: Patrik Dahlström --- drivers/iio/adc/palmas_gpadc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index 8c6ea4a3cd2e..da4908608a27 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -498,6 +498,13 @@ static int palmas_gpadc_get_adc_dt_data(struct platform_device *pdev, return 0; } +static void palmas_gpadc_reset(void *data) +{ + struct palmas_gpadc *adc = data; + if (adc->event0.enabled || adc->event1.enabled) + palmas_adc_reset_events(adc); +} + static int palmas_gpadc_probe(struct platform_device *pdev) { struct palmas_gpadc *adc; @@ -587,6 +594,10 @@ static int palmas_gpadc_probe(struct platform_device *pdev) palmas_gpadc_calibrate(adc, i); } + ret = devm_add_action(&pdev->dev, palmas_gpadc_reset, adc); + if (ret) + return ret; + return 0; } From patchwork Sat Apr 8 11:48:24 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: 81168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp837856vqo; Sat, 8 Apr 2023 05:14:28 -0700 (PDT) X-Google-Smtp-Source: AKy350ZiivBIUc1uGmsxO2wGQNxD8rqboaZlj5M2Dd1MwNdPAAoNRvMMBCiJkIzzFl/4XzEStst/ X-Received: by 2002:a17:90a:5108:b0:244:d441:8f68 with SMTP id t8-20020a17090a510800b00244d4418f68mr5318174pjh.16.1680956068085; Sat, 08 Apr 2023 05:14:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680956068; cv=none; d=google.com; s=arc-20160816; b=n2jTJg1d/Mb6K66qx/UoPET4b3D67yIBt0stC8+onLikUSweqewEqB1nltpF603b+A pGl3n9JEQPEBmTDy/xIqrWj+zgHMn45/+jhG3mEmX18xerlptRDjvJCVdowgpEPDouOO yaPEhY6i3zlS3Y5i8C1SDNBYgupVXdA7B0/98VSnIlwHXCn6MzU3HZDyAdQSiziiw56i ck5t6eVvqYdCzkHTaBkdOI/3BHkvB6wlyjmen0zA49aOFlEs9MDSRkU1/sHd5PBYbHAg JNSNy754w1mHWMEhmSWXfyFtjEaW7iGf3coAZ13GOb6kBz35XgJCjxANTVltD7UIC7EO J3Jg== 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=ozXExLLK749ql2WwoKfjB+Ge85Ngz7BDMw8CTZAqlOM=; b=Fgrgc2iSznb4U/4lfnPOQgSA7ecQJGhrQuCUAGpnvBrp5c1zGAxg0MJrK7GDdIVedq eoPbz7bC4/N1J0Ih/IJzdXCt/Yqz9Y3fl0nzv3MLJJrONR8SK+Zvf8F0bFADLioAfrBk tpGnuHO3gIPueokeKpXzHcMraEZQZh54mARlbwAK9j4FSli6tgHRYnaw2fylSHUl7Q71 Gw0E4FmXQvkGZUsp7ejR3gUQOMZAWwHcZnxvNPz4ySaperd3Nu7P4QxtB+soptU7N2z1 6rd7bBmJwD76inxpxXg/bF9LHbD/xKx6u0DumLk6fuEVOJO77qgVOrL+RMwHPomcQRlt Whig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b="XxN6/o9r"; 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 ez7-20020a17090ae14700b0024681cc291csi479962pjb.88.2023.04.08.05.14.16; Sat, 08 Apr 2023 05:14:28 -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="XxN6/o9r"; 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 S231210AbjDHLus (ORCPT + 99 others); Sat, 8 Apr 2023 07:50:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231207AbjDHLue (ORCPT ); Sat, 8 Apr 2023 07:50:34 -0400 Received: from pio-pvt-msa2.bahnhof.se (pio-pvt-msa2.bahnhof.se [79.136.2.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D88B6B76D; Sat, 8 Apr 2023 04:50:07 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTP id B4C2840505; Sat, 8 Apr 2023 13:49: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.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Authentication-Results: pio-pvt-msa2.bahnhof.se (amavisd-new); dkim=pass (2048-bit key) header.d=dalakolonin.se Received: from pio-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (pio-pvt-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wUuAbJ9u5nL4; Sat, 8 Apr 2023 13:49:56 +0200 (CEST) Received: by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id AA746403F0; Sat, 8 Apr 2023 13:49:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 7DE1E9602F; Sat, 8 Apr 2023 11:49: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 4k1x_U80Uto7; Sat, 8 Apr 2023 11:49:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 3B6CE9602B; Sat, 8 Apr 2023 11:49:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra.dalakolonin.se 3B6CE9602B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalakolonin.se; s=D374B428-D0A7-11ED-A657-75977B426508; t=1680954593; bh=ozXExLLK749ql2WwoKfjB+Ge85Ngz7BDMw8CTZAqlOM=; h=From:To:Date:Message-Id:MIME-Version; b=XxN6/o9rYAa3dFX1rU8s0qBGgB6mr3mxOKqmfL/F+IU58f8TQgTjDP/y0ijw2LlPi V5wRXbAC/+z4lVP9Us3ONxLHMUBAsOZXU/PDyGZBQMTvVFoEfpVyMeUuCgUt1HF87M Qlwrgi7YLLiMDhJHbg6ieYzjdyubX3Tu505aynnpSBJAfOPtl5d4Ovw60/e84Oi4N7 21yNVh/5QdrALhr84PTRqUlgAGf+0MyoKUdH/gbiA6ZywhGP/HhYIudO/myxfvkAOF MEEXoiF0Z7Zy6i4M+B84Y2KY5H/IWZZuAk7O7AJSVm7IcTa+VpUER2O9efaQlmkidP HYXnQlgWxSICg== 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 5_n072qCZTPr; Sat, 8 Apr 2023 11:49:53 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id DA94296028; Sat, 8 Apr 2023 11:49:52 +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 v4 8/9] iio: adc: palmas: add support for iio threshold events Date: Sat, 8 Apr 2023 13:48:24 +0200 Message-Id: <20230408114825.824505-9-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230408114825.824505-1-risca@dalakolonin.se> References: <20230408114825.824505-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?1762610190154047352?= X-GMAIL-MSGID: =?utf-8?q?1762610190154047352?= The palmas gpadc block has support for monitoring up to 2 ADC channels and issue an interrupt if they reach past a set threshold. This change hooks into the IIO events system and exposes to userspace the ability to configure these threshold values for each channel, but only allow up to 2 such thresholds to be enabled at any given time. Trying to enable a third channel will result in an error. Userspace is expected to input calibrated, as opposed to raw, values as threshold. However, it is not enough to do the opposite of what is done when converting the other way around. To account for tolerances in the ADC, the calculated raw threshold should be adjusted based on the ADC specifications for the device. These specifications include the integral nonlinearity (INL), offset, and gain error. To adjust the high threshold, use the following equation: (calibrated value + INL) * Gain error + offset = maximum value [1] Likewise, use the following equation for the low threshold: (calibrated value - INL) * Gain error - offset = minimum value The gain error is a combination of gain error, as listed in the datasheet, and gain error drift due to temperature and supply. The exact values for these specifications vary between palmas devices. This patch sets the values found in TWL6035, TWL6037 datasheet. [1] TI Application Report, SLIA087A, Guide to Using the GPADC in TPS65903x, TPS65917-Q1, TPS65919-Q1, and TPS65916 Devices. Signed-off-by: Patrik Dahlström --- V3 -> V4: * Avoid initializing variables unnecessarily. * Minor cosmetic fixes to comments. drivers/iio/adc/palmas_gpadc.c | 444 +++++++++++++++++++++++++++++++-- 1 file changed, 420 insertions(+), 24 deletions(-) diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index da4908608a27..f16f4ef184e4 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -79,10 +80,14 @@ static struct palmas_gpadc_info palmas_gpadc_info[] = { struct palmas_adc_event { bool enabled; int channel; - int raw_thresh; enum iio_event_direction direction; }; +struct palmas_gpadc_thresholds { + int high; + int low; +}; + /* * struct palmas_gpadc - the palmas_gpadc structure * @ch0_current: channel 0 current source setting @@ -120,10 +125,31 @@ struct palmas_gpadc { struct completion conv_completion; struct palmas_adc_event event0; struct palmas_adc_event event1; + struct palmas_gpadc_thresholds thresholds[PALMAS_ADC_CH_MAX]; int auto_conversion_period; struct mutex lock; }; +static struct palmas_adc_event *palmas_gpadc_get_event(struct palmas_gpadc *adc, + int adc_chan, + enum iio_event_direction dir) +{ + if (adc_chan == adc->event0.channel && dir == adc->event0.direction) + return &adc->event0; + + if (adc_chan == adc->event1.channel && dir == adc->event1.direction) + return &adc->event1; + + return NULL; +} + +static bool palmas_gpadc_channel_is_freerunning(struct palmas_gpadc *adc, + int adc_chan) +{ + return palmas_gpadc_get_event(adc, adc_chan, IIO_EV_DIR_RISING) || + palmas_gpadc_get_event(adc, adc_chan, IIO_EV_DIR_FALLING); +} + /* * GPADC lock issue in AUTO mode. * Impact: In AUTO mode, GPADC conversion can be locked after disabling AUTO @@ -193,11 +219,24 @@ static irqreturn_t palmas_gpadc_irq(int irq, void *data) static irqreturn_t palmas_gpadc_irq_auto(int irq, void *data) { - struct palmas_gpadc *adc = data; + struct iio_dev *indio_dev = data; + struct palmas_gpadc *adc = iio_priv(indio_dev); + struct palmas_adc_event *ev; dev_dbg(adc->dev, "Threshold interrupt %d occurs\n", irq); palmas_disable_auto_conversion(adc); + ev = (irq == adc->irq_auto_0) ? &adc->event0 : &adc->event1; + if (ev->channel != -1) { + enum iio_event_direction dir; + u64 code; + + dir = ev->direction; + code = IIO_UNMOD_EVENT_CODE(IIO_VOLTAGE, ev->channel, + IIO_EV_TYPE_THRESH, dir); + iio_push_event(indio_dev, code, iio_get_time_ns(indio_dev)); + } + return IRQ_HANDLED; } @@ -285,6 +324,9 @@ static int palmas_gpadc_read_prepare(struct palmas_gpadc *adc, int adc_chan) { int ret; + if (palmas_gpadc_channel_is_freerunning(adc, adc_chan)) + return 0; /* ADC already running */ + ret = palmas_gpadc_enable(adc, adc_chan, true); if (ret < 0) return ret; @@ -344,28 +386,43 @@ static int palmas_gpadc_start_conversion(struct palmas_gpadc *adc, int adc_chan) unsigned int val; int ret; - init_completion(&adc->conv_completion); - ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, - PALMAS_GPADC_SW_SELECT, - PALMAS_GPADC_SW_SELECT_SW_START_CONV0, - PALMAS_GPADC_SW_SELECT_SW_START_CONV0); - if (ret < 0) { - dev_err(adc->dev, "SELECT_SW_START write failed: %d\n", ret); - return ret; - } + if (palmas_gpadc_channel_is_freerunning(adc, adc_chan)) { + int event = (adc_chan == adc->event0.channel) ? 0 : 1; + unsigned int reg = (event == 0) ? + PALMAS_GPADC_AUTO_CONV0_LSB : + PALMAS_GPADC_AUTO_CONV1_LSB; - ret = wait_for_completion_timeout(&adc->conv_completion, - PALMAS_ADC_CONVERSION_TIMEOUT); - if (ret == 0) { - dev_err(adc->dev, "conversion not completed\n"); - return -ETIMEDOUT; - } + ret = palmas_bulk_read(adc->palmas, PALMAS_GPADC_BASE, + reg, &val, 2); + if (ret < 0) { + dev_err(adc->dev, "AUTO_CONV%x_LSB read failed: %d\n", + event, ret); + return ret; + } + } else { + init_completion(&adc->conv_completion); + ret = palmas_update_bits(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_SW_SELECT, + PALMAS_GPADC_SW_SELECT_SW_START_CONV0, + PALMAS_GPADC_SW_SELECT_SW_START_CONV0); + if (ret < 0) { + dev_err(adc->dev, "SELECT_SW_START write failed: %d\n", ret); + return ret; + } - ret = palmas_bulk_read(adc->palmas, PALMAS_GPADC_BASE, - PALMAS_GPADC_SW_CONV0_LSB, &val, 2); - if (ret < 0) { - dev_err(adc->dev, "SW_CONV0_LSB read failed: %d\n", ret); - return ret; + ret = wait_for_completion_timeout(&adc->conv_completion, + PALMAS_ADC_CONVERSION_TIMEOUT); + if (ret == 0) { + dev_err(adc->dev, "conversion not completed\n"); + return -ETIMEDOUT; + } + + ret = palmas_bulk_read(adc->palmas, PALMAS_GPADC_BASE, + PALMAS_GPADC_SW_CONV0_LSB, &val, 2); + if (ret < 0) { + dev_err(adc->dev, "SW_CONV0_LSB read failed: %d\n", ret); + return ret; + } } ret = val & 0xFFF; @@ -391,6 +448,98 @@ static int palmas_gpadc_get_calibrated_code(struct palmas_gpadc *adc, return val; } +/* + * The high and low threshold values are calculated based on the advice given + * in TI Application Report SLIA087A, "Guide to Using the GPADC in PS65903x, + * TPS65917-Q1, TPS65919-Q1, and TPS65916 Devices". This document recommend + * taking ADC tolerances into account and is based on the device integral non- + * linearity (INL), offset error and gain error: + * + * raw high threshold = (ideal threshold + INL) * gain error + offset error + * + * The gain error include both gain error, as specified in the datasheet, and + * the gain error drift. These paramenters vary depending on device and whether + * the the channel is calibrated (trimmed) or not. + */ +static int palmas_gpadc_threshold_with_tolerance(int val, const int INL, + const int gain_error, + const int offset_error) +{ + val = ((val + INL) * (1000 + gain_error)) / 1000 + offset_error; + + return clamp(val, 0, 0xFFF); +} + +/* + * The values below are taken from the datasheet of TWL6035, TWL6037. + * todo: get max INL, gain error, and offset error from OF. + */ +static int palmas_gpadc_get_high_threshold_raw(struct palmas_gpadc *adc, + struct palmas_adc_event *ev) +{ + const int adc_chan = ev->channel; + int val = adc->thresholds[adc_chan].high; + /* integral nonlinearity, measured in LSB */ + const int max_INL = 2; + /* measured in LSB */ + int max_offset_error; + /* 0.2% when calibrated */ + int max_gain_error = 2; + + val = (val * 1000) / adc->adc_info[adc_chan].gain; + + if (adc->adc_info[adc_chan].is_uncalibrated) { + /* 2% worse */ + max_gain_error += 20; + max_offset_error = 36; + } else { + val = (val * adc->adc_info[adc_chan].gain_error + + adc->adc_info[adc_chan].offset) / + 1000; + max_offset_error = 2; + } + + return palmas_gpadc_threshold_with_tolerance(val, + max_INL, + max_gain_error, + max_offset_error); +} + +/* + * The values below are taken from the datasheet of TWL6035, TWL6037. + * todo: get min INL, gain error, and offset error from OF. + */ +static int palmas_gpadc_get_low_threshold_raw(struct palmas_gpadc *adc, + struct palmas_adc_event *ev) +{ + const int adc_chan = ev->channel; + int val = adc->thresholds[adc_chan].low; + /* integral nonlinearity, measured in LSB */ + const int min_INL = -2; + /* measured in LSB */ + int min_offset_error; + /* -0.6% when calibrated */ + int min_gain_error = -6; + + val = (val * 1000) / adc->adc_info[adc_chan].gain; + + if (adc->adc_info[adc_chan].is_uncalibrated) { + /* 2% worse */ + min_gain_error -= 20; + min_offset_error = -36; + } else { + val = (val * adc->adc_info[adc_chan].gain_error - + adc->adc_info[adc_chan].offset) / + 1000; + min_offset_error = -2; + } + + return palmas_gpadc_threshold_with_tolerance(val, + min_INL, + min_gain_error, + min_offset_error); +} + static int palmas_gpadc_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { @@ -437,8 +586,218 @@ static int palmas_gpadc_read_raw(struct iio_dev *indio_dev, return ret; } +static int palmas_gpadc_read_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) +{ + struct palmas_gpadc *adc = iio_priv(indio_dev); + int adc_chan = chan->channel; + int ret = 0; + + if (adc_chan > PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH) + return -EINVAL; + + mutex_lock(&adc->lock); + + if (palmas_gpadc_get_event(adc, adc_chan, dir)) + ret = 1; + + mutex_unlock(&adc->lock); + + return ret; +} + +static int palmas_adc_configure_events(struct palmas_gpadc *adc); +static int palmas_adc_reset_events(struct palmas_gpadc *adc); + +static int palmas_gpadc_reconfigure_event_channels(struct palmas_gpadc *adc) +{ + return (adc->event0.enabled || adc->event1.enabled) ? + palmas_adc_configure_events(adc) : + palmas_adc_reset_events(adc); +} + +static int palmas_gpadc_enable_event_config(struct palmas_gpadc *adc, + const struct iio_chan_spec *chan, + enum iio_event_direction dir) +{ + struct palmas_adc_event *ev; + int adc_chan = chan->channel; + + if (palmas_gpadc_get_event(adc, adc_chan, dir)) + /* already enabled */ + return 0; + + if (adc->event0.channel == -1) { + ev = &adc->event0; + } else if (adc->event1.channel == -1) { + /* event0 has to be the lowest channel */ + if (adc_chan < adc->event0.channel) { + adc->event1 = adc->event0; + ev = &adc->event0; + } else { + ev = &adc->event1; + } + } else { /* both AUTO channels already in use */ + dev_warn(adc->dev, "event0 - %d, event1 - %d\n", + adc->event0.channel, adc->event1.channel); + return -EBUSY; + } + + ev->enabled = true; + ev->channel = adc_chan; + ev->direction = dir; + + return palmas_gpadc_reconfigure_event_channels(adc); +} + +static int palmas_gpadc_disable_event_config(struct palmas_gpadc *adc, + const struct iio_chan_spec *chan, + enum iio_event_direction dir) +{ + int adc_chan = chan->channel; + struct palmas_adc_event *ev = palmas_gpadc_get_event(adc, adc_chan, dir); + + if (!ev) + return 0; + + if (ev == &adc->event0) { + adc->event0 = adc->event1; + ev = &adc->event1; + } + + ev->enabled = false; + ev->channel = -1; + ev->direction = IIO_EV_DIR_NONE; + + return palmas_gpadc_reconfigure_event_channels(adc); +} + +static int palmas_gpadc_write_event_config(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + int state) +{ + struct palmas_gpadc *adc = iio_priv(indio_dev); + int adc_chan = chan->channel; + int ret; + + if (adc_chan > PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH) + return -EINVAL; + + mutex_lock(&adc->lock); + + if (state) + ret = palmas_gpadc_enable_event_config(adc, chan, dir); + else + ret = palmas_gpadc_disable_event_config(adc, chan, dir); + + mutex_unlock(&adc->lock); + + return ret; +} + +static int palmas_gpadc_read_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int *val, int *val2) +{ + struct palmas_gpadc *adc = iio_priv(indio_dev); + int adc_chan = chan->channel; + int ret; + + if (adc_chan > PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH) + return -EINVAL; + + mutex_lock(&adc->lock); + + switch (info) { + case IIO_EV_INFO_VALUE: + *val = (dir == IIO_EV_DIR_RISING) ? + adc->thresholds[adc_chan].high : + adc->thresholds[adc_chan].low; + ret = IIO_VAL_INT; + break; + default: + ret = -EINVAL; + break; + } + + mutex_unlock(&adc->lock); + + return ret; +} + +static int palmas_gpadc_write_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int val, int val2) +{ + struct palmas_gpadc *adc = iio_priv(indio_dev); + int adc_chan = chan->channel; + int old; + int ret; + + if (adc_chan > PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH) + return -EINVAL; + + mutex_lock(&adc->lock); + switch (info) { + case IIO_EV_INFO_VALUE: + if (val < 0 || val > 0xFFF) { + ret = -EINVAL; + break; + } + if (dir == IIO_EV_DIR_RISING) { + old = adc->thresholds[adc_chan].high; + adc->thresholds[adc_chan].high = val; + } + else { + old = adc->thresholds[adc_chan].low; + adc->thresholds[adc_chan].low = val; + } + ret = 0; + break; + default: + ret = -EINVAL; + goto out_unlock; + } + + if (val != old && palmas_gpadc_get_event(adc, adc_chan, dir)) + ret = palmas_gpadc_reconfigure_event_channels(adc); + +out_unlock: + mutex_unlock(&adc->lock); + + return ret; +} + static const struct iio_info palmas_gpadc_iio_info = { .read_raw = palmas_gpadc_read_raw, + .read_event_config = palmas_gpadc_read_event_config, + .write_event_config = palmas_gpadc_write_event_config, + .read_event_value = palmas_gpadc_read_event_value, + .write_event_value = palmas_gpadc_write_event_value, +}; + +static const struct iio_event_spec palmas_gpadc_events[] = { + { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_FALLING, + .mask_separate = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_ENABLE), + }, }; #define PALMAS_ADC_CHAN_IIO(chan, _type, chan_info) \ @@ -449,6 +808,8 @@ static const struct iio_info palmas_gpadc_iio_info = { BIT(chan_info), \ .indexed = 1, \ .channel = PALMAS_ADC_CH_##chan, \ + .event_spec = palmas_gpadc_events, \ + .num_event_specs = ARRAY_SIZE(palmas_gpadc_events) \ } static const struct iio_chan_spec palmas_gpadc_iio_channel[] = { @@ -555,6 +916,39 @@ static int palmas_gpadc_probe(struct platform_device *pdev) return dev_err_probe(adc->dev, ret, "request irq %d failed\n", adc->irq); + adc->irq_auto_0 = platform_get_irq(pdev, 1); + if (adc->irq_auto_0 < 0) + return dev_err_probe(adc->dev, adc->irq_auto_0, + "get auto0 irq failed\n"); + + ret = devm_request_threaded_irq(&pdev->dev, adc->irq_auto_0, NULL, + palmas_gpadc_irq_auto, IRQF_ONESHOT, + "palmas-adc-auto-0", indio_dev); + if (ret < 0) + return dev_err_probe(adc->dev, ret, + "request auto0 irq %d failed\n", + adc->irq_auto_0); + + adc->irq_auto_1 = platform_get_irq(pdev, 2); + if (adc->irq_auto_1 < 0) + return dev_err_probe(adc->dev, adc->irq_auto_1, + "get auto1 irq failed\n"); + + ret = devm_request_threaded_irq(&pdev->dev, adc->irq_auto_1, NULL, + palmas_gpadc_irq_auto, IRQF_ONESHOT, + "palmas-adc-auto-1", indio_dev); + if (ret < 0) + return dev_err_probe(adc->dev, ret, + "request auto1 irq %d failed\n", + adc->irq_auto_1); + + adc->event0.enabled = false; + adc->event0.channel = -1; + adc->event0.direction = IIO_EV_DIR_NONE; + adc->event1.enabled = false; + adc->event1.channel = -1; + adc->event1.direction = IIO_EV_DIR_NONE; + /* set the current source 0 (value 0/5/15/20 uA => 0..3) */ if (gpadc_pdata->ch0_current <= 1) adc->ch0_current = PALMAS_ADC_CH0_CURRENT_SRC_0; @@ -632,13 +1026,14 @@ static int palmas_adc_configure_events(struct palmas_gpadc *adc) int polarity; ch0 = ev->channel; - thres = ev->raw_thresh; conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV0_EN; switch (ev->direction) { case IIO_EV_DIR_RISING: + thres = palmas_gpadc_get_high_threshold_raw(adc, ev); polarity = 0; break; case IIO_EV_DIR_FALLING: + thres = palmas_gpadc_get_low_threshold_raw(adc, ev); polarity = PALMAS_GPADC_THRES_CONV0_MSB_THRES_CONV0_POL; break; default: @@ -668,13 +1063,14 @@ static int palmas_adc_configure_events(struct palmas_gpadc *adc) int polarity; ch1 = ev->channel; - thres = ev->raw_thresh; conv |= PALMAS_GPADC_AUTO_CTRL_AUTO_CONV1_EN; switch (ev->direction) { case IIO_EV_DIR_RISING: + thres = palmas_gpadc_get_high_threshold_raw(adc, ev); polarity = 0; break; case IIO_EV_DIR_FALLING: + thres = palmas_gpadc_get_low_threshold_raw(adc, ev); polarity = PALMAS_GPADC_THRES_CONV1_MSB_THRES_CONV1_POL; break; default: From patchwork Sat Apr 8 11:48:25 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: 81180 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp841811vqo; Sat, 8 Apr 2023 05:22:41 -0700 (PDT) X-Google-Smtp-Source: AKy350ZlVgKpz9HpgQvBHShTIzQ7tBnM7CKl+7+tsFwdcPPFjZfLIitUx7yKsZIIXhAhrVW+Afe2 X-Received: by 2002:a17:90b:350e:b0:23b:4bf6:bbfa with SMTP id ls14-20020a17090b350e00b0023b4bf6bbfamr2623818pjb.11.1680956561010; Sat, 08 Apr 2023 05:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680956560; cv=none; d=google.com; s=arc-20160816; b=dOaKp8zfUScXdWxFDXVfVqws9ZQc8O6NwLzwc4Ne16liDgMR4mDqnB3BJAPF6UDNS+ a3Tjp/1dpCdpB7W7TpuPX+a1NG8lpMsQTQrLAOBQyiOZeoi4VX0uDUOzXkjUh8gf1im0 Yx9hpBkF+/sMCgPAdRustMhCDtrsXJJOGxYXDD+QZGb7liKUsR6wOw8Ndfxc9x7NDU69 RNKYiB+7U33iyxhbz8ChAjXjuEFnuu0XCg9eTNI5/X3S4OOYFw+ac6JwgElwPRv9HKnX xP60mX+uHQ9B1CeeGdCi8hjEqddG54JMfKwyNOT5qy3OHzF2rqfgqxGo3W0UgnyDh4f6 VGiw== 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=kMqSuljo5JCHHUyQ0/vT6PhpwoOLfZm0bs5vSN/fU20=; b=MN7FQnL5O8gUp8zbika21O72p4gAl3kWbXTrHfHxb1O0qCO0WnHckxN9VvLcz5xdNA UnUBMAJN/w+PUvF78yRItclVp15ZD3jaw30V1Gp+6a0bOM2VKGTNn7OUhvKSR0NYCLkr Gh7iFtST7jwHzch0UhnfmSUil6WbuMPD8UE3u7mx41WLWJcKt4H3faOlj8trOJBTyXX3 S21PmhUqzfAcHimIk6RDDm+QvoFtgrQy/QKNbp6TepH1vJWW8r2fHmKWsF2Z4EEgIGq3 V0VTzUdGjYpBTNzzcGiHR2th0YNrF8vCp8rBU7r8t2ZNojSrnYxxuWvuSOuLt0zTfsMI w6Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dalakolonin.se header.s=D374B428-D0A7-11ED-A657-75977B426508 header.b=FsGhAvL5; 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 q18-20020a17090ad39200b0024046d91263si8262210pju.51.2023.04.08.05.22.28; Sat, 08 Apr 2023 05:22:40 -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=FsGhAvL5; 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 S231199AbjDHLuu (ORCPT + 99 others); Sat, 8 Apr 2023 07:50:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbjDHLug (ORCPT ); Sat, 8 Apr 2023 07:50:36 -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 F3C81113D2; Sat, 8 Apr 2023 04:50:09 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa3.bahnhof.se (Postfix) with ESMTP id 5BBE33F645; Sat, 8 Apr 2023 13:50:03 +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 X6S5QeEvuOoQ; Sat, 8 Apr 2023 13:50:02 +0200 (CEST) Received: by pio-pvt-msa3.bahnhof.se (Postfix) with ESMTPA id 4CECB3F6DD; Sat, 8 Apr 2023 13:50:02 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 9BDBD96041; Sat, 8 Apr 2023 11:50:01 +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 gJ1cKA0nyg2p; Sat, 8 Apr 2023 11:49:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTP id 633F996034; Sat, 8 Apr 2023 11:49:59 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.10.3 zimbra.dalakolonin.se 633F996034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dalakolonin.se; s=D374B428-D0A7-11ED-A657-75977B426508; t=1680954599; bh=kMqSuljo5JCHHUyQ0/vT6PhpwoOLfZm0bs5vSN/fU20=; h=From:To:Date:Message-Id:MIME-Version; b=FsGhAvL5t44Z1SD8WHPbetsORlyRXP+vtByn3xsRhQCLc+eYKMax3K5QQRel+VCDD yGKAjtTAMuAKNwCeyC++eSq+bKPbmy7IbgeXBu1ZsX9vE7qOeduTEz3TjM6q++FpTN xqar/NuLj9qV0LGY34Gdxf4SuUVozUJAKb5NgriQzak85ns3Z4ZAICSADouY/I3LgG fX9nBHjtDl+ud/LsUV7npB7gEE0DJnz08tTN2gz3huTr9IeO59qVIeLWIrT9se0qft DW8W/GcucplWGbLTKjYYJahd1VwzopppZeWueBPv4nb2+vZ9QQpeZr3/Iieki1VnF4 D6CZmz7Owrbog== 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 a4pO92bMA4Nq; Sat, 8 Apr 2023 11:49:59 +0000 (UTC) Received: from rack-server-1.dalakolonin.se (unknown [172.17.0.1]) by zimbra.dalakolonin.se (Postfix) with ESMTPSA id BB72996031; Sat, 8 Apr 2023 11:49:58 +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 v4 9/9] iio: adc: palmas: don't alter event config on suspend/resume Date: Sat, 8 Apr 2023 13:48:25 +0200 Message-Id: <20230408114825.824505-10-risca@dalakolonin.se> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230408114825.824505-1-risca@dalakolonin.se> References: <20230408114825.824505-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?1762610706926973024?= X-GMAIL-MSGID: =?utf-8?q?1762610706926973024?= The event config is controlled through the IIO events subsystem and device wakeup is controlled by /sys/devices/.../power/wakeup. Let's keep those two knobs independent. Signed-off-by: Patrik Dahlström --- drivers/iio/adc/palmas_gpadc.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c index f16f4ef184e4..f2ea3f2de363 100644 --- a/drivers/iio/adc/palmas_gpadc.c +++ b/drivers/iio/adc/palmas_gpadc.c @@ -1134,16 +1134,10 @@ 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 wakeup = adc->event0.enabled || adc->event1.enabled; - int ret; - if (!device_may_wakeup(dev) || !wakeup) + if (!device_may_wakeup(dev)) return 0; - ret = palmas_adc_configure_events(adc); - if (ret < 0) - return ret; - if (adc->event0.enabled) enable_irq_wake(adc->irq_auto_0); @@ -1157,16 +1151,10 @@ 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 wakeup = adc->event0.enabled || adc->event1.enabled; - int ret; - if (!device_may_wakeup(dev) || !wakeup) + if (!device_may_wakeup(dev)) return 0; - ret = palmas_adc_reset_events(adc); - if (ret < 0) - return ret; - if (adc->event0.enabled) disable_irq_wake(adc->irq_auto_0);