Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1038202lqp; Sun, 14 Apr 2024 10:58:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVIgzbaTENBAA1dY5kfBYrvXXYGZGeJJxgVWR2yuImE/uWVhIU/LBI6F1oZIEWaH+uAVgb4J3fNDmm+HkrhCkE6LpTFn2pMAqN8aq0HAw== X-Google-Smtp-Source: AGHT+IHlHW8ODMmTzBhPYPVb8bqyOHsrUmWCvJUB582q65lrJkSuV/hpcUIVlptMJR1SJPN+oIad X-Received: by 2002:a05:6512:4887:b0:515:d335:a0ab with SMTP id eq7-20020a056512488700b00515d335a0abmr4758559lfb.37.1713117493260; Sun, 14 Apr 2024 10:58:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713117493; cv=pass; d=google.com; s=arc-20160816; b=rXx4qcUF9YnQstHOvPbz+1ODAEtnMUjyKI5YdaGGw8lyG/5yVaxiuja2B3Cj8RfyWr IW7ZQRKBBrGEMxEl2pTRzaZ7eBF9fq42NOiGEma5v0wS2afihYdLuy7rtvuY/y1sEMN0 4bWYR6kO+10j3fEtj3VYwiwkmXfZaWuqWQpgi09KBrZWT3oD5JO45H5Gqysj3/fKIswt GsptFyqsM/FwZZA1BjipKeWjur55WW3/38m1UB7lJZfI1VX85/ylLmOQ7EPIOLuHERu5 h/E7QQ65hgVTY1p0xannqAxW2OQK2q6yKCTkkkHGuPU0QoN4E6Wjse+6w0w/HmlUNf+M RccQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=ZKSgSZr/52jxxhOzrlt61t9DbIznbduvvmE0nk+D74c=; fh=tE5n859cV0BjUJONcvWuvDBTrbwjawIl47goqTT+08o=; b=O1TZBCiujtUpml6Adl22daRc+mpbr3GYjMdOy/qpmOxHXWYP+F0IXQZTxzaGCuTVdR D5sWcg5AGEIqIE1Mxpijtgh0XTjidu4wG4Mlt3vm4RBLkeVn0vGf6ggWSyb9r61335HF vJikEK6mRI3ft8NLOM+WU1ovjP/WTkDVEbWZX6vUH8qrWyupLuxIwlfq6JKvOy/aXJe5 bhiu0hifRzjRVqFrAWbQkwt5RlG9CoILmoKJ242cWbFl7bWeYbwzTGeraq2GK0pcXSnJ NQh5bp+Xsr7fxI9tB8lx5v7N6Q5m0B1KrTuuVeIYE2za62SNsSjrJN5KcvrnVjCPSDfs CYqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=apJvp2ux; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-144316-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144316-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s28-20020a50ab1c000000b0056bad5416c4si3923385edc.72.2024.04.14.10.58.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Apr 2024 10:58:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-144316-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=apJvp2ux; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-144316-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-144316-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F35F51F2146A for ; Sun, 14 Apr 2024 17:58:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 69E8C136675; Sun, 14 Apr 2024 17:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="apJvp2ux" Received: from a.peacevolution.org (a.peacevolution.org [206.189.193.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24003135A6C; Sun, 14 Apr 2024 17:57:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=206.189.193.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713117475; cv=none; b=n/BWkzI+YnI59nnmkQpC8VhPip1OnZJ37KKynyX9we3lLP8207IyHwSRYbDbQc/fmz0DLjC9Pa7M7IMuayK/PmLMEgwsWhzqaaT2DMc9LcQeR7WqgCUwvaE0tWezPxRCqQLYbnJvnHmhhFR3eiXDaowtbijrgnaCt7fH1QNwHzw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713117475; c=relaxed/simple; bh=zIGUlsMmzRHbKuN0yC5dPYIwHXfnj1BUrSe5Hnhm/Ag=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hPr72lv0YXZXG91mY7YDmeRUWc4puZ77CUsMM6GPj7lIWFtml8iYDZRlPCKLpyd42HSGTkSjKX5Nrur4HAXWNi9Vo/D+O6hoQDanGNZvJGtGmrqNvyOVRI652rferM1m4oZnpdmmhcPsYkDSEP5sTo6HebyKcQxVrXZCsY+hgz4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org; spf=pass smtp.mailfrom=peacevolution.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b=apJvp2ux; arc=none smtp.client-ip=206.189.193.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=peacevolution.org 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=20Kleine-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org X-Spam-Level: **** 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= 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) -- 2.44.0