From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2226438467 for ; Tue, 21 Jul 2026 07:54:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784620464; cv=none; b=t21aTp8razf4wXVdGHCqnfF209IiBbqe+amnP+1d05GrGfbPzalSPDK4d494KDD8Zgi/ICEt9Tbp76N5BzkpcN0weQLABf4FbRVneK16Zz5I301l1GoXEqdXuSCIlThMp3foxdscDlCij7T6js6NjWaw5pRz9otpnWnOq+E8iDk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784620464; c=relaxed/simple; bh=9Ni9zhrtKci5P2BRwTspKb8GrclLS+sUdzCWkor5diY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UcNqO2IC48h7Q8pUbEuANAxok5Fc6ps5mSmVSzrCfZQH29hjLoTND83Dwe+qZGb/cCgpZwQbFy+0b6wu2hCf93EvHD2DR1FXV5HN9ZKTwipB6bUqhD1sDi+90JzpFYvS8Ff7mRW0mJdATNSUEpgKSl/jjkz5JuOCQBuFa4B7NGM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=jtCD3UVT; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jtCD3UVT" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2cacb8416a1so75660785ad.1 for ; Tue, 21 Jul 2026 00:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1784620462; x=1785225262; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7iH2zA1ruu4tS3rL/ntmqLvjt6Xg4qydbdtr1Vk28d0=; b=jtCD3UVTieOZoQqULOsFiXtIiCoplzhCAv/fsA99FqyzfH5Nqxnw59NIdTh3ofLGUW qvtbHKYC16tah68FgbRWN1SeZy6kIrcsQ0YA06NLuzkN3R8jw3Nz4ISvdISJ+XV7U+73 TRgTcJ+BaLButP4eeMzVzTttK+9/r0PnfRElI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784620462; x=1785225262; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=7iH2zA1ruu4tS3rL/ntmqLvjt6Xg4qydbdtr1Vk28d0=; b=NWEIuuQF8kyJtxj/R3+w4doAI+vQyWkSjZK15A0ekxUKhliXV/GUkJK8IymB/SfLFc 3BkPdcfBtpz6Pk7QAMipzCqUK5ueKK5JfvH06vi8ZsKdmq6I6BdUBKhkDj3QEcrqlTRf VKJOIsUG85j0iBsEtq6d5ncsGsx72GV2nBZ4lo2g09dKcP2DFR/bvN54mCS0VrQ9TOaa cWzQpJY5XRCAg1VC7q7vaJjPuqOMU0lrNaqFlGyXvFQBjYNvkauUMRYUL8wkLcnL4ojw 9av7+GncGGrKqm2TSYxkPdop5ivN6w92m16ABowB+u4bY+fkhOy8n7Yn4e3fmcrJQG/+ LZ/g== X-Forwarded-Encrypted: i=1; AHgh+RpomMViMDYGksLi4B09CLpjvGGN71qzLtgfzDo4aDJhgRiZRpc+Rht09AwdsinyFvZjKkKFonDk4aZ79gA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5+kl8hF3sQuE3w/C/87S8H+mmhnbp6hOGL8yFBAHJdVwtGfU4 kYQsPdb+wrK1tYTxJ8BqMKeLAWeH10dJ+7YtZFmo6IQwSE+LJqL/Njb+Xb7n82uGDA== X-Gm-Gg: AfdE7cmfAP2M6KTxE5J/9L2RRR9GhuSpcbPJIFxVeALJHyQ0ysQ0Gbw4Mzgoc4hKbOc VwO0j9weKK7z8x2SxZtJBJV8p2nm8HbGo23ax4I0gh+ekFxx7U5mml2aX79hKzNjzbdCAHiaRF0 oQWLtGE7qbINzko6YdSiZ/An72aZOFbUBzRBk2kNP4McqIQN+zv0N0A+85m/5+tFy2oGK6uu2qa LsCWswRrJ+MMPZEw+PLs7YQC6bkE+fgIJhw5J3MZmLjJzE5QZxkmB/WYzN4VaEgyNb3dlSe+1Yo TzM1DVzv50pJTLq8NuOC19YMQrKf5mJituw93ZeTZsaw3WCn4OdHECox4Qik/e6fvLEOGh8P4UT 9tOm2ERjzzpXjFsXz0s5GBv4Ufz8j13/Bj+TkxFNSyjao3wNYQOIIxguacddts8QXtn8bBqEvWZ WAHIHSRHPmoE9Hd9AfEpWk56gX/E5xGLm6K4arB7DGZheBW5aB71GKWnE33hQ= X-Received: by 2002:a17:902:d586:b0:2cc:df15:91f5 with SMTP id d9443c01a7336-2cf34a2a314mr196331925ad.44.1784620462223; Tue, 21 Jul 2026 00:54:22 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2a00:79e0:201d:8:3916:f048:32c3:931f]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf3448f705sm70724175ad.15.2026.07.21.00.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2026 00:54:21 -0700 (PDT) From: Chen-Yu Tsai To: Matthias Brugger , AngeloGioacchino Del Regno , Benson Leung , Tzung-Bi Shih , Dmitry Torokhov , Jiri Kosina , Andi Shyti Cc: Andy Shevchenko , Chen-Yu Tsai , linux-mediatek@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, chrome-platform@lists.linux.dev, linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/9] i2c: of-prober: Defer regulator_disable() on successful probe in simple helper Date: Tue, 21 Jul 2026 15:52:20 +0800 Message-ID: <20260721075226.2347933-7-wenst@chromium.org> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog In-Reply-To: <20260721075226.2347933-1-wenst@chromium.org> References: <20260721075226.2347933-1-wenst@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When a I2C component is found, it's device node is immediately enabled. This triggers device creation and driver binding. The prober will hold the regulator enable reference across this part. If the driver probes synchronously, then it happens within this window. On the other hand, if the driver probes asynchronously, there is high chance that it happens after the prober's cleanup function was called, in which case the regulator would have been disabled when the driver's probe function is called. This would then require the driver to wait 100 ms for the hardware to reinitialize, even if the probe function was just a split second late and the regulator was disabled a few milliseconds ago. Recently, some of the drivers for the component that are targeted by the I2C OF component prober gained the ability to skip waiting for hardware initialization if the regulator was left enabled. This happens when the PMIC has them on by default, or if the component prober left them on after probing the component. Wait a bit of time before dropping the enable refcount on our end so that the actual driver has the opportunity to catch and increase the refcount on their end. The 100 ms delay was arbitrarily chosen. Signed-off-by: Chen-Yu Tsai --- drivers/i2c/i2c-core-of-prober.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/i2c-core-of-prober.c b/drivers/i2c/i2c-core-of-prober.c index f9f3c0ef93ff..68c929b16b06 100644 --- a/drivers/i2c/i2c-core-of-prober.c +++ b/drivers/i2c/i2c-core-of-prober.c @@ -235,11 +235,23 @@ static int i2c_of_probe_simple_enable_regulator(struct device *dev, struct i2c_o return 0; } -static void i2c_of_probe_simple_disable_regulator(struct device *dev, struct i2c_of_probe_simple_ctx *ctx) +static void i2c_of_probe_simple_disable_regulator(struct device *dev, + struct i2c_of_probe_simple_ctx *ctx, + bool defer_disable) { if (!ctx->supply) return; + /* + * Wait a bit of time for async drivers to probe and increase the + * regulator enable count. This allows the drivers to check and + * skip waiting for re-initialization. + */ + if (defer_disable) { + dev_dbg(dev, "Deferring regulator disable\n"); + msleep(100); + } + dev_dbg(dev, "Disabling regulator supply \"%s\"\n", ctx->opts->supply_name); regulator_disable(ctx->supply); @@ -356,7 +368,7 @@ int i2c_of_probe_simple_enable(struct device *dev, struct device_node *bus_node, return 0; out_disable_regulator: - i2c_of_probe_simple_disable_regulator(dev, ctx); + i2c_of_probe_simple_disable_regulator(dev, ctx, false); out_put_gpiod: i2c_of_probe_simple_put_gpiod(ctx); out_put_supply: @@ -401,7 +413,7 @@ void i2c_of_probe_simple_cleanup(struct device *dev, void *data) i2c_of_probe_simple_disable_gpio(dev, ctx); i2c_of_probe_simple_put_gpiod(ctx); - i2c_of_probe_simple_disable_regulator(dev, ctx); + i2c_of_probe_simple_disable_regulator(dev, ctx, true); i2c_of_probe_simple_put_supply(ctx); } EXPORT_SYMBOL_NS_GPL(i2c_of_probe_simple_cleanup, "I2C_OF_PROBER"); -- 2.55.0.229.g6434b31f56-goog