Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2393457lqo; Mon, 20 May 2024 04:44:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXYUVHKIdu/2DZbeoy5WuoqVa5BLiXx8LXgfnZ7iHZiem3rLGKbbwd7F4NIET6fA7+2eTgfnmEUoYTNleWPZg4cDiywOe2+b9kKwLBFSg== X-Google-Smtp-Source: AGHT+IH03y/4gmnm7UtVGX01ZXYdExbgZNDkncR4p5cYQwl+JMauqT1ZNIrsbeFHjzgKbSYwDu/V X-Received: by 2002:a25:8142:0:b0:de8:bdd3:c113 with SMTP id 3f1490d57ef6-dee4f1a6bd9mr24543556276.25.1716205462486; Mon, 20 May 2024 04:44:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716205462; cv=pass; d=google.com; s=arc-20160816; b=N+14KpNN7BFuKh3SUa+ne95FNCTbNC/212fMpGMN0/7R0IpMOVJouSDgYGA4DA5oJE CAzkEyDJZ2uNS9dUvSSDFfcn2oQanEKHHXp5vE5LF9jp2pUReJnc6wTey6GeDwH3ncQA wnWcAnJlg+fObnKPKAIwsDFm5MtRg+q8tW6Rg+fkMIEOCb61fehidgnayC7/8o5c4dau 9q2t6jGz/xmgDOoauwHOSg2NOXN/oahIVzk5AteRnbokOpPtOn2yAnjNxOH/vZIN+6id TkSgH/2fQCJ6oQextxupv80+47ZSOVewQdfu8ROh8mHBFQS6qdvTevwL+Fy7a+OnsH73 ri3Q== 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=MfHPWVERiM3JcdOXsayW48lxmLCVqT1Mb85if9txXR0=; fh=gm1UZYh7W9K2T8s/K5d38/pBSAt/tm9l1453yLPretA=; b=FfJHCpmecsR62qwTX46q+UiC3/XEhw8H/F1h5Utnh2RZF32UzsW3XpqIT2IfTLmcWl rYG6GyaqnYbxIyF9JfPkM0XixgSNTuRKTSQpvHU4bddFrwNoQ4fPeNH7xSkd9fczYAXg cgH8iFICTtxLMDr2Qa8kZvM3qoNzuz8hRpuUl6Y8mTYFV9+pk+kUnji6EZrfR3FHbjW9 BG3x9hCaRpmoFvmUTnnc+D+AhLmAs7IEerCTderFm+Df/r5AjEgJnNQOxKt14Z+a6GRx wrV+MS7opU7q+emt1K9+2RSibfL1WI60YjYjuDN7iNjZAJ8YSs5x7cWI5LYBbL2KSMMv Yxkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FdrfVpyt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-183670-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183670-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f2b7492si249471966d6.379.2024.05.20.04.44.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 04:44:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183670-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FdrfVpyt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-183670-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183670-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 2B0461C21DAA for ; Mon, 20 May 2024 11:44:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DB6C53E31; Mon, 20 May 2024 11:44:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FdrfVpyt" 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 1FE7936134; Mon, 20 May 2024 11:44:10 +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=1716205451; cv=none; b=BkPHHmoyO6ts2BLqUGqXXjL3BGrh1I5qsa5s+Be071PMJLq8P1P6luaogopoz3/neA3cNv0zJ2g9jF9dPCTYvdH46sjqsLACD9F6UCwCSmBfuON7VPhAl8tsSt2ggd3BwGsvduWylobjwEWFbK9p9p4ezpHJiSZ4DGAJSTAw07g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716205451; c=relaxed/simple; bh=JrKEV3MF4JISD4JRKbt9/nLI81LbwnOvu1GLB3l2fNU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jInXotTqNF1l3iasUvVFEo8W9Hrn3UjEDT8xWeAgn6SeIDqT/iQay/3jFLcKQQyA7GZftxBUsN7iuBV6buD6SALSqcdyq+J54f8qloF4VE4o21qimMF0DqscTaTWisWD8oQ4AsF/tFGi1aflzIgK6olZrOh50tr1YrFwOzAx49A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FdrfVpyt; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99253C2BD10; Mon, 20 May 2024 11:44:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716205450; bh=JrKEV3MF4JISD4JRKbt9/nLI81LbwnOvu1GLB3l2fNU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FdrfVpytjcxGNGVDPVM8RdaPNXxGXcvni6qzf356GNvbFx/CVWMxAkrVW7P7m8Ydo 5QzfzSBBEuwyw109jarhFNUFF1TVcQ6NsGP/i66cbxOgUuBHoHU1TinEb3viwydYn9 GDyFwe2dw1zEukYjAhwlgOi31gHRvgZv8mXPs7c7fpW6v+3q7/CN2jp3xfgYolO4an o9hrWd+PG9SP3+HGvIrBtKlz1rJ9RyrlK8JC+TrFlC9DHZkip3e94tmGZR5gWJqr2r DXsiBU1cFUS18mficfXtS9l3+hWbnfus8ENNWgxJXgfgjkibd/Y1IRVppOdoioZkiL F5a+7CwldBNJQ== Received: from johan by xi.lan with local (Exim 4.97.1) (envelope-from ) id 1s91R0-000000004DR-0DSE; Mon, 20 May 2024 13:44:06 +0200 Date: Mon, 20 May 2024 13:44:06 +0200 From: Johan Hovold To: Doug Anderson Cc: Johan Hovold , Jiri Kosina , Benjamin Tissoires , Bjorn Andersson , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , 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, Steev Klimaszewski Subject: Re: [PATCH v2 4/7] HID: i2c-hid: elan: fix reset suspend current leakage Message-ID: References: <20240507144821.12275-1-johan+linaro@kernel.org> <20240507144821.12275-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: Hi Doug, and sorry about the late reply. Was travelling last week. On Fri, May 10, 2024 at 04:36:08PM -0700, Doug Anderson wrote: > On Tue, May 7, 2024 at 7:48 AM Johan Hovold wrote: > > > > @@ -40,17 +41,17 @@ static int elan_i2c_hid_power_up(struct i2chid_ops *ops) > > container_of(ops, struct i2c_hid_of_elan, ops); > > int ret; > > > > + gpiod_set_value_cansleep(ihid_elan->reset_gpio, 1); > > Could probably use a comment above it saying that this is important > when we have "no_reset_on_power_off" and doesn't do anything bad when > we don't so we can just do it unconditionally. Possibly, but I'd prefer not to add comments for things like this, which should be apparent from just looking at the code. And explicitly asserting reset before deasserting it is not unusual in any way. > > + > > if (ihid_elan->vcc33) { > > ret = regulator_enable(ihid_elan->vcc33); > > if (ret) > > - return ret; > > + goto err_deassert_reset; > > } > > > > ret = regulator_enable(ihid_elan->vccio); > > - if (ret) { > > - regulator_disable(ihid_elan->vcc33); > > - return ret; > > - } > > + if (ret) > > + goto err_disable_vcc33; > > > > if (ihid_elan->chip_data->post_power_delay_ms) > > msleep(ihid_elan->chip_data->post_power_delay_ms); > > @@ -60,6 +61,15 @@ static int elan_i2c_hid_power_up(struct i2chid_ops *ops) > > msleep(ihid_elan->chip_data->post_gpio_reset_on_delay_ms); > > > > return 0; > > + > > +err_disable_vcc33: > > + if (ihid_elan->vcc33) > > + regulator_disable(ihid_elan->vcc33); > > +err_deassert_reset: > > + if (ihid_elan->no_reset_on_power_off) > > + gpiod_set_value_cansleep(ihid_elan->reset_gpio, 0); > > Small nit about the error label: it sounds as if when you go here you > _will_ deassert reset when in actuality you might or might not > (depending on no_reset_on_power_off). Yes, this is similar to how err_disable_vcc33 may or may not disable the optional regulator. > Personally I prefer to label > error jumps based on things I've done instead of things that the error > jump needs to do, so you could call them "err_enabled_vcc33" and > "err_asserted_reset"... Naming labels after what they do is less error prone and also explicitly recommended by the coding style. > I don't feel that strongly about it, though, so if you love the label > you have then no need to change it. So I'd prefer keeping things this way. > > @@ -67,7 +77,14 @@ static void elan_i2c_hid_power_down(struct i2chid_ops *ops) > > struct i2c_hid_of_elan *ihid_elan = > > container_of(ops, struct i2c_hid_of_elan, ops); > > > > - gpiod_set_value_cansleep(ihid_elan->reset_gpio, 1); > > + /* > > + * Do not assert reset when the hardware allows for it to remain > > + * deasserted regardless of the state of the (shared) power supply to > > + * avoid wasting power when the supply is left on. > > + */ > > + if (!ihid_elan->no_reset_on_power_off) > > + gpiod_set_value_cansleep(ihid_elan->reset_gpio, 1); > > + > > if (ihid_elan->chip_data->post_gpio_reset_off_delay_ms) > > msleep(ihid_elan->chip_data->post_gpio_reset_off_delay_ms); > > Shouldn't the above two lines be inside the "if > (!ihid_elan->no_reset_on_power_off)" test? If you're not setting the > reset GPIO then you don't need to do the delay, right? Yes, I guess you're right. The off-delay is weird and not normally used, but apparently it is needed by some panel-follower use case. AFAICT it's not even related to the reset line, just a hack to add a delay before the panel is reset by some other driver (see f2f43bf15d7a ("HID: i2c-hid: elan: Add ili9882t timing")). I think that's why I just looked the other way and left this little oddity here unchanged. > > @@ -79,6 +96,7 @@ static void elan_i2c_hid_power_down(struct i2chid_ops *ops) > > static int i2c_hid_of_elan_probe(struct i2c_client *client) > > { > > struct i2c_hid_of_elan *ihid_elan; > > + int ret; > > > > ihid_elan = devm_kzalloc(&client->dev, sizeof(*ihid_elan), GFP_KERNEL); > > if (!ihid_elan) > > @@ -93,21 +111,38 @@ static int i2c_hid_of_elan_probe(struct i2c_client *client) > > if (IS_ERR(ihid_elan->reset_gpio)) > > return PTR_ERR(ihid_elan->reset_gpio); > > > > + ihid_elan->no_reset_on_power_off = of_property_read_bool(client->dev.of_node, > > + "no-reset-on-power-off"); > > Personally, I'd rather you query for the property before you request > the GPIO and then request the GPIO in the "powered off" state just to > keep everything in the most consistent state possible. No, I don't know what state the reset line is in before the driver probes. So either I leave it unchanged as I did in v1 or I assert it here unconditionally as I do in v2 (e.g. to avoid deasserting reset before the supply is stable). Johan