summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2023-05-29 11:37:40 +0100
committerMauro Carvalho Chehab <mchehab@kernel.org>2023-06-09 15:39:40 +0100
commite980fb04e779730b799a4ba712db901a7b08e8f9 (patch)
tree65cf2ac780bb89593e2faaa19b994fe247f21385
parent1e28b9e048b5edd29c7bf9c8ce6d9d5dcda6f36b (diff)
downloadlinux-stable-e980fb04e779730b799a4ba712db901a7b08e8f9.tar.gz
linux-stable-e980fb04e779730b799a4ba712db901a7b08e8f9.tar.bz2
linux-stable-e980fb04e779730b799a4ba712db901a7b08e8f9.zip
media: atomisp: Add enum_framesizes function for sensors with selection / crop support
Some sensor drivers with crop support (e.g. the ov5693 driver) only return the current crop rectangle + 1/2 (binning) of the current crop rectangle when calling their enum_frame_sizes op. This causes 2 issues: 1. Atomisp sets to the crop area to include the padding, where as the enum_framesizes ioctl should return values without padding. 2. With cropping a lot more standard resolutions are possible then just these 2 and many apps limit the list given to the end user to the list returned by enum_framesizes. Add an alternative enum_framesizes function for sensors which support cropping to fix both issues. Link: https://lore.kernel.org/r/20230529103741.11904-21-hdegoede@redhat.com Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
-rw-r--r--drivers/staging/media/atomisp/TODO3
-rw-r--r--drivers/staging/media/atomisp/pci/atomisp_ioctl.c69
2 files changed, 69 insertions, 3 deletions
diff --git a/drivers/staging/media/atomisp/TODO b/drivers/staging/media/atomisp/TODO
index 12fe1f21b169..b7a09eb20d0d 100644
--- a/drivers/staging/media/atomisp/TODO
+++ b/drivers/staging/media/atomisp/TODO
@@ -32,9 +32,6 @@ TODO
* The atomisp ov2680 and ov5693 sensor drivers bind to the same hw-ids as
the standard ov2680 and ov5693 drivers under drivers/media/i2c, which
conflicts. Drop the atomisp private ov2680 and ov5693 drivers:
- * Make atomisp code use v4l2 selections to deal with the extra padding
- it wants to receive from sensors instead of relying on the ov2680 code
- sending e.g. 1616x1216 for a 1600x1200 mode
* Port various ov2680 improvements from atomisp_ov2680.c to regular ov2680.c
and switch to regular ov2680 driver
* Make atomisp work with the regular ov5693 driver and drop atomisp_ov5693
diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
index c5465b28a65d..279493af6e0d 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c
@@ -697,6 +697,72 @@ static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
return 0;
}
+/*
+ * With crop any framesize <= sensor-size can be made, give
+ * userspace a list of sizes to choice from.
+ */
+static int atomisp_enum_framesizes_crop_inner(struct atomisp_device *isp,
+ struct v4l2_frmsizeenum *fsize,
+ struct v4l2_rect *active,
+ int *valid_sizes)
+{
+ static const struct v4l2_frmsize_discrete frame_sizes[] = {
+ { 1600, 1200 },
+ { 1600, 1080 },
+ { 1600, 900 },
+ { 1440, 1080 },
+ { 1280, 960 },
+ { 1280, 720 },
+ { 800, 600 },
+ { 640, 480 },
+ };
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(frame_sizes); i++) {
+ if (frame_sizes[i].width > active->width ||
+ frame_sizes[i].height > active->height)
+ continue;
+
+ /*
+ * Skip sizes where width and height are less then 2/3th of the
+ * sensor size to avoid sizes with a too small field of view.
+ */
+ if (frame_sizes[i].width < (active->width * 2 / 3) &&
+ frame_sizes[i].height < (active->height * 2 / 3))
+ continue;
+
+ if (*valid_sizes == fsize->index) {
+ fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
+ fsize->discrete = frame_sizes[i];
+ return 0;
+ }
+
+ (*valid_sizes)++;
+ }
+
+ return -EINVAL;
+}
+
+static int atomisp_enum_framesizes_crop(struct atomisp_device *isp,
+ struct v4l2_frmsizeenum *fsize)
+{
+ struct atomisp_input_subdev *input = &isp->inputs[isp->asd.input_curr];
+ struct v4l2_rect active = input->active_rect;
+ int ret, valid_sizes = 0;
+
+ ret = atomisp_enum_framesizes_crop_inner(isp, fsize, &active, &valid_sizes);
+ if (ret == 0)
+ return 0;
+
+ if (!input->binning_support)
+ return -EINVAL;
+
+ active.width /= 2;
+ active.height /= 2;
+
+ return atomisp_enum_framesizes_crop_inner(isp, fsize, &active, &valid_sizes);
+}
+
static int atomisp_enum_framesizes(struct file *file, void *priv,
struct v4l2_frmsizeenum *fsize)
{
@@ -711,6 +777,9 @@ static int atomisp_enum_framesizes(struct file *file, void *priv,
};
int ret;
+ if (input->crop_support)
+ return atomisp_enum_framesizes_crop(isp, fsize);
+
ret = v4l2_subdev_call(input->camera, pad, enum_frame_size, NULL, &fse);
if (ret)
return ret;