From patchwork Fri May 10 10:09:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 10938483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8376933 for ; Fri, 10 May 2019 10:09:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA5DC287D1 for ; Fri, 10 May 2019 10:09:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF36928BBB; Fri, 10 May 2019 10:09:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6726A287D1 for ; Fri, 10 May 2019 10:09:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727289AbfEJKJ1 (ORCPT ); Fri, 10 May 2019 06:09:27 -0400 Received: from mga01.intel.com ([192.55.52.88]:47868 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbfEJKJ1 (ORCPT ); Fri, 10 May 2019 06:09:27 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 May 2019 03:09:26 -0700 X-ExtLoop1: 1 Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga006.jf.intel.com with ESMTP; 10 May 2019 03:09:25 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTPS id 6BB1420800; Fri, 10 May 2019 13:09:24 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.89) (envelope-from ) id 1hP2T5-0003ox-80; Fri, 10 May 2019 13:09:31 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rajmohan.mani@intel.com, linux-media@vger.kernel.org Subject: [PATCH 1/5] ACPI: Enable driver and firmware hints to control power at probe time Date: Fri, 10 May 2019 13:09:26 +0300 Message-Id: <20190510100930.14641-2-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190510100930.14641-1-sakari.ailus@linux.intel.com> References: <20190510100930.14641-1-sakari.ailus@linux.intel.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 9 +++++++-- include/linux/device.h | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index b859d75eaf9f6..ca2409a30d26d 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1225,7 +1225,9 @@ 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 && + !(dev->driver->probe_powered_off && + device_property_present(dev, "avoid-power-probe"))) { /* * If the device's PM QoS resume latency limit or flags * have been exposed to user space, they have to be @@ -1273,7 +1275,10 @@ 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 && + !(dev->driver->probe_powered_off && + device_property_present(dev, "avoid-power-probe"))) { acpi_dev_pm_full_power(adev); acpi_device_wakeup_disable(adev); } diff --git a/include/linux/device.h b/include/linux/device.h index e85264fb66161..2a459fd5b954a 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -245,6 +245,11 @@ enum probe_type { * @owner: The module owner. * @mod_name: Used for built-in modules. * @suppress_bind_attrs: Disables bind/unbind via sysfs. + * @probe_powered_off: The driver supports its probe function being called while + * the device is powered off, 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. * @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. @@ -282,6 +287,7 @@ struct device_driver { const char *mod_name; /* used for built-in modules */ bool suppress_bind_attrs; /* disables bind/unbind via sysfs */ + bool probe_powered_off; enum probe_type probe_type; const struct of_device_id *of_match_table; From patchwork Fri May 10 10:09:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 10938485 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09FE91515 for ; Fri, 10 May 2019 10:09:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F007928BB7 for ; Fri, 10 May 2019 10:09:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E459328BBB; Fri, 10 May 2019 10:09:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81D4128BB7 for ; Fri, 10 May 2019 10:09:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727347AbfEJKJ2 (ORCPT ); Fri, 10 May 2019 06:09:28 -0400 Received: from mga07.intel.com ([134.134.136.100]:51551 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbfEJKJ1 (ORCPT ); Fri, 10 May 2019 06:09:27 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 May 2019 03:09:27 -0700 X-ExtLoop1: 1 Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga008.fm.intel.com with ESMTP; 10 May 2019 03:09:25 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTPS id D8DD820A47; Fri, 10 May 2019 13:09:24 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.89) (envelope-from ) id 1hP2T6-0003p0-05; Fri, 10 May 2019 13:09:32 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rajmohan.mani@intel.com, linux-media@vger.kernel.org Subject: [PATCH 2/5] ACPI: Add a convenience function to tell a device is suspended in probe Date: Fri, 10 May 2019 13:09:27 +0300 Message-Id: <20190510100930.14641-3-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190510100930.14641-1-sakari.ailus@linux.intel.com> References: <20190510100930.14641-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 X-Virus-Scanned: ClamAV using ClamSMTP 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 | 33 +++++++++++++++++++++++++++++++++ include/linux/acpi.h | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index ca2409a30d26d..774bf4380afd3 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1287,4 +1287,37 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on) return 1; } EXPORT_SYMBOL_GPL(acpi_dev_pm_attach); + +/** + * acpi_dev_powered_off_for_probe - Tell if a device is powered off for probe + * @dev: The device + * + * Tell whether a given device has not been powered on for probe or remove. + * + * 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_off + * and "avoid-power-probe" 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 + * powered off. + */ +bool acpi_dev_powered_off_for_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_powered_off_for_probe); + #endif /* CONFIG_PM */ diff --git a/include/linux/acpi.h b/include/linux/acpi.h index e22c237be46ae..fc6b97aadcf17 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -913,6 +913,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_powered_off_for_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; } @@ -922,6 +923,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) { return 0; } +static inline bool acpi_dev_powered_off_for_probe(struct device *dev) +{ + return false; +} #endif #if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP) From patchwork Fri May 10 10:09:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 10938491 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C4841515 for ; Fri, 10 May 2019 10:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BE5728BB7 for ; Fri, 10 May 2019 10:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 106B228BBB; Fri, 10 May 2019 10:09:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9456A28BBA for ; Fri, 10 May 2019 10:09:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727341AbfEJKJb (ORCPT ); Fri, 10 May 2019 06:09:31 -0400 Received: from mga12.intel.com ([192.55.52.136]:53503 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727348AbfEJKJb (ORCPT ); Fri, 10 May 2019 06:09:31 -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; 10 May 2019 03:09:28 -0700 X-ExtLoop1: 1 Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga006.fm.intel.com with ESMTP; 10 May 2019 03:09:27 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTPS id 7CD8420E12; Fri, 10 May 2019 13:09:25 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.89) (envelope-from ) id 1hP2T6-0003p3-EL; Fri, 10 May 2019 13:09:32 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rajmohan.mani@intel.com, linux-media@vger.kernel.org Subject: [PATCH 3/5] ov5670: Support probe whilst the device is off Date: Fri, 10 May 2019 13:09:28 +0300 Message-Id: <20190510100930.14641-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190510100930.14641-1-sakari.ailus@linux.intel.com> References: <20190510100930.14641-1-sakari.ailus@linux.intel.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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: Sakari Ailus Reviewed-by: Tomasz Figa --- drivers/media/i2c/ov5670.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c index 041fcbb4eebdf..57e8b92f90e09 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 powered_off; 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; + powered_off = acpi_dev_powered_off_for_probe(&client->dev); + if (!powered_off) { + /* Check module identity */ + ret = ov5670_identify_module(ov5670); + if (ret) { + err_msg = "ov5670_identify_module() error"; + goto error_print; + } } mutex_init(&ov5670->mutex); @@ -2500,11 +2504,9 @@ 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. - */ - pm_runtime_set_active(&client->dev); + /* Don't set the device's state to active if it's powered off. */ + if (!powered_off) + pm_runtime_set_active(&client->dev); pm_runtime_enable(&client->dev); pm_runtime_idle(&client->dev); @@ -2546,7 +2548,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 +2558,7 @@ MODULE_DEVICE_TABLE(acpi, ov5670_acpi_ids); static struct i2c_driver ov5670_i2c_driver = { .driver = { .name = "ov5670", + .probe_powered_off = true, .pm = &ov5670_pm_ops, .acpi_match_table = ACPI_PTR(ov5670_acpi_ids), }, From patchwork Fri May 10 10:09:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 10938497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0E441515 for ; Fri, 10 May 2019 10:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3FF0287D1 for ; Fri, 10 May 2019 10:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7F8328BBB; Fri, 10 May 2019 10:09:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81B7B28BB7 for ; Fri, 10 May 2019 10:09:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727357AbfEJKJb (ORCPT ); Fri, 10 May 2019 06:09:31 -0400 Received: from mga07.intel.com ([134.134.136.100]:51551 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727341AbfEJKJ2 (ORCPT ); Fri, 10 May 2019 06:09:28 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 May 2019 03:09:27 -0700 X-ExtLoop1: 1 Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga008.fm.intel.com with ESMTP; 10 May 2019 03:09:26 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTPS id 3B44D201EF; Fri, 10 May 2019 13:09:26 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.89) (envelope-from ) id 1hP2T7-0003p6-2J; Fri, 10 May 2019 13:09:33 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rajmohan.mani@intel.com, linux-media@vger.kernel.org Subject: [PATCH 4/5] media: i2c: imx319: Support probe while the device is off Date: Fri, 10 May 2019 13:09:29 +0300 Message-Id: <20190510100930.14641-5-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190510100930.14641-1-sakari.ailus@linux.intel.com> References: <20190510100930.14641-1-sakari.ailus@linux.intel.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c index 17c2e4b41221e..e929de86a8e22 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 powered_off; 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; + powered_off = acpi_dev_powered_off_for_probe(&client->dev); + if (!powered_off) { + /* 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); @@ -2492,11 +2496,9 @@ static int imx319_probe(struct i2c_client *client) if (ret < 0) goto error_media_entity; - /* - * Device is already turned on by i2c-core with ACPI domain PM. - * Enable runtime PM and turn off the device. - */ - pm_runtime_set_active(&client->dev); + /* Don't set the device's state to active if it's powered off. */ + if (!powered_off) + pm_runtime_set_active(&client->dev); pm_runtime_enable(&client->dev); pm_runtime_idle(&client->dev); @@ -2536,7 +2538,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 +2546,7 @@ MODULE_DEVICE_TABLE(acpi, imx319_acpi_ids); static struct i2c_driver imx319_i2c_driver = { .driver = { .name = "imx319", + .probe_powered_off = true, .pm = &imx319_pm_ops, .acpi_match_table = ACPI_PTR(imx319_acpi_ids), }, From patchwork Fri May 10 10:09:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 10938495 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF40517E0 for ; Fri, 10 May 2019 10:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF587287D1 for ; Fri, 10 May 2019 10:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3F8D28BBB; Fri, 10 May 2019 10:09:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB290287D1 for ; Fri, 10 May 2019 10:09:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727351AbfEJKJb (ORCPT ); Fri, 10 May 2019 06:09:31 -0400 Received: from mga12.intel.com ([192.55.52.136]:53503 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbfEJKJ3 (ORCPT ); Fri, 10 May 2019 06:09:29 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 May 2019 03:09:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,453,1549958400"; d="scan'208";a="170275100" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga002.fm.intel.com with ESMTP; 10 May 2019 03:09:27 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTPS id A7B1F20800; Fri, 10 May 2019 13:09:26 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.89) (envelope-from ) id 1hP2T7-0003p9-Pv; Fri, 10 May 2019 13:09:33 +0300 From: Sakari Ailus To: linux-acpi@vger.kernel.org Cc: rajmohan.mani@intel.com, linux-media@vger.kernel.org Subject: [PATCH 5/5] at24: Support probing while off Date: Fri, 10 May 2019 13:09:30 +0300 Message-Id: <20190510100930.14641-6-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190510100930.14641-1-sakari.ailus@linux.intel.com> References: <20190510100930.14641-1-sakari.ailus@linux.intel.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 63aa541c96088..b9dbe5b6a97be 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -579,6 +579,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 powered_off; struct regmap *regmap; size_t at24_size; bool writable; @@ -701,19 +702,24 @@ static int at24_probe(struct i2c_client *client) i2c_set_clientdata(client, at24); - /* enable runtime pm */ - pm_runtime_set_active(dev); + powered_off = acpi_dev_powered_off_for_probe(&client->dev); + if (!powered_off) + 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) { - err = -ENODEV; - goto err_clients; + if (!powered_off) { + err = at24_read(at24, 0, &test_byte, 1); + pm_runtime_idle(dev); + if (err) { + err = -ENODEV; + goto err_clients; + } } nvmem_config.name = dev_name(dev); @@ -752,12 +758,15 @@ static int at24_probe(struct i2c_client *client) static int at24_remove(struct i2c_client *client) { struct at24_data *at24; + bool powered_off; at24 = i2c_get_clientdata(client); at24_remove_dummy_clients(at24); pm_runtime_disable(&client->dev); - pm_runtime_set_suspended(&client->dev); + powered_off = acpi_dev_powered_off_for_probe(&client->dev); + if (!powered_off) + pm_runtime_set_suspended(&client->dev); return 0; } @@ -765,6 +774,7 @@ static int at24_remove(struct i2c_client *client) static struct i2c_driver at24_driver = { .driver = { .name = "at24", + .probe_powered_off = true, .of_match_table = at24_of_match, .acpi_match_table = ACPI_PTR(at24_acpi_ids), },