Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp441773rwb; Thu, 10 Nov 2022 03:04:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf4chotE7646TAICPyU8Lt1mgdpQxh0jmIAwiD9AZf4im+1kp+kYcct1oQQhyxmvo1QMWOHc X-Received: by 2002:a63:df07:0:b0:470:4f30:f743 with SMTP id u7-20020a63df07000000b004704f30f743mr1897999pgg.434.1668078295276; Thu, 10 Nov 2022 03:04:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668078295; cv=none; d=google.com; s=arc-20160816; b=0SeJ5YZu31NEinxWxiDN1kp7u+GfmmXRvl/s8aXTOV0CMPDOBfV1nVuof3UBL4K/bw G9wmorZLrBUoiZ8zReyqTcwlSzpc5477XIVQ0gwPsfJm3/9nPNmx4rmnLquX91ZzjEc2 edfuYdlobDENL9iPKhG1y0JshNVBIZd8H/w8Rr8Vt/BeXTlg/0/7iBCRVvOWKJQfqaFO /3ZEsCRUaOaE8SFQ8OXXOQA502K6xAlvbA/Q81W+FbOTSOUXk8inBP/01Y2qPMfqDHr7 Drubd0h8C287KMxKZrdkCHzhySPz7zsBkZeluZdmjBMCdEBj0iYNooHdIYvvQ9q3G+tE uBeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=pX92ujEcGAc8NiZI5yHP2jRaPWZN895tzcGmZQPOb4E=; b=c8TOCHr/Q70tHYVU/gLJn5u26sn/5hXr+rPstz9f81jKHcIQXFFApAIJUdRsxghLLe 6qo4ZOVVIMUzi/pu3ypke/BPjvOwWIQprEV0DAIOQ1N8RqAtaFhT88sb72ZK9U0k9dSj iylAch80xqx/CMwFwq5VIQRSZBqTOqaXmJ+H28n3rWyR09CFsEx6105ydfXAvwAx23JL 7W8UPnSg0Fj9n/ugxcU/B/qV+32GHsTLJ92o/c9YrkWNay0F36GkT1Fh30N6qL+MPBtw /Go6oGN9IHI1iXmAD+sn8A9IE32xvJgqVXIDxTf0fAOG809CtsxTeShTlCr/2MBg6le/ D8ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JR+G3toO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y8-20020a056a00180800b0055706edd79csi23062886pfa.240.2022.11.10.03.04.41; Thu, 10 Nov 2022 03:04:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JR+G3toO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229645AbiKJKdJ (ORCPT + 93 others); Thu, 10 Nov 2022 05:33:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbiKJKdG (ORCPT ); Thu, 10 Nov 2022 05:33:06 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E21017AA2 for ; Thu, 10 Nov 2022 02:33:05 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id a5so2369421edb.11 for ; Thu, 10 Nov 2022 02:33:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pX92ujEcGAc8NiZI5yHP2jRaPWZN895tzcGmZQPOb4E=; b=JR+G3toOdQeXLiy4cVbuSvTKePnWc3sXXfU8gLJ9sFlX1mm7ErpGupPL394P0bRE68 62O5PakLunRnmyf3N83r4YKVtz6VVdiHaj5koUBYp0s4ZK/8ICkkphJK/iiphh0q1GNK fl655RMqPuBj9Ed9A8kcRsydvUDO3i+UE0HoI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pX92ujEcGAc8NiZI5yHP2jRaPWZN895tzcGmZQPOb4E=; b=Lz2Hflr6sQd8hYTdbd9FiwfAo+QlfwFbGT9Ycs9Dke9PcOZE1UmS8+X51TOkFBuQbd fTq7PSiE12+647us5sNtgBLxFbUnswRufMSf5aSde0RNfDEvMj4Mh//2pnysGfQMEQmI tWihyvzx/HKbtcvlTWnQsLfhVqqVGy43VZBgEnA5mxjlKvbBqLpEqmTpaJiihKHYcUOR gD9cCkS4xVvG7swzq0wMky12h8SqnlYc95Hw9W7AmHcTdNco0eS6uOL5xtwB5SQSwBqE zcV2u0V1xRFV1ghFdIE3Bnb1THSXCQmwBdamWCrnMaCrMZZkvGB4sgadZfH44wmHGyVv d7Rg== X-Gm-Message-State: ACrzQf3DAMgfWSp6LsEyJmEJHCuqoq4OaampmcYXBW45BCy3Nxas9INC jlQG++pcATZEYDkqkj/7UJzBNw== X-Received: by 2002:a05:6402:4d5:b0:459:2b41:3922 with SMTP id n21-20020a05640204d500b004592b413922mr1968947edw.160.1668076384144; Thu, 10 Nov 2022 02:33:04 -0800 (PST) Received: from alco.roam.corp.google.com ([2620:0:1059:10:8565:42a1:677d:6677]) by smtp.gmail.com with ESMTPSA id o5-20020a170906768500b007a1d4944d45sm7137467ejm.142.2022.11.10.02.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 02:33:03 -0800 (PST) From: Ricardo Ribalda Date: Thu, 10 Nov 2022 11:32:49 +0100 Subject: [PATCH v3 1/1] i2c: Restore initial power state when we are done. MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20221109-i2c-waive-v3-1-d8651cb4b88d@chromium.org> References: <20221109-i2c-waive-v3-0-d8651cb4b88d@chromium.org> In-Reply-To: <20221109-i2c-waive-v3-0-d8651cb4b88d@chromium.org> To: Sakari Ailus , Tomasz Figa , "Rafael J. Wysocki" , Wolfram Sang Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , Hidenori Kobayashi X-Mailer: b4 0.11.0-dev-d93f8 X-Developer-Signature: v=1; a=openpgp-sha256; l=3357; i=ribalda@chromium.org; h=from:subject:message-id; bh=4xZlMSZRR+lV69Kk9aqulQA2DYYgaAnAPsqo4aA3H80=; b=owEBbQKS/ZANAwAKAdE30T7POsSIAcsmYgBjbNNcGyLgae/UE26tcRQv2oJssl7CVCij7n2Emrbh HzE7TraJAjMEAAEKAB0WIQREDzjr+/4oCDLSsx7RN9E+zzrEiAUCY2zTXAAKCRDRN9E+zzrEiO2xD/ 9sAKxxaHA2RfafWakiT1INPYALIsD9D5GLOAWO7nWIj+BVugl++ZqUHSB4qA0X1yi4MpxvvlgkDYFC B5qpoYxwElVc28cPQRXEn075JESc8feLMdNDhIZHFnRM1RwUCb2DsKiKWv4vkYvNCo7JquCKGZLZO/ rJHbWbJ2mDVSTfDZh7QQTyr4Ikfbd7y9Ym99Lw1M7QSYlFAy0/xxkYbEg8fMo1F7FxjxevzjxvtQSs UP57e3t8pyN1wOIqSKddxdfKedVDSjiGI9cq8yH8B3O7//Lf7QH0mFt18yGz+8/RkGook5OMd4t5gV KZ2PZ0v8HGssgo/A+o7FxDPnHqChxHVqpXKQvMUaWI0VX+kkR1jrpiluwG92bQFlpQSzOvLnYXsDLL zR/NghkkQ79LhcJQJTD2kFP27VtgTuFIK7wbkhPrxvRwJGFGH7zsBTwRn7TsVvNWQIu9N44P2n8kL+ ayiPmaDt89ndCYcu2ltwarip0Cu/SN4cxg5gAH/p//Dcl531qQNsz60ct4oCiLMt07VxPbD9pfAqrl i+QOCJOHUi+GQKw4BRi1EhM7t/tWP75LHXxHLsmZsoP6lNKmBOPOzjGOAfbweRfqTvL2PMB0X+JnDg nkBg40IP57yU4Dk0Qf4VIEiLDdNqe3aTvBxiHCCuhDlGGzweJHH5Vlg2dv9Q== X-Developer-Key: i=ribalda@chromium.org; a=openpgp; fpr=9EC3BB66E2FC129A6F90B39556A0D81F9F782DA9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A driver that supports I2C_DRV_ACPI_WAIVE_D0_PROBE is not expected to power off a device that it has not powered on previously. For devices operating in "full_power" mode, the first call to `i2c_acpi_waive_d0_probe` will return 0, which means that the device will be turned on with `dev_pm_domain_attach`. If probe fails or the device is removed the second call to `i2c_acpi_waive_d0_probe` will return 1, which means that the device will not be turned off. This is, it will be left in a different power state. Lets fix it. Fixes: b18c1ad685d9 ("i2c: Allow an ACPI driver to manage the device's power state during probe") Signed-off-by: Ricardo Ribalda diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index b4edf10e8fd0..75da19bcfb2b 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -467,6 +467,7 @@ static int i2c_device_probe(struct device *dev) { struct i2c_client *client = i2c_verify_client(dev); struct i2c_driver *driver; + bool full_power; int status; if (!client) @@ -545,8 +546,8 @@ static int i2c_device_probe(struct device *dev) if (status < 0) goto err_clear_wakeup_irq; - status = dev_pm_domain_attach(&client->dev, - !i2c_acpi_waive_d0_probe(dev)); + full_power = !i2c_acpi_waive_d0_probe(dev); + status = dev_pm_domain_attach(&client->dev, full_power); if (status) goto err_clear_wakeup_irq; @@ -580,12 +581,14 @@ static int i2c_device_probe(struct device *dev) if (status) goto err_release_driver_resources; + client->turn_off_on_remove = full_power; + return 0; err_release_driver_resources: devres_release_group(&client->dev, client->devres_group_id); err_detach_pm_domain: - dev_pm_domain_detach(&client->dev, !i2c_acpi_waive_d0_probe(dev)); + dev_pm_domain_detach(&client->dev, full_power); err_clear_wakeup_irq: dev_pm_clear_wake_irq(&client->dev); device_init_wakeup(&client->dev, false); @@ -610,7 +613,7 @@ static void i2c_device_remove(struct device *dev) devres_release_group(&client->dev, client->devres_group_id); - dev_pm_domain_detach(&client->dev, !i2c_acpi_waive_d0_probe(dev)); + dev_pm_domain_detach(&client->dev, client->turn_off_on_remove); dev_pm_clear_wake_irq(&client->dev); device_init_wakeup(&client->dev, false); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index f7c49bbdb8a1..6b2dacb0bae1 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -326,6 +326,8 @@ struct i2c_driver { * calls it to pass on slave events to the slave driver. * @devres_group_id: id of the devres group that will be created for resources * acquired when probing this device. + * @turn_off_on_remove: Record if we have turned on the device before probing + * so we can restore the initial state after remove/probe error. * * An i2c_client identifies a single device (i.e. chip) connected to an * i2c bus. The behaviour exposed to Linux is defined by the driver @@ -355,6 +357,7 @@ struct i2c_client { i2c_slave_cb_t slave_cb; /* callback for slave mode */ #endif void *devres_group_id; /* ID of probe devres group */ + bool turn_off_on_remove; /* power state when done */ }; #define to_i2c_client(d) container_of(d, struct i2c_client, dev) -- b4 0.11.0-dev-d93f8