Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1946980pxb; Fri, 5 Feb 2021 05:38:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgmY0Os36fD6qrmvYs3qpeGo7dyZ9PyebFQpAnk8dCuSYiuTc9zg0xUBU0vq5n6YysqH5k X-Received: by 2002:a05:6402:378:: with SMTP id s24mr3677256edw.376.1612532325740; Fri, 05 Feb 2021 05:38:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612532325; cv=none; d=google.com; s=arc-20160816; b=FKAyqtLRGolVRbe7I3B7JvCYYWRUQ7RIsqMQYDbkFWmhnOImPSGd20tDQ/+sgQxhYL HSk0hRsnXemcJ8C1kcpkMt6ArbCjt8z8AHno3WwOKTkS6WM6Zygujuzg8n6qA7R11aEv OehRa+w7AhoVH0EfmJM5DTz7fRMaB/nOuFXU6kphOdRJHPl57S6H/1THBpQ49hqGYGb8 xjBNnSCePluKZ0ycq8PhT+C54Ru8UCX7u+85S97vHXacxL1kXgYw99GaJWYf7aEe8yEZ BeGircjCbNlxmMX0FvQF0P89AJRf1/CAqMI6gP9XituKx+ol+YZ1yfqRsRATAE2d1SEl 870g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=QguCyynFWS9NS0aROIiWPhKHnaw8vyb7smUz4NBQyY8=; b=Yc7mA+m8L3FXMFJLvJVOfRl/OHnv2OiUde6MOGMdEcuSNff3m92KH3nBSGJQn1exRf UPkLUG+pfYA3xVRiJLfTQBqmCvHh5L1eZAlB2QgRPsiqW86sn+0V2ZIZuG2/zV58DqqQ 0IM/a4yJz1NgAVa7qRvu1S4+12qTPKYfDx8A9toPyYLYyGs/7DQZULDDiT/WjTXtKNUK uARVyOMxYjEr8hfyBuomOpUCWC6gg73XsvIO/c69WPskueOu97PbD7auBzmcnXy/5RXH XsDBFEmPrf0FdOeWkOs75l+jRGbalpXUcZcHu+RQETAF/ZTB4gV5MV3R+lhfnFvJLEQa Mkiw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j4si5287487ejv.17.2021.02.05.05.38.20; Fri, 05 Feb 2021 05:38:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230360AbhBENgI (ORCPT + 99 others); Fri, 5 Feb 2021 08:36:08 -0500 Received: from mga09.intel.com ([134.134.136.24]:26783 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229986AbhBENcR (ORCPT ); Fri, 5 Feb 2021 08:32:17 -0500 IronPort-SDR: G9HSbYOHf+zjsiFuHRdL+Ci5DUgBv9+0ButCcvbE8HE3aOrG2gLQRT1BUQMSiBCGNFFXUkC8KV mITvep/RDx2g== X-IronPort-AV: E=McAfee;i="6000,8403,9885"; a="181578728" X-IronPort-AV: E=Sophos;i="5.81,154,1610438400"; d="scan'208";a="181578728" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2021 05:25:01 -0800 IronPort-SDR: SVoxw9OfMZrC1wXygP9As+pPtInJSF7e03U1YzeFhiToz+fW9LiChSsdA7BMCqI6HNA7EralAs YfvjIXRMh0qg== X-IronPort-AV: E=Sophos;i="5.81,154,1610438400"; d="scan'208";a="357959766" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2021 05:24:58 -0800 Received: from punajuuri.localdomain (punajuuri.localdomain [192.168.240.130]) by paasikivi.fi.intel.com (Postfix) with ESMTP id B1680216F2; Fri, 5 Feb 2021 15:24:51 +0200 (EET) Received: from sailus by punajuuri.localdomain with local (Exim 4.92) (envelope-from ) id 1l816f-0005GX-G0; Fri, 05 Feb 2021 15:25:05 +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 v10 7/7] at24: Support probing while off Date: Fri, 5 Feb 2021 15:25:05 +0200 Message-Id: <20210205132505.20173-8-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210205132505.20173-1-sakari.ailus@linux.intel.com> References: <20210205132505.20173-1-sakari.ailus@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Reviewed-by: Tomasz Figa --- 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..69a5e4023d9e1 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 off_during_probe; 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; - } + off_during_probe = acpi_dev_state_low_power(&client->dev); + if (!off_during_probe) { + 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 (!off_during_probe) { + 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) -- 2.20.1