Received: by 2002:ab2:3c46:0:b0:1f5:f2ab:c469 with SMTP id x6csp149527lqf; Fri, 26 Apr 2024 02:29:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW9YOhLrU3GgpiAs3Pe7m93/qnwX2HWXPcNfWuy0pW/VcVZm1fcn/UNZ6eFeanBrZocoeZEgotX9TThyin7eJJmlzScqrLbRw6i8cH1ww== X-Google-Smtp-Source: AGHT+IFmPSHYJf9AMZPlE4t6UhyH2rGGB5/Vz82evQo+0KURoEs7seskQqMQpKLzBbY2ZHgM/dgc X-Received: by 2002:a05:6a00:895:b0:6ec:ed90:65ea with SMTP id q21-20020a056a00089500b006eced9065eamr2616849pfj.32.1714123796250; Fri, 26 Apr 2024 02:29:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714123796; cv=pass; d=google.com; s=arc-20160816; b=X2RL4njnh4VdxwpriulSeHP3gayLbW6FSO0HA/YnBEWPMBgad/09KJDN2J0MERMD1c aBcQ/Sfm3hJev9E9iO52exSwdQYuaN5QuRVDLE7Is9IT2QalgQZ5K3gVM3dtnb1RvTgM W+X17T/AW3aIow2i4avO0peEjoORc/b67ExltUzGY2Sdc66x8yWOLMB/2kte1vxZLrcq gh2BCZ3l5HA2IKECI4yf9WUX5+4HoMDWXYuKeFB6Nzto81AEie6Z4lceTyLvdSiPXszC //cLK8c8UMxe9Qs7iCJmoOsaR0JhCsyGk67e6WyDZK2x59R7w/Yws6xpBkVbheTIvL6f U5Wg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Ph0btD+NA88u9GqLbF09PkMwf5YgzOPgC0N/B04oNmY=; fh=iPbur1nbRtkjKVEHT+mvWfgrgtnfYPdFiJPlavfpbL8=; b=l2Ei48ob7ObQT1kJjXdsUgbvZY/UNCIAe8JyX8wD5GDzisGq1fyYbOBDH6em0nTRlG YLUHuCa2/wW9Y+qKDPz2qajMeQwkLajZ60Y5gi78c+yp6+5cTPRgMqwB8xTqlAPDSlu4 KDelLfGZm1C/GuWq9cMCyzQsjzfTYoY1rz+xeTE+tZQeu21pnH+Zl/O26sdH4y2rYTf9 EeIA6M1EIczrJOgJrJMxN90h2/ck0LkC285iu8TOsH4zZqCdb2XNL1+3i5tsohnWbQ9H +DR+iQOTHdzJBph0Q1PVfOh8xMBftS+XX3OJVmOLgj+qOvX4X5q1WTlc2YiTkuaUIJ/G CwJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iUqfNMNx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-159786-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c10-20020aa7880a000000b006ed4a9726besi14673753pfo.295.2024.04.26.02.29.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 02:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159786-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iUqfNMNx; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-159786-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159786-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 6245BB214D4 for ; Fri, 26 Apr 2024 09:29:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA2F713F422; Fri, 26 Apr 2024 09:29:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iUqfNMNx" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2F6E282EA; Fri, 26 Apr 2024 09:29:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714123777; cv=none; b=NZw9opJd2mLUZvFn+99J+qEYd6cgaDBMiSbJUbEbSuW/UeLShLl2SZHK7R8DpC5WbGJxtoGAARA0Mqz76kfr5bZjxdO39o7R26de9D574Crcy34yYpyLXmCSLswMmDzFc8LHAwRwo8xknkQs0OTK07rH1odcnrC2YVAq7m/gzzo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714123777; c=relaxed/simple; bh=G92cwOhiPQS7Q5kYfxITNoEUqeEw92zFYUHW/hjpagc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=L38RMI+afYhO4VFneyqOYXFUvRpVL+rtcYZal1mCAqUGd/MUoN1BV7zfWqyjuTtezYNYV42tHsPmmFCvKDEHC3NefepgXjA4igvWjYvVqMIEMiNV1GzyouhKIqULfgHFAaXCJOFkM9LNhLJADsTz3nPQedtcRw13FFCxBNwAMwY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iUqfNMNx; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FEFFC113CD; Fri, 26 Apr 2024 09:29:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714123776; bh=G92cwOhiPQS7Q5kYfxITNoEUqeEw92zFYUHW/hjpagc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iUqfNMNx7JSRrAXJvJBDJUeXLvPKDz8+GVpkqVRdxY8z9KaXmz7RK1sJrVTaBoWPN G6/3K2PysJY3ClJtgvNibwmWEkunQAum87+eIuagiO5CUZrF5DDT9cKB+RY2FwW4Cv f8BPBuSBFlgwSuXLihSNJVed/2hojzyyvxBz418X2mShdemMwpFL+fcSyy8UbqiDHA Bg021h3Yb4LJFb+V5xR1wuk+M9V+r1MkPtCjw6shabcUp2tbVUFpgB0ZudWKRC9Uwz rAOlGqCTRMC6PdBN8+WLgGbOhUZkwGXQomf510wCITZF+dUK9fU6KfynyNlUKkRmzC dOnPOFUhtjE+g== Received: from johan by xi.lan with local (Exim 4.97.1) (envelope-from ) id 1s0Htg-000000001bi-4A4q; Fri, 26 Apr 2024 11:29:37 +0200 Date: Fri, 26 Apr 2024 11:29:36 +0200 From: Johan Hovold To: Doug Anderson Cc: Johan Hovold , Jiri Kosina , Benjamin Tissoires , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio , Linus Walleij , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 4/6] HID: i2c-hid: elan: fix reset suspend current leakage Message-ID: References: <20240423134611.31979-1-johan+linaro@kernel.org> <20240423134611.31979-5-johan+linaro@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Apr 24, 2024 at 09:24:33AM -0700, Doug Anderson wrote: > On Wed, Apr 24, 2024 at 3:56 AM Johan Hovold wrote: > > On Tue, Apr 23, 2024 at 01:37:14PM -0700, Doug Anderson wrote: > > > On Tue, Apr 23, 2024 at 6:46 AM Johan Hovold wrote: > > > > @@ -87,12 +104,14 @@ static int i2c_hid_of_elan_probe(struct i2c_client *client) > > > > ihid_elan->ops.power_up = elan_i2c_hid_power_up; > > > > ihid_elan->ops.power_down = elan_i2c_hid_power_down; > > > > > > > > - /* Start out with reset asserted */ > > > > - ihid_elan->reset_gpio = > > > > - devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH); > > > > + ihid_elan->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", > > > > + GPIOD_ASIS); > > > > > > I'm not a huge fan of this part of the change. It feels like the GPIO > > > state should be initialized by the probe function. Right before we > > > call i2c_hid_core_probe() we should be in the state of "powered off" > > > and the reset line should be in a consistent state. If > > > "no_reset_on_power_off" then it should be de-asserted. Else it should > > > be asserted. > > Second, the device is not necessarily in the "powered off" state > > Logically, the driver treats it as being in "powered off" state, > though. That's why the i2c-hid core makes the call to power it on. IMO > we should strive to make it more of a consistent state, not less of > one. That's not really true. The device is often in an undefined power state and we try to make sure that the hand over is as smooth as possible to avoid resetting displays and similar unnecessarily. The power-on sequence is what brings the device into a defined power state. > > as the > > driver leaves the power supplies in whatever state that the boot > > firmware left them in. > > I guess it depends on the regulator. ;-) For GPIO-regulators they > aren't in whatever state the boot firmware left them in. For non-GPIO > regulators we (usually) do preserve the state that the boot firmware > left them in. Even for GPIO regulators we have the "regulator-boot-on" devicetree property which is supposed to be set if the boot firmware has left a regulator on so that the regulator initialisation can preserve the state. > > Not immediately asserting reset and instead leaving it in the state that > > the boot firmware left it in is also no different from what happens when > > a probe function bails out before requesting the reset line. > > > > > I think GPIOD_ASIS doesn't actually do anything useful for you, right? > > > i2c_hid_core_probe() will power on and the first thing that'll happen > > > there is that the reset line will be unconditionally asserted. > > > > It avoids asserting reset before we need to and thus also avoid the need > > to deassert it on early probe failures (e.g. if one of the regulator > > lookups fails). > > I guess so, though I'm of the opinion that we should be robust against > the state that firmware left things in. The firmware's job is to boot > the kernel and make sure that the system is running in a safe/reliable > way, not to optimize the power consumption of the board. Agreed. > If the > firmware left the line configured as "output low" then you'd let that > stand. If it's important for the line to be left in a certain state, > isn't it better to make that explicit? As I pointed out above we already do this for any error paths before requesting the reset line. And I also don't think we need to worry too much about power consumption in case of errors. But there is one case I had not considered before, and that is your gpio regulator example but where the boot-on flag does not match the actual regulator state. If the supply is on and reset deasserted, but the regulator-boot-on flag is not set, then we want to make sure that reset is asserted before disabling the supply when requesting the regulator. > Also note: if we really end up keeping GPIOD_ASIS, which I'm still not > convinced is the right move, the docs seem to imply that you need to > explicitly set a direction before using it. Your current patch doesn't > do that. You're right. It will work in my case because of the gpiolib open-drain implementation, but not generally. I'll add back the reset during early probe and add error handling for deasserting reset on machines like the X13s. On these, the touchscreen may now be reset a couple of times in case of probe deferrals, but device links should generally prevent that. Johan