Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2996706ybh; Mon, 16 Mar 2020 13:46:08 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsUCNZLQXKPAd4VRLDZybIoahdlsJKXBGZre7VnSYFxkbEGS2UvR1ImmvXV4mn3GxOxRK8l X-Received: by 2002:a05:6830:168b:: with SMTP id k11mr974288otr.156.1584391567941; Mon, 16 Mar 2020 13:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584391567; cv=none; d=google.com; s=arc-20160816; b=E9RuNROpnIv/g1ALXRD/ni6pk5ox6ATcRcVxpaczjnV444sdQWh1pnri6XKdwougGG o84CcoYDdBkAnB/7StkRcQEWj+3xOBNTDHDNQIXwUNCG7bwRcwqUoTMYmB6P42q7gN/E pGXUFgfT/cJQnfYROLWbs6t1on051IB4G59Iqz7v1mgk2e8xxpkP+fcbIKmCWSEOecUQ pnIJMZ9qEmwai2GrNNlhXEcCbEsTiRc6lfn+3M7isnjRmIxniCGlaRSicr9cIVNhG2eK PGYNohEdpOLspLYgfuOHxhsYw/lkjDkt8Mgt+jxzm5yNCMoCfmHWQ1ENiNa1P2HgZ7zY Ir8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=6w5R2hlj07lnVeDzyJYO2EJmrBE8etX6LeerIVFW24Y=; b=BbAt9nwLgGR+p38t2a6PYuwqqQPEHNIXezXd0tTvju0gOV9zIeXfWqVIiSZgP4zHkz VhD5aAI9jimqGpKzeu3y9THeRxlqXRAagUr9+EFTjwdVxGpMNG6bE1WFoWPNMY31fyjk EgFKJEYx0QB0YZGI18F+sWlWJggcIoxFGmNPMFHKi3bDK2NfiZV/7jp3PmQddtmQnoUf f6wmidIM4H0Ry0/LFLF+se6EXQ7eEdN0uPW9DLesNREA3I3uOvAS68RVMgivnJTCBrIF pZsT1Zp/F/BqeTFKvQSX17srOVVxJ2oi/Z1JJq7gLleeNXmD5maiiScsoPFAf4ejAo9v 7j/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a69si528572oib.90.2020.03.16.13.45.52; Mon, 16 Mar 2020 13:46:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732568AbgCPUne (ORCPT + 99 others); Mon, 16 Mar 2020 16:43:34 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:38201 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732537AbgCPUnd (ORCPT ); Mon, 16 Mar 2020 16:43:33 -0400 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.lab.pengutronix.de) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jDwa3-0006n7-SB; Mon, 16 Mar 2020 21:43:23 +0100 Received: from mfe by dude02.lab.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1jDwa2-0007Vh-2S; Mon, 16 Mar 2020 21:43:22 +0100 Date: Mon, 16 Mar 2020 21:43:22 +0100 From: Marco Felsch To: Stefan Lengfeld Cc: =?utf-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Dmitry Osipenko , Ludovic Desroches , Nicolas Ferre , Alexandre Belloni , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] i2c: at91: support atomic write xfer Message-ID: <20200316204322.GB17716@pengutronix.de> References: <9924dd54-dd8b-d130-9607-2bbbc65675d5@gmail.com> <20200316144221.GC19141@qmqm.qmqm.pl> <20200316172003.lguso2fczz5imh6g@porty> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200316172003.lguso2fczz5imh6g@porty> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 21:08:32 up 24 days, 7:25, 51 users, load average: 0.31, 0.28, 0.21 User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: mfe@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20-03-16 18:20, Stefan Lengfeld wrote: > Hi Michał, > > On Mon, Mar 16, 2020 at 03:42:21PM +0100, Michał Mirosław wrote: > > On Sun, Mar 15, 2020 at 11:46:33PM +0300, Dmitry Osipenko wrote: > > > 15.03.2020 21:27, Michał Mirosław пишет: > > > > Implement basic support for atomic write - enough to get a simple > > > > write to PMIC on shutdown. Only for chips having ALT_CMD register, > > > > eg. SAMA5D2. > > > > > > > > Signed-off-by: Michał Mirosław > > > > --- > > > > > > Hello Michał, > > > > > > ... > > > > + ret = pm_runtime_get_sync(dev->dev); > > > > + if (ret < 0) > > > > + goto out; > > > > > > Runtime PM can't be used while interrupts are disabled, unless > > > pm_runtime_irq_safe() is used and driver's RPM callback is IRQ-safe. > > > > I didn't get any warnings from lockdep and friends, but I'll double > > check if this is by luck. > > You can have a look at the I2C atomic patch for the imx-driver. See > > https://patchwork.ozlabs.org/patch/1225802/ > > In that patch Marco Felsch is using clk_enable() and clk_disable() calls. Yep because we need to handle the runtime_pm stuff by our-self. So for the imx case we need to handle the clk en-/disable stuff. Runtime pm is using a workqueue which can't be used in that late case. Regards, Marco > > > ... > > > > + timeout = jiffies + (2 + msg->len) * HZ/1000; > > > > + for (;;) { > > > > + stat = at91_twi_read(dev, AT91_TWI_SR); > > > > + if (stat & AT91_TWI_TXCOMP) > > > > + break; > > > > + if (time_after(jiffies, timeout)) { > > > > + ret = -ETIMEDOUT; > > > > + goto out; > > > > + } > > > > + udelay(100); > > > > + } > > > > > > Jiffies can't be used with the disabled interrupts because jiffies are > > > updated by timer's interrupt. > > > > > > Either ktime() API or iterator-based loop should be used. > > > > Thanks for the pointers. In my use-case power is cut from the CPU at this > > point so it didn't matter that the loop was infinite. > > Here again you can have a look at Marco Felsch's patch. He used the > function readb_poll_timeout_atomic(). So the loop can potentially > replaced by a single line. > > Kind regards, > Stefan > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |