Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1445860rwb; Thu, 10 Nov 2022 16:39:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf6+8evARlzfAwc/9jmtAEIr60CdJn2uQQwVRYz3+0Kd1z25o4H+lcLJM6nj1lOvvLFY42Qa X-Received: by 2002:a17:903:12c6:b0:186:5f86:da41 with SMTP id io6-20020a17090312c600b001865f86da41mr157504plb.73.1668127158056; Thu, 10 Nov 2022 16:39:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668127158; cv=none; d=google.com; s=arc-20160816; b=cxRhVKYyojjst7bLNfOvz5pTgxItk6N7tg0bsR4rIo8wXjY1ngOY1QSTFTTL2V06dM gV1kgSqcSgKsLrjynBJA+jobGd5pN2w+3ao30tx+t8F58Gc+Tra7YqvEycZ8t1AnpiUs LQaXsTMcycORh1Zfvx7jggUApCqBaY9WlGD2QPQkDGMX1gr2P+u/kYZUH5SK0tb7ZXP8 Vp5EE9ydztpDG5fK3xg9SDKhiQgI61xPkl+/qRB7+196+Oo9eOAGijPimuFNuamprqe6 RrpRTCUOIRQEnv1TTHmhEBonG5iFIyfh4rlrsazoRlVuubtYOpgcg0jcKZ9Cp3vzKF+/ fIdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=rgBWPJbei+FelwuPjDXn2dCEJUPh8F3/6uN4AZp70/o=; b=R16iTGwssiMnzwg3pJb8V1Usm8NznnsuYBqGenFeCu4mP/ytmN/XhIYTmZ06fI10/e woIH+m0M9VKpxAFlosmW+YWQRQxis9su+HOgzwFCt3SwTKETOl1Wm6CE1+aVA3sUPiNg Xclan6fv2GKAI/84vv+jWjhqKuXE6GmDsd3mSNSMfu72RGAsTcRpORj8jnORECBnRMIp 47lGK9/0C/pFmRBaWnjD4N2bA8QmgWAEWPtIFAGAl6Qwn6i4Xl91bS30YaN9MphxAcAt X1q0I5P2eE9L4Pc+x8w9kdjYST6CuA8QstMog3bwnHsgueHbooZp23RL465i5XDZSCk1 Hmrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ETy1FVWP; 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 oj17-20020a17090b4d9100b002130d0f6df8si1246917pjb.30.2022.11.10.16.39.05; Thu, 10 Nov 2022 16:39:18 -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=ETy1FVWP; 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 S230377AbiKKAUk (ORCPT + 92 others); Thu, 10 Nov 2022 19:20:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbiKKAUh (ORCPT ); Thu, 10 Nov 2022 19:20:37 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CD3A43865 for ; Thu, 10 Nov 2022 16:20:36 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id d59-20020a17090a6f4100b00213202d77e1so6378134pjk.2 for ; Thu, 10 Nov 2022 16:20:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=rgBWPJbei+FelwuPjDXn2dCEJUPh8F3/6uN4AZp70/o=; b=ETy1FVWPcrAfX01GsufjlOq61UfvWACkc/LKVL66MjfHjAL8Mvu607O5U9QmA5KaRJ 4iVw+0ZaYGBQeY246vJjOs+L0vrAMy1jViTZVtjzudQJ11osmTlfqAq8yJKRbW1zk8tI IDdPCv9LvmwB/SAiGsanFDk7hpN2aeztYysA0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rgBWPJbei+FelwuPjDXn2dCEJUPh8F3/6uN4AZp70/o=; b=cs0BSKxhT/jzcFIA9R0aX8tk4s0NVnUWgZnHAWlY29ylnshJtFlfjq5F+1OFR2fqc0 gPnOobz+gpBjQ7UWgMtFsKPP/Ac19vzwq+EW+ZALyQyskcdrMZpYP2YarzCy8TIxhnX4 aP7egMMAb1zMsQLK7i0k5eC2I8MhGIfRoALCkw/+yEmtgyo23Gnpg3P3Mikv+Pozz7nt vpoDajWHkoxzKB3Hr+av14j+mpTbwXGbhLETx21LpHVIXHEJsvi2Q/xRJO6l9TAfP3JQ lOgITE+s6CHB8BnC+/37CgXwrWI5x0C26hTk1VVkLWgeg5ji0EgL4emgeujizFyHH1Hx XgSQ== X-Gm-Message-State: ACrzQf0FHfzJkx1qz8I975CkPW29B2StVrm0+aI6hs/y2r0Rf2mmgEqz lssLq2Hk0DbT0axScwIxyEJzBA== X-Received: by 2002:a17:90a:194b:b0:212:e521:7cbd with SMTP id 11-20020a17090a194b00b00212e5217cbdmr2767295pjh.230.1668126035895; Thu, 10 Nov 2022 16:20:35 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:729a:7662:547f:f4a3]) by smtp.gmail.com with ESMTPSA id u14-20020a170903124e00b001869394a372sm259473plh.201.2022.11.10.16.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 16:20:35 -0800 (PST) Date: Fri, 11 Nov 2022 09:20:32 +0900 From: Hidenori Kobayashi To: Ricardo Ribalda Cc: Wolfram Sang , Tomasz Figa , "Rafael J. Wysocki" , stable@vger.kernel.org, linux-i2c@vger.kernel.org, Sergey Senozhatsky , Sakari Ailus , linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 1/1] i2c: Restore initial power state when we are done. Message-ID: <20221111002032.b7j3cizpe5nbj6id@google.com> References: <20221109-i2c-waive-v5-0-2839667f8f6a@chromium.org> <20221109-i2c-waive-v5-1-2839667f8f6a@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221109-i2c-waive-v5-1-2839667f8f6a@chromium.org> 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 Hi Ricardo, On Thu, Nov 10, 2022 at 05:20:39PM +0100, Ricardo Ribalda wrote: > 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. > > Reviewed-by: Sakari Ailus > Cc: stable@vger.kernel.org > Fixes: b18c1ad685d9 ("i2c: Allow an ACPI driver to manage the device's power state during probe") > Signed-off-by: Ricardo Ribalda It's much easier to read now. Thanks! Reviewed-by: Hidenori Kobayashi > diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c > index b4edf10e8fd0..6f4974c76404 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 do_power_on; > 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)); > + do_power_on = !i2c_acpi_waive_d0_probe(dev); > + status = dev_pm_domain_attach(&client->dev, do_power_on); > 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->power_off_on_remove = do_power_on; > + > 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, do_power_on); > 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->power_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..eba83bc5459e 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. > + * @power_off_on_remove: Record if we have turned on the device before probing > + * so we can turn off the device at removal. > * > * 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,8 @@ struct i2c_client { > i2c_slave_cb_t slave_cb; /* callback for slave mode */ > #endif > void *devres_group_id; /* ID of probe devres group */ > + bool power_off_on_remove; /* if device needs to be turned */ > + /* off by framework at removal */ > }; > #define to_i2c_client(d) container_of(d, struct i2c_client, dev) > > > -- > b4 0.11.0-dev-d93f8 >