Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2844181ybh; Mon, 16 Mar 2020 10:46:26 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtPbGxV4dPHRlRWeTrSZJZ6N4rJTdSpf30kG0nHsXod/CwmYR8MbLZU3VwBWFWRckrpNcZh X-Received: by 2002:a05:6830:231d:: with SMTP id u29mr314346ote.1.1584380785924; Mon, 16 Mar 2020 10:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584380785; cv=none; d=google.com; s=arc-20160816; b=SSt1yXIIitw/6zzO92pFCCmp1aajulvMUwHXQXVK+Yz7FXH6EeJ0OETUphtkFgEAAG VOBWiohJEkWTOxGer2qzJnKSyM835JqJnmAZTbFcNVlpHtEN9lZDlKeXMfuKH6745x3g sKK6ZzMZvTpPgngeHyiER/iC9G/4ZUlLxhj4I+/MzeiMzO2/7zVLda1ZuqOhEqgNuanE Wx3RwDnFLtNjVmvu4eDRnwzv10N0qP95gp3fDhAq7giU0jTYePg7sA7jWMDzTdr9Uv/Y WwVFYqE9ssFiXLgXYwFOMbl/xOL61CcYaIGjHmuqys5ulrhisxewZxGwXAyLQbF07DNm F0pw== 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=+B9JmGC21z+ERkSk4X79hhdaXnMRqgpCFhuGf8pVf58=; b=alodzeNgwz222hOBpCgfmYzXqqUwkcAXlpQMdJIggqV6sC22dArLVETF4gm3oPkKYd XhFXgExjtNbAmBzlEQjpACgzABtqKJvQMHoyOb7DS7WmbwB8ngLkLwfACz+lPyCpAgav SjklaUMWCJJ8LGObryxvKHp9vVL3PfbkZwqfNZSNA+uDV6wFzeoNERF+r2wAo6jMJ0aH DxpgJRIqqg4VdfkNAL+qvmXS8CxaJVzSIcV3u6Chu8rQJCjRMDWCtnHWNnOqeQXVCGe+ J/G0xOXIoJ7sVAHNWdHUxVCH0K4l3FNt4ca2ugFdMhPT2QpYwX6vjPc0j8TwbgHB4A5K UjRw== 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 y16si282831oie.225.2020.03.16.10.46.12; Mon, 16 Mar 2020 10:46:25 -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 S1731843AbgCPRor (ORCPT + 99 others); Mon, 16 Mar 2020 13:44:47 -0400 Received: from stcim.de ([78.46.90.227]:58902 "EHLO stcim.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730437AbgCPRor (ORCPT ); Mon, 16 Mar 2020 13:44:47 -0400 X-Greylist: delayed 1475 seconds by postgrey-1.27 at vger.kernel.org; Mon, 16 Mar 2020 13:44:46 EDT Received: from [2001:4dd7:15f0:0:a288:b4ff:fee5:f5cc] (helo=porty) by stcim with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jDtPI-00011x-JQ; Mon, 16 Mar 2020 18:20:04 +0100 Date: Mon, 16 Mar 2020 18:20:03 +0100 From: Stefan Lengfeld To: =?utf-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= Cc: Dmitry Osipenko , Ludovic Desroches , Nicolas Ferre , Alexandre Belloni , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Marco Felsch Subject: Re: [PATCH] i2c: at91: support atomic write xfer Message-ID: <20200316172003.lguso2fczz5imh6g@porty> References: <9924dd54-dd8b-d130-9607-2bbbc65675d5@gmail.com> <20200316144221.GC19141@qmqm.qmqm.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200316144221.GC19141@qmqm.qmqm.pl> X-PGP-Key: https://stefanchrist.eu/personal/Stefan_Lengfeld_0xE44A23B289092311.asc User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > > ... > > > + 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