From: Richard Acayan <mailingradian@gmail.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Tianshu Qiu <tian.shu.qiu@intel.com>,
linux-media@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-msm@vger.kernel.org
Cc: Robert Mader <robert.mader@collabora.com>,
Richard Acayan <mailingradian@gmail.com>
Subject: [PATCH v2 2/4] media: i2c: imx355: Support devicetree and power management
Date: Mon, 14 Jul 2025 17:02:30 -0400 [thread overview]
Message-ID: <20250714210227.714841-8-mailingradian@gmail.com> (raw)
In-Reply-To: <20250714210227.714841-6-mailingradian@gmail.com>
A device tree compatible makes it possible for this driver to be used on
Open Firmware devices. Initialization of power-managed resources such as
the reset GPIO and voltage regulators can be specified in the device
tree and handled by the driver. Add support for this so the Pixel 3a can
use the driver.
Signed-off-by: Richard Acayan <mailingradian@gmail.com>
---
drivers/media/i2c/imx355.c | 143 +++++++++++++++++++++++++++++++++----
1 file changed, 131 insertions(+), 12 deletions(-)
diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
index b2dce67c0b6b..6244e1a5876f 100644
--- a/drivers/media/i2c/imx355.c
+++ b/drivers/media/i2c/imx355.c
@@ -3,9 +3,14 @@
#include <linux/unaligned.h>
#include <linux/acpi.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/module.h>
+#include <linux/of.h>
#include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-event.h>
@@ -121,6 +126,16 @@ struct imx355 {
* Protect access to sensor v4l2 controls.
*/
struct mutex mutex;
+
+ struct clk *mclk;
+ struct gpio_desc *reset_gpio;
+ struct regulator_bulk_data supplies[3];
+};
+
+static const char * const imx355_supply_names[] = {
+ "avdd",
+ "dvdd",
+ "dovdd",
};
static const struct imx355_reg imx355_global_regs[] = {
@@ -1516,6 +1531,58 @@ static const struct v4l2_subdev_internal_ops imx355_internal_ops = {
.open = imx355_open,
};
+static int imx355_power_off(struct device *dev)
+{
+ struct i2c_client *client = container_of(dev, struct i2c_client, dev);
+ struct v4l2_subdev *sd = i2c_get_clientdata(client);
+ struct imx355 *imx355 = to_imx355(sd);
+
+ clk_disable_unprepare(imx355->mclk);
+
+ if (imx355->reset_gpio)
+ gpiod_set_value_cansleep(imx355->reset_gpio, 0);
+
+ regulator_bulk_disable(ARRAY_SIZE(imx355->supplies), imx355->supplies);
+
+ return 0;
+}
+
+static int imx355_power_on(struct device *dev)
+{
+ struct i2c_client *client = container_of(dev, struct i2c_client, dev);
+ struct v4l2_subdev *sd = i2c_get_clientdata(client);
+ struct imx355 *imx355 = to_imx355(sd);
+ int ret;
+
+ ret = clk_prepare_enable(imx355->mclk);
+ if (ret) {
+ dev_err(dev, "failed to enable clocks: %d\n", ret);
+ return ret;
+ }
+
+ ret = regulator_bulk_enable(ARRAY_SIZE(imx355->supplies),
+ imx355->supplies);
+ if (ret) {
+ dev_err(dev, "failed to enable regulators: %d\n", ret);
+ goto error_disable_clocks;
+ }
+
+ if (imx355->reset_gpio) {
+ usleep_range(5000, 5100);
+ gpiod_set_value_cansleep(imx355->reset_gpio, 1);
+ usleep_range(8000, 8100);
+ }
+
+ return 0;
+
+error_disable_clocks:
+ clk_disable_unprepare(imx355->mclk);
+ return ret;
+}
+
+static DEFINE_RUNTIME_DEV_PM_OPS(imx355_pm_ops, imx355_power_off,
+ imx355_power_on, NULL);
+
/* Initialize control handlers */
static int imx355_init_controls(struct imx355 *imx355)
{
@@ -1623,7 +1690,7 @@ static int imx355_init_controls(struct imx355 *imx355)
return ret;
}
-static struct imx355_hwcfg *imx355_get_hwcfg(struct device *dev)
+static struct imx355_hwcfg *imx355_get_hwcfg(struct device *dev, struct imx355 *imx355)
{
struct imx355_hwcfg *cfg;
struct v4l2_fwnode_endpoint bus_cfg = {
@@ -1648,11 +1715,15 @@ static struct imx355_hwcfg *imx355_get_hwcfg(struct device *dev)
if (!cfg)
goto out_err;
- ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
- &cfg->ext_clk);
- if (ret) {
- dev_err(dev, "can't get clock frequency");
- goto out_err;
+ if (imx355->mclk) {
+ cfg->ext_clk = clk_get_rate(imx355->mclk);
+ } else {
+ ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency",
+ &cfg->ext_clk);
+ if (ret) {
+ dev_err(dev, "can't get clock frequency");
+ goto out_err;
+ }
}
dev_dbg(dev, "ext clk: %d", cfg->ext_clk);
@@ -1683,6 +1754,7 @@ static struct imx355_hwcfg *imx355_get_hwcfg(struct device *dev)
static int imx355_probe(struct i2c_client *client)
{
struct imx355 *imx355;
+ size_t i;
int ret;
imx355 = devm_kzalloc(&client->dev, sizeof(*imx355), GFP_KERNEL);
@@ -1694,27 +1766,59 @@ static int imx355_probe(struct i2c_client *client)
/* Initialize subdev */
v4l2_i2c_subdev_init(&imx355->sd, client, &imx355_subdev_ops);
- /* Check module identity */
- ret = imx355_identify_module(imx355);
+ for (i = 0; i < ARRAY_SIZE(imx355_supply_names); i++)
+ imx355->supplies[i].supply = imx355_supply_names[i];
+
+ ret = devm_regulator_bulk_get(&client->dev,
+ ARRAY_SIZE(imx355->supplies),
+ imx355->supplies);
if (ret) {
- dev_err(&client->dev, "failed to find sensor: %d", ret);
+ dev_err_probe(&client->dev, ret, "could not get regulators");
goto error_probe;
}
- imx355->hwcfg = imx355_get_hwcfg(&client->dev);
+ imx355->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
+ GPIOD_OUT_LOW);
+ if (IS_ERR(imx355->reset_gpio)) {
+ ret = dev_err_probe(&client->dev, PTR_ERR(imx355->reset_gpio),
+ "failed to get gpios");
+ goto error_probe;
+ }
+
+ imx355->mclk = devm_clk_get_optional(&client->dev, "mclk");
+ if (IS_ERR(imx355->mclk)) {
+ ret = dev_err_probe(&client->dev, PTR_ERR(imx355->mclk),
+ "failed to get mclk");
+ goto error_probe;
+ }
+
+ imx355->hwcfg = imx355_get_hwcfg(&client->dev, imx355);
if (!imx355->hwcfg) {
dev_err(&client->dev, "failed to get hwcfg");
ret = -ENODEV;
goto error_probe;
}
+ ret = imx355_power_on(&client->dev);
+ if (ret) {
+ dev_err(&client->dev, "failed to power on sensor: %d", ret);
+ goto error_probe;
+ }
+
+ /* Check module identity */
+ ret = imx355_identify_module(imx355);
+ if (ret) {
+ dev_err(&client->dev, "failed to find sensor: %d", ret);
+ goto error_power_off;
+ }
+
/* Set default mode to max resolution */
imx355->cur_mode = &supported_modes[0];
ret = imx355_init_controls(imx355);
if (ret) {
dev_err(&client->dev, "failed to init controls: %d", ret);
- goto error_probe;
+ goto error_power_off;
}
/* Initialize subdev */
@@ -1754,6 +1858,9 @@ static int imx355_probe(struct i2c_client *client)
error_handler_free:
v4l2_ctrl_handler_free(imx355->sd.ctrl_handler);
+error_power_off:
+ imx355_power_off(&client->dev);
+
error_probe:
mutex_destroy(&imx355->mutex);
@@ -1770,7 +1877,11 @@ static void imx355_remove(struct i2c_client *client)
v4l2_ctrl_handler_free(sd->ctrl_handler);
pm_runtime_disable(&client->dev);
- pm_runtime_set_suspended(&client->dev);
+
+ if (!pm_runtime_status_suspended(&client->dev)) {
+ imx355_power_off(&client->dev);
+ pm_runtime_set_suspended(&client->dev);
+ }
mutex_destroy(&imx355->mutex);
}
@@ -1781,10 +1892,18 @@ static const struct acpi_device_id imx355_acpi_ids[] __maybe_unused = {
};
MODULE_DEVICE_TABLE(acpi, imx355_acpi_ids);
+static const struct of_device_id imx355_match_table[] __maybe_unused = {
+ { .compatible = "sony,imx355", },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, imx355_match_table);
+
static struct i2c_driver imx355_i2c_driver = {
.driver = {
.name = "imx355",
.acpi_match_table = ACPI_PTR(imx355_acpi_ids),
+ .of_match_table = of_match_ptr(imx355_match_table),
+ .pm = &imx355_pm_ops,
},
.probe = imx355_probe,
.remove = imx355_remove,
--
2.50.1
next prev parent reply other threads:[~2025-07-14 21:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-14 21:02 [PATCH v2 0/4] media: i2c: IMX355 for the Pixel 3a Richard Acayan
2025-07-14 21:02 ` [PATCH v2 1/4] dt-bindings: media: i2c: Add Sony IMX355 Richard Acayan
2025-07-15 8:27 ` Krzysztof Kozlowski
2025-07-17 21:51 ` Richard Acayan
2025-07-18 6:24 ` Krzysztof Kozlowski
2025-07-14 21:02 ` Richard Acayan [this message]
2025-07-15 10:04 ` [PATCH v2 2/4] media: i2c: imx355: Support devicetree and power management Konrad Dybcio
2025-07-14 21:02 ` [PATCH v2 3/4] arm64: dts: qcom: sdm670: remove camss endpoint nodes Richard Acayan
2025-07-14 21:02 ` [PATCH v2 4/4] arm64: dts: qcom: sdm670-google-sargo: add imx355 front camera Richard Acayan
2025-07-15 10:05 ` Konrad Dybcio
2025-07-15 8:25 ` [PATCH v2 0/4] media: i2c: IMX355 for the Pixel 3a Krzysztof Kozlowski
2025-07-15 8:49 ` Konrad Dybcio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250714210227.714841-8-mailingradian@gmail.com \
--to=mailingradian@gmail.com \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=robert.mader@collabora.com \
--cc=robh@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=tian.shu.qiu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).