mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 4/6] media: atomisp: Add Athesi RT80 sensors and 180-deg rotation quirk
       [not found] <20261130100835.12189-1-kkituyi@hotmail.com>
@ 2026-11-30 10:08 ` Kennedy Cheskaki
  2026-11-30 10:08 ` [PATCH 5/6] media: ov8858: Add ACPI ID INT3477 Kennedy Cheskaki
  2026-11-30 10:08 ` [PATCH 6/6] media: i2c: Add Himax HM2051 camera sensor driver Kennedy Cheskaki
  2 siblings, 0 replies; 4+ messages in thread
From: Kennedy Cheskaki @ 2026-11-30 10:08 UTC (permalink / raw)
  To: linux-media; +Cc: platform-driver-x86, linux-kernel, Kennedy Cheskaki

Register HIMX2051 and INT3477 in atomisp_sensor_configs and set
180-degree sensor rotation for INT3477 on the Athesi RT80 tablet.
Signed-off-by: Kennedy Cheskaki <kkituyi@hotmail.com>
---
 drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
index cca91c6..07cbf06 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_csi2_bridge.c
@@ -360,6 +360,8 @@ static const struct acpi_device_id atomisp_sensor_configs[] = {
 	 * an i2c-client for the VCM, so it is disabled for now.
 	 */
 	ATOMISP_SENSOR_CONFIG("INT33BE", 2, false),	/* OV5693 */
+	ATOMISP_SENSOR_CONFIG("HIMX2051", 1, false),	/* HM2051 */
+	ATOMISP_SENSOR_CONFIG("INT3477", 4, false),	/* OV8858 */
 	{}
 };
 
@@ -411,7 +413,9 @@ static int atomisp_csi2_parse_sensor_fwnode(struct acpi_device *adev,
 		return ret;
 
 	sensor->mclkspeed = PMC_CLK_RATE_19_2MHZ;
-	sensor->rotation = 0;
+	sensor->rotation = (dmi_match(DMI_SYS_VENDOR, "ATHESI") &&
+			    dmi_match(DMI_PRODUCT_NAME, "ATHESI RT80") &&
+			    acpi_dev_hid_uid_match(adev, "INT3477", NULL)) ? 180 : 0;
 	sensor->orientation = (sensor->link == 1) ?
 		V4L2_FWNODE_ORIENTATION_BACK : V4L2_FWNODE_ORIENTATION_FRONT;
 
-- 
2.56.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 5/6] media: ov8858: Add ACPI ID INT3477
       [not found] <20261130100835.12189-1-kkituyi@hotmail.com>
  2026-11-30 10:08 ` [PATCH 4/6] media: atomisp: Add Athesi RT80 sensors and 180-deg rotation quirk Kennedy Cheskaki
@ 2026-11-30 10:08 ` Kennedy Cheskaki
  2026-11-30 10:08 ` [PATCH 6/6] media: i2c: Add Himax HM2051 camera sensor driver Kennedy Cheskaki
  2 siblings, 0 replies; 4+ messages in thread
From: Kennedy Cheskaki @ 2026-11-30 10:08 UTC (permalink / raw)
  To: linux-media; +Cc: platform-driver-x86, linux-kernel, Kennedy Cheskaki

Allow the OmniVision OV8858 driver to bind via ACPI HID INT3477
used on Intel Cherry Trail tablets.
Signed-off-by: Kennedy Cheskaki <kkituyi@hotmail.com>
---
 drivers/media/i2c/ov8858.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/media/i2c/ov8858.c b/drivers/media/i2c/ov8858.c
index 72e63c9..df54af4 100644
--- a/drivers/media/i2c/ov8858.c
+++ b/drivers/media/i2c/ov8858.c
@@ -1983,6 +1983,12 @@ static const struct of_device_id ov8858_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, ov8858_of_match);
 
+static const struct acpi_device_id ov8858_acpi_ids[] = {
+	{ "INT3477" },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, ov8858_acpi_ids);
+
 static const struct acpi_device_id ov8858_acpi_ids[] __maybe_unused = {
 	{ .id = "INT3477" },
 	{ /* sentinel */ }
@@ -1994,6 +2000,7 @@ static struct i2c_driver ov8858_i2c_driver = {
 		.name = "ov8858",
 		.pm = &ov8858_pm_ops,
 		.of_match_table = ov8858_of_match,
+		.acpi_match_table = ov8858_acpi_ids,
 		.acpi_match_table = ACPI_PTR(ov8858_acpi_ids),
 	},
 	.probe		= ov8858_probe,
-- 
2.56.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 6/6] media: i2c: Add Himax HM2051 camera sensor driver
       [not found] <20261130100835.12189-1-kkituyi@hotmail.com>
  2026-11-30 10:08 ` [PATCH 4/6] media: atomisp: Add Athesi RT80 sensors and 180-deg rotation quirk Kennedy Cheskaki
  2026-11-30 10:08 ` [PATCH 5/6] media: ov8858: Add ACPI ID INT3477 Kennedy Cheskaki
@ 2026-11-30 10:08 ` Kennedy Cheskaki
  2026-12-01  5:03   ` Elgin Perumbilly
  2 siblings, 1 reply; 4+ messages in thread
From: Kennedy Cheskaki @ 2026-11-30 10:08 UTC (permalink / raw)
  To: linux-media; +Cc: platform-driver-x86, linux-kernel, Kennedy Cheskaki

Add V4L2 subdevice driver for the Himax HM2051 2MP CMOS image sensor
(ACPI HID HIMX2051), supporting 1616x1216 and 1296x736 at 30 fps.
Signed-off-by: Kennedy Cheskaki <kkituyi@hotmail.com>
---
 drivers/media/i2c/hm2051.c        | 614 ++++++++++++++++++++++++++++++
 drivers/media/i2c/hm2051_tables.h | 304 +++++++++++++++
 2 files changed, 918 insertions(+)
 create mode 100644 drivers/media/i2c/hm2051.c
 create mode 100644 drivers/media/i2c/hm2051_tables.h

diff --git a/drivers/media/i2c/hm2051.c b/drivers/media/i2c/hm2051.c
new file mode 100644
index 0000000..9ce0995
--- /dev/null
+++ b/drivers/media/i2c/hm2051.c
@@ -0,0 +1,614 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Himax HM2051 CMOS image sensor V4L2 subdevice driver
+ * Register tables and mode parameters extracted from Intel Unicam Windows driver.
+ */
+
+#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/pm_runtime.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-fwnode.h>
+#include <media/v4l2-subdev.h>
+
+#include "hm2051_tables.h"
+
+#define HM2051_CHIP_ID_H_REG		0x0001
+#define HM2051_CHIP_ID_L_REG		0x0002
+#define HM2051_CHIP_ID			0x2051
+
+#define HM2051_REG_EXPOSURE_H		0x0015
+#define HM2051_REG_EXPOSURE_L		0x0016
+#define HM2051_REG_GAIN			0x0018
+#define HM2051_REG_CMU_UPDATE		0x0000
+
+#define HM2051_EXPOSURE_MIN		1
+#define HM2051_EXPOSURE_MAX		0x1fff
+#define HM2051_EXPOSURE_DEFAULT		4000
+
+#define HM2051_GAIN_MIN			0
+#define HM2051_GAIN_MAX			0xff
+#define HM2051_GAIN_DEFAULT		200
+
+#define HM2051_PIXEL_RATE		48000000ULL
+#define HM2051_LINK_FREQ		240000000ULL
+
+#define HM2051_NATIVE_WIDTH		1616
+#define HM2051_NATIVE_HEIGHT		1216
+
+struct hm2051_mode {
+	u32 width;
+	u32 height;
+	u32 fps;
+	u32 hts;
+	u32 vts;
+	const struct hm2051_reg *regs;
+	unsigned int num_regs;
+};
+
+static const struct hm2051_mode supported_modes[] = {
+	{
+		.width = 1616,
+		.height = 1216,
+		.fps = 30,
+		.hts = 1800,
+		.vts = 1260,
+		.regs = hm2051_1616x1216_regs,
+		.num_regs = ARRAY_SIZE(hm2051_1616x1216_regs),
+	},
+	{
+		.width = 1296,
+		.height = 736,
+		.fps = 30,
+		.hts = 1800,
+		.vts = 800,
+		.regs = hm2051_1296x736_regs,
+		.num_regs = ARRAY_SIZE(hm2051_1296x736_regs),
+	},
+};
+
+static const s64 link_freq_menu_items[] = {
+	HM2051_LINK_FREQ,
+};
+
+struct hm2051 {
+	struct v4l2_subdev sd;
+	struct media_pad pad;
+	struct v4l2_ctrl_handler ctrl_handler;
+	struct clk *xvclk;
+	struct gpio_desc *reset_gpio;
+	struct gpio_desc *powerdown_gpio;
+	struct v4l2_ctrl *pixel_rate;
+	struct v4l2_ctrl *link_freq;
+	struct v4l2_ctrl *hblank;
+	struct v4l2_ctrl *vblank;
+	struct v4l2_ctrl *exposure;
+	struct v4l2_ctrl *gain;
+	const struct hm2051_mode *cur_mode;
+	struct mutex lock;
+	bool streaming;
+};
+
+static inline struct hm2051 *to_hm2051(struct v4l2_subdev *sd)
+{
+	return container_of(sd, struct hm2051, sd);
+}
+
+static int hm2051_read_reg(struct i2c_client *client, u16 reg, u8 *val)
+{
+	u8 buf[2] = { reg >> 8, reg & 0xff };
+	struct i2c_msg msgs[2] = {
+		{
+			.addr = client->addr,
+			.flags = 0,
+			.len = sizeof(buf),
+			.buf = buf,
+		},
+		{
+			.addr = client->addr,
+			.flags = I2C_M_RD,
+			.len = 1,
+			.buf = val,
+		},
+	};
+	int ret;
+
+	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
+	if (ret != ARRAY_SIZE(msgs))
+		return ret < 0 ? ret : -EIO;
+
+	return 0;
+}
+
+static int hm2051_write_reg(struct i2c_client *client, u16 reg, u8 val)
+{
+	u8 buf[3] = { reg >> 8, reg & 0xff, val };
+	int ret;
+
+	ret = i2c_master_send(client, buf, sizeof(buf));
+	if (ret != sizeof(buf))
+		return ret < 0 ? ret : -EIO;
+
+	return 0;
+}
+
+static int hm2051_write_regs(struct i2c_client *client,
+			     const struct hm2051_reg *regs, unsigned int len)
+{
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < len; i++) {
+		if (regs[i].reg == HM2051_REG_DELAY) {
+			msleep(regs[i].val);
+			continue;
+		}
+		ret = hm2051_write_reg(client, regs[i].reg, regs[i].val);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int hm2051_power_on(struct hm2051 *hm2051)
+{
+	int ret;
+
+	ret = clk_prepare_enable(hm2051->xvclk);
+	if (ret)
+		return ret;
+
+	gpiod_set_value_cansleep(hm2051->powerdown_gpio, 0);
+	gpiod_set_value_cansleep(hm2051->reset_gpio, 0);
+	usleep_range(5000, 10000);
+	return 0;
+}
+
+static void hm2051_power_off(struct hm2051 *hm2051)
+{
+	gpiod_set_value_cansleep(hm2051->reset_gpio, 1);
+	gpiod_set_value_cansleep(hm2051->powerdown_gpio, 1);
+	clk_disable_unprepare(hm2051->xvclk);
+}
+
+static int hm2051_identify(struct i2c_client *client)
+{
+	u8 id_h = 0, id_l = 0;
+	u16 id;
+	int ret;
+
+	ret = hm2051_read_reg(client, HM2051_CHIP_ID_H_REG, &id_h);
+	if (ret)
+		return ret;
+
+	ret = hm2051_read_reg(client, HM2051_CHIP_ID_L_REG, &id_l);
+	if (ret)
+		return ret;
+
+	id = ((u16)id_h << 8) | id_l;
+	if (id != HM2051_CHIP_ID) {
+		dev_err(&client->dev, "chip id mismatch: 0x%04x (expected 0x%04x)\n",
+			id, HM2051_CHIP_ID);
+		return -ENODEV;
+	}
+
+	dev_info(&client->dev, "found HM2051 sensor (chip id 0x%04x)\n", id);
+	return 0;
+}
+
+static int hm2051_set_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct hm2051 *hm2051 = container_of(ctrl->handler, struct hm2051,
+					     ctrl_handler);
+	struct i2c_client *client = v4l2_get_subdevdata(&hm2051->sd);
+	int ret = 0;
+
+	if (pm_runtime_get_if_in_use(&client->dev) <= 0)
+		return 0;
+
+	switch (ctrl->id) {
+	case V4L2_CID_EXPOSURE:
+		ret = hm2051_write_reg(client, HM2051_REG_EXPOSURE_H,
+				       (ctrl->val >> 8) & 0xff);
+		if (!ret)
+			ret = hm2051_write_reg(client, HM2051_REG_EXPOSURE_L,
+					       ctrl->val & 0xff);
+		if (!ret)
+			ret = hm2051_write_reg(client, HM2051_REG_CMU_UPDATE, 0x01);
+		break;
+	case V4L2_CID_ANALOGUE_GAIN:
+		ret = hm2051_write_reg(client, HM2051_REG_GAIN, ctrl->val & 0xff);
+		if (!ret)
+			ret = hm2051_write_reg(client, HM2051_REG_CMU_UPDATE, 0x01);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	pm_runtime_put(&client->dev);
+	return ret;
+}
+
+static const struct v4l2_ctrl_ops hm2051_ctrl_ops = {
+	.s_ctrl = hm2051_set_ctrl,
+};
+
+static int hm2051_init_controls(struct hm2051 *hm2051)
+{
+	struct v4l2_ctrl_handler *hdl = &hm2051->ctrl_handler;
+	const struct hm2051_mode *mode = hm2051->cur_mode;
+	s64 hblank, vblank;
+	int ret;
+
+	ret = v4l2_ctrl_handler_init(hdl, 6);
+	if (ret)
+		return ret;
+
+	hm2051->pixel_rate = v4l2_ctrl_new_std(hdl, &hm2051_ctrl_ops,
+					       V4L2_CID_PIXEL_RATE,
+					       HM2051_PIXEL_RATE,
+					       HM2051_PIXEL_RATE, 1,
+					       HM2051_PIXEL_RATE);
+
+	hm2051->link_freq = v4l2_ctrl_new_int_menu(hdl, &hm2051_ctrl_ops,
+						   V4L2_CID_LINK_FREQ,
+						   ARRAY_SIZE(link_freq_menu_items) - 1,
+						   0, link_freq_menu_items);
+	if (hm2051->link_freq)
+		hm2051->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
+	hblank = mode->hts - mode->width;
+	hm2051->hblank = v4l2_ctrl_new_std(hdl, &hm2051_ctrl_ops,
+					   V4L2_CID_HBLANK, hblank, hblank, 1,
+					   hblank);
+	if (hm2051->hblank)
+		hm2051->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
+	vblank = mode->vts - mode->height;
+	hm2051->vblank = v4l2_ctrl_new_std(hdl, &hm2051_ctrl_ops,
+					   V4L2_CID_VBLANK, vblank, vblank, 1,
+					   vblank);
+	if (hm2051->vblank)
+		hm2051->vblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
+	hm2051->exposure = v4l2_ctrl_new_std(hdl, &hm2051_ctrl_ops,
+					     V4L2_CID_EXPOSURE,
+					     HM2051_EXPOSURE_MIN,
+					     HM2051_EXPOSURE_MAX, 1,
+					     HM2051_EXPOSURE_DEFAULT);
+
+	hm2051->gain = v4l2_ctrl_new_std(hdl, &hm2051_ctrl_ops,
+					 V4L2_CID_ANALOGUE_GAIN,
+					 HM2051_GAIN_MIN, HM2051_GAIN_MAX, 1,
+					 HM2051_GAIN_DEFAULT);
+
+	if (hdl->error) {
+		ret = hdl->error;
+		v4l2_ctrl_handler_free(hdl);
+		return ret;
+	}
+
+	hm2051->sd.ctrl_handler = hdl;
+	return 0;
+}
+
+static int hm2051_enum_mbus_code(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_state *sd_state,
+				 struct v4l2_subdev_mbus_code_enum *code)
+{
+	if (code->index > 0)
+		return -EINVAL;
+
+	code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
+	return 0;
+}
+
+static int hm2051_enum_frame_size(struct v4l2_subdev *sd,
+				  struct v4l2_subdev_state *sd_state,
+				  struct v4l2_subdev_frame_size_enum *fse)
+{
+	if (fse->index >= ARRAY_SIZE(supported_modes))
+		return -EINVAL;
+
+	if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10)
+		return -EINVAL;
+
+	fse->min_width = supported_modes[fse->index].width;
+	fse->max_width = fse->min_width;
+	fse->min_height = supported_modes[fse->index].height;
+	fse->max_height = fse->min_height;
+	return 0;
+}
+
+static int hm2051_enum_frame_interval(struct v4l2_subdev *sd,
+				      struct v4l2_subdev_state *sd_state,
+				      struct v4l2_subdev_frame_interval_enum *fie)
+{
+	unsigned int i;
+
+	if (fie->index > 0 || fie->code != MEDIA_BUS_FMT_SBGGR10_1X10)
+		return -EINVAL;
+
+	for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
+		if (fie->width == supported_modes[i].width &&
+		    fie->height == supported_modes[i].height) {
+			fie->interval.numerator = 1;
+			fie->interval.denominator = supported_modes[i].fps;
+			return 0;
+		}
+	}
+
+	return -EINVAL;
+}
+
+static void hm2051_fill_pad_format(const struct hm2051_mode *mode,
+				   struct v4l2_mbus_framefmt *fmt)
+{
+	fmt->width = mode->width;
+	fmt->height = mode->height;
+	fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
+	fmt->field = V4L2_FIELD_NONE;
+	fmt->colorspace = V4L2_COLORSPACE_RAW;
+}
+
+static int hm2051_init_state(struct v4l2_subdev *sd,
+			     struct v4l2_subdev_state *sd_state)
+{
+	struct v4l2_mbus_framefmt *fmt =
+		v4l2_subdev_state_get_format(sd_state, 0);
+
+	hm2051_fill_pad_format(&supported_modes[0], fmt);
+	return 0;
+}
+
+static int hm2051_set_pad_format(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_state *sd_state,
+				 struct v4l2_subdev_format *fmt)
+{
+	struct hm2051 *hm2051 = to_hm2051(sd);
+	const struct hm2051_mode *mode;
+	struct v4l2_mbus_framefmt *framefmt;
+
+	mode = v4l2_find_nearest_size(supported_modes,
+				      ARRAY_SIZE(supported_modes),
+				      width, height,
+				      fmt->format.width, fmt->format.height);
+
+	hm2051_fill_pad_format(mode, &fmt->format);
+
+	framefmt = v4l2_subdev_state_get_format(sd_state, 0);
+	*framefmt = fmt->format;
+
+	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
+		mutex_lock(&hm2051->lock);
+		hm2051->cur_mode = mode;
+		mutex_unlock(&hm2051->lock);
+	}
+
+	return 0;
+}
+
+static int hm2051_get_selection(struct v4l2_subdev *sd,
+				struct v4l2_subdev_state *sd_state,
+				struct v4l2_subdev_selection *sel)
+{
+	switch (sel->target) {
+	case V4L2_SEL_TGT_NATIVE_SIZE:
+	case V4L2_SEL_TGT_CROP_BOUNDS:
+	case V4L2_SEL_TGT_CROP_DEFAULT:
+		sel->r.left = 0;
+		sel->r.top = 0;
+		sel->r.width = HM2051_NATIVE_WIDTH;
+		sel->r.height = HM2051_NATIVE_HEIGHT;
+		return 0;
+	default:
+		return -EINVAL;
+	}
+}
+
+static int hm2051_s_stream(struct v4l2_subdev *sd, int enable)
+{
+	struct hm2051 *hm2051 = to_hm2051(sd);
+	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	int ret = 0;
+
+	mutex_lock(&hm2051->lock);
+
+	if (hm2051->streaming == !!enable)
+		goto unlock;
+
+	if (enable) {
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
+			goto unlock;
+
+		ret = hm2051_write_regs(client, hm2051_init_regs,
+					ARRAY_SIZE(hm2051_init_regs));
+		if (ret)
+			goto err_rpm;
+
+		ret = hm2051_write_regs(client, hm2051->cur_mode->regs,
+					hm2051->cur_mode->num_regs);
+		if (ret)
+			goto err_rpm;
+
+		ret = __v4l2_ctrl_handler_setup(&hm2051->ctrl_handler);
+		if (ret)
+			goto err_rpm;
+
+		ret = hm2051_write_regs(client, hm2051_stream_on_regs,
+					ARRAY_SIZE(hm2051_stream_on_regs));
+		if (ret)
+			goto err_rpm;
+
+		hm2051->streaming = true;
+	} else {
+		hm2051_write_regs(client, hm2051_stream_off_regs,
+				  ARRAY_SIZE(hm2051_stream_off_regs));
+		pm_runtime_put(&client->dev);
+		hm2051->streaming = false;
+	}
+
+	mutex_unlock(&hm2051->lock);
+	return 0;
+
+err_rpm:
+	pm_runtime_put(&client->dev);
+unlock:
+	mutex_unlock(&hm2051->lock);
+	return ret;
+}
+
+static const struct v4l2_subdev_video_ops hm2051_video_ops = {
+	.s_stream = hm2051_s_stream,
+};
+
+static const struct v4l2_subdev_pad_ops hm2051_pad_ops = {
+	.enum_mbus_code = hm2051_enum_mbus_code,
+	.enum_frame_size = hm2051_enum_frame_size,
+	.enum_frame_interval = hm2051_enum_frame_interval,
+	.get_fmt = v4l2_subdev_get_fmt,
+	.set_fmt = hm2051_set_pad_format,
+	.get_selection = hm2051_get_selection,
+};
+
+static const struct v4l2_subdev_ops hm2051_subdev_ops = {
+	.video = &hm2051_video_ops,
+	.pad = &hm2051_pad_ops,
+};
+
+static const struct v4l2_subdev_internal_ops hm2051_internal_ops = {
+	.init_state = hm2051_init_state,
+};
+
+static int hm2051_probe(struct i2c_client *client)
+{
+	struct hm2051 *hm2051;
+	int ret;
+
+	hm2051 = devm_kzalloc(&client->dev, sizeof(*hm2051), GFP_KERNEL);
+	if (!hm2051)
+		return -ENOMEM;
+
+	mutex_init(&hm2051->lock);
+	hm2051->cur_mode = &supported_modes[0];
+
+	hm2051->xvclk = devm_clk_get(&client->dev, "xvclk");
+	if (IS_ERR(hm2051->xvclk)) {
+		ret = dev_err_probe(&client->dev, PTR_ERR(hm2051->xvclk),
+				    "failed to get xvclk\n");
+		goto err_mutex;
+	}
+
+	hm2051->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset",
+						     GPIOD_OUT_HIGH);
+	if (IS_ERR(hm2051->reset_gpio)) {
+		ret = PTR_ERR(hm2051->reset_gpio);
+		goto err_mutex;
+	}
+
+	hm2051->powerdown_gpio = devm_gpiod_get_optional(&client->dev, "powerdown",
+							 GPIOD_OUT_HIGH);
+	if (IS_ERR(hm2051->powerdown_gpio)) {
+		ret = PTR_ERR(hm2051->powerdown_gpio);
+		goto err_mutex;
+	}
+
+	v4l2_i2c_subdev_init(&hm2051->sd, client, &hm2051_subdev_ops);
+	hm2051->sd.internal_ops = &hm2051_internal_ops;
+	hm2051->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
+	hm2051->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
+
+	hm2051->pad.flags = MEDIA_PAD_FL_SOURCE;
+	ret = media_entity_pads_init(&hm2051->sd.entity, 1, &hm2051->pad);
+	if (ret)
+		goto err_mutex;
+
+	ret = hm2051_init_controls(hm2051);
+	if (ret)
+		goto err_media;
+
+	ret = hm2051_power_on(hm2051);
+	if (ret)
+		goto err_media;
+
+	pm_runtime_set_active(&client->dev);
+	pm_runtime_enable(&client->dev);
+
+	ret = hm2051_identify(client);
+	if (ret) {
+		hm2051_power_off(hm2051);
+		goto err_rpm;
+	}
+
+	hm2051->sd.state_lock = hm2051->ctrl_handler.lock;
+	ret = v4l2_subdev_init_finalize(&hm2051->sd);
+	if (ret)
+		goto err_rpm;
+
+	ret = v4l2_async_register_subdev_sensor(&hm2051->sd);
+	if (ret)
+		goto err_subdev_cleanup;
+
+	pm_runtime_idle(&client->dev);
+	return 0;
+
+err_subdev_cleanup:
+	v4l2_subdev_cleanup(&hm2051->sd);
+err_rpm:
+	pm_runtime_disable(&client->dev);
+	pm_runtime_set_suspended(&client->dev);
+	v4l2_ctrl_handler_free(&hm2051->ctrl_handler);
+err_media:
+	media_entity_cleanup(&hm2051->sd.entity);
+err_mutex:
+	mutex_destroy(&hm2051->lock);
+	return ret;
+}
+
+static void hm2051_remove(struct i2c_client *client)
+{
+	struct v4l2_subdev *sd = i2c_get_clientdata(client);
+	struct hm2051 *hm2051 = to_hm2051(sd);
+
+	v4l2_async_unregister_subdev(sd);
+	v4l2_subdev_cleanup(sd);
+	media_entity_cleanup(&sd->entity);
+	v4l2_ctrl_handler_free(&hm2051->ctrl_handler);
+	pm_runtime_disable(&client->dev);
+	pm_runtime_set_suspended(&client->dev);
+	mutex_destroy(&hm2051->lock);
+}
+
+static const struct acpi_device_id hm2051_acpi_ids[] = {
+	{ "HIMX2051" },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, hm2051_acpi_ids);
+
+static const struct i2c_device_id hm2051_id_table[] = {
+	{ "hm2051" },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, hm2051_id_table);
+
+static struct i2c_driver hm2051_i2c_driver = {
+	.driver = {
+		.name = "hm2051",
+		.acpi_match_table = hm2051_acpi_ids,
+	},
+	.probe = hm2051_probe,
+	.remove = hm2051_remove,
+	.id_table = hm2051_id_table,
+};
+module_i2c_driver(hm2051_i2c_driver);
+
+MODULE_DESCRIPTION("Himax HM2051 CMOS image sensor driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/i2c/hm2051_tables.h b/drivers/media/i2c/hm2051_tables.h
new file mode 100644
index 0000000..4945daa
--- /dev/null
+++ b/drivers/media/i2c/hm2051_tables.h
@@ -0,0 +1,304 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __HM2051_TABLES_H__
+#define __HM2051_TABLES_H__
+
+#include <linux/types.h>
+
+#define HM2051_REG_DELAY	0xffff
+
+struct hm2051_reg {
+	u16 reg;
+	u16 val;
+};
+
+static const struct hm2051_reg hm2051_init_regs[] = {
+	{ 0x0022, 0x00 },
+	{ 0x0000, 0x00 },
+	{ 0x0100, 0x00 },
+	{ 0x0101, 0x00 },
+	{ 0x0005, 0x02 },
+	{ HM2051_REG_DELAY, 0x0064 },
+	{ 0x0026, 0x08 },
+	{ 0x002a, 0x52 },
+	{ 0x0006, 0x00 },
+	{ 0x000f, 0x00 },
+	{ 0x0024, 0x40 },
+	{ 0x0027, 0x23 },
+	{ 0x0065, 0x01 },
+	{ 0x0074, 0x13 },
+	{ 0x002b, 0x00 },
+	{ 0x002c, 0x06 },
+	{ 0x0040, 0x00 },
+	{ 0x0044, 0x03 },
+	{ 0x0045, 0x63 },
+	{ 0x0046, 0x5f },
+	{ 0x0049, 0xc0 },
+	{ 0x004b, 0x03 },
+	{ 0x0070, 0x2f },
+	{ 0x0072, 0xfb },
+	{ 0x0073, 0x77 },
+	{ 0x0075, 0x40 },
+	{ 0x0078, 0x65 },
+	{ 0x0080, 0x98 },
+	{ 0x0082, 0x09 },
+	{ 0x0083, 0x3c },
+	{ 0x0087, 0x41 },
+	{ 0x008d, 0x20 },
+	{ 0x008e, 0x30 },
+	{ 0x009d, 0x11 },
+	{ 0x009e, 0x12 },
+	{ 0x0090, 0x00 },
+	{ 0x0091, 0x01 },
+	{ 0x0092, 0x02 },
+	{ 0x0093, 0x03 },
+	{ 0x00c0, 0x64 },
+	{ 0x00c1, 0x15 },
+	{ 0x00c2, 0x00 },
+	{ 0x00c3, 0x02 },
+	{ 0x00c4, 0x0b },
+	{ 0x00c6, 0x83 },
+	{ 0x00c7, 0x02 },
+	{ 0x00cc, 0x00 },
+	{ 0x4b3b, 0x12 },
+	{ 0x4b41, 0x10 },
+	{ 0x0165, 0x03 },
+	{ 0x018c, 0x00 },
+	{ 0x0195, 0x06 },
+	{ 0x0196, 0x4f },
+	{ 0x0197, 0x04 },
+	{ 0x0198, 0xbf },
+	{ 0x0144, 0x12 },
+	{ 0x0140, 0x20 },
+	{ 0x015a, 0x80 },
+	{ 0x015d, 0x20 },
+	{ 0x0160, 0x65 },
+	{ 0x001d, 0x40 },
+	{ 0x0006, 0x00 },
+	{ 0x000d, 0x00 },
+	{ 0x000e, 0x00 },
+	{ 0x000f, 0x00 },
+	{ 0x0024, 0x40 },
+	{ 0x0027, 0x23 },
+	{ 0x0065, 0x01 },
+	{ 0x0074, 0x13 },
+	{ 0x0160, 0x65 },
+	{ 0x0183, 0x00 },
+	{ 0x0123, 0xc5 },
+	{ 0x4b50, 0x08 },
+	{ 0x4b51, 0xe2 },
+	{ 0x4b0a, 0x06 },
+	{ 0x4b0b, 0x50 },
+	{ 0x4b20, 0x9e },
+	{ 0x4b07, 0xbd },
+	{ 0x4b30, 0x0e },
+	{ 0x4b30, 0x0f },
+};
+
+static const struct hm2051_reg hm2051_1616x1216_regs[] = {
+	{ 0x0022, 0x00 },
+	{ 0x0000, 0x00 },
+	{ 0x0100, 0x00 },
+	{ 0x0101, 0x00 },
+	{ 0x0005, 0x02 },
+	{ HM2051_REG_DELAY, 0x0096 },
+	{ 0x0026, 0x07 },
+	{ 0x002a, 0x43 },
+	{ 0x0006, 0x00 },
+	{ 0x000f, 0x00 },
+	{ 0x0024, 0x40 },
+	{ 0x0027, 0x23 },
+	{ 0x0065, 0x01 },
+	{ 0x0074, 0x13 },
+	{ 0x002b, 0x00 },
+	{ 0x002c, 0x06 },
+	{ 0x0040, 0x00 },
+	{ 0x0044, 0x03 },
+	{ 0x0045, 0x63 },
+	{ 0x0046, 0x5f },
+	{ 0x0049, 0xc0 },
+	{ 0x004b, 0x03 },
+	{ 0x0070, 0x2f },
+	{ 0x0072, 0xfb },
+	{ 0x0073, 0x77 },
+	{ 0x0075, 0x40 },
+	{ 0x0078, 0x65 },
+	{ 0x0080, 0x98 },
+	{ 0x0082, 0x09 },
+	{ 0x0083, 0x3c },
+	{ 0x0087, 0x41 },
+	{ 0x008d, 0x20 },
+	{ 0x008e, 0x30 },
+	{ 0x009d, 0x11 },
+	{ 0x009e, 0x12 },
+	{ 0x0090, 0x00 },
+	{ 0x0091, 0x01 },
+	{ 0x0092, 0x02 },
+	{ 0x0093, 0x03 },
+	{ 0x00c0, 0x64 },
+	{ 0x00c1, 0x15 },
+	{ 0x00c2, 0x00 },
+	{ 0x00c3, 0x02 },
+	{ 0x00c4, 0x0b },
+	{ 0x00c6, 0x83 },
+	{ 0x00c7, 0x02 },
+	{ 0x00cc, 0x00 },
+	{ 0x4b3b, 0x12 },
+	{ 0x4b41, 0x10 },
+	{ 0x0165, 0x03 },
+	{ 0x018c, 0x00 },
+	{ 0x0195, 0x06 },
+	{ 0x0196, 0x4f },
+	{ 0x0197, 0x04 },
+	{ 0x0198, 0xbf },
+	{ 0x0144, 0x12 },
+	{ 0x0140, 0x20 },
+	{ 0x015a, 0x80 },
+	{ 0x015d, 0x20 },
+	{ 0x0160, 0x65 },
+	{ 0x001d, 0x40 },
+	{ 0x0006, 0x00 },
+	{ 0x000d, 0x00 },
+	{ 0x000e, 0x00 },
+	{ 0x000f, 0x00 },
+	{ 0x0024, 0x40 },
+	{ 0x0027, 0x23 },
+	{ 0x0065, 0x01 },
+	{ 0x0074, 0x13 },
+	{ 0x0160, 0x65 },
+	{ 0x0183, 0x00 },
+	{ 0x0123, 0xc5 },
+	{ 0x4b50, 0x08 },
+	{ 0x4b51, 0xe2 },
+	{ 0x4b0a, 0x06 },
+	{ 0x4b0b, 0x50 },
+	{ 0x4b20, 0x9e },
+	{ 0x4b07, 0xbd },
+	{ 0x4b30, 0x0e },
+	{ 0x4b30, 0x0f },
+	{ 0x0000, 0x00 },
+	{ 0x0100, 0x00 },
+	{ 0x0101, 0x00 },
+	{ 0x0005, 0x02 },
+	{ 0x0025, 0x00 },
+	{ 0x0100, 0x01 },
+	{ 0x0165, 0x03 },
+	{ 0x018c, 0x00 },
+	{ 0x0195, 0x06 },
+	{ 0x0196, 0x4f },
+	{ 0x0197, 0x04 },
+	{ 0x0198, 0xbf },
+	{ 0x0144, 0x10 },
+	{ 0x0140, 0x20 },
+	{ 0x015a, 0x30 },
+	{ 0x015d, 0xff },
+	{ 0x0160, 0x61 },
+};
+
+static const struct hm2051_reg hm2051_1296x736_regs[] = {
+	{ 0x0022, 0x00 },
+	{ HM2051_REG_DELAY, 0x0028 },
+	{ 0x0000, 0x00 },
+	{ 0x0100, 0x00 },
+	{ 0x0101, 0x00 },
+	{ HM2051_REG_DELAY, 0x0032 },
+	{ 0x0005, 0x02 },
+	{ HM2051_REG_DELAY, 0x0064 },
+	{ 0x0026, 0x07 },
+	{ 0x002a, 0x43 },
+	{ 0x0006, 0x04 },
+	{ 0x000f, 0x00 },
+	{ 0x0024, 0x40 },
+	{ 0x0027, 0x23 },
+	{ 0x0065, 0x01 },
+	{ 0x0074, 0x1b },
+	{ 0x002b, 0x00 },
+	{ 0x002c, 0x06 },
+	{ 0x0040, 0x00 },
+	{ 0x0044, 0x03 },
+	{ 0x0045, 0x63 },
+	{ 0x0046, 0x5f },
+	{ 0x0049, 0xc0 },
+	{ 0x004b, 0x03 },
+	{ 0x0070, 0x2f },
+	{ 0x0072, 0xfb },
+	{ 0x0073, 0x77 },
+	{ 0x0075, 0x40 },
+	{ 0x0078, 0x65 },
+	{ 0x0080, 0x98 },
+	{ 0x0082, 0x09 },
+	{ 0x0083, 0x3c },
+	{ 0x0087, 0x41 },
+	{ 0x008d, 0x20 },
+	{ 0x008e, 0x30 },
+	{ 0x009d, 0x11 },
+	{ 0x009e, 0x12 },
+	{ 0x0090, 0x00 },
+	{ 0x0091, 0x01 },
+	{ 0x0092, 0x02 },
+	{ 0x0093, 0x03 },
+	{ 0x00c0, 0x64 },
+	{ 0x00c1, 0x15 },
+	{ 0x00c2, 0x00 },
+	{ 0x00c3, 0x02 },
+	{ 0x00c4, 0x0b },
+	{ 0x00c6, 0x83 },
+	{ 0x00c7, 0x02 },
+	{ 0x00cc, 0x00 },
+	{ 0x4b3b, 0x12 },
+	{ 0x4b41, 0x10 },
+	{ 0x0165, 0x03 },
+	{ 0x018c, 0x00 },
+	{ 0x0195, 0x06 },
+	{ 0x0196, 0x4f },
+	{ 0x0197, 0x04 },
+	{ 0x0198, 0xbf },
+	{ 0x0144, 0x12 },
+	{ 0x0140, 0x20 },
+	{ 0x015a, 0x80 },
+	{ 0x015d, 0x20 },
+	{ 0x0160, 0x65 },
+	{ 0x0123, 0xd5 },
+	{ 0x0660, 0x00 },
+	{ 0x0661, 0xa0 },
+	{ 0x0662, 0x05 },
+	{ 0x0663, 0xaf },
+	{ 0x0664, 0x00 },
+	{ 0x0665, 0x2e },
+	{ 0x0666, 0x03 },
+	{ 0x0667, 0x0d },
+	{ 0x4b50, 0x00 },
+	{ 0x4b51, 0xcd },
+	{ 0x4b0a, 0x05 },
+	{ 0x4b0b, 0x10 },
+	{ 0x4b20, 0xde },
+	{ 0x4b07, 0xbd },
+	{ 0x0000, 0x00 },
+	{ 0x0100, 0x00 },
+	{ 0x0101, 0x00 },
+	{ 0x0005, 0x03 },
+	{ 0x0025, 0x00 },
+	{ 0x0100, 0x01 },
+	{ 0x0165, 0x03 },
+	{ 0x018c, 0x00 },
+	{ 0x0195, 0x06 },
+	{ 0x0196, 0x4f },
+	{ 0x0197, 0x04 },
+	{ 0x0198, 0xbf },
+	{ 0x0144, 0x10 },
+	{ 0x0140, 0x20 },
+	{ 0x015a, 0x30 },
+	{ 0x015d, 0xff },
+	{ 0x0160, 0x61 },
+};
+
+static const struct hm2051_reg hm2051_stream_on_regs[] = {
+	{ 0x0100, 0x01 },
+	{ 0x0101, 0x01 },
+	{ 0x0005, 0x01 },
+};
+
+static const struct hm2051_reg hm2051_stream_off_regs[] = {
+	{ 0x0005, 0x00 },
+};
+
+#endif /* __HM2051_TABLES_H__ */
-- 
2.56.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 6/6] media: i2c: Add Himax HM2051 camera sensor driver
  2026-11-30 10:08 ` [PATCH 6/6] media: i2c: Add Himax HM2051 camera sensor driver Kennedy Cheskaki
@ 2026-12-01  5:03   ` Elgin Perumbilly
  0 siblings, 0 replies; 4+ messages in thread
From: Elgin Perumbilly @ 2026-12-01  5:03 UTC (permalink / raw)
  To: Kennedy Cheskaki
  Cc: platform-driver-x86, linux-kernel, linux-media, Tarang Raval

Hi Kennedy,

>Add V4L2 subdevice driver for the Himax HM2051 2MP CMOS image sensor
>(ACPI HID HIMX2051), supporting 1616x1216 and 1296x736 at 30 fps.
>Signed-off-by: Kennedy Cheskaki <kkituyi@hotmail.com>
>---
> drivers/media/i2c/hm2051.c        | 614 ++++++++++++++++++++++++++++++
> drivers/media/i2c/hm2051_tables.h | 304 +++++++++++++++
> 2 files changed, 918 insertions(+)
> create mode 100644 drivers/media/i2c/hm2051.c
> create mode 100644 drivers/media/i2c/hm2051_tables.h
>
>diff --git a/drivers/media/i2c/hm2051.c b/drivers/media/i2c/hm2051.c
>new file mode 100644
>index 0000000..9ce0995
>--- /dev/null
>+++ b/drivers/media/i2c/hm2051.c
>@@ -0,0 +1,614 @@
>+// SPDX-License-Identifier: GPL-2.0
>+/*
>+ * Himax HM2051 CMOS image sensor V4L2 subdevice driver
>+ * Register tables and mode parameters extracted from Intel Unicam Windows driver.
>+ */
>+
>+#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/pm_runtime.h>
>+#include <media/v4l2-ctrls.h>
>+#include <media/v4l2-device.h>
>+#include <media/v4l2-fwnode.h>
>+#include <media/v4l2-subdev.h>
>+
>+#include "hm2051_tables.h"
>+

You can keep the register tables in the same file.

>+#define HM2051_CHIP_ID_H_REG		0x0001
>+#define HM2051_CHIP_ID_L_REG		0x0002
>+#define HM2051_CHIP_ID			0x2051
>+
>+#define HM2051_REG_EXPOSURE_H		0x0015
>+#define HM2051_REG_EXPOSURE_L		0x0016
>+#define HM2051_REG_GAIN			0x0018
>+#define HM2051_REG_CMU_UPDATE		0x0000
>+
>+#define HM2051_EXPOSURE_MIN		1
>+#define HM2051_EXPOSURE_MAX		0x1fff
>+#define HM2051_EXPOSURE_DEFAULT		4000
>+
>+#define HM2051_GAIN_MIN			0
>+#define HM2051_GAIN_MAX			0xff
>+#define HM2051_GAIN_DEFAULT		200
>+
>+#define HM2051_PIXEL_RATE		48000000ULL
>+#define HM2051_LINK_FREQ		240000000ULL
>+
>+#define HM2051_NATIVE_WIDTH		1616
>+#define HM2051_NATIVE_HEIGHT		1216
>+
>+struct hm2051_mode {
>+	u32 width;
>+	u32 height;
>+	u32 fps;
>+	u32 hts;
>+	u32 vts;
>+	const struct hm2051_reg *regs;
>+	unsigned int num_regs;
>+};
>+
>+static const struct hm2051_mode supported_modes[] = {
>+	{
>+		.width = 1616,
>+		.height = 1216,
>+		.fps = 30,
>+		.hts = 1800,
>+		.vts = 1260,
>+		.regs = hm2051_1616x1216_regs,
>+		.num_regs = ARRAY_SIZE(hm2051_1616x1216_regs),
>+	},
>+	{
>+		.width = 1296,
>+		.height = 736,
>+		.fps = 30,
>+		.hts = 1800,
>+		.vts = 800,
>+		.regs = hm2051_1296x736_regs,
>+		.num_regs = ARRAY_SIZE(hm2051_1296x736_regs),
>+	},
>+};
>+
>+static const s64 link_freq_menu_items[] = {
>+	HM2051_LINK_FREQ,
>+};
>+
>+struct hm2051 {
>+	struct v4l2_subdev sd;
>+	struct media_pad pad;
>+	struct v4l2_ctrl_handler ctrl_handler;
>+	struct clk *xvclk;
>+	struct gpio_desc *reset_gpio;
>+	struct gpio_desc *powerdown_gpio;
>+	struct v4l2_ctrl *pixel_rate;
>+	struct v4l2_ctrl *link_freq;
>+	struct v4l2_ctrl *hblank;
>+	struct v4l2_ctrl *vblank;
>+	struct v4l2_ctrl *exposure;
>+	struct v4l2_ctrl *gain;
>+	const struct hm2051_mode *cur_mode;
>+	struct mutex lock;
>+	bool streaming;
>+};
>+
>+static inline struct hm2051 *to_hm2051(struct v4l2_subdev *sd)
>+{
>+	return container_of(sd, struct hm2051, sd);
>+}

Please use container_of_const() here.

>+
>+static int hm2051_read_reg(struct i2c_client *client, u16 reg, u8 *val)
>+{
>+	u8 buf[2] = { reg >> 8, reg & 0xff };
>+	struct i2c_msg msgs[2] = {
>+		{
>+			.addr = client->addr,
>+			.flags = 0,
>+			.len = sizeof(buf),
>+			.buf = buf,
>+		},
>+		{
>+			.addr = client->addr,
>+			.flags = I2C_M_RD,
>+			.len = 1,
>+			.buf = val,
>+		},
>+	};
>+	int ret;
>+
>+	ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
>+	if (ret != ARRAY_SIZE(msgs))
>+		return ret < 0 ? ret : -EIO;
>+
>+	return 0;
>+}
>+
>+static int hm2051_write_reg(struct i2c_client *client, u16 reg, u8 val)
>+{
>+	u8 buf[3] = { reg >> 8, reg & 0xff, val };
>+	int ret;
>+
>+	ret = i2c_master_send(client, buf, sizeof(buf));
>+	if (ret != sizeof(buf))
>+		return ret < 0 ? ret : -EIO;
>+
>+	return 0;
>+}
>+
>+static int hm2051_write_regs(struct i2c_client *client,
>+			     const struct hm2051_reg *regs, unsigned int len)
>+{
>+	unsigned int i;
>+	int ret;
>+
>+	for (i = 0; i < len; i++) {
>+		if (regs[i].reg == HM2051_REG_DELAY) {
>+			msleep(regs[i].val);
>+			continue;
>+		}
>+		ret = hm2051_write_reg(client, regs[i].reg, regs[i].val);
>+		if (ret)
>+			return ret;
>+	}
>+
>+	return 0;
>+}
>+

Use the CCI interface for register read and write operations

>+static int hm2051_power_on(struct hm2051 *hm2051)
>+{
>+	int ret;
>+
>+	ret = clk_prepare_enable(hm2051->xvclk);
>+	if (ret)
>+		return ret;
>+
>+	gpiod_set_value_cansleep(hm2051->powerdown_gpio, 0);
>+	gpiod_set_value_cansleep(hm2051->reset_gpio, 0);
>+	usleep_range(5000, 10000);
>+	return 0;
>+}
>+
>+static void hm2051_power_off(struct hm2051 *hm2051)
>+{
>+	gpiod_set_value_cansleep(hm2051->reset_gpio, 1);
>+	gpiod_set_value_cansleep(hm2051->powerdown_gpio, 1);
>+	clk_disable_unprepare(hm2051->xvclk);
>+}
>+
>+static int hm2051_identify(struct i2c_client *client)
>+{
>+	u8 id_h = 0, id_l = 0;
>+	u16 id;
>+	int ret;
>+
>+	ret = hm2051_read_reg(client, HM2051_CHIP_ID_H_REG, &id_h);
>+	if (ret)
>+		return ret;
>+
>+	ret = hm2051_read_reg(client, HM2051_CHIP_ID_L_REG, &id_l);
>+	if (ret)
>+		return ret;
>+
>+	id = ((u16)id_h << 8) | id_l;
>+	if (id != HM2051_CHIP_ID) {
>+		dev_err(&client->dev, "chip id mismatch: 0x%04x (expected 0x%04x)\n",
>+			id, HM2051_CHIP_ID);
>+		return -ENODEV;
>+	}
>+
>+	dev_info(&client->dev, "found HM2051 sensor (chip id 0x%04x)\n", id);
>+	return 0;
>+}
>+
>+static int hm2051_set_ctrl(struct v4l2_ctrl *ctrl)
>+{
>+	struct hm2051 *hm2051 = container_of(ctrl->handler, struct hm2051,
>+					     ctrl_handler);
>+	struct i2c_client *client = v4l2_get_subdevdata(&hm2051->sd);
>+	int ret = 0;
>+
>+	if (pm_runtime_get_if_in_use(&client->dev) <= 0)
>+		return 0;
>+
>+	switch (ctrl->id) {
>+	case V4L2_CID_EXPOSURE:
>+		ret = hm2051_write_reg(client, HM2051_REG_EXPOSURE_H,
>+				       (ctrl->val >> 8) & 0xff);
>+		if (!ret)
>+			ret = hm2051_write_reg(client, HM2051_REG_EXPOSURE_L,
>+					       ctrl->val & 0xff);
>+		if (!ret)
>+			ret = hm2051_write_reg(client, HM2051_REG_CMU_UPDATE, 0x01);
>+		break;
>+	case V4L2_CID_ANALOGUE_GAIN:
>+		ret = hm2051_write_reg(client, HM2051_REG_GAIN, ctrl->val & 0xff);
>+		if (!ret)
>+			ret = hm2051_write_reg(client, HM2051_REG_CMU_UPDATE, 0x01);
>+		break;
>+	default:
>+		ret = -EINVAL;
>+		break;
>+	}
>+
>+	pm_runtime_put(&client->dev);
>+	return ret;
>+}
>+
>+static const struct v4l2_ctrl_ops hm2051_ctrl_ops = {
>+	.s_ctrl = hm2051_set_ctrl,
>+};
>+
>+static int hm2051_init_controls(struct hm2051 *hm2051)
>+{
>+	struct v4l2_ctrl_handler *hdl = &hm2051->ctrl_handler;
>+	const struct hm2051_mode *mode = hm2051->cur_mode;
>+	s64 hblank, vblank;
>+	int ret;
>+
>+	ret = v4l2_ctrl_handler_init(hdl, 6);
>+	if (ret)
>+		return ret;
>+
>+	hm2051->pixel_rate = v4l2_ctrl_new_std(hdl, &hm2051_ctrl_ops,
>+					       V4L2_CID_PIXEL_RATE,
>+					       HM2051_PIXEL_RATE,
>+					       HM2051_PIXEL_RATE, 1,
>+					       HM2051_PIXEL_RATE);
>+
>+	hm2051->link_freq = v4l2_ctrl_new_int_menu(hdl, &hm2051_ctrl_ops,
>+						   V4L2_CID_LINK_FREQ,
>+						   ARRAY_SIZE(link_freq_menu_items) - 1,
>+						   0, link_freq_menu_items);
>+	if (hm2051->link_freq)
>+		hm2051->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
>+
>+	hblank = mode->hts - mode->width;
>+	hm2051->hblank = v4l2_ctrl_new_std(hdl, &hm2051_ctrl_ops,
>+					   V4L2_CID_HBLANK, hblank, hblank, 1,
>+					   hblank);
>+	if (hm2051->hblank)
>+		hm2051->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
>+
>+	vblank = mode->vts - mode->height;
>+	hm2051->vblank = v4l2_ctrl_new_std(hdl, &hm2051_ctrl_ops,
>+					   V4L2_CID_VBLANK, vblank, vblank, 1,
>+					   vblank);
>+	if (hm2051->vblank)
>+		hm2051->vblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
>+
>+	hm2051->exposure = v4l2_ctrl_new_std(hdl, &hm2051_ctrl_ops,
>+					     V4L2_CID_EXPOSURE,
>+					     HM2051_EXPOSURE_MIN,
>+					     HM2051_EXPOSURE_MAX, 1,
>+					     HM2051_EXPOSURE_DEFAULT);
>+
>+	hm2051->gain = v4l2_ctrl_new_std(hdl, &hm2051_ctrl_ops,
>+					 V4L2_CID_ANALOGUE_GAIN,
>+					 HM2051_GAIN_MIN, HM2051_GAIN_MAX, 1,
>+					 HM2051_GAIN_DEFAULT);
>+
>+	if (hdl->error) {
>+		ret = hdl->error;
>+		v4l2_ctrl_handler_free(hdl);
>+		return ret;
>+	}
>+
>+	hm2051->sd.ctrl_handler = hdl;
>+	return 0;
>+}
>+
>+static int hm2051_enum_mbus_code(struct v4l2_subdev *sd,
>+				 struct v4l2_subdev_state *sd_state,
>+				 struct v4l2_subdev_mbus_code_enum *code)
>+{
>+	if (code->index > 0)
>+		return -EINVAL;
>+
>+	code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
>+	return 0;
>+}
>+
>+static int hm2051_enum_frame_size(struct v4l2_subdev *sd,
>+				  struct v4l2_subdev_state *sd_state,
>+				  struct v4l2_subdev_frame_size_enum *fse)
>+{
>+	if (fse->index >= ARRAY_SIZE(supported_modes))
>+		return -EINVAL;
>+
>+	if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10)
>+		return -EINVAL;
>+
>+	fse->min_width = supported_modes[fse->index].width;
>+	fse->max_width = fse->min_width;
>+	fse->min_height = supported_modes[fse->index].height;
>+	fse->max_height = fse->min_height;
>+	return 0;
>+}
>+
>+static int hm2051_enum_frame_interval(struct v4l2_subdev *sd,
>+				      struct v4l2_subdev_state *sd_state,
>+				      struct v4l2_subdev_frame_interval_enum *fie)
>+{
>+	unsigned int i;
>+
>+	if (fie->index > 0 || fie->code != MEDIA_BUS_FMT_SBGGR10_1X10)
>+		return -EINVAL;
>+
>+	for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
>+		if (fie->width == supported_modes[i].width &&
>+		    fie->height == supported_modes[i].height) {
>+			fie->interval.numerator = 1;
>+			fie->interval.denominator = supported_modes[i].fps;
>+			return 0;
>+		}
>+	}
>+
>+	return -EINVAL;
>+}
>+
>+static void hm2051_fill_pad_format(const struct hm2051_mode *mode,
>+				   struct v4l2_mbus_framefmt *fmt)
>+{
>+	fmt->width = mode->width;
>+	fmt->height = mode->height;
>+	fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
>+	fmt->field = V4L2_FIELD_NONE;
>+	fmt->colorspace = V4L2_COLORSPACE_RAW;
>+}
>+
>+static int hm2051_init_state(struct v4l2_subdev *sd,
>+			     struct v4l2_subdev_state *sd_state)
>+{
>+	struct v4l2_mbus_framefmt *fmt =
>+		v4l2_subdev_state_get_format(sd_state, 0);
>+
>+	hm2051_fill_pad_format(&supported_modes[0], fmt);
>+	return 0;
>+}
>+
>+static int hm2051_set_pad_format(struct v4l2_subdev *sd,
>+				 struct v4l2_subdev_state *sd_state,
>+				 struct v4l2_subdev_format *fmt)
>+{
>+	struct hm2051 *hm2051 = to_hm2051(sd);
>+	const struct hm2051_mode *mode;
>+	struct v4l2_mbus_framefmt *framefmt;
>+
>+	mode = v4l2_find_nearest_size(supported_modes,
>+				      ARRAY_SIZE(supported_modes),
>+				      width, height,
>+				      fmt->format.width, fmt->format.height);
>+
>+	hm2051_fill_pad_format(mode, &fmt->format);
>+
>+	framefmt = v4l2_subdev_state_get_format(sd_state, 0);
>+	*framefmt = fmt->format;
>+
>+	if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
>+		mutex_lock(&hm2051->lock);
>+		hm2051->cur_mode = mode;
>+		mutex_unlock(&hm2051->lock);
>+	}
>+
>+	return 0;
>+}
>+
>+static int hm2051_get_selection(struct v4l2_subdev *sd,
>+				struct v4l2_subdev_state *sd_state,
>+				struct v4l2_subdev_selection *sel)
>+{
>+	switch (sel->target) {
>+	case V4L2_SEL_TGT_NATIVE_SIZE:
>+	case V4L2_SEL_TGT_CROP_BOUNDS:
>+	case V4L2_SEL_TGT_CROP_DEFAULT:
>+		sel->r.left = 0;
>+		sel->r.top = 0;
>+		sel->r.width = HM2051_NATIVE_WIDTH;
>+		sel->r.height = HM2051_NATIVE_HEIGHT;
>+		return 0;
>+	default:
>+		return -EINVAL;
>+	}
>+}
>+
>+static int hm2051_s_stream(struct v4l2_subdev *sd, int enable)
>+{
>+	struct hm2051 *hm2051 = to_hm2051(sd);
>+	struct i2c_client *client = v4l2_get_subdevdata(sd);
>+	int ret = 0;
>+

Use the enable_streams and disable_streams pad ops.

>+	mutex_lock(&hm2051->lock);
>+
>+	if (hm2051->streaming == !!enable)
>+		goto unlock;
>+
>+	if (enable) {
>+		ret = pm_runtime_resume_and_get(&client->dev);
>+		if (ret < 0)
>+			goto unlock;
>+
>+		ret = hm2051_write_regs(client, hm2051_init_regs,
>+					ARRAY_SIZE(hm2051_init_regs));
>+		if (ret)
>+			goto err_rpm;
>+
>+		ret = hm2051_write_regs(client, hm2051->cur_mode->regs,
>+					hm2051->cur_mode->num_regs);
>+		if (ret)
>+			goto err_rpm;
>+
>+		ret = __v4l2_ctrl_handler_setup(&hm2051->ctrl_handler);
>+		if (ret)
>+			goto err_rpm;
>+
>+		ret = hm2051_write_regs(client, hm2051_stream_on_regs,
>+					ARRAY_SIZE(hm2051_stream_on_regs));
>+		if (ret)
>+			goto err_rpm;
>+
>+		hm2051->streaming = true;
>+	} else {
>+		hm2051_write_regs(client, hm2051_stream_off_regs,
>+				  ARRAY_SIZE(hm2051_stream_off_regs));
>+		pm_runtime_put(&client->dev);
>+		hm2051->streaming = false;
>+	}
>+
>+	mutex_unlock(&hm2051->lock);
>+	return 0;
>+
>+err_rpm:
>+	pm_runtime_put(&client->dev);
>+unlock:
>+	mutex_unlock(&hm2051->lock);
>+	return ret;
>+}
>+

Best Regards,
Elgin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-01  5:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20261130100835.12189-1-kkituyi@hotmail.com>
2026-11-30 10:08 ` [PATCH 4/6] media: atomisp: Add Athesi RT80 sensors and 180-deg rotation quirk Kennedy Cheskaki
2026-11-30 10:08 ` [PATCH 5/6] media: ov8858: Add ACPI ID INT3477 Kennedy Cheskaki
2026-11-30 10:08 ` [PATCH 6/6] media: i2c: Add Himax HM2051 camera sensor driver Kennedy Cheskaki
2026-12-01  5:03   ` Elgin Perumbilly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®