[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260107134844.68074-2-karthikey3608@gmail.com>
Date: Wed, 7 Jan 2026 19:18:42 +0530
From: Karthikey D Kadati <karthikey3608@...il.com>
To: Hans de Goede <hansg@...nel.org>,
Mauro Carvalho Chehab <mchehab@...nel.org>
Cc: Sakari Ailus <sakari.ailus@...ux.intel.com>,
linux-media@...r.kernel.org,
linux-staging@...ts.linux.dev,
linux-kernel@...r.kernel.org,
Karthikey D Kadati <karthikey3608@...il.com>
Subject: [PATCH v2 RESEND v2 1/3] media: atomisp: replace shadow zoom structs with v4l2_rect
Remove custom atomisp_zoom_point and atomisp_zoom_region structs and
usage in favor of standard v4l2_rect within atomisp_dz_config.
This aligns the driver with V4L2 standards and removes unnecessary
custom types.
Also standardizes the internal ia_css_region struct members to match
V4L2 naming conventions (left, top, width, height) to facilitate the
bridge mapping.
Updates atomisp_cmd.c and sh_css_params.c to use the new member names
and ensures safe math using long long casts to prevent overflow during
resolution scaling.
Signed-off-by: Karthikey D Kadati <karthikey3608@...il.com>
---
.../media/atomisp/include/linux/atomisp.h | 19 +--
.../staging/media/atomisp/pci/atomisp_cmd.c | 130 +++++++++---------
.../staging/media/atomisp/pci/ia_css_types.h | 6 +-
.../staging/media/atomisp/pci/sh_css_params.c | 16 +--
4 files changed, 79 insertions(+), 92 deletions(-)
diff --git a/drivers/staging/media/atomisp/include/linux/atomisp.h b/drivers/staging/media/atomisp/include/linux/atomisp.h
index fcf116cc4..b5cce12c1 100644
--- a/drivers/staging/media/atomisp/include/linux/atomisp.h
+++ b/drivers/staging/media/atomisp/include/linux/atomisp.h
@@ -326,27 +326,12 @@ struct atomisp_resolution {
u32 height; /** Height */
};
-/*
- * This specifies the coordinates (x,y)
- */
-struct atomisp_zoom_point {
- s32 x; /** x coordinate */
- s32 y; /** y coordinate */
-};
-
-/*
- * This specifies the region
- */
-struct atomisp_zoom_region {
- struct atomisp_zoom_point
- origin; /* Starting point coordinates for the region */
- struct atomisp_resolution resolution; /* Region resolution */
-};
+#include <linux/videodev2.h>
struct atomisp_dz_config {
u32 dx; /** Horizontal zoom factor */
u32 dy; /** Vertical zoom factor */
- struct atomisp_zoom_region zoom_region; /** region for zoom */
+ struct v4l2_rect zoom_region; /** region for zoom */
};
struct atomisp_parm {
diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
index 327836372..4ed6b8aea 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c
@@ -1764,15 +1764,13 @@ int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd,
return -EINVAL;
}
- if (dz_config->zoom_region.resolution.width
- == asd->sensor_array_res.width
- || dz_config->zoom_region.resolution.height
- == asd->sensor_array_res.height) {
+ if (dz_config->zoom_region.width == asd->sensor_array_res.width ||
+ dz_config->zoom_region.height == asd->sensor_array_res.height) {
/*no need crop region*/
- dz_config->zoom_region.origin.x = 0;
- dz_config->zoom_region.origin.y = 0;
- dz_config->zoom_region.resolution.width = eff_res.width;
- dz_config->zoom_region.resolution.height = eff_res.height;
+ dz_config->zoom_region.left = 0;
+ dz_config->zoom_region.top = 0;
+ dz_config->zoom_region.width = eff_res.width;
+ dz_config->zoom_region.height = eff_res.height;
return 0;
}
@@ -1783,18 +1781,18 @@ int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd,
*/
if (!IS_ISP2401) {
- dz_config->zoom_region.origin.x = dz_config->zoom_region.origin.x
- * eff_res.width
- / asd->sensor_array_res.width;
- dz_config->zoom_region.origin.y = dz_config->zoom_region.origin.y
- * eff_res.height
- / asd->sensor_array_res.height;
- dz_config->zoom_region.resolution.width = dz_config->zoom_region.resolution.width
- * eff_res.width
- / asd->sensor_array_res.width;
- dz_config->zoom_region.resolution.height = dz_config->zoom_region.resolution.height
- * eff_res.height
- / asd->sensor_array_res.height;
+ dz_config->zoom_region.left =
+ (s32)((long long)dz_config->zoom_region.left *
+ eff_res.width / asd->sensor_array_res.width);
+ dz_config->zoom_region.top =
+ (s32)((long long)dz_config->zoom_region.top *
+ eff_res.height / asd->sensor_array_res.height);
+ dz_config->zoom_region.width =
+ (u32)((long long)dz_config->zoom_region.width *
+ eff_res.width / asd->sensor_array_res.width);
+ dz_config->zoom_region.height =
+ (u32)((long long)dz_config->zoom_region.height *
+ eff_res.height / asd->sensor_array_res.height);
/*
* Set same ratio of crop region resolution and current pipe output
* resolution
@@ -1821,62 +1819,66 @@ int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd,
- asd->sensor_array_res.width
* out_res.height / out_res.width;
h_offset = h_offset / 2;
- if (dz_config->zoom_region.origin.y < h_offset)
- dz_config->zoom_region.origin.y = 0;
+ if (dz_config->zoom_region.top < h_offset)
+ dz_config->zoom_region.top = 0;
else
- dz_config->zoom_region.origin.y = dz_config->zoom_region.origin.y - h_offset;
+ dz_config->zoom_region.top -= h_offset;
w_offset = 0;
} else {
w_offset = asd->sensor_array_res.width
- asd->sensor_array_res.height
* out_res.width / out_res.height;
w_offset = w_offset / 2;
- if (dz_config->zoom_region.origin.x < w_offset)
- dz_config->zoom_region.origin.x = 0;
+ if (dz_config->zoom_region.left < w_offset)
+ dz_config->zoom_region.left = 0;
else
- dz_config->zoom_region.origin.x = dz_config->zoom_region.origin.x - w_offset;
+ dz_config->zoom_region.left -= w_offset;
h_offset = 0;
}
- dz_config->zoom_region.origin.x = dz_config->zoom_region.origin.x
- * eff_res.width
- / (asd->sensor_array_res.width - 2 * w_offset);
- dz_config->zoom_region.origin.y = dz_config->zoom_region.origin.y
- * eff_res.height
- / (asd->sensor_array_res.height - 2 * h_offset);
- dz_config->zoom_region.resolution.width = dz_config->zoom_region.resolution.width
- * eff_res.width
- / (asd->sensor_array_res.width - 2 * w_offset);
- dz_config->zoom_region.resolution.height = dz_config->zoom_region.resolution.height
- * eff_res.height
- / (asd->sensor_array_res.height - 2 * h_offset);
- }
-
- if (out_res.width * dz_config->zoom_region.resolution.height
- > dz_config->zoom_region.resolution.width * out_res.height) {
- dz_config->zoom_region.resolution.height =
- dz_config->zoom_region.resolution.width
- * out_res.height / out_res.width;
+ dz_config->zoom_region.left =
+ (s32)((long long)dz_config->zoom_region.left *
+ eff_res.width /
+ (asd->sensor_array_res.width - 2 * w_offset));
+ dz_config->zoom_region.top =
+ (s32)((long long)dz_config->zoom_region.top *
+ eff_res.height /
+ (asd->sensor_array_res.height - 2 * h_offset));
+ dz_config->zoom_region.width =
+ (u32)((long long)dz_config->zoom_region.width *
+ eff_res.width /
+ (asd->sensor_array_res.width - 2 * w_offset));
+ dz_config->zoom_region.height =
+ (u32)((long long)dz_config->zoom_region.height *
+ eff_res.height /
+ (asd->sensor_array_res.height - 2 * h_offset));
+ }
+
+ if ((long long)out_res.width * dz_config->zoom_region.height >
+ (long long)dz_config->zoom_region.width * out_res.height) {
+ dz_config->zoom_region.height =
+ (u32)((long long)dz_config->zoom_region.width *
+ out_res.height / out_res.width);
} else {
- dz_config->zoom_region.resolution.width =
- dz_config->zoom_region.resolution.height
- * out_res.width / out_res.height;
+ dz_config->zoom_region.width =
+ (u32)((long long)dz_config->zoom_region.height *
+ out_res.width / out_res.height);
}
dev_dbg(asd->isp->dev,
"%s crop region:(%d,%d),(%d,%d) eff_res(%d, %d) array_size(%d,%d) out_res(%d, %d)\n",
- __func__, dz_config->zoom_region.origin.x,
- dz_config->zoom_region.origin.y,
- dz_config->zoom_region.resolution.width,
- dz_config->zoom_region.resolution.height,
+ __func__, dz_config->zoom_region.left,
+ dz_config->zoom_region.top,
+ dz_config->zoom_region.width,
+ dz_config->zoom_region.height,
eff_res.width, eff_res.height,
asd->sensor_array_res.width,
asd->sensor_array_res.height,
out_res.width, out_res.height);
- if ((dz_config->zoom_region.origin.x +
- dz_config->zoom_region.resolution.width
+ if ((dz_config->zoom_region.left +
+ dz_config->zoom_region.width
> eff_res.width) ||
- (dz_config->zoom_region.origin.y +
- dz_config->zoom_region.resolution.height
+ (dz_config->zoom_region.top +
+ dz_config->zoom_region.height
> eff_res.height))
return -EINVAL;
@@ -1901,10 +1903,10 @@ static bool atomisp_check_zoom_region(
config.width = asd->sensor_array_res.width;
config.height = asd->sensor_array_res.height;
- w = dz_config->zoom_region.origin.x +
- dz_config->zoom_region.resolution.width;
- h = dz_config->zoom_region.origin.y +
- dz_config->zoom_region.resolution.height;
+ w = dz_config->zoom_region.left +
+ dz_config->zoom_region.width;
+ h = dz_config->zoom_region.top +
+ dz_config->zoom_region.height;
if ((w <= config.width) && (h <= config.height) && w > 0 && h > 0)
flag = true;
@@ -1912,10 +1914,10 @@ static bool atomisp_check_zoom_region(
/* setting error zoom region */
dev_err(asd->isp->dev,
"%s zoom region ERROR:dz_config:(%d,%d),(%d,%d)array_res(%d, %d)\n",
- __func__, dz_config->zoom_region.origin.x,
- dz_config->zoom_region.origin.y,
- dz_config->zoom_region.resolution.width,
- dz_config->zoom_region.resolution.height,
+ __func__, dz_config->zoom_region.left,
+ dz_config->zoom_region.top,
+ dz_config->zoom_region.width,
+ dz_config->zoom_region.height,
config.width, config.height);
return flag;
diff --git a/drivers/staging/media/atomisp/pci/ia_css_types.h b/drivers/staging/media/atomisp/pci/ia_css_types.h
index 676d7e20b..5c21a5415 100644
--- a/drivers/staging/media/atomisp/pci/ia_css_types.h
+++ b/drivers/staging/media/atomisp/pci/ia_css_types.h
@@ -431,8 +431,10 @@ struct ia_css_point {
* This specifies the region
*/
struct ia_css_region {
- struct ia_css_point origin; /** Starting point coordinates for the region */
- struct ia_css_resolution resolution; /** Region resolution */
+ s32 left; /** Starting point coordinates for the region */
+ s32 top;
+ s32 width; /** Region resolution */
+ s32 height;
};
/**
diff --git a/drivers/staging/media/atomisp/pci/sh_css_params.c b/drivers/staging/media/atomisp/pci/sh_css_params.c
index 11d62313c..0435f20a7 100644
--- a/drivers/staging/media/atomisp/pci/sh_css_params.c
+++ b/drivers/staging/media/atomisp/pci/sh_css_params.c
@@ -658,9 +658,7 @@ static const struct ia_css_dz_config default_dz_config = {
HRT_GDC_N,
HRT_GDC_N,
{
- \
- {0, 0}, \
- {0, 0}, \
+ 0, 0, 0, 0
}
};
@@ -1210,8 +1208,8 @@ ia_css_process_zoom_and_motion(
}
assert(stage->stage_num < SH_CSS_MAX_STAGES);
- if (params->dz_config.zoom_region.resolution.width == 0 &&
- params->dz_config.zoom_region.resolution.height == 0) {
+ if (params->dz_config.zoom_region.width == 0 &&
+ params->dz_config.zoom_region.height == 0) {
sh_css_update_uds_and_crop_info(
&info->sp,
&binary->in_frame_info,
@@ -4096,10 +4094,10 @@ sh_css_update_uds_and_crop_info_based_on_zoom_region(
assert(motion_vector);
assert(uds);
assert(sp_out_crop_pos);
- x0 = zoom->zoom_region.origin.x;
- y0 = zoom->zoom_region.origin.y;
- x1 = zoom->zoom_region.resolution.width + x0;
- y1 = zoom->zoom_region.resolution.height + y0;
+ x0 = zoom->zoom_region.left;
+ y0 = zoom->zoom_region.top;
+ x1 = zoom->zoom_region.width + x0;
+ y1 = zoom->zoom_region.height + y0;
if ((x0 > x1) || (y0 > y1) || (x1 > pipe_in_res.width) || (y1 > pipe_in_res.height))
return -EINVAL;
--
2.43.0
Powered by blists - more mailing lists