Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4952022rwb; Sun, 13 Nov 2022 18:01:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf4fZEczKmUHErNXpMEO6NLBPD1Ui4v1K91+w4cd1zpiOAAA1ZYbaJ2ajroboppPym5O+W90 X-Received: by 2002:a17:906:ce29:b0:7a6:598f:1fb1 with SMTP id sd9-20020a170906ce2900b007a6598f1fb1mr8858572ejb.606.1668391280836; Sun, 13 Nov 2022 18:01:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668391280; cv=none; d=google.com; s=arc-20160816; b=dYVLcfNbxSskyQO+i82RUy3QAMbkQHNkheG2dV7fkRxhIY3KLyYA6MuPzIFaEq4qnu K13BzpoGbiZyUkoBEqXWLpZSKn849iYfjRbmaT2ZhFoyk/PW/C0MPiACWnqNvNDCviNJ YBdJrjYC1xSzAeO2JeWP0XzvELWV9cCQuJjtkQSXuKGvrPIVp9A/aNRPEiCxTbvXxGC8 ARSjv3TDWpfTOMxnGHKr9+Um12UA5ybXZvSOpmfXdIOdhSga8HZAGTalyFnMsPG+t+sZ EtQ2LvWSAfMOVLxnM7Dn+960sxSVQ7PSjWcCgW19467155CyRVVScyxuW7WOqKL5DETh 3QjA== 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 :feedback-id:dkim-signature:dkim-signature; bh=8v64se4ndLgqbFDAHIerqamapO8xDSwZD3YbrOF2gwU=; b=uc4Nhly/4SwmFuWOgz7PVqqJVWJc8pSFtJ2hLVnePVrOK9sAc/rEeGnu97h13LFoFU Bh2++TYZa9rNOqIAXf9lUEkLr+cjP+ftqoaxCdv74CFh36f+ntwpQcymXUQeKd4j7QNc q3ml3JwiYOM8n4pInnNV88ROIcCmjWTBsqz1JPx2nwWc8+Df7d1EdrLnLbtr7GMEV625 EsPdrqnHLS1q3fxebfirm+hMXjjRNe3P2x80Y/ExtXCTdJXHfjJk8MNoUvxNUL3hWmGu hdx7YHLQ1pnl+iD6fLeq0vAfJD11T5Sx9GrWDGZFPb85JU1InkZpxUX/KWwASX2iIrer HH2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm2 header.b="nW/Za3Em"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=LR4qa+zq; 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=sholland.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j11-20020a05640211cb00b004615c5728e8si9089564edw.494.2022.11.13.18.00.58; Sun, 13 Nov 2022 18:01:20 -0800 (PST) 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=@sholland.org header.s=fm2 header.b="nW/Za3Em"; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=LR4qa+zq; 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=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235485AbiKNB6M (ORCPT + 90 others); Sun, 13 Nov 2022 20:58:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235753AbiKNB57 (ORCPT ); Sun, 13 Nov 2022 20:57:59 -0500 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A79256385 for ; Sun, 13 Nov 2022 17:57:56 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id AB4C13200918; Sun, 13 Nov 2022 20:57:55 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 13 Nov 2022 20:57:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1668391075; x=1668477475; bh=8v 64se4ndLgqbFDAHIerqamapO8xDSwZD3YbrOF2gwU=; b=nW/Za3EmB97fE3xQuz U6IjghrHUwvxKsNRYAo8tZ4gfTFvimat3kKsyL+VLjfRGPJ5zYlnB51PnMgHErdz Jgsdcq2Blkkn1IGrQ82ih1dfhaC3wX8rTcSjWHtrAmflQ14Al8CyaK/4PZytH8ub FBmKyvt74izhN6/cVv7dkRKszHISqk01Zi7jtxnpKCN5SATtcwEjjce6u+28HZFt Q9pbVdOKS/MaA/JD1aZpbebRw38r8Q2+hxewAkQM2X5XqSh/xEFK5b5DuJONAlJw CJ80JOXmUQ+u18v1BmERKTU8nryl8s1u1aOlM40aMHH6FOslFE2THipsR2BtZbA4 fiDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1668391075; x=1668477475; bh=8v64se4ndLgqb FDAHIerqamapO8xDSwZD3YbrOF2gwU=; b=LR4qa+zqLoevQmTaWy4UOL7sr85kK PxsH3h3OkgY4sJXhswK2jBoXG+CxNsvMXsSgTeccvtLW2lKqADVrSHbT5vuo6uMA 0IMUXs8TF0t/T2ikJGGH3MDM9PnOEDUu8eEhsmkDIb2zcD5NqIebFIhOJu2hpj14 UhI0aMo73HNIoz4IDdwM+T4IKhyceGKvKFM/Ax5PpiqPgKAkURqdZHnN+4EfnvZL Hn9efLrK/Xr01xHE5KuMC4k3JY/n3ebtLoQfPElN3YqdIPDjozErKP28Wlrn/KpQ mmRL/JEYSgyLUYAdUzrG1D9y2yPCxX6tPd0BoPR7EeyJ93dsKSlWkS49A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrgedugdegtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpedukeetueduhedtleetvefguddvvdejhfefudelgfduveeggeehgfdu feeitdevteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 13 Nov 2022 20:57:54 -0500 (EST) From: Samuel Holland To: Chen-Yu Tsai , Jernej Skrabec Cc: Ivaylo Dimitrov , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, Andre Przywara , Samuel Holland Subject: [PATCH v3 2/3] bus: sunxi-rsb: Support atomic transfers Date: Sun, 13 Nov 2022 19:57:48 -0600 Message-Id: <20221114015749.28490-3-samuel@sholland.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221114015749.28490-1-samuel@sholland.org> References: <20221114015749.28490-1-samuel@sholland.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 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 When communicating with a PMIC during system poweroff (pm_power_off()), IRQs are disabled and we are in a RCU read-side critical section, so we cannot use wait_for_completion_io_timeout(). Instead, poll the status register for transfer completion. Fixes: d787dcdb9c8f ("bus: sunxi-rsb: Add driver for Allwinner Reduced Serial Bus") Signed-off-by: Samuel Holland --- Changes in v3: - Clear the interrupt status register after polling Changes in v2: - Add Fixes tag to patch 2 - Only check for specific status bits when polling drivers/bus/sunxi-rsb.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/bus/sunxi-rsb.c b/drivers/bus/sunxi-rsb.c index 17343cd75338..3aa91aed3bf7 100644 --- a/drivers/bus/sunxi-rsb.c +++ b/drivers/bus/sunxi-rsb.c @@ -267,6 +267,9 @@ EXPORT_SYMBOL_GPL(sunxi_rsb_driver_register); /* common code that starts a transfer */ static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb) { + u32 int_mask, status; + bool timeout; + if (readl(rsb->regs + RSB_CTRL) & RSB_CTRL_START_TRANS) { dev_dbg(rsb->dev, "RSB transfer still in progress\n"); return -EBUSY; @@ -274,13 +277,23 @@ static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb) reinit_completion(&rsb->complete); - writel(RSB_INTS_LOAD_BSY | RSB_INTS_TRANS_ERR | RSB_INTS_TRANS_OVER, - rsb->regs + RSB_INTE); + int_mask = RSB_INTS_LOAD_BSY | RSB_INTS_TRANS_ERR | RSB_INTS_TRANS_OVER; + writel(int_mask, rsb->regs + RSB_INTE); writel(RSB_CTRL_START_TRANS | RSB_CTRL_GLOBAL_INT_ENB, rsb->regs + RSB_CTRL); - if (!wait_for_completion_io_timeout(&rsb->complete, - msecs_to_jiffies(100))) { + if (irqs_disabled()) { + timeout = readl_poll_timeout_atomic(rsb->regs + RSB_INTS, + status, (status & int_mask), + 10, 100000); + writel(status, rsb->regs + RSB_INTS); + } else { + timeout = !wait_for_completion_io_timeout(&rsb->complete, + msecs_to_jiffies(100)); + status = rsb->status; + } + + if (timeout) { dev_dbg(rsb->dev, "RSB timeout\n"); /* abort the transfer */ @@ -292,18 +305,18 @@ static int _sunxi_rsb_run_xfer(struct sunxi_rsb *rsb) return -ETIMEDOUT; } - if (rsb->status & RSB_INTS_LOAD_BSY) { + if (status & RSB_INTS_LOAD_BSY) { dev_dbg(rsb->dev, "RSB busy\n"); return -EBUSY; } - if (rsb->status & RSB_INTS_TRANS_ERR) { - if (rsb->status & RSB_INTS_TRANS_ERR_ACK) { + if (status & RSB_INTS_TRANS_ERR) { + if (status & RSB_INTS_TRANS_ERR_ACK) { dev_dbg(rsb->dev, "RSB slave nack\n"); return -EINVAL; } - if (rsb->status & RSB_INTS_TRANS_ERR_DATA) { + if (status & RSB_INTS_TRANS_ERR_DATA) { dev_dbg(rsb->dev, "RSB transfer data error\n"); return -EIO; } -- 2.37.3