From patchwork Sun Mar 3 21:54:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13579901 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7047E7A711; Sun, 3 Mar 2024 21:54:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709502869; cv=none; b=Hixs2F3GZ2YNQhvoqkHMDIQXh0h5w26N1SIP9BdVescbREY7ot3JTRCAvMr6FE5vqktRhQh9TPbIqcpRI6ezwJFUxbDqreRMHIlx+M561jjPh5bhxu5F8wxQ3I/aLfKYsRj0LCDGIRpxa6Uw2/eLLqxp7d1u6nFY+WkVJkZzZxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709502869; c=relaxed/simple; bh=OV2BerEmGLyPMQ/gowlOSwu8bjIp13BojidEhFbGVVY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iJeK/PGtw78/sPwxAcZe1o6meJAhQdKb+tiqzA6VP4P/KpxpZKoqc7k5VsMlcFb5hcYjzbFjnIjzbQHmf4ax7iQs1p5WYSHKsDBfVEWpwada6NfOCTAmiA7pnK4RQAc2vnM3PVRJ2DWiG4PS3T22DCsAiYJhTNa4BMHi+p6ciQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gmcKH3Bl; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gmcKH3Bl" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-564647bcdbfso4483697a12.2; Sun, 03 Mar 2024 13:54:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709502865; x=1710107665; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0Ho0szSHDTNaBA5W7zm6nIHAh8L8WnnynqO9y1D6L1U=; b=gmcKH3BlSJt3jNUexJ7TrI8tj1AIsNM5i+we38/8Xmp77gqmuR5A9rTlSx8LucVUdi 3EhxF2yFYRhP27rBdM6gPTvb/Z0oJN2gjx3y/RURty2ecSNAhmk8gIqryLNqvj+tqUwK bwcmpVb6MmYSXFkX0NNj6iCy0QVWUU37QFPNnSo6P1GaXvD85PoUZgBJhRdPgZzHhcAX hkcUzxGOFxiK7IqbmUxazQM3jIaoNw9JgCbZBDXDi11KmdwLaDukrAkWmSuclVMHBw0K o2oEP0suWmyS1YWZf2E0E8hXNqiVQpAvZNwMY5H3TXwuBot24NoczXJ/XQgDSxRIBZcR rsPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709502865; x=1710107665; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0Ho0szSHDTNaBA5W7zm6nIHAh8L8WnnynqO9y1D6L1U=; b=YXU6kN2kt6bQqIiRiUOQzB13ft7OeT6WwcvwVSN8EHgOqVLwDxM+QaDqGz34QMi1ho hn8h7hd5p6v1RszV2QubTHzxw70687MuRiNeYL7lvlGAbSZk9cmkj5F3WUwnABd2UU7S WvdRBd3iJlYJVneLX3XkP5GTuRFGwc0K53JO4kMLoCAqAh77n9oiSU+ZaQgiPDFb5ILV JFl3GSYLV3rB6a7q2gno+g/s/dxuEEfdhNqzR316HBNAiHiwdRX8rzaB3XqQv8yaDFK7 grFrsSZvXhxulNFd4+Ya7SBU28Y9UoOqa5Ff9pe6kIcgyQI5t7QeZxraMPiqVGKGrFo+ +sjA== X-Forwarded-Encrypted: i=1; AJvYcCVqLtlIzJ4kPRlim7yQfeQa2NwqmsZI9Qz/ly2wgIcU8RgniWbPWnMBfYrFPzIWSjJjsPT0eMOie0UNu3IAFC5aTGMZpDtqjj8N5Spj40HNmvPngoPc+Tb5UlC8DE3faReMOZKNkxxo6EHWvQU6RbKV00S/e+XQ9RdeAJj/iifLF2MHfA== X-Gm-Message-State: AOJu0YyLNrHD/HcIBQL9rdK0gRQ/BdC5NmXJx1dyaLHRtDySPrL2pFBM FSc1ILq0RjEAeQ4W/b8mekmd+cpjRcn0gA9fa1qGlViJrQjhTzz0ge3WrqfMAoo+tg== X-Google-Smtp-Source: AGHT+IGTf2zlY4nMs6fsLtpP3ttwdiS4Jm7qw733rstZj4C4IUwxzxePw3TOnmBp1kIqwOkONFt03g== X-Received: by 2002:a05:6402:2317:b0:566:43ab:8b78 with SMTP id l23-20020a056402231700b0056643ab8b78mr5310243eda.30.1709502864884; Sun, 03 Mar 2024 13:54:24 -0800 (PST) Received: from [127.0.1.1] (2a02-8389-41cf-e200-b3d8-5b4b-5188-4373.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:b3d8:5b4b:5188:4373]) by smtp.gmail.com with ESMTPSA id n22-20020a05640205d600b00566d6950d14sm2783250edx.92.2024.03.03.13.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 13:54:24 -0800 (PST) From: Javier Carrasco Date: Sun, 03 Mar 2024 22:54:20 +0100 Subject: [PATCH v3 1/3] iio: humidity: hdc3020: add power management Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240303-hdc3020-pm-v3-1-48bc02b5241b@gmail.com> References: <20240303-hdc3020-pm-v3-0-48bc02b5241b@gmail.com> In-Reply-To: <20240303-hdc3020-pm-v3-0-48bc02b5241b@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Li peiyu <579lpy@gmail.com>, Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1709502861; l=5255; i=javier.carrasco.cruz@gmail.com; s=20230509; h=from:subject:message-id; bh=OV2BerEmGLyPMQ/gowlOSwu8bjIp13BojidEhFbGVVY=; b=Mf1F2FjClyyJhbpKfUhEBNZCuqeHHMXL9e7VJOLYtdfVXn3Ko6larZLZ7V+5BdMUvi7ZNAxJU 5pPmqhWY8ywCwOMjPjU1nefZfQvJQLrx6AKlzIBUj6zV6gxgxbAfAGu X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= The HDC3020 sensor carries out periodic measurements during normal operation, but as long as the power supply is enabled, it will carry on in low-power modes. In order to avoid that and reduce power consumption, the device can be switched to Trigger-on Demand mode, and if possible, turn off its regulator. According to the datasheet, the maximum "Power Up Ready" is 5 ms. Add resume/suspend pm operations to manage measurement mode and regulator state. Signed-off-by: Javier Carrasco --- drivers/iio/humidity/hdc3020.c | 95 +++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/drivers/iio/humidity/hdc3020.c b/drivers/iio/humidity/hdc3020.c index 1e5d0d4797b1..7f93024b850c 100644 --- a/drivers/iio/humidity/hdc3020.c +++ b/drivers/iio/humidity/hdc3020.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -68,6 +70,7 @@ struct hdc3020_data { struct i2c_client *client; + struct regulator *vdd_supply; /* * Ensure that the sensor configuration (currently only heater is * supported) will not be changed during the process of reading @@ -551,9 +554,45 @@ static const struct iio_info hdc3020_info = { .write_event_value = hdc3020_write_thresh, }; -static void hdc3020_stop(void *data) +static int hdc3020_power_off(struct hdc3020_data *data) { - hdc3020_exec_cmd((struct hdc3020_data *)data, HDC3020_EXIT_AUTO); + hdc3020_exec_cmd(data, HDC3020_EXIT_AUTO); + + return regulator_disable(data->vdd_supply); +} + +static int hdc3020_power_on(struct hdc3020_data *data) +{ + int ret; + + ret = regulator_enable(data->vdd_supply); + if (ret) + return ret; + + fsleep(5000); + + if (data->client->irq) { + /* + * The alert output is activated by default upon power up, + * hardware reset, and soft reset. Clear the status register. + */ + ret = hdc3020_exec_cmd(data, HDC3020_S_STATUS); + if (ret) { + hdc3020_power_off(data); + return ret; + } + } + + ret = hdc3020_exec_cmd(data, HDC3020_S_AUTO_10HZ_MOD0); + if (ret) + hdc3020_power_off(data); + + return ret; +} + +static void hdc3020_exit(void *data) +{ + hdc3020_power_off(data); } static int hdc3020_probe(struct i2c_client *client) @@ -569,6 +608,8 @@ static int hdc3020_probe(struct i2c_client *client) if (!indio_dev) return -ENOMEM; + dev_set_drvdata(&client->dev, indio_dev); + data = iio_priv(indio_dev); data->client = client; mutex_init(&data->lock); @@ -580,6 +621,20 @@ static int hdc3020_probe(struct i2c_client *client) indio_dev->info = &hdc3020_info; indio_dev->channels = hdc3020_channels; indio_dev->num_channels = ARRAY_SIZE(hdc3020_channels); + + data->vdd_supply = devm_regulator_get(&client->dev, "vdd"); + if (IS_ERR(data->vdd_supply)) + return dev_err_probe(&client->dev, PTR_ERR(data->vdd_supply), + "Unable to get VDD regulator\n"); + + ret = hdc3020_power_on(data); + if (ret) + return dev_err_probe(&client->dev, ret, "Power on failed\n"); + + ret = devm_add_action_or_reset(&data->client->dev, hdc3020_exit, data); + if (ret) + return ret; + if (client->irq) { ret = devm_request_threaded_irq(&client->dev, client->irq, NULL, hdc3020_interrupt_handler, @@ -588,25 +643,8 @@ static int hdc3020_probe(struct i2c_client *client) if (ret) return dev_err_probe(&client->dev, ret, "Failed to request IRQ\n"); - - /* - * The alert output is activated by default upon power up, - * hardware reset, and soft reset. Clear the status register. - */ - ret = hdc3020_exec_cmd(data, HDC3020_S_STATUS); - if (ret) - return ret; } - ret = hdc3020_exec_cmd(data, HDC3020_S_AUTO_10HZ_MOD0); - if (ret) - return dev_err_probe(&client->dev, ret, - "Unable to set up measurement\n"); - - ret = devm_add_action_or_reset(&data->client->dev, hdc3020_stop, data); - if (ret) - return ret; - ret = devm_iio_device_register(&data->client->dev, indio_dev); if (ret) return dev_err_probe(&client->dev, ret, "Failed to add device"); @@ -614,6 +652,24 @@ static int hdc3020_probe(struct i2c_client *client) return 0; } +static int hdc3020_suspend(struct device *dev) +{ + struct iio_dev *iio_dev = dev_get_drvdata(dev); + struct hdc3020_data *data = iio_priv(iio_dev); + + return hdc3020_power_off(data); +} + +static int hdc3020_resume(struct device *dev) +{ + struct iio_dev *iio_dev = dev_get_drvdata(dev); + struct hdc3020_data *data = iio_priv(iio_dev); + + return hdc3020_power_on(data); +} + +static DEFINE_SIMPLE_DEV_PM_OPS(hdc3020_pm_ops, hdc3020_suspend, hdc3020_resume); + static const struct i2c_device_id hdc3020_id[] = { { "hdc3020" }, { "hdc3021" }, @@ -633,6 +689,7 @@ MODULE_DEVICE_TABLE(of, hdc3020_dt_ids); static struct i2c_driver hdc3020_driver = { .driver = { .name = "hdc3020", + .pm = pm_sleep_ptr(&hdc3020_pm_ops), .of_match_table = hdc3020_dt_ids, }, .probe = hdc3020_probe, From patchwork Sun Mar 3 21:54:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13579902 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5BD27A738; Sun, 3 Mar 2024 21:54:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709502870; cv=none; b=X+Z3yHJN6SZuNcfOAaaTWzMRqbrKYBIJA7pgKz7VquZLMAC26sx6StIEelCpQebOYmAmH9qNwrr/CLbMKi7C1SkPAgp2Map4jkGm7vDSy+JksfLgj/W1ozSTeZ6NtbGY6SynBpjdIWpDTdTcOMHH2yPQ3lpHFlPqE2ci6q+s1HU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709502870; c=relaxed/simple; bh=FyoFAj3XNHmn1ZPjLNGWR7C/mqk62+JmZYN8Us3NcAA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sNtN7xWHVM1FXrlGoDGNocQir/+s3Kr4mNQiWnC2Ak03Zypq26QMF7seWgzGEJW+aj9y+F07j2TmMT6nrdW8s3gE3T7iLkliIadGQ00j7vqo6l2dJdSOblIfngLXvC+/ij5YrwKBg1gT1HAlz2n9p0i/sEJVv24BmP4rdQGMQfw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cLqBTsJK; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cLqBTsJK" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2d28464c554so51613111fa.3; Sun, 03 Mar 2024 13:54:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709502866; x=1710107666; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NYWBE/cU69IZWYVF1QnqRyE+9E0HjWVFlCV9Txn1TiE=; b=cLqBTsJKl7BkkD8gAi5g/33jlytYWDXZOkjiZq5NvuXfLXgSPJ/LAByg6Acj0W02Go 3v487MEiTyD1OGOKepZUJpH1n6Jd7COMyubiBmSWXF1Anjy3AYYK4vxvsQuflvjJlkQD JAWjhMKgqqdkFewyMsL4ZHklnKMnbN3bWqxhMHkuVXzemnKdZm5LULR0YrLAKgW41MVg ZZGWlwNzkx3GepHX1QVYIqJBMRejtJq0S8Wf1BwL3SPzdC5byulA5wh7t1tiud9xxFSe 6Ej21Wptzb2FVcMMSnMnbviCl6ulQh+Le/0aeZqOeOdsf5qVQD0/RhI2GlfeYMQIQG++ q0Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709502866; x=1710107666; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NYWBE/cU69IZWYVF1QnqRyE+9E0HjWVFlCV9Txn1TiE=; b=i0EHo8lSPty6qai0WZgLDvO1rC9AyPBS0xHsIUZA3vn1FQ0UxAXSLxFtQSYedusr07 YqWGq1ypPotjVPvyvj74QnERR7GD9JLT7z+LXtu2vPVnlheo41RY/a4X+ZX4nBk6oUaG NXwRkFOTWyS0UQGZoJ7qP7+HSf8Z31C8ZzEBKDUp9fLja+kMu/4bHpouHTil0fu5MG22 UlvGQi121gxSKIg4siEr4amHrCVk2XhKKO1k2/GPUdMh6iPMdFq00y2XGIWdu5QjlAdI oEekAgZ1zBfWqwlQoUYNmagwHQ1wfcgFw8PgDfKd3VmB7codHWyNKSnoZF2V5FKpkY1V /ZAg== X-Forwarded-Encrypted: i=1; AJvYcCWnHm70ikBC/i9KmPs2XkgAwPBEt8ty6w+J5a4iMx7qlmIClrxwMAnYf76zHozlu0/g4fdWg5Ny8MNExIfeAldDYXkm+xaC1ZP8Tmq34QmryJyR8okWVbCt0TlBBzwufODz07CDFyKcGyykD1YXjlSE6ezUKDELsflCM77ihM9FUA58Pg== X-Gm-Message-State: AOJu0Yz3wzSiR8WlRjii8A2MDFCboce2zbG/2+kIxMpkL7/NZahd3++k 35+zx54C/tqiVzOgbPCx7Zirriti49O8ukZAgWdWkW/ViC0Ax1gZGhcJdud9GjnXyw== X-Google-Smtp-Source: AGHT+IE8lrQZt4yf2NOcmxYnZSegdVRNezb1RXhcelAz4SiIe7XiJTncw5NoliUUa5EXVaB8rgPSAg== X-Received: by 2002:a2e:95d5:0:b0:2d2:5668:3a40 with SMTP id y21-20020a2e95d5000000b002d256683a40mr5024483ljh.4.1709502866415; Sun, 03 Mar 2024 13:54:26 -0800 (PST) Received: from [127.0.1.1] (2a02-8389-41cf-e200-b3d8-5b4b-5188-4373.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:b3d8:5b4b:5188:4373]) by smtp.gmail.com with ESMTPSA id n22-20020a05640205d600b00566d6950d14sm2783250edx.92.2024.03.03.13.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 13:54:26 -0800 (PST) From: Javier Carrasco Date: Sun, 03 Mar 2024 22:54:21 +0100 Subject: [PATCH v3 2/3] dt-bindings: iio: humidity: hdc3020: add reset-gpios Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240303-hdc3020-pm-v3-2-48bc02b5241b@gmail.com> References: <20240303-hdc3020-pm-v3-0-48bc02b5241b@gmail.com> In-Reply-To: <20240303-hdc3020-pm-v3-0-48bc02b5241b@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Li peiyu <579lpy@gmail.com>, Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Javier Carrasco , Krzysztof Kozlowski X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1709502861; l=1328; i=javier.carrasco.cruz@gmail.com; s=20230509; h=from:subject:message-id; bh=FyoFAj3XNHmn1ZPjLNGWR7C/mqk62+JmZYN8Us3NcAA=; b=uWOq6TOxCi+og8LiQrahRgzmKnOlQnEdg8sgoANEyUEdYybucjlCulLDtM+CS453cuqlnIR8D R+mXaOkGRUGADzz/Lk6X9eDCVw8Wtbx7+IsF3v3V9Zz3GyxguVrCrII X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= The HDC3020 provides an active low reset signal that is still not described in the bindings. Add reset-gpios to the bindings and the example. Reviewed-by: Krzysztof Kozlowski Signed-off-by: Javier Carrasco --- Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml b/Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml index 8b5dedd1a598..b375d307513f 100644 --- a/Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml +++ b/Documentation/devicetree/bindings/iio/humidity/ti,hdc3020.yaml @@ -34,6 +34,9 @@ properties: reg: maxItems: 1 + reset-gpios: + maxItems: 1 + required: - compatible - reg @@ -43,6 +46,7 @@ additionalProperties: false examples: - | + #include #include i2c { #address-cells = <1>; @@ -54,5 +58,6 @@ examples: vdd-supply = <&vcc_3v3>; interrupt-parent = <&gpio3>; interrupts = <23 IRQ_TYPE_EDGE_RISING>; + reset-gpios = <&gpio3 27 GPIO_ACTIVE_LOW>; }; }; From patchwork Sun Mar 3 21:54:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 13579903 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 113037AE69; Sun, 3 Mar 2024 21:54:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709502871; cv=none; b=WAhhkAncC7vtxOB6YTUUO36HFLkNdx7Bcyipj3J5gz++SVL6GxfDbeg5GcTP33YfiunxjmgOc0eh7Jk5a6KeiillvUWERNPcx4A3FDqMZlcbJMQw7tCDdbyz8g0j2N1ig4DvLLtbp2+6lCTtZQBLDRYebPp6ixUTrrwDsaq7aNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709502871; c=relaxed/simple; bh=aVC+szChqUVwP9dorH1s8x/ORY9BRZBBC5IcgeZmXjg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=P84b+j5UeABYtxB33pWiwrJYrolTdjzTf1pYKExgzB/BV67R1KK12t+/3Xno//IUReyOTCYs2ugQWPRPHChLRCywK2IG3IO1vSHVSmSRx8CNiGlRtPL97P3Xd7y49WCNElGD8t5L6tQTSANrEtjMN6+H/b4e6dHIL6R319Nre2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LAPuQsRR; arc=none smtp.client-ip=209.85.208.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LAPuQsRR" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-565a3910f86so5780691a12.3; Sun, 03 Mar 2024 13:54:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709502868; x=1710107668; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=9wfVpFY3RFJ1WZsM48MjjCquUKLQaa0zbDWX/ailz6E=; b=LAPuQsRRH3MtUkpY4uyzvQAxycxbMMxYnRebDqj2r3fgGbzn+Zdse+rMlsApbCOgnj KjfW4ho58K0ywn1Ge75S/GrtIAl9od3B10LKqTRt2b7W8uEENq+2gzQFKn5gh4Hf86Jt LltZmjFCm3HPShymDFrZvXFCeRHpWTA/narVc/YTy9gIKGd5+XRU1SUt8tDai+oMmYw3 OFmiUK1dEal48If07a9zZLeizupanwAB/5PIoKG2VfNBxrNul2jtdQzd2x2oCKjzmNy2 suxh0kBAkSp+jj7DPFB95yP8GKCWOZl95D+X5YHDTelv06eLWQkSxnojpb4qEz/9PML6 gkSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709502868; x=1710107668; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9wfVpFY3RFJ1WZsM48MjjCquUKLQaa0zbDWX/ailz6E=; b=Sop0gEfcW9nDp5yuvWdjKdrJUevz/ddrNZjpQPj1qc7hIzrfZ7Vz0W66KfrNavqFSg +UrFNf1BgkP7o2iCPFieP1ZTTgXE1M4h2Kq/H41Cd7mGfM1Socff9vmQvafZauEVLiVm BDKjbyCS4Od1L7OHMFBUbYidE34qjpyeRvFABN+PNa8BD7uW8WZM0MIAVxiPylt35hwg dtm92NZWoOgQg6KPRjlzG/KTYNIbmTHxdKp8BZqKSfYuMP1saX5DklA+nc+FfGbT6mEC tN6E7bTlK+g78A5i1AROQbJilMTfoz3jLtEyeT1Jsb+mkSazv7nSYShFSNi7/oV5chfJ 7JLQ== X-Forwarded-Encrypted: i=1; AJvYcCWj3LSGRPsh/NNMmauEy8LkSj7Dw+4Vqg8L1sWsEqIhEiENglAvHKYNdO3ulUOroLqm+TNd4mRBlCm8f3bjtVATa0TdzTtk82RIr8uqRzN9lGB8mXw26M0sZvijf2gbodAsNZvZIW1QA1mXf4jIcvGTTT+drR3BfyaeSasrFVYFYM7VFA== X-Gm-Message-State: AOJu0YwjT+QhyHkHj9WxNvAGXy1AxhOmB1SbfOdG/UGP9GqiNB9rX2ge 7uEjfGLLgs1b9o785wJgRo+BMPSljk97gWBJyggbR4JkHvZmhsFmpjHFX1GOrswcwg== X-Google-Smtp-Source: AGHT+IHlckUN5ksJiFKHAfgeDqB9otVgcaNUqPtywMP22W0xmNKg7pinjAu1q0x4S4lT+ZC662dFAQ== X-Received: by 2002:a05:6402:26c5:b0:564:3392:e9db with SMTP id x5-20020a05640226c500b005643392e9dbmr6313049edd.33.1709502867851; Sun, 03 Mar 2024 13:54:27 -0800 (PST) Received: from [127.0.1.1] (2a02-8389-41cf-e200-b3d8-5b4b-5188-4373.cable.dynamic.v6.surfer.at. [2a02:8389:41cf:e200:b3d8:5b4b:5188:4373]) by smtp.gmail.com with ESMTPSA id n22-20020a05640205d600b00566d6950d14sm2783250edx.92.2024.03.03.13.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 13:54:27 -0800 (PST) From: Javier Carrasco Date: Sun, 03 Mar 2024 22:54:22 +0100 Subject: [PATCH v3 3/3] iio: humidity: hdc3020: add reset management Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240303-hdc3020-pm-v3-3-48bc02b5241b@gmail.com> References: <20240303-hdc3020-pm-v3-0-48bc02b5241b@gmail.com> In-Reply-To: <20240303-hdc3020-pm-v3-0-48bc02b5241b@gmail.com> To: Jonathan Cameron , Lars-Peter Clausen , Li peiyu <579lpy@gmail.com>, Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Jonathan Cameron , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1709502861; l=2300; i=javier.carrasco.cruz@gmail.com; s=20230509; h=from:subject:message-id; bh=aVC+szChqUVwP9dorH1s8x/ORY9BRZBBC5IcgeZmXjg=; b=xhvMcJZaOIgBiJ8bzYqJ/tYs7KdeFM+Wd6KN70+V7hWYPyQ2kzRvnmsoX3Zm9WEFQFe2IKYAg tg+4Ko2kB1QAgRb8ys164IE+lFVQKv8CSAOa57mZnOoVr73mFaO8t2L X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=tIGJV7M+tCizagNijF0eGMBGcOsPD+0cWGfKjl4h6K8= The HDC3020 provides an active low reset signal that must be handled if connected. Asserting this signal turns the device into Trigger-on Demand measurement mode, reducing its power consumption when no measurements are required like in low-power modes. According to the datasheet, the longest "Reset Ready" is 3 ms, which is only taken into account if the reset signal is defined. Signed-off-by: Javier Carrasco --- drivers/iio/humidity/hdc3020.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/iio/humidity/hdc3020.c b/drivers/iio/humidity/hdc3020.c index 7f93024b850c..cdc4789213ba 100644 --- a/drivers/iio/humidity/hdc3020.c +++ b/drivers/iio/humidity/hdc3020.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,7 @@ struct hdc3020_data { struct i2c_client *client; + struct gpio_desc *reset_gpio; struct regulator *vdd_supply; /* * Ensure that the sensor configuration (currently only heater is @@ -558,6 +560,9 @@ static int hdc3020_power_off(struct hdc3020_data *data) { hdc3020_exec_cmd(data, HDC3020_EXIT_AUTO); + if (data->reset_gpio) + gpiod_set_value_cansleep(data->reset_gpio, 1); + return regulator_disable(data->vdd_supply); } @@ -571,6 +576,11 @@ static int hdc3020_power_on(struct hdc3020_data *data) fsleep(5000); + if (data->reset_gpio) { + gpiod_set_value_cansleep(data->reset_gpio, 0); + fsleep(3000); + } + if (data->client->irq) { /* * The alert output is activated by default upon power up, @@ -627,6 +637,12 @@ static int hdc3020_probe(struct i2c_client *client) return dev_err_probe(&client->dev, PTR_ERR(data->vdd_supply), "Unable to get VDD regulator\n"); + data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", + GPIOD_OUT_HIGH); + if (IS_ERR(data->reset_gpio)) + return dev_err_probe(&client->dev, PTR_ERR(data->reset_gpio), + "Cannot get reset GPIO\n"); + ret = hdc3020_power_on(data); if (ret) return dev_err_probe(&client->dev, ret, "Power on failed\n");