Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp574440lqh; Tue, 7 May 2024 07:50:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW4j5gQIi/SWx178xWugeM0bMaS2yysvv+hryXZoNnxJRdqCrL/aQ4a8ICYBde6O8T/+7ZP7Mp/kKsA7K2DL3NpuwwsyrcieSDG8/BAyg== X-Google-Smtp-Source: AGHT+IFzthDgkL2YLRWfa366GIz7XS/NjLFtAQg9bS6E3pabrvoCpjTVYrIqDkIGF1f8wYte40c+ X-Received: by 2002:a05:620a:831a:b0:790:f7e2:9eaa with SMTP id pa26-20020a05620a831a00b00790f7e29eaamr12827320qkn.40.1715093450741; Tue, 07 May 2024 07:50:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715093450; cv=pass; d=google.com; s=arc-20160816; b=Z+eP6VI/gqNdEhERIAh4SX3gvj8CkOfAXTtv+R4j0EhslckVdhKxWe3fzuHcHx0Ldr CS0j6TF9nq9kmTie04YahAO1TnpSOkFNOlf2CTJhwTyhgjE2PlVNgz5vWNPN8E1c5v/x o0jrx0QnfbJNZ5D2koahwBo9ttvpPVlQ/LUi9ogcck8ER9uTgajUn2vJK/rryifdKYhK JLVNpKfjr4D/qzCzgO43UVSSbci9FkJ+gtGRSK/CY+4rHqs5uJNQBxIjFaZd8IRyXnqB uTJ2C7TJYROBZOstHNOm1+h4EfqfqmZRsJysmGJPLDMJ+hauWbF7M/otOsYMQ4OUsH6z vKjg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UwJlNjAwlNHePyCla8Ax1XhpW185K8DKCk9uYyzGrxE=; fh=bmdOdqUamwvW1ytNfOhOERrYqkmSTVRKLZmZfy5T3mY=; b=a9W/YGr+xOX42b2hg187/UWhwn+AfsHGR0AXqZWKQkvrLj5JPOW3EIf0p3gHzLYYp2 /x0tw5Bq3BW1+/zXBrnxmvM5905ftZgnTAoRMbGuku0BSfuDGnn0b+WBsftENXGdCaMJ d08p7L0auzZK+T4/7W6i8UxtSLwoemDabfsn4r1foHoDcMrknNYCvmQQsNBAaAamwoFD +MT0rBmLWwj+iFMSDCqaCCUBtjvmbaJk8haq+kRV4mZqHwCztC8L6S/y1auSZzwrmuiv LVI4oZovvcV0vfk8A8aELgwm45XzKcCSx64dlzBvT4M+Q6nTj8H1xntOplzWDqb0wMXq lS2w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N4CKJ8Ee; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171618-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171618-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 z6-20020ae9f446000000b007929c2d72adsi3776365qkl.460.2024.05.07.07.50.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 07:50:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-171618-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=N4CKJ8Ee; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-171618-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-171618-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 682E61C236FF for ; Tue, 7 May 2024 14:50:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D916116C6A8; Tue, 7 May 2024 14:48:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N4CKJ8Ee" 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 C71EF161327; Tue, 7 May 2024 14:48:50 +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=1715093330; cv=none; b=CtKUU8gsJyy4bvJiYEfF1ucs5SAe3t+LjtK/OaRG0oZ0plZF+zKgK5FG4i/e01E5rhOirjkKE9wPGQmoAVEuwX56OSNSB+zwTOmRBjOAIIMqyfxjqRVazQm3cG3is7DbYA8AUFvI66hs1zISt5WFEO26OvWe+mqZDJGKGBSCvgU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715093330; c=relaxed/simple; bh=ZGUlbQ7dRiwmfFZzy/vMmEaZuterDFUAiXiGbZMveFc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k5PIuoftMDeTPnCzdpulsFy1lBmmlwQs/XX1QtfoTCju12X/FzudwRvtBcgQ0ygRChxVN936EStTENh9TbngENeVsxflGKQ5EDtZAkVnKIGM1nBxudKufGyq1qhFUAh46FeTarjr6DKU8UaiWLFbQR5bCLtMI2FVtST2WpSb4V8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N4CKJ8Ee; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45F66C4DDE2; Tue, 7 May 2024 14:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715093330; bh=ZGUlbQ7dRiwmfFZzy/vMmEaZuterDFUAiXiGbZMveFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N4CKJ8Ee0uU2em/ltjSb1fiFRGxoQs8zPYUcsCRIxMH/ghJLUjHaeG3tsarobxthu dK/qElcXQuqx633Yr4Bs1l61uSWeKwDb7YpxjGOh3+xK1rWDbZFMD/BdNEESPzrKaB ETRuvZMxKq2e4Q0zum3KzTmnWVeTQGWgfAi7NJX6H+0+eb9AkGsg4RT5hillWXeWqw 8vkX0LzsajuIm+hcirkrlNxf3OGtlcGkZs+hLN34HTetOxClP1y3zR53O+rqJPPqYf 20Y68aLflCPOGkMaFIXxn33cXlorhAEzf4Ayz8qqIIpZ1AU24DQnyzixrPgFN8OdXD UxDuC5SDbDBaA== Received: from johan by xi.lan with local (Exim 4.97.1) (envelope-from ) id 1s4M7g-000000003Cu-2Pvk; Tue, 07 May 2024 16:48:52 +0200 From: Johan Hovold To: Jiri Kosina , Benjamin Tissoires , Bjorn Andersson Cc: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Konrad Dybcio , Linus Walleij , Douglas Anderson , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Steev Klimaszewski Subject: [PATCH v2 4/7] HID: i2c-hid: elan: fix reset suspend current leakage Date: Tue, 7 May 2024 16:48:18 +0200 Message-ID: <20240507144821.12275-5-johan+linaro@kernel.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240507144821.12275-1-johan+linaro@kernel.org> References: <20240507144821.12275-1-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-Transfer-Encoding: 8bit The Elan eKTH5015M touch controller found on the Lenovo ThinkPad X13s shares the VCC33 supply with other peripherals that may remain powered during suspend (e.g. when enabled as wakeup sources). The reset line is also wired so that it can be left deasserted when the supply is off. This is important as it avoids holding the controller in reset for extended periods of time when it remains powered, which can lead to increased power consumption, and also avoids leaking current through the X13s reset circuitry during suspend (and after driver unbind). Use the new 'no-reset-on-power-off' devicetree property to determine when reset needs to be asserted on power down. Notably this also avoids wasting power on machine variants without a touchscreen for which the driver would otherwise exit probe with reset asserted. Fixes: bd3cba00dcc6 ("HID: i2c-hid: elan: Add support for Elan eKTH6915 i2c-hid touchscreens") Cc: stable@vger.kernel.org # 6.0 Cc: Douglas Anderson Tested-by: Steev Klimaszewski Signed-off-by: Johan Hovold --- drivers/hid/i2c-hid/i2c-hid-of-elan.c | 59 +++++++++++++++++++++------ 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid-of-elan.c b/drivers/hid/i2c-hid/i2c-hid-of-elan.c index 5b91fb106cfc..091e37933225 100644 --- a/drivers/hid/i2c-hid/i2c-hid-of-elan.c +++ b/drivers/hid/i2c-hid/i2c-hid-of-elan.c @@ -31,6 +31,7 @@ struct i2c_hid_of_elan { struct regulator *vcc33; struct regulator *vccio; struct gpio_desc *reset_gpio; + bool no_reset_on_power_off; const struct elan_i2c_hid_chip_data *chip_data; }; @@ -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); + 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); + + return ret; } static void elan_i2c_hid_power_down(struct i2chid_ops *ops) @@ -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); @@ -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"); + ihid_elan->vccio = devm_regulator_get(&client->dev, "vccio"); - if (IS_ERR(ihid_elan->vccio)) - return PTR_ERR(ihid_elan->vccio); + if (IS_ERR(ihid_elan->vccio)) { + ret = PTR_ERR(ihid_elan->vccio); + goto err_deassert_reset; + } ihid_elan->chip_data = device_get_match_data(&client->dev); if (ihid_elan->chip_data->main_supply_name) { ihid_elan->vcc33 = devm_regulator_get(&client->dev, ihid_elan->chip_data->main_supply_name); - if (IS_ERR(ihid_elan->vcc33)) - return PTR_ERR(ihid_elan->vcc33); + if (IS_ERR(ihid_elan->vcc33)) { + ret = PTR_ERR(ihid_elan->vcc33); + goto err_deassert_reset; + } } - return i2c_hid_core_probe(client, &ihid_elan->ops, - ihid_elan->chip_data->hid_descriptor_address, 0); + ret = i2c_hid_core_probe(client, &ihid_elan->ops, + ihid_elan->chip_data->hid_descriptor_address, 0); + if (ret) + goto err_deassert_reset; + + return 0; + +err_deassert_reset: + if (ihid_elan->no_reset_on_power_off) + gpiod_set_value_cansleep(ihid_elan->reset_gpio, 0); + + return ret; } static const struct elan_i2c_hid_chip_data elan_ekth6915_chip_data = { -- 2.43.2