From: Hans de Goede <hansg@kernel.org>
To: Bingbu Cao <bingbu.cao@intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Hans de Goede <hansg@kernel.org>, linux-media@vger.kernel.org
Subject: [PATCH 21/25] media: i2c: ov01a10: Add ov01a10_sensor_cfg struct
Date: Tue, 14 Oct 2025 19:40:29 +0200 [thread overview]
Message-ID: <20251014174033.20534-22-hansg@kernel.org> (raw)
In-Reply-To: <20251014174033.20534-1-hansg@kernel.org>
Add a struct with some sensor variant (ov01a10 / ov01a1b / ov01a1s)
specific settings.
This is a preparation patch for adding support for the ov01a1s sensor
which uses the same sensor with a different (RGBI) color-filter.
Signed-off-by: Hans de Goede <hansg@kernel.org>
---
drivers/media/i2c/ov01a10.c | 87 +++++++++++++++++++++++++------------
1 file changed, 60 insertions(+), 27 deletions(-)
diff --git a/drivers/media/i2c/ov01a10.c b/drivers/media/i2c/ov01a10.c
index 17d8778561d4..51c9c015765f 100644
--- a/drivers/media/i2c/ov01a10.c
+++ b/drivers/media/i2c/ov01a10.c
@@ -88,16 +88,6 @@
#define OV01A10_REG_TEST_PATTERN CCI_REG8(0x4503)
#define OV01A10_TEST_PATTERN_ENABLE BIT(7)
-/*
- * The native ov01a10 bayer-pattern is GBRG, but there was a driver bug enabling
- * hflip/mirroring by default resulting in BGGR. Because of this bug Intel's
- * proprietary IPU6 userspace stack expects BGGR. So we report BGGR to not break
- * userspace and fix things up by shifting the crop window-x coordinate by 1
- * when hflip is *disabled*.
- */
-#define OV01A10_MEDIA_BUS_FMT MEDIA_BUS_FMT_SBGGR10_1X10
-#define OV01A10_BAYER_PATTERN_SIZE 2 /* 2x2 */
-
struct ov01a10_link_freq_config {
const struct reg_sequence *regs;
int regs_len;
@@ -246,9 +236,19 @@ static const char * const ov01a10_supply_names[] = {
"dvdd", /* Digital core power */
};
+struct ov01a10_sensor_cfg {
+ const char *model;
+ u32 bus_fmt;
+ int pattern_size;
+ int border_size;
+ bool invert_hflip_shift;
+ bool invert_vflip_shift;
+};
+
struct ov01a10 {
struct device *dev;
struct regmap *regmap;
+ const struct ov01a10_sensor_cfg *cfg;
struct v4l2_subdev sd;
struct media_pad pad;
struct v4l2_ctrl_handler ctrl_handler;
@@ -311,14 +311,15 @@ static int ov01a10_test_pattern(struct ov01a10 *ov01a10, u32 pattern)
NULL);
}
-static int ov01a10_set_hflip(struct ov01a10 *ov01a10, u32 hflip)
+static int ov01a10_set_hflip(struct ov01a10 *ov01a10, bool hflip)
{
struct v4l2_rect *crop = ov01a10_get_active_crop(ov01a10);
+ const struct ov01a10_sensor_cfg *cfg = ov01a10->cfg;
u32 val, offset;
int ret = 0;
offset = crop->left;
- if (!hflip)
+ if ((hflip ^ cfg->invert_hflip_shift) && cfg->border_size)
offset++;
val = hflip ? 0 : FIELD_PREP(OV01A10_HFLIP_MASK, 0x1);
@@ -330,14 +331,15 @@ static int ov01a10_set_hflip(struct ov01a10 *ov01a10, u32 hflip)
return ret;
}
-static int ov01a10_set_vflip(struct ov01a10 *ov01a10, u32 vflip)
+static int ov01a10_set_vflip(struct ov01a10 *ov01a10, bool vflip)
{
struct v4l2_rect *crop = ov01a10_get_active_crop(ov01a10);
+ const struct ov01a10_sensor_cfg *cfg = ov01a10->cfg;
u32 val, offset;
int ret = 0;
offset = crop->top;
- if (vflip)
+ if ((vflip ^ cfg->invert_vflip_shift) && cfg->border_size)
offset++;
val = vflip ? FIELD_PREP(OV01A10_VFLIP_MASK, 0x1) : 0;
@@ -500,13 +502,14 @@ static int ov01a10_init_controls(struct ov01a10 *ov01a10)
return ret;
}
-static void ov01a10_fill_format(struct v4l2_mbus_framefmt *fmt,
+static void ov01a10_fill_format(struct ov01a10 *ov01a10,
+ struct v4l2_mbus_framefmt *fmt,
unsigned int width, unsigned int height)
{
memset(fmt, 0, sizeof(*fmt));
fmt->width = width;
fmt->height = height;
- fmt->code = OV01A10_MEDIA_BUS_FMT;
+ fmt->code = ov01a10->cfg->bus_fmt;
fmt->field = V4L2_FIELD_NONE;
fmt->colorspace = V4L2_COLORSPACE_RAW;
}
@@ -626,9 +629,9 @@ static int ov01a10_set_format(struct v4l2_subdev *sd,
struct v4l2_subdev_format *fmt)
{
struct v4l2_rect *crop = v4l2_subdev_state_get_crop(sd_state, fmt->pad);
- const int pattern_size = OV01A10_BAYER_PATTERN_SIZE;
- const int border_size = OV01A10_BAYER_PATTERN_SIZE;
struct ov01a10 *ov01a10 = to_ov01a10(sd);
+ const int pattern_size = ov01a10->cfg->pattern_size;
+ const int border_size = ov01a10->cfg->border_size;
unsigned int width, height;
width = clamp_val(ALIGN(fmt->format.width, pattern_size),
@@ -648,7 +651,7 @@ static int ov01a10_set_format(struct v4l2_subdev *sd,
crop->height = height;
}
- ov01a10_fill_format(&fmt->format, width, height);
+ ov01a10_fill_format(ov01a10, &fmt->format, width, height);
*v4l2_subdev_state_get_format(sd_state, fmt->pad) = fmt->format;
if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
@@ -660,8 +663,10 @@ static int ov01a10_set_format(struct v4l2_subdev *sd,
static int ov01a10_init_state(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state)
{
+ struct ov01a10 *ov01a10 = to_ov01a10(sd);
+
*v4l2_subdev_state_get_crop(sd_state, 0) = ov01a10_default_crop;
- ov01a10_fill_format(v4l2_subdev_state_get_format(sd_state, 0),
+ ov01a10_fill_format(ov01a10, v4l2_subdev_state_get_format(sd_state, 0),
OV01A10_DEFAULT_WIDTH, OV01A10_DEFAULT_HEIGHT);
return 0;
@@ -671,10 +676,12 @@ static int ov01a10_enum_mbus_code(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_mbus_code_enum *code)
{
+ struct ov01a10 *ov01a10 = to_ov01a10(sd);
+
if (code->index > 0)
return -EINVAL;
- code->code = OV01A10_MEDIA_BUS_FMT;
+ code->code = ov01a10->cfg->bus_fmt;
return 0;
}
@@ -683,8 +690,9 @@ static int ov01a10_enum_frame_size(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_frame_size_enum *fse)
{
- const int pattern_size = OV01A10_BAYER_PATTERN_SIZE;
- const int border_size = OV01A10_BAYER_PATTERN_SIZE;
+ struct ov01a10 *ov01a10 = to_ov01a10(sd);
+ const int pattern_size = ov01a10->cfg->pattern_size;
+ const int border_size = ov01a10->cfg->border_size;
if (fse->index)
return -EINVAL;
@@ -701,7 +709,8 @@ static int ov01a10_get_selection(struct v4l2_subdev *sd,
struct v4l2_subdev_state *state,
struct v4l2_subdev_selection *sel)
{
- const int border_size = OV01A10_BAYER_PATTERN_SIZE;
+ struct ov01a10 *ov01a10 = to_ov01a10(sd);
+ const int border_size = ov01a10->cfg->border_size;
switch (sel->target) {
case V4L2_SEL_TGT_CROP:
@@ -732,9 +741,9 @@ static int ov01a10_set_selection(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_selection *sel)
{
- const int pattern_size = OV01A10_BAYER_PATTERN_SIZE;
- const int border_size = OV01A10_BAYER_PATTERN_SIZE;
struct ov01a10 *ov01a10 = to_ov01a10(sd);
+ const int pattern_size = ov01a10->cfg->pattern_size;
+ const int border_size = ov01a10->cfg->border_size;
struct v4l2_mbus_framefmt *format;
struct v4l2_rect *crop;
struct v4l2_rect rect;
@@ -974,20 +983,28 @@ static void ov01a10_remove(struct i2c_client *client)
static int ov01a10_probe(struct i2c_client *client)
{
+ const struct ov01a10_sensor_cfg *cfg;
struct ov01a10 *ov01a10;
int ret;
+ cfg = device_get_match_data(&client->dev);
+ if (!cfg)
+ return -EINVAL;
+
ov01a10 = devm_kzalloc(&client->dev, sizeof(*ov01a10), GFP_KERNEL);
if (!ov01a10)
return -ENOMEM;
ov01a10->dev = &client->dev;
+ ov01a10->cfg = cfg;
ov01a10->regmap = devm_cci_regmap_init_i2c(client, 16);
if (IS_ERR(ov01a10->regmap))
return PTR_ERR(ov01a10->regmap);
v4l2_i2c_subdev_init(&ov01a10->sd, client, &ov01a10_subdev_ops);
+ /* Override driver->name with actual sensor model */
+ v4l2_i2c_subdev_set_name(&ov01a10->sd, client, cfg->model, NULL);
ov01a10->sd.internal_ops = &ov01a10_internal_ops;
ret = ov01a10_check_hwcfg(ov01a10);
@@ -1059,8 +1076,24 @@ static DEFINE_RUNTIME_DEV_PM_OPS(ov01a10_pm_ops, ov01a10_power_off,
ov01a10_power_on, NULL);
#ifdef CONFIG_ACPI
+/*
+ * The native ov01a10 bayer-pattern is GBRG, but there was a driver bug enabling
+ * hflip/mirroring by default resulting in BGGR. Because of this bug Intel's
+ * proprietary IPU6 userspace stack expects BGGR. So we report BGGR to not break
+ * userspace and fix things up by shifting the crop window-x coordinate by 1
+ * when hflip is *disabled*.
+ */
+static const struct ov01a10_sensor_cfg ov01a10_cfg = {
+ .model = "ov01a10",
+ .bus_fmt = MEDIA_BUS_FMT_SBGGR10_1X10,
+ .pattern_size = 2, /* 2x2 */
+ .border_size = 2,
+ .invert_hflip_shift = true,
+ .invert_vflip_shift = false,
+};
+
static const struct acpi_device_id ov01a10_acpi_ids[] = {
- { "OVTI01A0" },
+ { "OVTI01A0", (uintptr_t)&ov01a10_cfg },
{ }
};
--
2.51.0
next prev parent reply other threads:[~2025-10-14 17:41 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-14 17:40 [PATCH 00/25] media: i2c: ov01a10: Add crop, ov01a1b and ov01a1s support Hans de Goede
2025-10-14 17:40 ` [PATCH 01/25] media: i2c: ov01a10: Fix the horizontal flip control Hans de Goede
2025-10-27 19:00 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 02/25] media: i2c: ov01a10: Fix reported pixel-rate value Hans de Goede
2025-10-27 19:03 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 03/25] media: i2c: ov01a10: Fix gain range Hans de Goede
2025-10-27 19:14 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 04/25] media: i2c: ov01a10: Add missing v4l2_subdev_cleanup() calls Hans de Goede
2025-10-15 2:37 ` Bingbu Cao
2025-10-15 2:46 ` Bingbu Cao
2025-10-28 11:24 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 05/25] media: i2c: ov01a10: Fix passing stream instead of pad to v4l2_subdev_state_get_format() Hans de Goede
2025-10-28 11:40 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 06/25] media: i2c: ov01a10: Fix test-pattern disabling Hans de Goede
2025-10-15 2:34 ` Bingbu Cao
2025-10-28 12:08 ` Mehdi Djait
2025-10-28 14:38 ` Hans de Goede
2025-10-28 15:38 ` Mehdi Djait
2025-10-28 15:52 ` Hans de Goede
2025-10-29 17:44 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 07/25] media: i2c: ov01a10: Change default vblank value to a vblank resulting in 30 fps Hans de Goede
2025-10-28 16:57 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 08/25] media: i2c: ov01a10: Convert to new CCI register access helpers Hans de Goede
2025-10-28 17:01 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 09/25] media: i2c: ov01a10: Remove overly verbose probe() error reporting Hans de Goede
2025-10-28 17:02 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 10/25] media: i2c: ov01a10: Store dev pointer in struct ov01a10 Hans de Goede
2025-10-28 17:18 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 11/25] media: i2c: ov01a10: Add ov01a10_check_hwcfg() function Hans de Goede
2025-10-28 17:29 ` Mehdi Djait
2025-10-28 20:09 ` Hans de Goede
2025-10-29 17:30 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 12/25] media: i2c: ov01a10: Add power on/off sequencing support Hans de Goede
2025-10-28 18:06 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 13/25] media: i2c: ov01a10: Don't update pixel_rate and link_freq from set_fmt Hans de Goede
2025-10-28 18:15 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 14/25] media: i2c: ov01a10: Move setting of ctrl->flags to after checking ctrl_hdlr->error Hans de Goede
2025-10-28 18:18 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 15/25] media: i2c: ov01a10: Use native and default for pixel-array size names Hans de Goede
2025-10-28 19:01 ` Mehdi Djait
2025-10-28 20:19 ` Hans de Goede
2025-10-14 17:40 ` [PATCH 16/25] media: i2c: ov01a10: Add cropping support / allow arbitrary sizes Hans de Goede
2025-11-06 15:28 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 17/25] media: i2c: ov01a10: Remove struct ov01a10_reg_list Hans de Goede
2025-10-28 19:13 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 18/25] media: i2c: ov01a10: Replace exposure->min/step with direct define use Hans de Goede
2025-10-28 19:19 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 19/25] media: i2c: ov01a10: Only set register 0x0305 once Hans de Goede
2025-10-28 19:25 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 20/25] media: i2c: ov01a10: Remove values set by controls from global_setting[] Hans de Goede
2025-10-29 17:50 ` Mehdi Djait
2025-10-14 17:40 ` Hans de Goede [this message]
2025-11-06 15:33 ` [PATCH 21/25] media: i2c: ov01a10: Add ov01a10_sensor_cfg struct Mehdi Djait
2025-10-14 17:40 ` [PATCH 22/25] media: i2c: ov01a10: Optimize setting h/vflip values Hans de Goede
2025-11-06 15:54 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 23/25] media: i2c: ov01a10: Add ov01a1b support Hans de Goede
2025-11-06 16:16 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 24/25] media: i2c: ov01a10: Add ov01a1s support Hans de Goede
2025-11-06 16:17 ` Mehdi Djait
2025-10-14 17:40 ` [PATCH 25/25] media: i2c: ov01a10: Register tweaks for ov01a1s model Hans de Goede
2025-10-15 10:45 ` kernel test robot
2025-11-07 9:17 ` Mehdi Djait
2025-11-13 9:54 ` Hans de Goede
2025-11-17 8:17 ` Mehdi Djait
2025-10-28 20:06 ` [PATCH 00/25] media: i2c: ov01a10: Add crop, ov01a1b and ov01a1s support Hans de Goede
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=20251014174033.20534-22-hansg@kernel.org \
--to=hansg@kernel.org \
--cc=bingbu.cao@intel.com \
--cc=linux-media@vger.kernel.org \
--cc=sakari.ailus@linux.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).