From nobody Sun Nov 24 18:27:14 2024 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 769691AB525; Sat, 2 Nov 2024 19:54:41 +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=1730577284; cv=none; b=o6KZs0hhz8IRu6L42jZW6L0c2jUksvWi27TqRAImRZEV4STapFSR3QA7EugIIDOnziybCjGvUQzLEqQ/c+kgHL/R8YK2Q3hQb0Ud8ZJBGLDfAzgZS+mLYalgd/w08RQe+Rm5jxSDvlVOlETIPRnbFJVss6ednZoDAIibyPRFFYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730577284; c=relaxed/simple; bh=/YzjZ2+kWaCJYiOsHNNNL2840PxUKMK+oiKSq/YkNaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UiKa3T35JYI+QHk8lj2SV05HjXNU1bMX9ufsLegFIpySXHNgja5P2lbMobIhV0LkE7tD3Oi5Zg14u7PGdqmz9fRQ375NIAcGbei3Li5Ylcsa/CMuMiGA5Zf1U/VXO3FKaf2kQsrb9nDnZi0qrpLlVnB2wwabpnyq5bn3xZ00JL8= 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=VAUl+C68; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="VAUl+C68" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 307724C845; Sat, 2 Nov 2024 19:54:39 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= , Ondrej Jirman , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Dragan Simic , phone-devel@vger.kernel.org, Krzysztof Kozlowski Subject: [PATCH v4 1/6] dt-bindings: iio: light: stk33xx: add vdd and leda regulators Date: Sat, 2 Nov 2024 15:50:35 -0400 Message-ID: <20241102195037.3013934-5-aren@peacevolution.org> In-Reply-To: <20241102195037.3013934-3-aren@peacevolution.org> References: <20241102195037.3013934-3-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: quoted-printable 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=1730577280; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=6wjZ1pTHZq/+k3MCnSbbzmSo0hoqjpDUYVU+ZZfLBNM=; b=VAUl+C68ru76ec7Nb1Mb9ewjMuuI0BS5yVVgiZzYbG1egtlzzsh+ja7Si9tRUCmfImF0EN mgJfFaitBAaR2zB3PqoQZVBgsVfbO5iyyCQHBC0Ux6Y/CrbqRpTNKsBhNqKA3kDTsjFB52 olPU/ef1KtJVkPoyexcTUwmxVvoQ40s= Content-Type: text/plain; charset="utf-8" stk3310 and stk3311 are typically connected to power supplies for the chip (vdd) and the infrared LED (leda). Add properties so we can power these up / down appropriately. Signed-off-by: Aren Moynihan Reviewed-by: Krzysztof Kozlowski --- Notes: Changes in v2: - add leda-supply - add supplies to examples Documentation/devicetree/bindings/iio/light/stk33xx.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/light/stk33xx.yaml b/Doc= umentation/devicetree/bindings/iio/light/stk33xx.yaml index e4341fdced98..96ee8ec16463 100644 --- a/Documentation/devicetree/bindings/iio/light/stk33xx.yaml +++ b/Documentation/devicetree/bindings/iio/light/stk33xx.yaml @@ -34,6 +34,8 @@ properties: interrupts: maxItems: 1 =20 + vdd-supply: true + leda-supply: true proximity-near-level: true =20 required: @@ -57,6 +59,8 @@ examples: proximity-near-level =3D <25>; interrupt-parent =3D <&gpio1>; interrupts =3D <5 IRQ_TYPE_LEVEL_LOW>; + vdd-supply =3D <&vdd_regulator>; + leda-supply =3D <&led_regulator>; }; }; ... --=20 2.47.0 From nobody Sun Nov 24 18:27:14 2024 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 B02DE1AB51B; Sat, 2 Nov 2024 19:55:00 +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=1730577302; cv=none; b=Vi6YX1n9Sw+LYX4b0P+LiUGuSPta+p0xiDPwmXhr2+F4MFwmcx6l/rd1izURO+CvbC4Sad0fTOy3bje1joQKWoGNRL6EDxKvkjeRSJprexrOLjnkztb2SVJHivOMOzPjG1hcuhUNMDkJPTj/LsrKYgDwvyCcF9rD7YsSlTg4t7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730577302; c=relaxed/simple; bh=7FJEqZXWfSfqVHK3f18vO7zpSkgyXuTiGdBKpvwy7Dg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mnz4kn4bSyNtlX7SPoP1TI5IRYx/aHgCv732oSVxP4X2I0BjO27IC0eKCb8jyokKtrHWEDDH7qlDareNyMJqlZxsfF+KQc4yISGEsUfnDkfWM8fVombaURhUCJSSpNmJpFrbAdRS6ypWT7gaLv2HOSK07YqAsVcxjv2FupxUals= 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=N7FNSpab; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="N7FNSpab" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 519BC4C832; Sat, 2 Nov 2024 19:54:58 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= , Ondrej Jirman , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Dragan Simic , phone-devel@vger.kernel.org Subject: [PATCH v4 2/6] iio: light: stk3310: handle all remove logic with devm callbacks Date: Sat, 2 Nov 2024 15:50:37 -0400 Message-ID: <20241102195037.3013934-7-aren@peacevolution.org> In-Reply-To: <20241102195037.3013934-3-aren@peacevolution.org> References: <20241102195037.3013934-3-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: quoted-printable 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=1730577299; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=muOFYNTzaO2s6LuQjYw2jR7V/iVjO+R6V5aOyyeC/fE=; b=N7FNSpabyT6u3ukvz2bGjgD3Kioi/Imge8JRYxQFCk/rPJ43by7Uq54vvUM7JGmALM8AbD TtrYr8kRff/oSFO2M9ES5MPF1Bxlnzy1RgeNDHDPq9FjiiwFM7AAqCQF/MAl4DGeztFM2n i+adxee2o+IWMf48clpCf+XkW19ahIw= Content-Type: text/plain; charset="utf-8" Using devm callbacks helps to make the ordering of probe / remove operations easier to reason about and removes some duplicate code between the probe error path and driver remove. --- Notes: Changes in v4: - also replace mutex_init with devm_mutex_init =20 Added in v3 drivers/iio/light/stk3310.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index ed20b6714546..181b7acb3f96 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -484,6 +484,17 @@ static int stk3310_set_state(struct stk3310_data *data= , u8 state) return ret; } =20 +static void stk3310_set_state_disable(void *private) +{ + int ret; + struct stk3310_data *data =3D private; + struct device *dev =3D &data->client->dev; + + ret =3D stk3310_set_state(data, STK3310_STATE_STANDBY); + if (ret) + dev_err(dev, "failed to set state to standby: %d\n", ret); +} + static int stk3310_init(struct iio_dev *indio_dev) { int ret; @@ -491,6 +502,7 @@ static int stk3310_init(struct iio_dev *indio_dev) u8 state; struct stk3310_data *data =3D iio_priv(indio_dev); struct i2c_client *client =3D data->client; + struct device *dev =3D &client->dev; =20 ret =3D regmap_read(data->regmap, STK3310_REG_ID, &chipid); if (ret < 0) @@ -507,6 +519,10 @@ static int stk3310_init(struct iio_dev *indio_dev) return ret; } =20 + ret =3D devm_add_action_or_reset(&client->dev, stk3310_set_state_disable,= data); + if (ret) + return dev_err_probe(dev, ret, "failed to register cleanup function\n"); + /* Enable PS interrupts */ ret =3D regmap_field_write(data->reg_int_ps, STK3310_PSINT_EN); if (ret < 0) @@ -624,7 +640,7 @@ static int stk3310_probe(struct i2c_client *client) device_property_read_u32(&client->dev, "proximity-near-level", &data->ps_near_level); =20 - mutex_init(&data->lock); + devm_mutex_init(&client->dev, &data->lock); =20 ret =3D stk3310_regmap_init(data); if (ret < 0) @@ -650,29 +666,17 @@ static int stk3310_probe(struct i2c_client *client) if (ret < 0) { dev_err(&client->dev, "request irq %d failed\n", client->irq); - goto err_standby; + return ret; } } =20 - ret =3D iio_device_register(indio_dev); + ret =3D devm_iio_device_register(&client->dev, indio_dev); if (ret < 0) { dev_err(&client->dev, "device_register failed\n"); - goto err_standby; + return ret; } =20 return 0; - -err_standby: - stk3310_set_state(data, STK3310_STATE_STANDBY); - return ret; -} - -static void stk3310_remove(struct i2c_client *client) -{ - struct iio_dev *indio_dev =3D i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - stk3310_set_state(iio_priv(indio_dev), STK3310_STATE_STANDBY); } =20 static int stk3310_suspend(struct device *dev) @@ -736,7 +740,6 @@ static struct i2c_driver stk3310_driver =3D { .acpi_match_table =3D stk3310_acpi_id, }, .probe =3D stk3310_probe, - .remove =3D stk3310_remove, .id_table =3D stk3310_i2c_id, }; =20 --=20 2.47.0 From nobody Sun Nov 24 18:27:14 2024 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 7DE9914F12F; Sat, 2 Nov 2024 19:55:41 +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=1730577343; cv=none; b=nbEcXzl5XqisCPfsemvJ5K63/NDLaKxaVqPlaHd7W1IP2DunryuM+wh3PLgx3SB4DrRhUmNoJnVrusuEGxpTxz4gaoughgr3fVFQFm2WDhV8UcXBQ37b9SqagqRRp+j1o89bSbs7C6nlPArxVsHRzQe/r8P8Xi+zZpFzH6+rgco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730577343; c=relaxed/simple; bh=umjP4aXqz5QQ2yU6yTjfsFbN/Fg9BNOjZ+Nj8S3y9FU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MUlEFKVzD/q2wLqoCYNZY0Fix7yJG+CdZouGHIDUakklgEIviLOvFXRA5QQehhfjrKSgvEjywjTffq8n73fzN+7J/zMYfdMwAIoA8SLntL0sw8XYaXI/t9XiG3Dq27zP+4Gso35Z2AvI/5gqKVsDobLyGLBaQdTGkFYlB+2brCM= 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=OW4ekAto; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="OW4ekAto" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 61D1C4C832; Sat, 2 Nov 2024 19:55:39 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= , Ondrej Jirman , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Dragan Simic , phone-devel@vger.kernel.org Subject: [PATCH v4 3/6] iio: light: stk3310: Implement vdd and leda supplies Date: Sat, 2 Nov 2024 15:50:39 -0400 Message-ID: <20241102195037.3013934-9-aren@peacevolution.org> In-Reply-To: <20241102195037.3013934-3-aren@peacevolution.org> References: <20241102195037.3013934-3-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: quoted-printable 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=1730577340; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=bZ4cqFntykXHpbFFV4ZfGRHhWWvK0O7Az93eNAhN7Dc=; b=OW4ekAto3UFMKXXS3S0cDNzAePkehJMi1jH2TlRvY/Fy2fyyCuWKyfKeXbKV6yFTFk/riD /XXAgwAbUG7sYkXkMd+CcaRmJZ/uFTMefVd6Eo3Tyhkq4c6eKktdx2YajP4A5ULvl/1t45 yVIE9EZPVPuSD3UAEHmroZ4HUASpkIw= Content-Type: text/plain; charset="utf-8" The vdd and leda supplies must be powered on for the chip to function and can be powered off during system suspend. This was originally based on a patch by Ondrej Jirman[1], but has been rewritten since. 1: https://codeberg.org/megi/linux/commit/a933aff8b7a0e6e3c9cf1d832dcba0702= 2bbfa82 Signed-off-by: Aren Moynihan --- Notes: Changes in v4: - fix variable declaration order in stk3310_resume to match the rest of the driver =20 Changes in v3: - use bulk regulators instead of two individual ones - handle cleanup using devm callbacks instead of the remove function =20 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 | 76 ++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index 181b7acb3f96..f93689c61f44 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -13,6 +13,8 @@ #include #include #include +#include + #include #include #include @@ -130,6 +132,7 @@ struct stk3310_data { struct regmap_field *reg_int_ps; struct regmap_field *reg_flag_psint; struct regmap_field *reg_flag_nf; + struct regulator_bulk_data supplies[2]; }; =20 static const struct iio_event_spec stk3310_events[] =3D { @@ -621,6 +624,31 @@ static irqreturn_t stk3310_irq_event_handler(int irq, = void *private) return IRQ_HANDLED; } =20 +static int stk3310_regulators_enable(struct stk3310_data *data) +{ + int ret; + + ret =3D regulator_bulk_enable(ARRAY_SIZE(data->supplies), data->supplies); + if (ret) + return ret; + + /* we need a short delay to allow the chip time to power on */ + fsleep(1000); + + return 0; +} + +static void stk3310_regulators_disable(void *private) +{ + int ret; + struct stk3310_data *data =3D private; + struct device *dev =3D &data->client->dev; + + ret =3D regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies= ); + if (ret) + dev_err(dev, "failed to disable regulators: %d\n", ret); +} + static int stk3310_probe(struct i2c_client *client) { int ret; @@ -642,6 +670,13 @@ static int stk3310_probe(struct i2c_client *client) =20 devm_mutex_init(&client->dev, &data->lock); =20 + data->supplies[0].supply =3D "vdd"; + data->supplies[1].supply =3D "leda"; + ret =3D devm_regulator_bulk_get(&client->dev, ARRAY_SIZE(data->supplies), + data->supplies); + if (ret) + return dev_err_probe(&client->dev, ret, "get regulators failed\n"); + ret =3D stk3310_regmap_init(data); if (ret < 0) return ret; @@ -652,6 +687,16 @@ static int stk3310_probe(struct i2c_client *client) indio_dev->channels =3D stk3310_channels; indio_dev->num_channels =3D ARRAY_SIZE(stk3310_channels); =20 + ret =3D stk3310_regulators_enable(data); + if (ret) + return dev_err_probe(&client->dev, ret, + "regulator enable failed\n"); + + ret =3D devm_add_action_or_reset(&client->dev, stk3310_regulators_disable= , data); + if (ret) + return dev_err_probe(&client->dev, ret, + "failed to register regulator cleanup\n"); + ret =3D stk3310_init(indio_dev); if (ret < 0) return ret; @@ -682,18 +727,45 @@ static int stk3310_probe(struct i2c_client *client) static int stk3310_suspend(struct device *dev) { struct stk3310_data *data; + int ret; =20 data =3D iio_priv(i2c_get_clientdata(to_i2c_client(dev))); =20 - return stk3310_set_state(data, STK3310_STATE_STANDBY); + ret =3D stk3310_set_state(data, STK3310_STATE_STANDBY); + if (ret) + return ret; + + regcache_mark_dirty(data->regmap); + + ret =3D regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies= ); + if (ret) { + dev_err(dev, "failed to disable regulators: %d\n", ret); + return ret; + } + + return 0; } =20 static int stk3310_resume(struct device *dev) { - u8 state =3D 0; + int ret; struct stk3310_data *data; + u8 state =3D 0; =20 data =3D iio_priv(i2c_get_clientdata(to_i2c_client(dev))); + + ret =3D stk3310_regulators_enable(data); + if (ret) { + dev_err(dev, "Failed to re-enable regulators: %d", ret); + return ret; + } + + ret =3D regcache_sync(data->regmap); + if (ret) { + dev_err(dev, "Failed to restore registers: %d\n", ret); + return ret; + } + if (data->ps_enabled) state |=3D STK3310_STATE_EN_PS; if (data->als_enabled) --=20 2.47.0 From nobody Sun Nov 24 18:27:14 2024 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 516031AB51B; Sat, 2 Nov 2024 19:56:05 +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=1730577366; cv=none; b=InRmO/UId8bfQ8dUG+eGo55axoRlRi+ysGwoMT9B+K811DRKY8HMDNkbumK75LSYvYpxmFu63fp7kKZtIw8bHfbnynjuFRSzWj0u22VRrE1Gd6wV0SUnIjXrIoomzWfUxV54H/CwX/4tuzNr2+DeO8JiJKOfSMCtLtFUa1INM84= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730577366; c=relaxed/simple; bh=28wySHybmNzvDTM0gtkqKltIIyZ02cQb/jqmatJ5bvY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kH63BdhrpqD5QtPI20YcFe2fGqhnIB/wbLzZTMqrY/yk5k8NRU4fqLbYz6ge94Lh3hUK5awm5P0gM0K0LNty25OEnEdhiE76g+gby8I+rVn37WajL6kKj3ul7eB8QcL1Lqmkpqj2sDC7CGyyDj8Ux4JVEMHomrv2me4fDotCaV4= 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=ZBbr8wfw; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="ZBbr8wfw" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 605304C847; Sat, 2 Nov 2024 19:56:03 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= , Ondrej Jirman , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Dragan Simic , phone-devel@vger.kernel.org Subject: [PATCH v4 4/6] iio: light: stk3310: use dev_err_probe where possible Date: Sat, 2 Nov 2024 15:50:41 -0400 Message-ID: <20241102195037.3013934-11-aren@peacevolution.org> In-Reply-To: <20241102195037.3013934-3-aren@peacevolution.org> References: <20241102195037.3013934-3-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: quoted-printable 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=1730577364; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=EOQ+icUlK1H5YL/QrrfHa7ZgZuPTLdaho4son5PhToI=; b=ZBbr8wfwo3qQ6VZx2PM+mCKxgFgJ/XzgEIbWYqxxV53kdJtu1IBxYs/14HzjzlLCmsI4jP h0+CYKNKBlldsH12AbP+Fb/Fi3RtW5SWO0+akM3HX4gLAKYE1ihUITbcPR4JxGcegEhi5O WVHfe7SmFGbvI01CTC/SvMfZUL4D0qI= Content-Type: text/plain; charset="utf-8" Using dev_err_probe instead of dev_err and return makes the errors easier to understand by including the error name, and saves a little code. Signed-off-by: Aren Moynihan --- Notes: Changes in v4: - Get a struct device ahead of time so it can be passed as "dev" instead of "&client->dev" =20 No changes in v3 =20 Added in v2 drivers/iio/light/stk3310.c | 61 ++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index f93689c61f44..c9a3f02bdd80 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -61,12 +61,12 @@ #define STK3310_REGFIELD(name) \ do { \ data->reg_##name =3D \ - devm_regmap_field_alloc(&client->dev, regmap, \ + devm_regmap_field_alloc(dev, regmap, \ stk3310_reg_field_##name); \ - if (IS_ERR(data->reg_##name)) { \ - dev_err(&client->dev, "reg field alloc failed.\n"); \ - return PTR_ERR(data->reg_##name); \ - } \ + if (IS_ERR(data->reg_##name)) \ + return dev_err_probe(dev, \ + PTR_ERR(data->reg_##name), \ + "reg field alloc failed.\n"); \ } while (0) =20 static const struct reg_field stk3310_reg_field_state =3D @@ -517,10 +517,8 @@ static int stk3310_init(struct iio_dev *indio_dev) =20 state =3D STK3310_STATE_EN_ALS | STK3310_STATE_EN_PS; ret =3D stk3310_set_state(data, state); - if (ret < 0) { - dev_err(&client->dev, "failed to enable sensor"); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "failed to enable sensor\n"); =20 ret =3D devm_add_action_or_reset(&client->dev, stk3310_set_state_disable,= data); if (ret) @@ -529,9 +527,9 @@ static int stk3310_init(struct iio_dev *indio_dev) /* Enable PS interrupts */ ret =3D regmap_field_write(data->reg_int_ps, STK3310_PSINT_EN); if (ret < 0) - dev_err(&client->dev, "failed to enable interrupts!\n"); + return dev_err_probe(dev, ret, "failed to enable interrupts!\n"); =20 - return ret; + return 0; } =20 static bool stk3310_is_volatile_reg(struct device *dev, unsigned int reg) @@ -560,14 +558,14 @@ static const struct regmap_config stk3310_regmap_conf= ig =3D { static int stk3310_regmap_init(struct stk3310_data *data) { struct regmap *regmap; - struct i2c_client *client; + struct i2c_client *client =3D data->client; + struct device *dev =3D &client->dev; =20 - client =3D data->client; regmap =3D devm_regmap_init_i2c(client, &stk3310_regmap_config); - if (IS_ERR(regmap)) { - dev_err(&client->dev, "regmap initialization failed.\n"); - return PTR_ERR(regmap); - } + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), + "regmap initialization failed.\n"); + data->regmap =3D regmap; =20 STK3310_REGFIELD(state); @@ -654,12 +652,11 @@ static int stk3310_probe(struct i2c_client *client) int ret; struct iio_dev *indio_dev; struct stk3310_data *data; + struct device *dev =3D &client->dev; =20 indio_dev =3D devm_iio_device_alloc(&client->dev, sizeof(*data)); - if (!indio_dev) { - dev_err(&client->dev, "iio allocation failed!\n"); - return -ENOMEM; - } + if (!indio_dev) + return dev_err_probe(dev, -ENOMEM, "iio allocation failed!\n"); =20 data =3D iio_priv(indio_dev); data->client =3D client; @@ -675,7 +672,7 @@ static int stk3310_probe(struct i2c_client *client) ret =3D devm_regulator_bulk_get(&client->dev, ARRAY_SIZE(data->supplies), data->supplies); if (ret) - return dev_err_probe(&client->dev, ret, "get regulators failed\n"); + return dev_err_probe(dev, ret, "get regulators failed\n"); =20 ret =3D stk3310_regmap_init(data); if (ret < 0) @@ -689,13 +686,11 @@ static int stk3310_probe(struct i2c_client *client) =20 ret =3D stk3310_regulators_enable(data); if (ret) - return dev_err_probe(&client->dev, ret, - "regulator enable failed\n"); + return dev_err_probe(dev, ret, "regulator enable failed\n"); =20 ret =3D devm_add_action_or_reset(&client->dev, stk3310_regulators_disable= , data); if (ret) - return dev_err_probe(&client->dev, ret, - "failed to register regulator cleanup\n"); + return dev_err_probe(dev, ret, "failed to register regulator cleanup\n"); =20 ret =3D stk3310_init(indio_dev); if (ret < 0) @@ -708,18 +703,14 @@ static int stk3310_probe(struct i2c_client *client) IRQF_TRIGGER_FALLING | IRQF_ONESHOT, STK3310_EVENT, indio_dev); - if (ret < 0) { - dev_err(&client->dev, "request irq %d failed\n", - client->irq); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "request irq %d failed\n", + client->irq); } =20 ret =3D devm_iio_device_register(&client->dev, indio_dev); - if (ret < 0) { - dev_err(&client->dev, "device_register failed\n"); - return ret; - } + if (ret < 0) + return dev_err_probe(dev, ret, "device_register failed\n"); =20 return 0; } --=20 2.47.0 From nobody Sun Nov 24 18:27:14 2024 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 6DF731A4E9E; Sat, 2 Nov 2024 19:56:23 +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=1730577386; cv=none; b=K4STmQCORW3blaF2Ckb3SV4BL17atjcBRvrYKGOFAGDBrzmEGKNI9lIHcaJ4badL84m3ON9ry2dohgBUTqbxhimmiExnTFEz3RL4VE7wbd9Az/PyS+Ua0cgBAEf0dKJiXmqm6ET8F6XIiWnIYo9VWd1hM1xHrXLmjPos2dvSNUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730577386; c=relaxed/simple; bh=4eVyemtYA34bmRuiZAcr9XBoupD7yQ73G+EnUW2d1zM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YyD2G8OX8BHThGn9gLQJha320Bdgpwt+x+45dkolbB8xDORMYQOdUlmPn3+scwYXzjcuE5wfcStobOniUOOhngVXwDqv+Bva+99rT20CnFZIaPlo8sww2vTOS68uJfEerAYpi0pR4glVfOkKuGJgVjHod7gyMeVsittiQlCc2Go= 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=iKg1Bs5e; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="iKg1Bs5e" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 69A2B4C84C; Sat, 2 Nov 2024 19:56:21 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= , Ondrej Jirman , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Dragan Simic , phone-devel@vger.kernel.org Subject: [PATCH v4 5/6] iio: light: stk3310: log error if reading the chip id fails Date: Sat, 2 Nov 2024 15:50:43 -0400 Message-ID: <20241102195037.3013934-13-aren@peacevolution.org> In-Reply-To: <20241102195037.3013934-3-aren@peacevolution.org> References: <20241102195037.3013934-3-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: quoted-printable 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=1730577382; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=uvvNhj8Jh93zpagJdBLhHBNGJCsGSzK4C5YOxnQO53E=; b=iKg1Bs5ez3k57s5TX8B2KsJGqvkshKKwCERTQrh5gkSzMVC+c1ahFcgX9DDVEtcz8uswXR CQ73g9pKzfXbtlIPoTpg53k6VMYFigxLTGRewaGMfCZfXj+vXRY4NBSDCmwxoZkJtUhqZr u3lpZEO0IZNZsuJa/CQw3I5UB/Jg0VY= Content-Type: text/plain; charset="utf-8" If the chip isn't powered, this call is likely to return an error. Without a log here the driver will silently fail to probe. Potential errors include ENXIO (when the chip isn't powered) and ETIMEDOUT (when the i2c bus isn't powered). This function is only called from stk3310_probe, and this condition should return an error, which fits what dev_err_probe is designed for. Signed-off-by: Aren Moynihan --- Notes: Changes in v4: - get a struct device ahead of time so it can be passed as "dev" instead of "&client->dev" =20 Changes in v2: - use dev_err_probe drivers/iio/light/stk3310.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index c9a3f02bdd80..becd6901dfef 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -509,7 +509,7 @@ static int stk3310_init(struct iio_dev *indio_dev) =20 ret =3D regmap_read(data->regmap, STK3310_REG_ID, &chipid); if (ret < 0) - return ret; + return dev_err_probe(dev, ret, "failed to read chip id\n"); =20 ret =3D stk3310_check_chip_id(chipid); if (ret < 0) --=20 2.47.0 From nobody Sun Nov 24 18:27:14 2024 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 93E851ABED7; Sat, 2 Nov 2024 19:56:28 +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=1730577390; cv=none; b=AXqFB1qdVZHwaKkIahcSUAHf5lT1Oi+hr1U2RGRj38YM66BKw2wUS6tYO1ya0QutpC3m+RkvnPiQjR3T8YmIbTbxhU3kr3hWqloDPs+3PmrDmAXtypC1K/G5+djimxqHgUCcRBdtJLGMameXKypK72NojxbeimtXL5hevxGTKrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730577390; c=relaxed/simple; bh=Az7W1ohdHrR78IqIcSfKr8mkmXTqZ+V08E1PhLHn4d4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ACKTU23Bcg+4hCGhJQEBnqthcwD4srTgo09WDuayQemQNNT7+TRAzKRIJ2HBbF8kHFq6aKhfuUSVFwIikfHLjYG8CpozpA+EcgYUNA/NMIB8Jg9IdeUz3vqujqwooSU6ByurYAOWrzyQ9/4ndsuWAuqxkojPcmjXh37+bn/Q8D8= 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=Pjp06f/L; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="Pjp06f/L" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id ACC684C854; Sat, 2 Nov 2024 19:56:26 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?UTF-8?q?Barnab=C3=A1s=20Cz=C3=A9m=C3=A1n?= , Ondrej Jirman , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Dragan Simic , phone-devel@vger.kernel.org Subject: [PATCH v4 6/6] arm64: dts: allwinner: pinephone: Add power supplies to stk3311 Date: Sat, 2 Nov 2024 15:50:45 -0400 Message-ID: <20241102195037.3013934-15-aren@peacevolution.org> In-Reply-To: <20241102195037.3013934-3-aren@peacevolution.org> References: <20241102195037.3013934-3-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: quoted-printable 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=1730577387; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=1Fb34FGXqzMNx+nxE4qoPozuG7GAzwlPuHgHmRcGRGE=; b=Pjp06f/LQfljxy4nUX7anE7BKppC4jnYqRqIDe1m7j06931HUoyxpBYZ6g1MUUe0uReAXB 89CSOhXwYBG+oYdlidrjtzcCkFSUADPTFl3zAgUDxisOqeX11FOGMjeZExcKpc9yHtVrk+ ivqT/Kd9YSRMrm65fNEpQdifcsk3ZAA= Content-Type: text/plain; charset="utf-8" From: Ondrej Jirman This allows the driver to properly handle powering this device, and disable power during suspend. Signed-off-by: Ondrej Jirman Signed-off-by: Aren Moynihan --- Notes: Changes in v2: - add leda-supply arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi b/arch= /arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi index 6d152066a59a..618341b63db2 100644 --- a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi +++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtsi @@ -260,6 +260,8 @@ light-sensor@48 { reg =3D <0x48>; interrupt-parent =3D <&pio>; interrupts =3D <1 0 IRQ_TYPE_EDGE_FALLING>; /* PB0 */ + vdd-supply =3D <®_ldo_io0>; + leda-supply =3D <®_dldo1>; }; =20 /* Accelerometer/gyroscope */ --=20 2.47.0