From patchwork Mon Aug 26 08:31:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 11114253 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6923314DE for ; Mon, 26 Aug 2019 08:32:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4F6F12080C for ; Mon, 26 Aug 2019 08:32:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730630AbfHZIcc (ORCPT ); Mon, 26 Aug 2019 04:32:32 -0400 Received: from mga14.intel.com ([192.55.52.115]:42753 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729841AbfHZIc2 (ORCPT ); Mon, 26 Aug 2019 04:32:28 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 01:32:27 -0700 X-IronPort-AV: E=Sophos;i="5.64,431,1559545200"; d="scan'208";a="263867644" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 01:32:25 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 95CE220B47; Mon, 26 Aug 2019 11:32:23 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1i2APB-0002KB-3y; Mon, 26 Aug 2019 11:31:13 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH v2 1/5] ACPI: Enable driver and firmware hints to control power at probe time Date: Mon, 26 Aug 2019 11:31:08 +0300 Message-Id: <20190826083112.8888-2-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190826083112.8888-1-sakari.ailus@linux.intel.com> References: <20190826083112.8888-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Allow drivers and firmware tell ACPI that there's no need to power on a device for probe. This requires both a hint from the firmware as well as an indication from a driver to leave the device off. Signed-off-by: Sakari Ailus --- drivers/acpi/device_pm.c | 15 +++++++++++++-- include/linux/device.h | 7 +++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index f616b16c1f0be..adcdf78ce4de8 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1276,7 +1276,12 @@ static void acpi_dev_pm_detach(struct device *dev, bool power_off) if (adev && dev->pm_domain == &acpi_general_pm_domain) { dev_pm_domain_set(dev, NULL); acpi_remove_pm_notifier(adev); - if (power_off) { + if (power_off +#ifdef CONFIG_PM + && !(dev->driver->probe_low_power && + device_property_present(dev, "probe-low-power")) +#endif + ) { /* * If the device's PM QoS resume latency limit or flags * have been exposed to user space, they have to be @@ -1324,7 +1329,13 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on) acpi_add_pm_notifier(adev, dev, acpi_pm_notify_work_func); dev_pm_domain_set(dev, &acpi_general_pm_domain); - if (power_on) { + + if (power_on +#ifdef CONFIG_PM + && !(dev->driver->probe_low_power && + device_property_present(dev, "probe-low-power")) +#endif + ) { acpi_dev_pm_full_power(adev); acpi_device_wakeup_disable(adev); } diff --git a/include/linux/device.h b/include/linux/device.h index 6717adee33f01..4bc0ea4a3201a 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -248,6 +248,12 @@ enum probe_type { * @owner: The module owner. * @mod_name: Used for built-in modules. * @suppress_bind_attrs: Disables bind/unbind via sysfs. + * @probe_low_power: The driver supports its probe function being called while + * the device is in a low power state, independently of the + * expected behaviour on combination of a given bus and + * firmware interface etc. The driver is responsible for + * powering the device on using runtime PM in such case. + * This configuration has no effect if CONFIG_PM is disabled. * @probe_type: Type of the probe (synchronous or asynchronous) to use. * @of_match_table: The open firmware table. * @acpi_match_table: The ACPI match table. @@ -285,6 +291,7 @@ struct device_driver { const char *mod_name; /* used for built-in modules */ bool suppress_bind_attrs; /* disables bind/unbind via sysfs */ + bool probe_low_power; enum probe_type probe_type; const struct of_device_id *of_match_table; From patchwork Mon Aug 26 08:31:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 11114257 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCFD61800 for ; Mon, 26 Aug 2019 08:32:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C51482087E for ; Mon, 26 Aug 2019 08:32:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730614AbfHZIco (ORCPT ); Mon, 26 Aug 2019 04:32:44 -0400 Received: from mga06.intel.com ([134.134.136.31]:55345 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbfHZIc1 (ORCPT ); Mon, 26 Aug 2019 04:32:27 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 01:32:26 -0700 X-IronPort-AV: E=Sophos;i="5.64,431,1559545200"; d="scan'208";a="204502153" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 01:32:25 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 9F1F820B48; Mon, 26 Aug 2019 11:32:23 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1i2APB-0002KE-5R; Mon, 26 Aug 2019 11:31:13 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH v2 2/5] ACPI: Add a convenience function to tell a device is suspended in probe Date: Mon, 26 Aug 2019 11:31:09 +0300 Message-Id: <20190826083112.8888-3-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190826083112.8888-1-sakari.ailus@linux.intel.com> References: <20190826083112.8888-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add a convenience function to tell whether a device is suspended for probe or remove, for busses where the custom is that drivers don't need to resume devices in probe, or suspend them in their remove handlers. Returns false on non-ACPI systems. Suggested-by: Mika Westerberg Signed-off-by: Sakari Ailus --- drivers/acpi/device_pm.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index adcdf78ce4de8..7d6b40396ea71 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1344,4 +1344,39 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on) return 1; } EXPORT_SYMBOL_GPL(acpi_dev_pm_attach); + +/** + * acpi_dev_low_power_state_probe - Tell if a device is in a low power state + * during probe + * @dev: The device + * + * Tell whether a given device is in a low power state during the driver's probe + * or remove operation. + * + * Drivers of devices on certain busses such as I²C can generally assume (on + * ACPI based systems) that the devices they control are powered on without + * driver having to do anything about it. Using struct + * device_driver.probe_low_power and "probe-low-power" property, this can be + * negated and the driver has full control of the device power management. + * Always returns false on non-ACPI based systems. True is returned on ACPI + * based systems iff the device is in a low power state during probe or remove. + */ +bool acpi_dev_low_power_state_probe(struct device *dev) +{ + int power_state; + int ret; + + if (!is_acpi_device_node(dev_fwnode(dev))) + return false; + + ret = acpi_device_get_power(ACPI_COMPANION(dev), &power_state); + if (ret) { + dev_warn(dev, "Cannot obtain power state (%d)\n", ret); + return false; + } + + return power_state != ACPI_STATE_D0; +} +EXPORT_SYMBOL_GPL(acpi_dev_low_power_state_probe); + #endif /* CONFIG_PM */ diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 9426b9aaed86f..a20b4246107ac 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -912,6 +912,7 @@ int acpi_dev_resume(struct device *dev); int acpi_subsys_runtime_suspend(struct device *dev); int acpi_subsys_runtime_resume(struct device *dev); int acpi_dev_pm_attach(struct device *dev, bool power_on); +bool acpi_dev_low_power_state_probe(struct device *dev); #else static inline int acpi_dev_runtime_suspend(struct device *dev) { return 0; } static inline int acpi_dev_runtime_resume(struct device *dev) { return 0; } @@ -921,6 +922,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) { return 0; } +static inline bool acpi_dev_low_power_state_probe(struct device *dev) +{ + return false; +} #endif #if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP) From patchwork Mon Aug 26 08:31:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 11114249 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CA6F1800 for ; Mon, 26 Aug 2019 08:32:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 10A0A2173E for ; Mon, 26 Aug 2019 08:32:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729842AbfHZIc1 (ORCPT ); Mon, 26 Aug 2019 04:32:27 -0400 Received: from mga03.intel.com ([134.134.136.65]:19475 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729820AbfHZIc1 (ORCPT ); Mon, 26 Aug 2019 04:32:27 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 01:32:26 -0700 X-IronPort-AV: E=Sophos;i="5.64,431,1559545200"; d="scan'208";a="191664253" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 01:32:25 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id A7A6620B4B; Mon, 26 Aug 2019 11:32:23 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1i2APB-0002KH-6Y; Mon, 26 Aug 2019 11:31:13 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH v2 3/5] ov5670: Support probe whilst the device is in a low power state Date: Mon, 26 Aug 2019 11:31:10 +0300 Message-Id: <20190826083112.8888-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190826083112.8888-1-sakari.ailus@linux.intel.com> References: <20190826083112.8888-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Tell ACPI device PM code that the driver supports the device being in a low power state when the driver's probe function is entered. Signed-off-by: Sakari Ailus --- drivers/media/i2c/ov5670.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c index 041fcbb4eebdf..760fce93337cd 100644 --- a/drivers/media/i2c/ov5670.c +++ b/drivers/media/i2c/ov5670.c @@ -2444,6 +2444,7 @@ static int ov5670_probe(struct i2c_client *client) struct ov5670 *ov5670; const char *err_msg; u32 input_clk = 0; + bool low_power; int ret; device_property_read_u32(&client->dev, "clock-frequency", &input_clk); @@ -2460,11 +2461,14 @@ static int ov5670_probe(struct i2c_client *client) /* Initialize subdev */ v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops); - /* Check module identity */ - ret = ov5670_identify_module(ov5670); - if (ret) { - err_msg = "ov5670_identify_module() error"; - goto error_print; + low_power = acpi_dev_low_power_state_probe(&client->dev); + if (!low_power) { + /* Check module identity */ + ret = ov5670_identify_module(ov5670); + if (ret) { + err_msg = "ov5670_identify_module() error"; + goto error_print; + } } mutex_init(&ov5670->mutex); @@ -2501,10 +2505,10 @@ static int ov5670_probe(struct i2c_client *client) ov5670->streaming = false; /* - * Device is already turned on by i2c-core with ACPI domain PM. - * Enable runtime PM and turn off the device. + * Don't set the device's state to active if it's in a low power state. */ - pm_runtime_set_active(&client->dev); + if (!low_power) + pm_runtime_set_active(&client->dev); pm_runtime_enable(&client->dev); pm_runtime_idle(&client->dev); @@ -2546,7 +2550,7 @@ static const struct dev_pm_ops ov5670_pm_ops = { #ifdef CONFIG_ACPI static const struct acpi_device_id ov5670_acpi_ids[] = { - {"INT3479"}, + { "INT3479" }, { /* sentinel */ } }; @@ -2556,6 +2560,7 @@ MODULE_DEVICE_TABLE(acpi, ov5670_acpi_ids); static struct i2c_driver ov5670_i2c_driver = { .driver = { .name = "ov5670", + .probe_low_power = true, .pm = &ov5670_pm_ops, .acpi_match_table = ACPI_PTR(ov5670_acpi_ids), }, From patchwork Mon Aug 26 08:31:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 11114251 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 04EAA1800 for ; Mon, 26 Aug 2019 08:32:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DEF082080C for ; Mon, 26 Aug 2019 08:32:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730632AbfHZIcc (ORCPT ); Mon, 26 Aug 2019 04:32:32 -0400 Received: from mga06.intel.com ([134.134.136.31]:55345 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730614AbfHZIc2 (ORCPT ); Mon, 26 Aug 2019 04:32:28 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 01:32:27 -0700 X-IronPort-AV: E=Sophos;i="5.64,431,1559545200"; d="scan'208";a="187527581" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 01:32:26 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id B16BF20B4E; Mon, 26 Aug 2019 11:32:23 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1i2APB-0002KK-7k; Mon, 26 Aug 2019 11:31:13 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH v2 4/5] media: i2c: imx319: Support probe while the device is off Date: Mon, 26 Aug 2019 11:31:11 +0300 Message-Id: <20190826083112.8888-5-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190826083112.8888-1-sakari.ailus@linux.intel.com> References: <20190826083112.8888-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Rajmohan Mani Tell ACPI device PM code that the driver supports the device being powered off when the driver's probe function is entered. Signed-off-by: Rajmohan Mani Signed-off-by: Sakari Ailus --- drivers/media/i2c/imx319.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c index 17c2e4b41221e..1a01946f4d5bf 100644 --- a/drivers/media/i2c/imx319.c +++ b/drivers/media/i2c/imx319.c @@ -2424,6 +2424,7 @@ static struct imx319_hwcfg *imx319_get_hwcfg(struct device *dev) static int imx319_probe(struct i2c_client *client) { struct imx319 *imx319; + bool low_power; int ret; u32 i; @@ -2436,11 +2437,14 @@ static int imx319_probe(struct i2c_client *client) /* Initialize subdev */ v4l2_i2c_subdev_init(&imx319->sd, client, &imx319_subdev_ops); - /* Check module identity */ - ret = imx319_identify_module(imx319); - if (ret) { - dev_err(&client->dev, "failed to find sensor: %d", ret); - goto error_probe; + low_power = acpi_dev_low_power_state_probe(&client->dev); + if (!low_power) { + /* Check module identity */ + ret = imx319_identify_module(imx319); + if (ret) { + dev_err(&client->dev, "failed to find sensor: %d", ret); + goto error_probe; + } } imx319->hwcfg = imx319_get_hwcfg(&client->dev); @@ -2493,10 +2497,10 @@ static int imx319_probe(struct i2c_client *client) goto error_media_entity; /* - * Device is already turned on by i2c-core with ACPI domain PM. - * Enable runtime PM and turn off the device. + * Don't set the device's state to active if it's in a low power state. */ - pm_runtime_set_active(&client->dev); + if (!low_power) + pm_runtime_set_active(&client->dev); pm_runtime_enable(&client->dev); pm_runtime_idle(&client->dev); @@ -2536,7 +2540,7 @@ static const struct dev_pm_ops imx319_pm_ops = { }; static const struct acpi_device_id imx319_acpi_ids[] = { - { "SONY319A" }, + { "SONY319A", }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(acpi, imx319_acpi_ids); @@ -2544,6 +2548,7 @@ MODULE_DEVICE_TABLE(acpi, imx319_acpi_ids); static struct i2c_driver imx319_i2c_driver = { .driver = { .name = "imx319", + .probe_low_power = true, .pm = &imx319_pm_ops, .acpi_match_table = ACPI_PTR(imx319_acpi_ids), }, From patchwork Mon Aug 26 08:31:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 11114259 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA0771800 for ; Mon, 26 Aug 2019 08:33:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 90BA12087E for ; Mon, 26 Aug 2019 08:33:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730660AbfHZIdB (ORCPT ); Mon, 26 Aug 2019 04:33:01 -0400 Received: from mga12.intel.com ([192.55.52.136]:51354 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726401AbfHZIdA (ORCPT ); Mon, 26 Aug 2019 04:33:00 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 01:33:00 -0700 X-IronPort-AV: E=Sophos;i="5.64,431,1559545200"; d="scan'208";a="380462601" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Aug 2019 01:32:58 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id B9CED20B51; Mon, 26 Aug 2019 11:32:23 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1i2APB-0002KN-8u; Mon, 26 Aug 2019 11:31:13 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH v2 5/5] at24: Support probing while off Date: Mon, 26 Aug 2019 11:31:12 +0300 Message-Id: <20190826083112.8888-6-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190826083112.8888-1-sakari.ailus@linux.intel.com> References: <20190826083112.8888-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org In certain use cases (where the chip is part of a camera module, and the camera module is wired together with a camera privacy LED), powering on the device during probe is undesirable. Add support for the at24 to execute probe while being powered off. For this to happen, a hint in form of a device property is required from the firmware. Signed-off-by: Sakari Ailus --- drivers/misc/eeprom/at24.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 518945b2f7374..a56cd6a6105c0 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -565,6 +565,7 @@ static int at24_probe(struct i2c_client *client) bool i2c_fn_i2c, i2c_fn_block; unsigned int i, num_addresses; struct at24_data *at24; + bool low_power; struct regmap *regmap; bool writable; u8 test_byte; @@ -702,19 +703,24 @@ static int at24_probe(struct i2c_client *client) i2c_set_clientdata(client, at24); - /* enable runtime pm */ - pm_runtime_set_active(dev); + low_power = acpi_dev_low_power_state_probe(&client->dev); + if (!low_power) + pm_runtime_set_active(dev); + pm_runtime_enable(dev); /* - * Perform a one-byte test read to verify that the - * chip is functional. + * Perform a one-byte test read to verify that the chip is functional, + * unless powering on the device is to be avoided during probe (i.e. + * it's powered off right now). */ - err = at24_read(at24, 0, &test_byte, 1); - pm_runtime_idle(dev); - if (err) { - pm_runtime_disable(dev); - return -ENODEV; + if (!low_power) { + err = at24_read(at24, 0, &test_byte, 1); + pm_runtime_idle(dev); + if (err) { + pm_runtime_disable(dev); + return -ENODEV; + } } dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n", @@ -726,8 +732,12 @@ static int at24_probe(struct i2c_client *client) static int at24_remove(struct i2c_client *client) { + bool low_power; + pm_runtime_disable(&client->dev); - pm_runtime_set_suspended(&client->dev); + low_power = acpi_dev_low_power_state_probe(&client->dev); + if (!low_power) + pm_runtime_set_suspended(&client->dev); return 0; } @@ -735,6 +745,7 @@ static int at24_remove(struct i2c_client *client) static struct i2c_driver at24_driver = { .driver = { .name = "at24", + .probe_low_power = true, .of_match_table = at24_of_match, .acpi_match_table = ACPI_PTR(at24_acpi_ids), },