From patchwork Thu Jan 28 23:27:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 372911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95ADFC433E0 for ; Thu, 28 Jan 2021 23:31:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6041664DFD for ; Thu, 28 Jan 2021 23:31:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231209AbhA1XbA (ORCPT ); Thu, 28 Jan 2021 18:31:00 -0500 Received: from mga11.intel.com ([192.55.52.93]:4524 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbhA1X3S (ORCPT ); Thu, 28 Jan 2021 18:29:18 -0500 IronPort-SDR: shD4p6NIhhDYysjMOHVHh5S6pluVZI9JCxZsyDK4Hxw6NgEBIjEk05jhKaplqSoZrLDdWz6SI4 G+K7y+RAXlrA== X-IronPort-AV: E=McAfee;i="6000,8403,9878"; a="176824524" X-IronPort-AV: E=Sophos;i="5.79,383,1602572400"; d="scan'208";a="176824524" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2021 15:27:33 -0800 IronPort-SDR: +ZI6vXBLOqRjUcuHT/LG/VTH07moeD/Zdy9kQBygbrtWx9TEZE9zLp7UchICfQpI7U7kqq5+zu e91yvUuuJz/w== X-IronPort-AV: E=Sophos;i="5.79,383,1602572400"; d="scan'208";a="354359314" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2021 15:27:29 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id BB510211D8; Fri, 29 Jan 2021 01:27:27 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1l5GhF-0004F8-MI; Fri, 29 Jan 2021 01:27:29 +0200 From: Sakari Ailus To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , rajmohan.mani@intel.com, Tomasz Figa , Bartosz Golaszewski , Bingbu Cao , Chiranjeevi Rapolu , Hyungwoo Yang , linux-media@vger.kernel.org Subject: [PATCH v9 1/7] ACPI: scan: Obtain device's desired enumeration power state Date: Fri, 29 Jan 2021 01:27:23 +0200 Message-Id: <20210128232729.16064-1-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903081550.6012-1-sakari.ailus@linux.intel.com> References: <20200903081550.6012-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Store a device's desired enumeration power state in struct acpi_device_power_flags during acpi_device object's initialisation. Signed-off-by: Sakari Ailus --- drivers/acpi/scan.c | 6 ++++++ include/acpi/acpi_bus.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 1d7a02ee45e05..b077c645c9845 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -987,6 +987,8 @@ static void acpi_bus_init_power_state(struct acpi_device *device, int state) static void acpi_bus_get_power_flags(struct acpi_device *device) { + unsigned long long pre; + acpi_status status; u32 i; /* Presence of _PS0|_PR0 indicates 'power manageable' */ @@ -1008,6 +1010,10 @@ static void acpi_bus_get_power_flags(struct acpi_device *device) if (acpi_has_method(device->handle, "_DSW")) device->power.flags.dsw_present = 1; + status = acpi_evaluate_integer(device->handle, "_PRE", NULL, &pre); + if (ACPI_SUCCESS(status) && !pre) + device->power.flags.allow_low_power_probe = 1; + /* * Enumerate supported power management states */ diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 02a716a0af5d4..020b850120883 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -258,7 +258,8 @@ struct acpi_device_power_flags { u32 power_removed:1; /* Optimize Dx->D0 */ u32 ignore_parent:1; /* Power is independent of parent power state */ u32 dsw_present:1; /* _DSW present? */ - u32 reserved:26; + u32 allow_low_power_probe:1; /* Allow low power state in device probe */ + u32 reserved:25; }; struct acpi_device_power_state { From patchwork Thu Sep 3 08:15:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 255917 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7BADC433E2 for ; Thu, 3 Sep 2020 08:16:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADA1720FC3 for ; Thu, 3 Sep 2020 08:16:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728742AbgICIPy (ORCPT ); Thu, 3 Sep 2020 04:15:54 -0400 Received: from mga04.intel.com ([192.55.52.120]:11134 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728807AbgICIPo (ORCPT ); Thu, 3 Sep 2020 04:15:44 -0400 IronPort-SDR: 8aasJwJ8OdVhdK3q6ewGNN2YoXr/Dii7kTgbnPljM2Elw8Im+GYEWN/wYb9bzN2n+CkO6Vx2+Y FsGTc2yhYnDA== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="154939220" X-IronPort-AV: E=Sophos;i="5.76,385,1592895600"; d="scan'208";a="154939220" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 01:15:43 -0700 IronPort-SDR: EAXJbZnsEs/BQyZ5dVBgJOC2gV6IhKzVeGK0MVe2vovYcr93xjn8kWkFFVu84U62kXLFXI5bgB J+Edj+OLZDhw== X-IronPort-AV: E=Sophos;i="5.76,385,1592895600"; d="scan'208";a="331719609" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 01:15:40 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 78D092098B; Thu, 3 Sep 2020 11:15:38 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1kDkPO-0001cC-J5; Thu, 03 Sep 2020 11:15:50 +0300 From: Sakari Ailus To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , rajmohan.mani@intel.com, Tomasz Figa , Bartosz Golaszewski , Bingbu Cao , Chiranjeevi Rapolu , Hyungwoo Yang , linux-media@vger.kernel.org Subject: [PATCH v8 2/6] Documentation: ACPI: Document i2c-allow-low-power-probe _DSD property Date: Thu, 3 Sep 2020 11:15:46 +0300 Message-Id: <20200903081550.6012-3-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903081550.6012-1-sakari.ailus@linux.intel.com> References: <20200903081550.6012-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Document the probe-low-power _DSD property and how it is used with I²C drivers. Signed-off-by: Sakari Ailus --- .../acpi/dsd/i2c-allow-low-power-probe.rst | 60 +++++++++++++++++++ Documentation/firmware-guide/acpi/index.rst | 1 + 2 files changed, 61 insertions(+) create mode 100644 Documentation/firmware-guide/acpi/dsd/i2c-allow-low-power-probe.rst diff --git a/Documentation/firmware-guide/acpi/dsd/i2c-allow-low-power-probe.rst b/Documentation/firmware-guide/acpi/dsd/i2c-allow-low-power-probe.rst new file mode 100644 index 0000000000000..7e7ed3ad3ac69 --- /dev/null +++ b/Documentation/firmware-guide/acpi/dsd/i2c-allow-low-power-probe.rst @@ -0,0 +1,60 @@ +.. SPDX-License-Identifier: GPL-2.0 + +====================================== +Probing I²C devices in low power state +====================================== + +Introduction +============ + +In some cases it may be preferred to leave certain devices powered off for the +entire system bootup if powering on these devices has adverse side effects, +beyond just powering on the said device. Linux recognizes the _DSD property [1] +"i2c-allow-low-power-probe" that can be used for this purpose. + +How it works +============ + +The boolean device property "i2c-allow-low-power-probe" may be used to tell +Linux that the I²C framework should instruct the kernel ACPI framework to leave +the device in the low power state. If the driver indicates its support for this +by setting the I2C_DRV_FL_ALLOW_LOW_POWER_PROBE flag in struct i2c_driver.flags +field and the "i2c-allow-low-power-probe" property is present, the device will +not be powered on for probe. + +The downside is that as the device is not powered on, even if there's a problem +with the device, the driver likely probes just fine but the first user will +find out the device doesn't work, instead of a failure at probe time. This +feature should thus be used sparingly. + +Example +======= + +An ASL example describing an ACPI device using this property looks like +this. Some objects not relevant from the example point of view have been +omitted. + + Device (CAM0) + { + Name (_HID, "SONY319A") + Name (_UID, Zero) + Name (_CRS, ResourceTemplate () + { + I2cSerialBus(0x0020, ControllerInitiated, 0x00061A80, + AddressingMode7Bit, "\\_SB.PCI0.I2C0", + 0x00, ResourceConsumer) + }) + Name (PRT4, Package() { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "i2c-allow-low-power-probe", 1 }, + } + }) + } + +References +========== + +[1] Device Properties UUID For _DSD. + https://www.uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf, + referenced 2020-09-02. diff --git a/Documentation/firmware-guide/acpi/index.rst b/Documentation/firmware-guide/acpi/index.rst index ad3b5afdae77e..1f87b7072d1e6 100644 --- a/Documentation/firmware-guide/acpi/index.rst +++ b/Documentation/firmware-guide/acpi/index.rst @@ -11,6 +11,7 @@ ACPI Support dsd/graph dsd/data-node-references dsd/leds + dsd/i2c-allow-low-power-probe enumeration osi method-customizing From patchwork Thu Sep 3 08:15:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 255915 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3863FC43461 for ; Thu, 3 Sep 2020 08:16:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 194F221582 for ; Thu, 3 Sep 2020 08:16:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728785AbgICIQx (ORCPT ); Thu, 3 Sep 2020 04:16:53 -0400 Received: from mga11.intel.com ([192.55.52.93]:55066 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726268AbgICIPw (ORCPT ); Thu, 3 Sep 2020 04:15:52 -0400 IronPort-SDR: rI+AfeZJmpPuVy+DLZznknJ4NeF13cGaxn1VZGbyy373drL9gNYNcTQct0UaJAjHi2kSFqNUSG vChVspQuqNHA== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="155042682" X-IronPort-AV: E=Sophos;i="5.76,385,1592895600"; d="scan'208";a="155042682" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 01:15:43 -0700 IronPort-SDR: 81e430P+oAXdH2KRXA5YExJnmsxD424q4QQ5wHiDUiJGzEOLZXOLSzGtPLE/UtxoU81OhgIXjP 64ipYFdqhwXw== X-IronPort-AV: E=Sophos;i="5.76,385,1592895600"; d="scan'208";a="477963176" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 01:15:40 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 85E1820F67; Thu, 3 Sep 2020 11:15:38 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1kDkPO-0001cG-Km; Thu, 03 Sep 2020 11:15:50 +0300 From: Sakari Ailus To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , rajmohan.mani@intel.com, Tomasz Figa , Bartosz Golaszewski , Bingbu Cao , Chiranjeevi Rapolu , Hyungwoo Yang , linux-media@vger.kernel.org Subject: [PATCH v8 3/6] ACPI: Add a convenience function to tell a device is in low power state Date: Thu, 3 Sep 2020 11:15:47 +0300 Message-Id: <20200903081550.6012-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903081550.6012-1-sakari.ailus@linux.intel.com> References: <20200903081550.6012-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a convenience function to tell whether a device is in low power state, primarily for use in drivers' probe or remove functions on busses where the custom is to power on the device for the duration of both. Returns false on non-ACPI systems. Suggested-by: Mika Westerberg Signed-off-by: Sakari Ailus Reviewed-by: Rafael J. Wysocki --- drivers/acpi/device_pm.c | 31 +++++++++++++++++++++++++++++++ include/linux/acpi.h | 5 +++++ 2 files changed, 36 insertions(+) diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index 94d91c67aeaeb..e3c488d4af0d4 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1344,4 +1344,35 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on) return 1; } EXPORT_SYMBOL_GPL(acpi_dev_pm_attach); + +/** + * acpi_dev_state_low_power - Check the current ACPI power state of a device. + * @dev: Physical device the ACPI power state of which to check + * + * On a system without ACPI, return false. On a system with ACPI, return true if + * the current ACPI power state of the device is not D0, or false otherwise. + * + * Note that the power state of a device is not well-defined after it has been + * passed to acpi_device_set_power() and before that function returns, so it is + * not valid to ask for the ACPI power state of the device in that time frame. + */ +bool acpi_dev_state_low_power(struct device *dev) +{ + struct acpi_device *adev = ACPI_COMPANION(dev); + int power_state; + int ret; + + if (!adev) + return false; + + ret = acpi_device_get_power(adev, &power_state); + if (ret) { + dev_dbg(dev, "Cannot obtain power state (%d)\n", ret); + return false; + } + + return power_state != ACPI_STATE_D0; +} +EXPORT_SYMBOL_GPL(acpi_dev_state_low_power); + #endif /* CONFIG_PM */ diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 17e80e182802e..d76d851259a49 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -978,6 +978,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_state_low_power(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; } @@ -987,6 +988,10 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) { return 0; } +static inline bool acpi_dev_state_low_power(struct device *dev) +{ + return false; +} #endif #if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP) From patchwork Thu Jan 28 23:27:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 372913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACA51C433E0 for ; Thu, 28 Jan 2021 23:29:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 73C8F64DEF for ; Thu, 28 Jan 2021 23:29:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231772AbhA1X3Y (ORCPT ); Thu, 28 Jan 2021 18:29:24 -0500 Received: from mga04.intel.com ([192.55.52.120]:11312 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231513AbhA1X3T (ORCPT ); Thu, 28 Jan 2021 18:29:19 -0500 IronPort-SDR: 2Lfkh+y0XdiWFM1RhVKIyZOuERlW1SSeEgkgUQ3hjSQ4hok+tmNz/EE22sXEKBD5wfn1Aed3Ov FDisEphvnWhw== X-IronPort-AV: E=McAfee;i="6000,8403,9878"; a="177768134" X-IronPort-AV: E=Sophos;i="5.79,383,1602572400"; d="scan'208";a="177768134" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2021 15:27:33 -0800 IronPort-SDR: WCx/m01j6xtYhvcaFuyKyMG1Fg0i7wPeQdkRETAoQEE5B85ceO473+mD9Kh3G/ttDLffWU4iLy GBRR/U0tf3GQ== X-IronPort-AV: E=Sophos;i="5.79,383,1602572400"; d="scan'208";a="357611614" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2021 15:27:29 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id CEC7221D65; Fri, 29 Jan 2021 01:27:27 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1l5GhF-0004FJ-PB; Fri, 29 Jan 2021 01:27:29 +0200 From: Sakari Ailus To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , rajmohan.mani@intel.com, Tomasz Figa , Bartosz Golaszewski , Bingbu Cao , Chiranjeevi Rapolu , Hyungwoo Yang , linux-media@vger.kernel.org Subject: [PATCH v9 4/7] ACPI: Add a convenience function to tell a device is in low power state Date: Fri, 29 Jan 2021 01:27:26 +0200 Message-Id: <20210128232729.16064-4-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903081550.6012-1-sakari.ailus@linux.intel.com> References: <20200903081550.6012-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a convenience function to tell whether a device is in low power state, primarily for use in drivers' probe or remove functions on busses where the custom is to power on the device for the duration of both. Returns false on non-ACPI systems. Suggested-by: Mika Westerberg Signed-off-by: Sakari Ailus Reviewed-by: Rafael J. Wysocki --- drivers/acpi/device_pm.c | 31 +++++++++++++++++++++++++++++++ include/linux/acpi.h | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c index 096153761ebc3..1b5336af0b4cd 100644 --- a/drivers/acpi/device_pm.c +++ b/drivers/acpi/device_pm.c @@ -1336,4 +1336,35 @@ int acpi_dev_pm_attach(struct device *dev, bool power_on) return 1; } EXPORT_SYMBOL_GPL(acpi_dev_pm_attach); + +/** + * acpi_dev_state_low_power - Check the current ACPI power state of a device. + * @dev: Physical device the ACPI power state of which to check + * + * On a system without ACPI, return false. On a system with ACPI, return true if + * the current ACPI power state of the device is not D0, or false otherwise. + * + * Note that the power state of a device is not well-defined after it has been + * passed to acpi_device_set_power() and before that function returns, so it is + * not valid to ask for the ACPI power state of the device in that time frame. + */ +bool acpi_dev_state_low_power(struct device *dev) +{ + struct acpi_device *adev = ACPI_COMPANION(dev); + int power_state; + int ret; + + if (!adev) + return false; + + ret = acpi_device_get_power(adev, &power_state); + if (ret) { + dev_dbg(dev, "Cannot obtain power state (%d)\n", ret); + return false; + } + + return power_state != ACPI_STATE_D0; +} +EXPORT_SYMBOL_GPL(acpi_dev_state_low_power); + #endif /* CONFIG_PM */ diff --git a/include/linux/acpi.h b/include/linux/acpi.h index 4703daafcce9e..864786adb567c 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -982,6 +982,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_state_low_power(struct device *dev); #else static inline int acpi_subsys_runtime_suspend(struct device *dev) { return 0; } static inline int acpi_subsys_runtime_resume(struct device *dev) { return 0; } @@ -989,6 +990,11 @@ static inline int acpi_dev_pm_attach(struct device *dev, bool power_on) { return 0; } + +static inline bool acpi_dev_state_low_power(struct device *dev) +{ + return false; +} #endif #if defined(CONFIG_ACPI) && defined(CONFIG_PM_SLEEP) From patchwork Thu Sep 3 08:15:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 255916 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4440DC433E7 for ; Thu, 3 Sep 2020 08:16:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11BBD21775 for ; Thu, 3 Sep 2020 08:16:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728400AbgICIQI (ORCPT ); Thu, 3 Sep 2020 04:16:08 -0400 Received: from mga11.intel.com ([192.55.52.93]:55073 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728084AbgICIPy (ORCPT ); Thu, 3 Sep 2020 04:15:54 -0400 IronPort-SDR: VeM3gue3AyTUSLsowWIy5m7T93eKukZesyfQQuv6rhVg3PlvAlqdvwV6/9mrJ/k7Vq85zMlfQC 3T9qGTWxNHUg== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="155042692" X-IronPort-AV: E=Sophos;i="5.76,385,1592895600"; d="scan'208";a="155042692" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 01:15:48 -0700 IronPort-SDR: tqvZzK2Ztz14SAZ6772nzD6HINT9KZzdFaANpdZFs9b+pVMI4C/RmVtznGjhiGNDDrtNGIuSiM MJZUU8WkU8Dg== X-IronPort-AV: E=Sophos;i="5.76,385,1592895600"; d="scan'208";a="477963193" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 01:15:45 -0700 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 9B4F4212D7; Thu, 3 Sep 2020 11:15:38 +0300 (EEST) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1kDkPO-0001cM-Nw; Thu, 03 Sep 2020 11:15:50 +0300 From: Sakari Ailus To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , rajmohan.mani@intel.com, Tomasz Figa , Bartosz Golaszewski , Bingbu Cao , Chiranjeevi Rapolu , Hyungwoo Yang , linux-media@vger.kernel.org Subject: [PATCH v8 5/6] media: i2c: imx319: Support probe while the device is off Date: Thu, 3 Sep 2020 11:15:49 +0300 Message-Id: <20200903081550.6012-6-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903081550.6012-1-sakari.ailus@linux.intel.com> References: <20200903081550.6012-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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 | 74 +++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c index 17c2e4b41221e..6b63bb0abb138 100644 --- a/drivers/media/i2c/imx319.c +++ b/drivers/media/i2c/imx319.c @@ -140,6 +140,8 @@ struct imx319 { /* Streaming on/off */ bool streaming; + /* True if the device has been identified */ + bool identified; }; static const struct imx319_reg imx319_global_regs[] = { @@ -2084,6 +2086,31 @@ imx319_set_pad_format(struct v4l2_subdev *sd, return 0; } +/* Verify chip ID */ +static int imx319_identify_module(struct imx319 *imx319) +{ + struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); + int ret; + u32 val; + + if (imx319->identified) + return 0; + + ret = imx319_read_reg(imx319, IMX319_REG_CHIP_ID, 2, &val); + if (ret) + return ret; + + if (val != IMX319_CHIP_ID) { + dev_err(&client->dev, "chip id mismatch: %x!=%x", + IMX319_CHIP_ID, val); + return -EIO; + } + + imx319->identified = true; + + return 0; +} + /* Start streaming */ static int imx319_start_streaming(struct imx319 *imx319) { @@ -2091,6 +2118,10 @@ static int imx319_start_streaming(struct imx319 *imx319) const struct imx319_reg_list *reg_list; int ret; + ret = imx319_identify_module(imx319); + if (ret) + return ret; + /* Global Setting */ reg_list = &imx319_global_setting; ret = imx319_write_regs(imx319, reg_list->regs, reg_list->num_of_regs); @@ -2210,26 +2241,6 @@ static int __maybe_unused imx319_resume(struct device *dev) return ret; } -/* Verify chip ID */ -static int imx319_identify_module(struct imx319 *imx319) -{ - struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); - int ret; - u32 val; - - ret = imx319_read_reg(imx319, IMX319_REG_CHIP_ID, 2, &val); - if (ret) - return ret; - - if (val != IMX319_CHIP_ID) { - dev_err(&client->dev, "chip id mismatch: %x!=%x", - IMX319_CHIP_ID, val); - return -EIO; - } - - return 0; -} - static const struct v4l2_subdev_core_ops imx319_subdev_core_ops = { .subscribe_event = v4l2_ctrl_subdev_subscribe_event, .unsubscribe_event = v4l2_event_subdev_unsubscribe, @@ -2424,6 +2435,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 +2448,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_state_low_power(&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 +2508,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 +2551,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); @@ -2549,6 +2564,7 @@ static struct i2c_driver imx319_i2c_driver = { }, .probe_new = imx319_probe, .remove = imx319_remove, + .flags = I2C_DRV_FL_ALLOW_LOW_POWER_PROBE, }; module_i2c_driver(imx319_i2c_driver); From patchwork Thu Jan 28 23:27:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 373556 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B10C4C4332B for ; Thu, 28 Jan 2021 23:30:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79FC864DEF for ; Thu, 28 Jan 2021 23:30:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231847AbhA1XaN (ORCPT ); Thu, 28 Jan 2021 18:30:13 -0500 Received: from mga03.intel.com ([134.134.136.65]:43776 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231823AbhA1X3z (ORCPT ); Thu, 28 Jan 2021 18:29:55 -0500 IronPort-SDR: 3WBZ1Nu8sYrVQR2msFLGIfKO1hYQRNs9rAb/mwLizMT38NU5FKOg6DTLiCzkMwtylvNWR5yv0e qbQTxB6m30Qg== X-IronPort-AV: E=McAfee;i="6000,8403,9878"; a="180409646" X-IronPort-AV: E=Sophos;i="5.79,383,1602572400"; d="scan'208";a="180409646" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2021 15:28:09 -0800 IronPort-SDR: PKcTIpeDHXll7OPFhTlejycM7e3qTfiK+uA8wLFUo3qvu5KdbmgUtH+37NTcCZasi+1RpZRyd2 4m/CRPeg5LKQ== X-IronPort-AV: E=Sophos;i="5.79,383,1602572400"; d="scan'208";a="573829749" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2021 15:28:04 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id DC25821FFD; Fri, 29 Jan 2021 01:27:27 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1l5GhF-0004FQ-Qr; Fri, 29 Jan 2021 01:27:29 +0200 From: Sakari Ailus To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , rajmohan.mani@intel.com, Tomasz Figa , Bartosz Golaszewski , Bingbu Cao , Chiranjeevi Rapolu , Hyungwoo Yang , linux-media@vger.kernel.org Subject: [PATCH v9 6/7] media: i2c: imx319: Support probe while the device is off Date: Fri, 29 Jan 2021 01:27:28 +0200 Message-Id: <20210128232729.16064-6-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903081550.6012-1-sakari.ailus@linux.intel.com> References: <20200903081550.6012-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@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 Reviewed-by: Bingbu Cao --- drivers/media/i2c/imx319.c | 72 +++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c index 8473c0bbb35d6..e0b22e9318fed 100644 --- a/drivers/media/i2c/imx319.c +++ b/drivers/media/i2c/imx319.c @@ -140,6 +140,8 @@ struct imx319 { /* Streaming on/off */ bool streaming; + /* True if the device has been identified */ + bool identified; }; static const struct imx319_reg imx319_global_regs[] = { @@ -2084,6 +2086,31 @@ imx319_set_pad_format(struct v4l2_subdev *sd, return 0; } +/* Verify chip ID */ +static int imx319_identify_module(struct imx319 *imx319) +{ + struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); + int ret; + u32 val; + + if (imx319->identified) + return 0; + + ret = imx319_read_reg(imx319, IMX319_REG_CHIP_ID, 2, &val); + if (ret) + return ret; + + if (val != IMX319_CHIP_ID) { + dev_err(&client->dev, "chip id mismatch: %x!=%x", + IMX319_CHIP_ID, val); + return -EIO; + } + + imx319->identified = true; + + return 0; +} + /* Start streaming */ static int imx319_start_streaming(struct imx319 *imx319) { @@ -2091,6 +2118,10 @@ static int imx319_start_streaming(struct imx319 *imx319) const struct imx319_reg_list *reg_list; int ret; + ret = imx319_identify_module(imx319); + if (ret) + return ret; + /* Global Setting */ reg_list = &imx319_global_setting; ret = imx319_write_regs(imx319, reg_list->regs, reg_list->num_of_regs); @@ -2208,26 +2239,6 @@ static int __maybe_unused imx319_resume(struct device *dev) return ret; } -/* Verify chip ID */ -static int imx319_identify_module(struct imx319 *imx319) -{ - struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd); - int ret; - u32 val; - - ret = imx319_read_reg(imx319, IMX319_REG_CHIP_ID, 2, &val); - if (ret) - return ret; - - if (val != IMX319_CHIP_ID) { - dev_err(&client->dev, "chip id mismatch: %x!=%x", - IMX319_CHIP_ID, val); - return -EIO; - } - - return 0; -} - static const struct v4l2_subdev_core_ops imx319_subdev_core_ops = { .subscribe_event = v4l2_ctrl_subdev_subscribe_event, .unsubscribe_event = v4l2_event_subdev_unsubscribe, @@ -2422,6 +2433,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; @@ -2434,11 +2446,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_state_low_power(&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); @@ -2491,10 +2506,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); @@ -2547,6 +2562,7 @@ static struct i2c_driver imx319_i2c_driver = { }, .probe_new = imx319_probe, .remove = imx319_remove, + .flags = I2C_DRV_FL_ALLOW_LOW_POWER_PROBE, }; module_i2c_driver(imx319_i2c_driver); From patchwork Thu Jan 28 23:27:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 373557 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2102DC433E0 for ; Thu, 28 Jan 2021 23:30:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2F1964DEF for ; Thu, 28 Jan 2021 23:30:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231835AbhA1XaA (ORCPT ); Thu, 28 Jan 2021 18:30:00 -0500 Received: from mga11.intel.com ([192.55.52.93]:4529 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231716AbhA1X3X (ORCPT ); Thu, 28 Jan 2021 18:29:23 -0500 IronPort-SDR: mgDMOhO0nkpXPz0URwuX/JYXp7F6/ziXjT36x6R656MO+bQwAqC3eFDHjFhDB1NlJcYbloZdoV 1CX4P6gmORUA== X-IronPort-AV: E=McAfee;i="6000,8403,9878"; a="176824531" X-IronPort-AV: E=Sophos;i="5.79,383,1602572400"; d="scan'208";a="176824531" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2021 15:27:37 -0800 IronPort-SDR: lFKxtB3Xuv8REmfggSX5QXJUb9ljAv5w+FI+6V5ANE0nQPHo+aHt6ZEJOPMoIwaYdjMIqjYMUR 2ISAMVKwfpfg== X-IronPort-AV: E=Sophos;i="5.79,383,1602572400"; d="scan'208";a="354359332" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2021 15:27:34 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id E27F82230C; Fri, 29 Jan 2021 01:27:27 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1l5GhF-0004FT-Rc; Fri, 29 Jan 2021 01:27:29 +0200 From: Sakari Ailus To: linux-i2c@vger.kernel.org Cc: Wolfram Sang , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , rajmohan.mani@intel.com, Tomasz Figa , Bartosz Golaszewski , Bingbu Cao , Chiranjeevi Rapolu , Hyungwoo Yang , linux-media@vger.kernel.org Subject: [PATCH v9 7/7] at24: Support probing while off Date: Fri, 29 Jan 2021 01:27:29 +0200 Message-Id: <20210128232729.16064-7-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200903081550.6012-1-sakari.ailus@linux.intel.com> References: <20200903081550.6012-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@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 | 43 +++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index 926408b41270c..dd0b3f24e3808 100644 --- a/drivers/misc/eeprom/at24.c +++ b/drivers/misc/eeprom/at24.c @@ -595,6 +595,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; @@ -750,14 +751,16 @@ static int at24_probe(struct i2c_client *client) i2c_set_clientdata(client, at24); - err = regulator_enable(at24->vcc_reg); - if (err) { - dev_err(dev, "Failed to enable vcc regulator\n"); - return err; - } + low_power = acpi_dev_state_low_power(&client->dev); + if (!low_power) { + err = regulator_enable(at24->vcc_reg); + if (err) { + dev_err(dev, "Failed to enable vcc regulator\n"); + return err; + } - /* enable runtime pm */ - pm_runtime_set_active(dev); + pm_runtime_set_active(dev); + } pm_runtime_enable(dev); at24->nvmem = devm_nvmem_register(dev, &nvmem_config); @@ -768,14 +771,17 @@ static int at24_probe(struct i2c_client *client) } /* - * 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); - if (err) { - pm_runtime_disable(dev); - regulator_disable(at24->vcc_reg); - return -ENODEV; + if (!low_power) { + err = at24_read(at24, 0, &test_byte, 1); + if (err) { + pm_runtime_disable(dev); + regulator_disable(at24->vcc_reg); + return -ENODEV; + } } pm_runtime_idle(dev); @@ -795,9 +801,11 @@ static int at24_remove(struct i2c_client *client) struct at24_data *at24 = i2c_get_clientdata(client); pm_runtime_disable(&client->dev); - if (!pm_runtime_status_suspended(&client->dev)) - regulator_disable(at24->vcc_reg); - pm_runtime_set_suspended(&client->dev); + if (!acpi_dev_state_low_power(&client->dev)) { + if (!pm_runtime_status_suspended(&client->dev)) + regulator_disable(at24->vcc_reg); + pm_runtime_set_suspended(&client->dev); + } return 0; } @@ -834,6 +842,7 @@ static struct i2c_driver at24_driver = { .probe_new = at24_probe, .remove = at24_remove, .id_table = at24_ids, + .flags = I2C_DRV_FL_ALLOW_LOW_POWER_PROBE, }; static int __init at24_init(void)