From patchwork Sun Apr 14 17:57:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 13629176 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B929C4345F for ; Sun, 14 Apr 2024 17:58:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jc91s1jnPFN+Et/NYaeVMkddkRT7FIKkFDYWJO6MhFM=; b=T96yoOmAVt3dcz cJUlQ6anAwKn5DVLKqF7OmUWc5FhWGLM4EZdwdpG5yYyVaIOYt+5vElY10zN92pba1mDDgiA3zPJv Dd0JHV08LnynrpL/CGvHwVxYGXZHT9E6r3fYAxE7HbVfxV3J9+M16JCsMC6z73RnYydHIdhzOqkCR iE3bcDneUGsUV+72Lv4HFKxgmqGtYsByC1X0qNugNIahkk29IYvZcYn44RFwhEqzJarjwwRVOhNhJ KixqgAzeKdZGVrXETA2nUiW2M1MRyTQwmjUm0iT5gPmWX2eHitnrnR4Uko1Ne5letKs3qblg/fqVc txrj+TynF9Q1kip1mozg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rw472-000000062oz-1tRL; Sun, 14 Apr 2024 17:57:56 +0000 Received: from a.peacevolution.org ([206.189.193.133]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rw46z-000000062ni-3x71 for linux-arm-kernel@lists.infradead.org; Sun, 14 Apr 2024 17:57:55 +0000 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id D8FB347965; Sun, 14 Apr 2024 17:57:51 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Liam Girdwood , Mark Brown Cc: Aren Moynihan , Andy Shevchenko , Ondrej Jirman , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , linux-iio@vger.kernel.org, phone-devel@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Willow Barraco Subject: [PATCH 2/4] iio: light: stk3310: Implement vdd supply and power it off during suspend Date: Sun, 14 Apr 2024 13:57:14 -0400 Message-ID: <20240414175716.958831-2-aren@peacevolution.org> In-Reply-To: <20240414175716.958831-1-aren@peacevolution.org> References: <20240414175300.956243-1-aren@peacevolution.org> <20240414175716.958831-1-aren@peacevolution.org> MIME-Version: 1.0 Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org X-Spamd-Bar: ++++ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1713117473; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=ZKSgSZr/52jxxhOzrlt61t9DbIznbduvvmE0nk+D74c=; b=apJvp2uxLX++fTOkwbVsX7C+kB+jPyIlrIE4AdtpWE3L5VYuZbvakkgCW2Z5U65LZ42tyD XrGjA6nmS3WSOdjT3wxoIvvicMTgUnI0NDNxrxT5csega06OKL83o4eFE3aTrb8/+THORg 81m+ubmpuFGWceJWeE5c90HOWbL0+KE= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240414_105754_210102_34504E1D X-CRM114-Status: GOOD ( 16.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ondrej Jirman VDD power input can be used to completely power off the chip during system suspend. Do so if available. Signed-off-by: Ondrej Jirman Signed-off-by: Aren Moynihan --- drivers/iio/light/stk3310.c | 56 +++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index 7b71ad71d78d..bfa090538df7 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -16,6 +16,7 @@ #include #include #include +#include #define STK3310_REG_STATE 0x00 #define STK3310_REG_PSCTRL 0x01 @@ -117,6 +118,7 @@ struct stk3310_data { struct regmap_field *reg_int_ps; struct regmap_field *reg_flag_psint; struct regmap_field *reg_flag_nf; + struct regulator *vdd_reg; }; static const struct iio_event_spec stk3310_events[] = { @@ -607,6 +609,16 @@ static int stk3310_probe(struct i2c_client *client) mutex_init(&data->lock); + data->vdd_reg = devm_regulator_get_optional(&client->dev, "vdd"); + if (IS_ERR(data->vdd_reg)) { + ret = PTR_ERR(data->vdd_reg); + if (ret == -ENODEV) + data->vdd_reg = NULL; + else + return dev_err_probe(&client->dev, ret, + "get regulator vdd failed\n"); + } + ret = stk3310_regmap_init(data); if (ret < 0) return ret; @@ -617,9 +629,18 @@ static int stk3310_probe(struct i2c_client *client) indio_dev->channels = stk3310_channels; indio_dev->num_channels = ARRAY_SIZE(stk3310_channels); + if (data->vdd_reg) { + ret = regulator_enable(data->vdd_reg); + if (ret) + return dev_err_probe(&client->dev, ret, + "regulator vdd enable failed\n"); + + usleep_range(1000, 2000); + } + ret = stk3310_init(indio_dev); if (ret < 0) - return ret; + goto err_vdd_disable; if (client->irq > 0) { ret = devm_request_threaded_irq(&client->dev, client->irq, @@ -645,32 +666,61 @@ static int stk3310_probe(struct i2c_client *client) err_standby: stk3310_set_state(data, STK3310_STATE_STANDBY); +err_vdd_disable: + if (data->vdd_reg) + regulator_disable(data->vdd_reg); return ret; } static void stk3310_remove(struct i2c_client *client) { struct iio_dev *indio_dev = i2c_get_clientdata(client); + struct stk3310_data *data = iio_priv(indio_dev); iio_device_unregister(indio_dev); stk3310_set_state(iio_priv(indio_dev), STK3310_STATE_STANDBY); + if (data->vdd_reg) + regulator_disable(data->vdd_reg); } static int stk3310_suspend(struct device *dev) { struct stk3310_data *data; + int ret; data = iio_priv(i2c_get_clientdata(to_i2c_client(dev))); - return stk3310_set_state(data, STK3310_STATE_STANDBY); + ret = stk3310_set_state(data, STK3310_STATE_STANDBY); + if (ret) + return ret; + + if (data->vdd_reg) { + regcache_mark_dirty(data->regmap); + regulator_disable(data->vdd_reg); + } + + return 0; } static int stk3310_resume(struct device *dev) { - u8 state = 0; struct stk3310_data *data; + u8 state = 0; + int ret; data = iio_priv(i2c_get_clientdata(to_i2c_client(dev))); + + if (data->vdd_reg) { + ret = regulator_enable(data->vdd_reg); + if (ret) { + dev_err(dev, "Failed to re-enable regulator vdd\n"); + return ret; + } + + usleep_range(1000, 2000); + regcache_sync(data->regmap); + } + if (data->ps_enabled) state |= STK3310_STATE_EN_PS; if (data->als_enabled)