From patchwork Fri Apr 26 19:51:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 55906 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hK6tg-0003j3-KL; Fri, 26 Apr 2019 19:52:36 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726933AbfDZTwf (ORCPT + 1 other); Fri, 26 Apr 2019 15:52:35 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:40740 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726890AbfDZTwf (ORCPT ); Fri, 26 Apr 2019 15:52:35 -0400 Received: from localhost.localdomain (unknown [IPv6:2804:431:9718:9080:61b7:f4a4:2020:fc95]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: tonyk) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id DECD7272EC0; Fri, 26 Apr 2019 20:52:29 +0100 (BST) From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: linux-media@vger.kernel.org Cc: mchehab@kernel.org, hverkuil@xs4all.nl, helen.koike@collabora.com, kernel@collabora.com, lucmaga@gmail.com, lkcamp@lists.libreplanetbr.org, =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v5 11/14] media: vimc: sen: Add support for multiplanar formats Date: Fri, 26 Apr 2019 16:51:11 -0300 Message-Id: <20190426195114.5002-12-andrealmeid@collabora.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190426195114.5002-1-andrealmeid@collabora.com> References: <20190426195114.5002-1-andrealmeid@collabora.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org This commit adapts vimc-sensor to handle multiplanar pixel formats, adapting the memory allocation and TPG configuration. Signed-off-by: André Almeida Acked-by: Helen Koike --- Change in v5: none Changes in v4: - Correct `unsigned int ret` to `int ret` - Remove label `free_planes` from else scope Changes in v3: - Adapt to new vimc_frame Changes in v2: - Fix alignment issues - Remove unnecessary variable assignment - Reuse and share the code to free the memory of planes with a goto drivers/media/platform/vimc/vimc-sensor.c | 53 +++++++++++++---------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/drivers/media/platform/vimc/vimc-sensor.c b/drivers/media/platform/vimc/vimc-sensor.c index 3495a3f3dd60..5432fb852137 100644 --- a/drivers/media/platform/vimc/vimc-sensor.c +++ b/drivers/media/platform/vimc/vimc-sensor.c @@ -97,16 +97,17 @@ static int vimc_sen_get_fmt(struct v4l2_subdev *sd, static void vimc_sen_tpg_s_format(struct vimc_sen_device *vsen) { u32 pixelformat = vsen->ved.stream->producer_pixfmt; - const struct v4l2_format_info *pix_info; - - pix_info = v4l2_format_info(pixelformat); + unsigned int i; tpg_reset_source(&vsen->tpg, vsen->mbus_format.width, vsen->mbus_format.height, vsen->mbus_format.field); - tpg_s_bytesperline(&vsen->tpg, 0, - vsen->mbus_format.width * pix_info->bpp[0]); tpg_s_buf_height(&vsen->tpg, vsen->mbus_format.height); tpg_s_fourcc(&vsen->tpg, pixelformat); + + for (i = 0; i < tpg_g_planes(&vsen->tpg); i++) + tpg_s_bytesperline(&vsen->tpg, i, + vsen->frame.fmt.plane_fmt[i].bytesperline); + /* TODO: add support for V4L2_FIELD_ALTERNATE */ tpg_s_field(&vsen->tpg, vsen->mbus_format.field, false); tpg_s_colorspace(&vsen->tpg, vsen->mbus_format.colorspace); @@ -182,8 +183,12 @@ static struct vimc_frame *vimc_sen_process_frame(struct vimc_ent_device *ved, { struct vimc_sen_device *vsen = container_of(ved, struct vimc_sen_device, ved); + unsigned int i; + + for (i = 0; i < tpg_g_planes(&vsen->tpg); i++) + tpg_fill_plane_buffer(&vsen->tpg, 0, i, + vsen->frame.plane_addr[i]); - tpg_fill_plane_buffer(&vsen->tpg, 0, 0, vsen->frame.plane_addr[0]); return &vsen->frame; } @@ -191,36 +196,40 @@ static int vimc_sen_s_stream(struct v4l2_subdev *sd, int enable) { struct vimc_sen_device *vsen = container_of(sd, struct vimc_sen_device, sd); + unsigned int i; + int ret = 0; if (enable) { - u32 pixelformat = vsen->ved.stream->producer_pixfmt; - const struct v4l2_format_info *pix_info; - unsigned int frame_size; - /* Calculate the frame size */ - pix_info = v4l2_format_info(pixelformat); - frame_size = vsen->mbus_format.width * pix_info->bpp[0] * - vsen->mbus_format.height; - + vimc_fill_frame(&vsen->frame, vsen->ved.stream->producer_pixfmt, + vsen->mbus_format.width, + vsen->mbus_format.height); /* * Allocate the frame buffer. Use vmalloc to be able to * allocate a large amount of memory */ - vsen->frame.plane_addr[0] = vmalloc(frame_size); - if (!vsen->frame.plane_addr[0]) - return -ENOMEM; + for (i = 0; i < vsen->frame.fmt.num_planes; i++) { + vsen->frame.plane_addr[i] = + vmalloc(vsen->frame.fmt.plane_fmt[i].sizeimage); + if (!vsen->frame.plane_addr[i]) { + ret = -ENOMEM; + goto free_planes; + } + } /* configure the test pattern generator */ vimc_sen_tpg_s_format(vsen); - } else { - - vfree(vsen->frame.plane_addr[0]); - vsen->frame.plane_addr[0] = NULL; return 0; } - return 0; +free_planes: + for (i = 0; i < vsen->frame.fmt.num_planes; i++) { + vfree(vsen->frame.plane_addr[i]); + vsen->frame.plane_addr[i] = NULL; + } + + return ret; } static const struct v4l2_subdev_core_ops vimc_sen_core_ops = {