public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-media@vger.kernel.org
Cc: Bingbu Cao <bingbu.cao@intel.com>,
	Hans de Goede <hansg@kernel.org>,
	mehdi.djait@intel.com
Subject: [PATCH v2 12/23] media: i2c: ov01a10: Add power on/off sequencing support
Date: Mon, 12 Jan 2026 11:59:38 +0200	[thread overview]
Message-ID: <20260112095949.3851-13-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20260112095949.3851-1-sakari.ailus@linux.intel.com>

From: Hans de Goede <hansg@kernel.org>

So far the ov01a10 driver has only been used on laptops with an IVSC chip
where the IVSC chip controls the power on/off sequencing of the sensor.

But there are also designs with an ov01a10 sensor where the kernel needs
to directly take care of the power-sequencing, controlling clks, regulators
and GPIOs. Add support for these designs.

The 2 ms minimum reset assertion time is taken from other Omnivision sensor
drivers like the ov5675. The 20 ms delay after reset de-assert comes from
the out of tree ov01a1s driver.

Signed-off-by: Hans de Goede <hansg@kernel.org>
Reviewed-by: Mehdi Djait <mehdi.djait@linux.intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/media/i2c/ov01a10.c | 126 +++++++++++++++++++++++++++++++++++-
 1 file changed, 123 insertions(+), 3 deletions(-)

diff --git a/drivers/media/i2c/ov01a10.c b/drivers/media/i2c/ov01a10.c
index 0ef4bbc93d66..fee24acef4b2 100644
--- a/drivers/media/i2c/ov01a10.c
+++ b/drivers/media/i2c/ov01a10.c
@@ -7,10 +7,14 @@
 
 #include <linux/acpi.h>
 #include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 
 #include <media/v4l2-cci.h>
 #include <media/v4l2-ctrls.h>
@@ -20,6 +24,7 @@
 #define OV01A10_LINK_FREQ_400MHZ	400000000ULL
 #define OV01A10_SCLK			80000000LL
 #define OV01A10_DATA_LANES		1
+#define OV01A10_MCLK			19200000
 
 #define OV01A10_REG_CHIP_ID		CCI_REG24(0x300a)
 #define OV01A10_CHIP_ID			0x560141
@@ -278,6 +283,12 @@ static const struct ov01a10_mode supported_modes[] = {
 	},
 };
 
+static const char * const ov01a10_supply_names[] = {
+	"dovdd",	/* Digital I/O power */
+	"avdd",		/* Analog power */
+	"dvdd",		/* Digital core power */
+};
+
 struct ov01a10 {
 	struct device *dev;
 	struct regmap *regmap;
@@ -294,6 +305,11 @@ struct ov01a10 {
 
 	const struct ov01a10_mode *cur_mode;
 	u32 link_freq_index;
+
+	struct clk *clk;
+	struct gpio_desc *reset;
+	struct gpio_desc *powerdown;
+	struct regulator_bulk_data supplies[ARRAY_SIZE(ov01a10_supply_names)];
 };
 
 static inline struct ov01a10 *to_ov01a10(struct v4l2_subdev *subdev)
@@ -726,6 +742,92 @@ static const struct media_entity_operations ov01a10_subdev_entity_ops = {
 	.link_validate = v4l2_subdev_link_validate,
 };
 
+static int ov01a10_get_pm_resources(struct ov01a10 *ov01a10)
+{
+	unsigned long freq;
+	int i, ret;
+
+	ov01a10->clk = devm_v4l2_sensor_clk_get(ov01a10->dev, NULL);
+	if (IS_ERR(ov01a10->clk))
+		return dev_err_probe(ov01a10->dev, PTR_ERR(ov01a10->clk),
+				     "getting clock\n");
+
+	freq = clk_get_rate(ov01a10->clk);
+	if (freq != OV01A10_MCLK)
+		return dev_err_probe(ov01a10->dev, -EINVAL,
+				     "external clock %lu is not supported",
+				     freq);
+
+	ov01a10->reset = devm_gpiod_get_optional(ov01a10->dev, "reset",
+						 GPIOD_OUT_HIGH);
+	if (IS_ERR(ov01a10->reset))
+		return dev_err_probe(ov01a10->dev, PTR_ERR(ov01a10->reset),
+				     "getting reset gpio\n");
+
+	ov01a10->powerdown = devm_gpiod_get_optional(ov01a10->dev, "powerdown",
+						 GPIOD_OUT_HIGH);
+	if (IS_ERR(ov01a10->powerdown))
+		return dev_err_probe(ov01a10->dev, PTR_ERR(ov01a10->powerdown),
+				     "getting powerdown gpio\n");
+
+	for (i = 0; i < ARRAY_SIZE(ov01a10_supply_names); i++)
+		ov01a10->supplies[i].supply = ov01a10_supply_names[i];
+
+	ret = devm_regulator_bulk_get(ov01a10->dev,
+				      ARRAY_SIZE(ov01a10_supply_names),
+				      ov01a10->supplies);
+	if (ret)
+		return dev_err_probe(ov01a10->dev, ret, "getting regulators\n");
+
+	return 0;
+}
+
+static int ov01a10_power_on(struct device *dev)
+{
+	struct v4l2_subdev *sd = dev_get_drvdata(dev);
+	struct ov01a10 *ov01a10 = to_ov01a10(sd);
+	int ret;
+
+	ret = clk_prepare_enable(ov01a10->clk);
+	if (ret) {
+		dev_err(dev, "Error enabling clk: %d\n", ret);
+		return ret;
+	}
+
+	ret = regulator_bulk_enable(ARRAY_SIZE(ov01a10_supply_names),
+				    ov01a10->supplies);
+	if (ret) {
+		dev_err(dev, "Error enabling regulators: %d\n", ret);
+		clk_disable_unprepare(ov01a10->clk);
+		return ret;
+	}
+
+	if (ov01a10->reset || ov01a10->powerdown) {
+		/* Assert reset/powerdown for at least 2ms on back to back off-on */
+		fsleep(2000);
+		gpiod_set_value_cansleep(ov01a10->powerdown, 0);
+		gpiod_set_value_cansleep(ov01a10->reset, 0);
+		fsleep(20000);
+	}
+
+	return 0;
+}
+
+static int ov01a10_power_off(struct device *dev)
+{
+	struct v4l2_subdev *sd = dev_get_drvdata(dev);
+	struct ov01a10 *ov01a10 = to_ov01a10(sd);
+
+	gpiod_set_value_cansleep(ov01a10->reset, 1);
+	gpiod_set_value_cansleep(ov01a10->powerdown, 1);
+
+	regulator_bulk_disable(ARRAY_SIZE(ov01a10_supply_names),
+			       ov01a10->supplies);
+
+	clk_disable_unprepare(ov01a10->clk);
+	return 0;
+}
+
 static int ov01a10_identify_module(struct ov01a10 *ov01a10)
 {
 	int ret;
@@ -801,7 +903,10 @@ static void ov01a10_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)) {
+		ov01a10_power_off(&client->dev);
+		pm_runtime_set_suspended(&client->dev);
+	}
 }
 
 static int ov01a10_probe(struct i2c_client *client)
@@ -826,15 +931,23 @@ static int ov01a10_probe(struct i2c_client *client)
 	if (ret)
 		return ret;
 
-	ret = ov01a10_identify_module(ov01a10);
+	ret = ov01a10_get_pm_resources(ov01a10);
+	if (ret)
+		return ret;
+
+	ret = ov01a10_power_on(&client->dev);
 	if (ret)
 		return ret;
 
+	ret = ov01a10_identify_module(ov01a10);
+	if (ret)
+		goto err_power_off;
+
 	ov01a10->cur_mode = &supported_modes[0];
 
 	ret = ov01a10_init_controls(ov01a10);
 	if (ret)
-		return ret;
+		goto err_power_off;
 
 	ov01a10->sd.state_lock = ov01a10->ctrl_handler.lock;
 	ov01a10->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
@@ -875,9 +988,15 @@ static int ov01a10_probe(struct i2c_client *client)
 err_handler_free:
 	v4l2_ctrl_handler_free(ov01a10->sd.ctrl_handler);
 
+err_power_off:
+	ov01a10_power_off(&client->dev);
+
 	return ret;
 }
 
+static DEFINE_RUNTIME_DEV_PM_OPS(ov01a10_pm_ops, ov01a10_power_off,
+				 ov01a10_power_on, NULL);
+
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id ov01a10_acpi_ids[] = {
 	{ "OVTI01A0" },
@@ -890,6 +1009,7 @@ MODULE_DEVICE_TABLE(acpi, ov01a10_acpi_ids);
 static struct i2c_driver ov01a10_i2c_driver = {
 	.driver = {
 		.name = "ov01a10",
+		.pm = pm_sleep_ptr(&ov01a10_pm_ops),
 		.acpi_match_table = ACPI_PTR(ov01a10_acpi_ids),
 	},
 	.probe = ov01a10_probe,
-- 
2.47.3


  parent reply	other threads:[~2026-01-12 10:00 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-12  9:59 [PATCH v2 00/23] media: i2c: ov01a10: Add crop, ov01a1b support Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 01/23] media: i2c: ov01a10: Fix the horizontal flip control Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 02/23] media: i2c: ov01a10: Fix reported pixel-rate value Sakari Ailus
2026-01-13  2:43   ` Bingbu Cao
2026-01-12  9:59 ` [PATCH v2 03/23] media: i2c: ov01a10: Fix analogue gain range Sakari Ailus
2026-01-13  2:42   ` Bingbu Cao
2026-01-12  9:59 ` [PATCH v2 04/23] media: i2c: ov01a10: Add missing v4l2_subdev_cleanup() calls Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 05/23] media: i2c: ov01a10: Fix passing stream instead of pad to v4l2_subdev_state_get_format() Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 06/23] media: i2c: ov01a10: Fix test-pattern disabling Sakari Ailus
2026-01-13  2:59   ` Bingbu Cao
2026-01-13  8:14     ` Sakari Ailus
2026-01-13 10:41       ` Hans de Goede
2026-01-13 10:40     ` Hans de Goede
2026-01-12  9:59 ` [PATCH v2 07/23] media: i2c: ov01a10: Change default vblank value to a vblank resulting in 30 fps Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 08/23] media: i2c: ov01a10: Convert to new CCI register access helpers Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 09/23] media: i2c: ov01a10: Remove overly verbose probe() error reporting Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 10/23] media: i2c: ov01a10: Store dev pointer in struct ov01a10 Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 11/23] media: i2c: ov01a10: Add ov01a10_check_hwcfg() function Sakari Ailus
2026-01-12  9:59 ` Sakari Ailus [this message]
2026-01-12  9:59 ` [PATCH v2 13/23] media: i2c: ov01a10: Don't update pixel_rate and link_freq from set_fmt Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 14/23] media: i2c: ov01a10: Move setting of ctrl->flags to after checking ctrl_hdlr->error Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 15/23] media: i2c: ov01a10: Use native and default for pixel-array size names Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 16/23] media: i2c: ov01a10: Add cropping support / allow arbitrary sizes Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 17/23] media: i2c: ov01a10: Remove struct ov01a10_reg_list Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 18/23] media: i2c: ov01a10: Replace exposure->min/step with direct define use Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 19/23] media: i2c: ov01a10: Only set register 0x0305 once Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 20/23] media: i2c: ov01a10: Remove values set by controls from global_setting[] Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 21/23] media: i2c: ov01a10: Add ov01a10_sensor_cfg struct Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 22/23] media: i2c: ov01a10: Optimize setting h/vflip values Sakari Ailus
2026-01-12  9:59 ` [PATCH v2 23/23] media: i2c: ov01a10: Add ov01a1b support Sakari Ailus

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=20260112095949.3851-13-sakari.ailus@linux.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=bingbu.cao@intel.com \
    --cc=hansg@kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mehdi.djait@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