Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp82064lqd; Tue, 23 Apr 2024 15:42:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUjBINpOrqTIBLIRSXCzZU5aXUnwJSIOf9RFArmvLbY/hxfXhx5wdQfbW2YCSbI997O5Tgj1cTEE7LyN2vKWxO0xw5TCxHpnsRIA8Z2OA== X-Google-Smtp-Source: AGHT+IGZJZ8/AVQQHQvxVmF7MW+cO6++OG69BhvP92x5D1Ar3Knt68pgEiF7uI8jGsnM0BSx+L7d X-Received: by 2002:a05:6214:5817:b0:6a0:9361:f986 with SMTP id mk23-20020a056214581700b006a09361f986mr697650qvb.40.1713912175785; Tue, 23 Apr 2024 15:42:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713912175; cv=pass; d=google.com; s=arc-20160816; b=MMQoDz8cVE3FXuWjquLkHfA4zHkINa72zFnDYs1XQpQRgkttbQozLjhNC7LD/Boref QCr8SOV2T1noI7Cp54gtT401hSZ4OjgUnBskqE4Nuhax3kl86w22QVEjupVxzEtJ7zhx kS46Og4trtWor8hO3Q3WJV9BIh8fepzaxI6Gu1/iF2AB/EOuxu7bKTizIjhReiL09KTf 3isHsv9mAz/6c5YrSL5SYEAGR1FVqheG/fiz063nSsfSc8R2kdWKiu8qfGXdImclKiTd TmNpcjdY+PH+fI6Qmb89MZcEBSs24nACWkAAHQsQnT1XVYCjrDaZmAz/zYuLX+KR7c2s 5BtA== 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=Pocgw671NmVP3upSEXxvVD2OibWy7kumLvOzth5JeTg=; fh=tE5n859cV0BjUJONcvWuvDBTrbwjawIl47goqTT+08o=; b=waDHIv5oS4rb9lvg0Nn+uFAChFPWFlzRrNbjMHHjHgSM3BK7qZge2KcjJL9/U2vddS Y5y7Fib+9ZagXrb5Ho1JSwDfgW2/LMkNen2MX/vte1buQNn6qJ6nFafcZS3jeSTTgyOw rclNAZlWh13tlTAULhGEkB46v1yAOuoWab57FQLKw6OwTzdRsiHchGrSjt8nAcb+F/s6 y+MbhZSlqHUQ+dthuaCOJnKiWOLtFqW+8KnBVC2yeiJWn5C1Z9aqw8JiZj9Zc8pA/qGO pN29bn5OzZegetNKrFYu1899kjvrgg+sAWc8vFJsb+PmimxlEGROM+LVXbwJ6Dsq6SUC bnzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=l+nUddnX; 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-155966-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155966-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gc3-20020a056214230300b006a083b11373si4809796qvb.385.2024.04.23.15.42.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 15:42:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-155966-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=l+nUddnX; 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-155966-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-155966-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 4593C1C23BD4 for ; Tue, 23 Apr 2024 22:42:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3648B54919; Tue, 23 Apr 2024 22:41:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="l+nUddnX" 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 8C48818EA8; Tue, 23 Apr 2024 22:41:18 +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=1713912080; cv=none; b=C7oIvdDgG5IBFXalcbHyO9rkYT0JfH1Wa9CxfxIsn7Mi6GCPFr2OlI34lSAXMduob4MjnUeP8T+XuDZSgEl9nqrFna5BtUBfElcKg+vcRHbd/aEllR0sIt/LU4m413IgFEsT4v1tKoszUVHnz7KhhEnsU9ieaObjp/r22ix9WVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713912080; c=relaxed/simple; bh=9WFlEslTo17+AMX3ugsxbIxUCsN22DM+tnAYsHJ1wgk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aOMo5JyhR/ZbbwtT53WLDQmUo8YmADB6zBl7lJLjlIEcI6+RAq1XcLnZcR8zZv9Y+xfveUoTe1vo4/uBDqXUeXzrvjLa8/fM5tLgACbwb/zd+pu6gidN0ghHzbKl4RjudXqqG9yVSLlejpFTpB1F6MGlYuZbbzkko8vqH4WCQUw= 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=l+nUddnX; 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 0E5CB47A5A; Tue, 23 Apr 2024 22:41:11 +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 v2 2/6] iio: light: stk3310: Implement vdd supply and power it off during suspend Date: Tue, 23 Apr 2024 18:33:05 -0400 Message-ID: <20240423223309.1468198-4-aren@peacevolution.org> In-Reply-To: <20240423223309.1468198-2-aren@peacevolution.org> References: <20240423223309.1468198-2-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=1713912072; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=Pocgw671NmVP3upSEXxvVD2OibWy7kumLvOzth5JeTg=; b=l+nUddnXDeq2ogq+5wgM2loG+Zhw9lbTkOdpiEms8CGYX47TIDLx5TnywJYBYr8tJVrN9f 8Pem/UxHV78BEhybQuH9K5YyOFtNDmESnC3g4YfWLylccPCttb6Dl3OhrMQZXMEXaW/0bS ZNCp+zXZmDGGd5WHjWsxyyeXXmk0lQE= 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 --- Notes: Changes in v2: - always enable / disable regulators and rely on a dummy regulator if one isn't specified - replace usleep_range with fsleep - reorder includes so iio headers are last - add missing error handling to resume drivers/iio/light/stk3310.c | 49 ++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index 7b71ad71d78d..a0547eeca3e3 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -13,6 +13,8 @@ #include #include #include +#include + #include #include #include @@ -117,6 +119,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 +610,10 @@ static int stk3310_probe(struct i2c_client *client) mutex_init(&data->lock); + data->vdd_reg = devm_regulator_get(&client->dev, "vdd"); + if (IS_ERR(data->vdd_reg)) + return dev_err_probe(&client->dev, ret, "get regulator vdd failed\n"); + ret = stk3310_regmap_init(data); if (ret < 0) return ret; @@ -617,9 +624,17 @@ static int stk3310_probe(struct i2c_client *client) indio_dev->channels = stk3310_channels; indio_dev->num_channels = ARRAY_SIZE(stk3310_channels); + ret = regulator_enable(data->vdd_reg); + if (ret) + return dev_err_probe(&client->dev, ret, + "regulator vdd enable failed\n"); + + /* we need a short delay to allow the chip time to power on */ + fsleep(1000); + 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 +660,60 @@ static int stk3310_probe(struct i2c_client *client) err_standby: stk3310_set_state(data, STK3310_STATE_STANDBY); +err_vdd_disable: + 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); + 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; + + 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))); + + ret = regulator_enable(data->vdd_reg); + if (ret) { + dev_err(dev, "Failed to re-enable regulator vdd\n"); + return ret; + } + + fsleep(1000); + + ret = regcache_sync(data->regmap); + if (ret) { + dev_err(dev, "Failed to restore registers: %d\n", ret); + return ret; + } + if (data->ps_enabled) state |= STK3310_STATE_EN_PS; if (data->als_enabled) -- 2.44.0