From patchwork Mon Oct 28 14:19:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 13853568 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 BC7A51DD0C9; Mon, 28 Oct 2024 14:21:50 +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=1730125312; cv=none; b=LZo0QavqlqmfGuyY0vIbydTph3TzJ1tCQZTtnYvytHVBg2GgbUIJt7V6qqu0ViTtIPpNIa/RobfFhVitDqi0aQAYKth0r2FEgRiddTUFkZKIuTVU/PxFS9CMVDHaln8mn5ihz2lsSudDyS+75JiPRbrO/qM2Zo/NKt9Qd4jim3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730125312; c=relaxed/simple; bh=/YzjZ2+kWaCJYiOsHNNNL2840PxUKMK+oiKSq/YkNaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GVRpOzZ7xUdKOgZh6OMXQKIQ+zRSfDBLnqrO4P1ODfqmPRmQ1S1ho506NY65WiIdDA39gF85hMpQh+6SHv1XjKxk0Nr43kl4j8DlQyW4oXLgTXCwfwDB/+Evd2aTadLGpxGsWpceDZPKi/S56D86QqlnH19MuUYR6SbR7bBiBuE= 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=lIbTPM/A; 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="lIbTPM/A" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 588034C736; Mon, 28 Oct 2024 14:21:48 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?utf-8?b?QmFybmFiw6FzIEN6?= =?utf-8?b?w6ltw6Fu?= , Andy Shevchenko , Ondrej Jirman , =?utf-8?q?Uwe_Kleine-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 v3 1/6] dt-bindings: iio: light: stk33xx: add vdd and leda regulators Date: Mon, 28 Oct 2024 10:19:55 -0400 Message-ID: <20241028142000.1058149-2-aren@peacevolution.org> In-Reply-To: <20241028142000.1058149-1-aren@peacevolution.org> References: <20241028142000.1058149-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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=1730125309; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=6wjZ1pTHZq/+k3MCnSbbzmSo0hoqjpDUYVU+ZZfLBNM=; b=lIbTPM/AeaMflAcdwUJTLIqKg+0qzjN+F7YnXFOaviiL719lrG2kCKUyGQWu4NKN79l5qL 5mqVD0tWkcaaCIf3a1sRdridQwMCanS1iTHnmY5GoM4GLEIMQpq+ZcPYw6LsTkZLoS7yEw yQBC8DXXeh9XO+ZV2jk9kFdDP9rki/Y= 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/Documentation/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 + vdd-supply: true + leda-supply: true proximity-near-level: true required: @@ -57,6 +59,8 @@ examples: proximity-near-level = <25>; interrupt-parent = <&gpio1>; interrupts = <5 IRQ_TYPE_LEVEL_LOW>; + vdd-supply = <&vdd_regulator>; + leda-supply = <&led_regulator>; }; }; ... From patchwork Mon Oct 28 14:19:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 13853569 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 AA7F51DE3B2; Mon, 28 Oct 2024 14:21:59 +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=1730125321; cv=none; b=KxXfN6WMR5Q7X8Jlac3F6mm8FnkZwCuA4TtPWfoJcPu9q+gfr+2OFYXNvsvSXTgLtJCL2ayFhKt0q7Jk9kZs2qT8sxxC3aYDMYNA5d4XOf2kmz6gjdV/mqHlxiJMuhItMrY635b5oczuNvvTv8K5BdommzfJPqdOSC9GZUnJiB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730125321; c=relaxed/simple; bh=507hLKffuNcyueEfogPk5RCl8UnnoDrtN4ihkP6hxtY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KetvArYx1B5CCXzuce0BvcA7kWzw+NXEbDb6TD8nUHqZ719HRhkguqn06x9RFOflv1KXmKoZIQabSzfjMJaaIQm4XonzFLt9mPPB8kvfx8wE7gnU5eDcr5l20qHJ5gwb5P2V0pm74EcQgKiXR6rvnhTOExghqOeiv56nDMgSglI= 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=N2EsH13F; 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="N2EsH13F" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 8BFDB4C6A3; Mon, 28 Oct 2024 14:21:57 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?utf-8?b?QmFybmFiw6FzIEN6?= =?utf-8?b?w6ltw6Fu?= , Andy Shevchenko , Ondrej Jirman , =?utf-8?q?Uwe_Kleine-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 v3 2/6] iio: light: stk3310: handle all remove logic with devm callbacks Date: Mon, 28 Oct 2024 10:19:56 -0400 Message-ID: <20241028142000.1058149-3-aren@peacevolution.org> In-Reply-To: <20241028142000.1058149-1-aren@peacevolution.org> References: <20241028142000.1058149-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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=1730125318; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=XdEG+PzvG0Vo99BU/R4RjPsHvmaNQJ3LSrH+8TVql9M=; b=N2EsH13FDOQFjN8HkB+osgOBN8dUDuhjxjaYEcRsLPXlm636aADXeXR8Ybm0VHHf8pGmmv YScoijdrRYm4Jrw2F3qOCB+ANT9XC/0ViSVsKemakgDBPPVntrbuj8e0HHL06jWOL6jpX6 94B/thP/0MgpRh548+mX3NM11ZItS+g= 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: Added in v3 drivers/iio/light/stk3310.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index ed20b6714546..2e1aa551bdbc 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; } +static void stk3310_set_state_disable(void *private) +{ + int ret; + struct stk3310_data *data = private; + struct device *dev = &data->client->dev; + + ret = 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; @@ -507,6 +518,11 @@ static int stk3310_init(struct iio_dev *indio_dev) return ret; } + ret = devm_add_action_or_reset(&client->dev, stk3310_set_state_disable, data); + if (ret) + return dev_err_probe(&client->dev, ret, + "failed to register cleanup function\n"); + /* Enable PS interrupts */ ret = regmap_field_write(data->reg_int_ps, STK3310_PSINT_EN); 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; } } - ret = iio_device_register(indio_dev); + ret = devm_iio_device_register(&client->dev, indio_dev); if (ret < 0) { dev_err(&client->dev, "device_register failed\n"); - goto err_standby; + return ret; } 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 = i2c_get_clientdata(client); - - iio_device_unregister(indio_dev); - stk3310_set_state(iio_priv(indio_dev), STK3310_STATE_STANDBY); } static int stk3310_suspend(struct device *dev) @@ -736,7 +740,6 @@ static struct i2c_driver stk3310_driver = { .acpi_match_table = stk3310_acpi_id, }, .probe = stk3310_probe, - .remove = stk3310_remove, .id_table = stk3310_i2c_id, }; From patchwork Mon Oct 28 14:19:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 13853570 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 D6ED21DE3DB; Mon, 28 Oct 2024 14:22:01 +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=1730125324; cv=none; b=DO1U2rN3jysFTkNCcaQIv3rViZ16H8PWvIQUBAvTw3Y1zVtr3A6c8nFkR6/2gHC1s3tyJ+0NGAw1n2Az9O8ScKj0GWN0/2xVsfncYWqG/VCWjh8W7jox7f/v0lfATfEqMr1JNZghYo4VizVwGhYjif23JoF9Ptf+i+hwtJZFm+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730125324; c=relaxed/simple; bh=U8rlJZTMqpHnsFmbKCMlHFvFQ6aACYBAaLdN4IKCXrw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P5PP+p+bC9mEDQQ+qogjoNhhhGdSxlWBI6Ac4QY6Wp87Vzz7wCLJ3x2s5SBVgpYrzT1LbjrKij2H2c3i0DLdEcby36Hqj8JoCZxiD119zZpA0yDyFHRVF3rkqZ/JdGcFnr/oqhf/IyZGzTmQXRmpR2yl/9Vfol86ARPfaQL+x3Y= 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=brSA4imX; 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="brSA4imX" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id D55D14C75C; Mon, 28 Oct 2024 14:21:59 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?utf-8?b?QmFybmFiw6FzIEN6?= =?utf-8?b?w6ltw6Fu?= , Andy Shevchenko , Ondrej Jirman , =?utf-8?q?Uwe_Kleine-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 v3 3/6] iio: light: stk3310: Implement vdd and leda supplies Date: Mon, 28 Oct 2024 10:19:57 -0400 Message-ID: <20241028142000.1058149-4-aren@peacevolution.org> In-Reply-To: <20241028142000.1058149-1-aren@peacevolution.org> References: <20241028142000.1058149-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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=1730125321; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=XzAaEXLSb0gVUT48L6jxPocvqnzRypxww88Qv3DK4cg=; b=brSA4imXB0mSeHbBEkm0HIhd4Kor5Vt3u76cpfTs6Mort8TXHc5mtytkhkZxfEUntzK3TF Gte8CA20RGA0VPC2Tog1IkFQC1N0k/1QvyQo4L4fTi9n1UfQGWKGH61OSyFvEVE+8iDfI5 uk41hR2FP09oEmQGNBA8dnFAiQDdsLE= The vdd and leda supplies must be powered on for the chip to function and can be powered off during system suspend. Co-developed-by: Ondrej Jirman Signed-off-by: Aren Moynihan --- Notes: I'm not sure what the proper way to handle attribution for this patch is. It was origionally based on a patch by Ondrej Jirman[1], but I have rewritten a large portion if it. I have included a Co-developed-by tag to indicate this, but haven't sent him this patch, so I'm not sure what to do about a Signed-off-by. 1: https://codeberg.org/megi/linux/commit/a933aff8b7a0e6e3c9cf1d832dcba07022bbfa82 Changes in v3: - use bulk regulators instead of two individual ones - handle cleanup using devm callbacks instead of the remove function 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 2e1aa551bdbc..f02b4d20c282 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]; }; static const struct iio_event_spec stk3310_events[] = { @@ -621,6 +624,31 @@ static irqreturn_t stk3310_irq_event_handler(int irq, void *private) return IRQ_HANDLED; } +static int stk3310_regulators_enable(struct stk3310_data *data) +{ + int ret; + + ret = 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 = private; + struct device *dev = &data->client->dev; + + ret = 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) mutex_init(&data->lock); + data->supplies[0].supply = "vdd"; + data->supplies[1].supply = "leda"; + ret = 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 = stk3310_regmap_init(data); if (ret < 0) return ret; @@ -652,6 +687,16 @@ static int stk3310_probe(struct i2c_client *client) indio_dev->channels = stk3310_channels; indio_dev->num_channels = ARRAY_SIZE(stk3310_channels); + ret = stk3310_regulators_enable(data); + if (ret) + return dev_err_probe(&client->dev, ret, + "regulator enable failed\n"); + + ret = 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 = 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; 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); + + ret = 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; } 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 = stk3310_regulators_enable(data); + if (ret) { + dev_err(dev, "Failed to re-enable regulators: %d", ret); + return ret; + } + + 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) From patchwork Mon Oct 28 14:19:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 13853571 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 390AA1DE4F1; Mon, 28 Oct 2024 14:22:07 +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=1730125329; cv=none; b=o9BW1u6nc3ecF7SjXjmYk6UYqwxsJOKftKKo7i2hreq2gPoQWuX7IXOmUyZuJM+PhbxDtsWV1SZVZO84Tjpn5P59Bc9ozJgc1oeftUt4VcuueiDdaadt1AtjdYKlDXZqEnanrGwygiEOTiQehOqSHHyyMjnHuzp9am3Rv8fKfyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730125329; c=relaxed/simple; bh=R0QdaxKXZI0DFp2QnvBUzElHKM3qvbEjHucu9DEE1mk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xq6d+8ktvWq72+GfxkpOSMzHx0yEeG1nTY8XgagiaE8JW4i+ixdFO60kvsAIzH1HM5uormTEfz6mJCsr85YeJuyaLiLE3lyV6RGyNY2WWYgXxjHJnZ6ZJQp9GDbvscBNGOZkV94DtFaB7loBGFh09wv4g+xadVBe8UrFWhhlI+I= 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=cqf1pXMj; 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="cqf1pXMj" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 303D24C772; Mon, 28 Oct 2024 14:22:05 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?utf-8?b?QmFybmFiw6FzIEN6?= =?utf-8?b?w6ltw6Fu?= , Andy Shevchenko , Ondrej Jirman , =?utf-8?q?Uwe_Kleine-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 v3 4/6] iio: light: stk3310: use dev_err_probe where possible Date: Mon, 28 Oct 2024 10:19:58 -0400 Message-ID: <20241028142000.1058149-5-aren@peacevolution.org> In-Reply-To: <20241028142000.1058149-1-aren@peacevolution.org> References: <20241028142000.1058149-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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=1730125326; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=BYRnEk36IG62nZFzfPUk6ctg8BAgE9bbIy4meLjMgzI=; b=cqf1pXMjukY8Zv46PsYKFeV55lZhBqM38mH3p3E4cmvuH9UV6mTtFWKG3tCX4bitZ0DpkP pJEptKQFJXJIWJd9qgHzxkrmJqnaKg3g6B7eBrEGf+yj19ePMOkBzrdPjo88UYI3SxqAYG 8NcgYXvHDVm6ZbRJW5Z5M9R3nisONzk= 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: Added in v2 drivers/iio/light/stk3310.c | 47 ++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/drivers/iio/light/stk3310.c b/drivers/iio/light/stk3310.c index f02b4d20c282..968a2cc59d09 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -63,10 +63,10 @@ data->reg_##name = \ devm_regmap_field_alloc(&client->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(&client->dev, \ + PTR_ERR(data->reg_##name), \ + "reg field alloc failed.\n"); \ } while (0) static const struct reg_field stk3310_reg_field_state = @@ -516,10 +516,8 @@ static int stk3310_init(struct iio_dev *indio_dev) state = STK3310_STATE_EN_ALS | STK3310_STATE_EN_PS; ret = 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(&client->dev, ret, "failed to enable sensor\n"); ret = devm_add_action_or_reset(&client->dev, stk3310_set_state_disable, data); if (ret) @@ -529,9 +527,10 @@ static int stk3310_init(struct iio_dev *indio_dev) /* Enable PS interrupts */ ret = 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(&client->dev, ret, + "failed to enable interrupts!\n"); - return ret; + return 0; } static bool stk3310_is_volatile_reg(struct device *dev, unsigned int reg) @@ -564,10 +563,10 @@ static int stk3310_regmap_init(struct stk3310_data *data) client = data->client; regmap = 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(&client->dev, PTR_ERR(regmap), + "regmap initialization failed.\n"); + data->regmap = regmap; STK3310_REGFIELD(state); @@ -656,10 +655,8 @@ static int stk3310_probe(struct i2c_client *client) struct stk3310_data *data; indio_dev = 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(&client->dev, -ENOMEM, "iio allocation failed!\n"); data = iio_priv(indio_dev); data->client = client; @@ -708,18 +705,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(&client->dev, ret, "request irq %d failed\n", + client->irq); } ret = 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(&client->dev, ret, "device_register failed\n"); return 0; } From patchwork Mon Oct 28 14:19:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 13853572 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 7CFD41DE893; Mon, 28 Oct 2024 14:22:10 +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=1730125332; cv=none; b=g9FKSugafQfeePWuIVugLi8pb9Z12njiYDxyNYopZytCiTJT205vkYsLPBhbr6XsAjTg9vIWtjpAk++Xy9s+nGnrwY+ERso0PR1kI70NtFFxLi1rLUCvBrXJVTcQ+co8ALlKm+Bv5hj6buhBSYcXPszdyNmOoz/upojj7bXeGt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730125332; c=relaxed/simple; bh=xy1888VHpVySLIXoHRU06rkgRL+BdqrF5ELLd40oswY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KSEZvb68+jCMlz8adxb6XCugGrB9npKKpgtt/FC1u4pILiR0ykux/4SB1S3lDlz2lNBAOw+OgQ9wzc5exX0MrK/1ScRE7EecNw/YPvce4bMcGbnAMcBkkEIH6N1SvEADhc3c1kR+goyALWuoMgupBi2b93zqvtzchMHspzBRmEY= 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=FBqMepA1; 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="FBqMepA1" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 8DB834C784; Mon, 28 Oct 2024 14:22:08 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?utf-8?b?QmFybmFiw6FzIEN6?= =?utf-8?b?w6ltw6Fu?= , Andy Shevchenko , Ondrej Jirman , =?utf-8?q?Uwe_Kleine-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 v3 5/6] iio: light: stk3310: log error if reading the chip id fails Date: Mon, 28 Oct 2024 10:19:59 -0400 Message-ID: <20241028142000.1058149-6-aren@peacevolution.org> In-Reply-To: <20241028142000.1058149-1-aren@peacevolution.org> References: <20241028142000.1058149-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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=1730125329; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=i3SJsn209UDpyRULEXcIotSNd90N8HU8i+Pdz1wraJM=; b=FBqMepA1LEQfxSQzxA8lQ7FXfVil2UfQKoUX/doiPoLlKCQ+r0/cnJtv9A6iO7QSWOzHwa y3iP0aHsKbF15e8rC43zc0nB+8ka+zp6c91Z0Ch9bc38wA/iEY0MCJWqDkdU75psvUDhzO Woiq9EL4FydfpkCjf+85CXPyDBjKpcw= 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. Common errors are ENXIO (when the chip isn't powered) and ETIMEDOUT (when the i2c bus isn't powered). Signed-off-by: Aren Moynihan --- Notes: 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 968a2cc59d09..d314659e7dc2 100644 --- a/drivers/iio/light/stk3310.c +++ b/drivers/iio/light/stk3310.c @@ -508,7 +508,7 @@ static int stk3310_init(struct iio_dev *indio_dev) ret = regmap_read(data->regmap, STK3310_REG_ID, &chipid); if (ret < 0) - return ret; + return dev_err_probe(&client->dev, ret, "failed to read chip id\n"); ret = stk3310_check_chip_id(chipid); if (ret < 0) From patchwork Mon Oct 28 14:20:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 13853573 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 DCDD81DDC2F; Mon, 28 Oct 2024 14:22:17 +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=1730125339; cv=none; b=LRiZs9Xo8mi0i0W6ifdD5Nha+K1L0/PkMp6RQZxsgbws2sul63ZDS+j5uR92gaxS2GuUC7dC5dKdX/dCCmjQwJ9pMx61ZllsbfNnlj+b1dsHsUSkHk9l1Fe+MlTPCsUk8PBDBwGEWWqU/z8CERy7l7Tq0N8ygc5OUWSZD44xuX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730125339; c=relaxed/simple; bh=Az7W1ohdHrR78IqIcSfKr8mkmXTqZ+V08E1PhLHn4d4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QvtsjepH/M5f1gGnNE2ZdgL4c/t1iFE7dut8UWglSaD3Spin3+ifn3vkkt/JN5FPT6bnx5Vw1mRGZO0XR6sEcGgTAE96ilBydzgSu2ZjhFvxdm0pZDno37qGFkosvEALAyMOc45NYfIRylB5OwNypR1fkiSBDuGZ7gMyO7cgytc= 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=FkSuad9R; 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="FkSuad9R" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id D87254C77B; Mon, 28 Oct 2024 14:22:15 +0000 (UTC) From: Aren Moynihan To: Jonathan Cameron , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Aren Moynihan , Kaustabh Chakraborty , =?utf-8?b?QmFybmFiw6FzIEN6?= =?utf-8?b?w6ltw6Fu?= , Andy Shevchenko , Ondrej Jirman , =?utf-8?q?Uwe_Kleine-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 v3 6/6] arm64: dts: allwinner: pinephone: Add power supplies to stk3311 Date: Mon, 28 Oct 2024 10:20:00 -0400 Message-ID: <20241028142000.1058149-7-aren@peacevolution.org> In-Reply-To: <20241028142000.1058149-1-aren@peacevolution.org> References: <20241028142000.1058149-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-iio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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=1730125337; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=1Fb34FGXqzMNx+nxE4qoPozuG7GAzwlPuHgHmRcGRGE=; b=FkSuad9R/jOLZe6Le3I3hEkUAGnymubOEJP9B67v9DKLxDo0Kv1JVBbAyoZo6mAvNAhWwl CEgB3woOmCngbAnZe2SqrND+rM0eK4TqqQs3T0Xez4k8T4NTn+CU3f795Y1nQvttv5Qf22 9EbvET02emJZvfxMPsW9m7Ucx4vHdW8= 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 = <0x48>; interrupt-parent = <&pio>; interrupts = <1 0 IRQ_TYPE_EDGE_FALLING>; /* PB0 */ + vdd-supply = <®_ldo_io0>; + leda-supply = <®_dldo1>; }; /* Accelerometer/gyroscope */