From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89DE0C433EF for ; Fri, 8 Jul 2022 07:32:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237630AbiGHHcN (ORCPT ); Fri, 8 Jul 2022 03:32:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237455AbiGHHcL (ORCPT ); Fri, 8 Jul 2022 03:32:11 -0400 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 397897D1C5; Fri, 8 Jul 2022 00:32:08 -0700 (PDT) Received: by mail-qk1-f171.google.com with SMTP id z12so15131637qki.3; Fri, 08 Jul 2022 00:32:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GyuWdxIYPEX32KTLf4+nqWMB/g4jdV/r/sv49wLRugA=; b=O/EhcTLBcdUYcej0PJL9wrq1jdAI3f1er75yakc7c8iLr9dImV91wAInhH6UE1+kIK zqJE+jJ+2FmofdDcEzTonAyTwf4/AUJe6ZeWrSUvGlxDEHGP3HQfDiVBk2FuNidKEfjH jxKagvlTT/LMmaoX+POKdDYEw2WDsnuNLtfBjXPSZHnC4Ce8dJ0Bi370aRY+VaYyadAo vw9EV1QXqoPaXMSHnjIZvRLTph4alJthxD/AB8FTwgs44Hj5Rb/i5upUBaF7nNHvl9+V rWkepWOX3JlMZzuU9f48IiDfXdCA6y1gtHVf9m7wte9meRApQOvICqLzM2knxR/uH0L3 Vf/A== X-Gm-Message-State: AJIora//+zeHsRLXkBfQR8Z8MC+QWLqIZaM9KHFKW5dPYQXSaBlbEXUE Lq0kmQLvAt/tHnOKQ0ntzyAcUoiurcemCA== X-Google-Smtp-Source: AGRyM1v8atxASgO5r0j+Uh7oAbbEC1ERTW5qINwQKbtZVTWuqtH54DwvdOHRk+SSRFEtDP/Q3UIoaA== X-Received: by 2002:a05:620a:2624:b0:6b5:3f21:b26d with SMTP id z36-20020a05620a262400b006b53f21b26dmr1316237qko.233.1657265527120; Fri, 08 Jul 2022 00:32:07 -0700 (PDT) Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com. [209.85.128.182]) by smtp.gmail.com with ESMTPSA id bi13-20020a05620a318d00b006a6c552736asm33620223qkb.119.2022.07.08.00.32.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Jul 2022 00:32:06 -0700 (PDT) Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-31caffa4a45so119017057b3.3; Fri, 08 Jul 2022 00:32:06 -0700 (PDT) X-Received: by 2002:a81:1090:0:b0:31c:9be5:6c95 with SMTP id 138-20020a811090000000b0031c9be56c95mr2513847ywq.384.1657265526102; Fri, 08 Jul 2022 00:32:06 -0700 (PDT) MIME-Version: 1.0 References: <20220701163916.111435-1-phil.edworthy@renesas.com> <20220701163916.111435-3-phil.edworthy@renesas.com> In-Reply-To: From: Geert Uytterhoeven Date: Fri, 8 Jul 2022 09:31:54 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 2/2] i2c: Add Renesas RZ/V2M controller To: Phil Edworthy Cc: Andy Shevchenko , Philipp Zabel , Wolfram Sang , Jarkko Nikula , Krzysztof Kozlowski , Sam Protsenko , Rob Herring , Sven Peter , Jan Dabros , Lukas Bulwahn , Tyrone Ting , Arnd Bergmann , Olof Johansson , Biju Das , Geert Uytterhoeven , Linux I2C , Linux-Renesas Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Hi Phil, On Thu, Jul 7, 2022 at 8:47 PM Phil Edworthy wrote: > On 07 July 2022 18:46 Geert Uytterhoeven wrote: > > On Thu, Jul 7, 2022 at 6:37 PM Phil Edworthy wrote: > > > On 07 July 2022 08:21 Phil Edworthy wrote: > > > > On 03 July 2022 16:17 Andy Shevchenko wrote: > > > > > On Sun, Jul 03, 2022 at 10:41:45AM +0200, Geert Uytterhoeven wrote: > > > > > > On Sat, Jul 2, 2022 at 1:51 PM Andy Shevchenko > > > > > > wrote: > > > > > > > On Fri, Jul 01, 2022 at 05:39:16PM +0100, Phil Edworthy wrote: > > > > > > > > Yet another i2c controller from Renesas that is found on the > > > > RZ/V2M > > > > > > > > (r9a09g011) SoC. It can support only 100kHz and 400KHz > > operation. > > > > > > > > > > ... > > > > All other suggested changes are ok. > > > > > > > > > > > > > > > > + pm_runtime_get_sync(dev); > > > > > > > > > > > > pm_runtime_resume_and_get() ;-) > > > > > > > > > > This makes sense only if we test for error. Otherwise the put might > > > > > imbalance > > > > > counter. > > > > I added code to check the return value and to my surprise it returned > > > > -EACCES. > > > > Some digging later, this only happens when I have an i2c controller > > > > enabled that doesn't have any children. > > > > > > > > rpm_resume() returns -EACCES [1] because runtime_status and > > last_status > > > > are set to RPM_SUSPENDED. > > > > > > > > The i2c controller that does have a child has runtime_status = > > RPM_ACTIVE > > > > as there is a call to pm_runtime_resume_and_get() on it due to the i2c > > > > controller performing an i2c transfer for the slave device. > > > > > > > > I am currently struggling to work out why this is happening... > > > > > > First pm_suspend() works it's way down to __pm_runtime_disable(): > > > __pm_runtime_disable+0x134/0x1e0 > > > __device_suspend_late+0x28/0x1c4 > > > dpm_suspend_late+0x158/0x230 > > > suspend_devices_and_enter+0x1c8/0x4b4 > > > pm_suspend+0x210/0x28c > > > At the end of which, runtime_status and last_status are both > > RPM_SUSPENDED, > > > and disable_depth = 1 [1] > > > > > > After that rzv2m_i2c_suspend() is called triggering the EACCES error > > > condition [2]: > > > rpm_resume+0x338/0x630 > > > __pm_runtime_resume+0x4c/0x80 > > > rzv2m_i2c_suspend+0x24/0xb0 > > > pm_generic_suspend_noirq+0x30/0x50 > > > genpd_finish_suspend+0xb0/0x130 > > > genpd_suspend_noirq+0x14/0x20 > > > __device_suspend_noirq+0x68/0x1d0 > > > dpm_noirq_suspend_devices+0x110/0x1dc > > > dpm_suspend_noirq+0x24/0xa0 > > > suspend_devices_and_enter+0x2f0/0x4b4 > > > pm_suspend+0x210/0x28c > > > > > > I think using runtime PM from within driver suspend/resume is simply not > > > supported. However I had some difficulty following the runtime PM code, > > > so I could be wrong. > > > > Oh, it's a NOIRQ system sleep op. You indeed cannot use runtime resume > > from such a callback, as the latter may sleep. > Thanks for confirming this. > > I believe i2c controller driver should use NOIRQ system sleep ops as i2c > children may need to send I2C messages during suspend, and the noirq > sleep ops are called after the late sleep ops (used by some i2c children > drivers). > > So should I just use clk_prepare_enable() and clk_prepare_enable() > within the i2c controller's suspend and resume? That's one option. There's also i2c_mark_adapter_suspended(). And if you care about sending messages in atomic/noirq context, you want to implement i2c_algorithm.master_xfer_atomic(). You may want to have a look at drivers/i2c/busses/i2c-sh_mobile.c, which is used to control the PMIC on R-Car SoCs. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds