From patchwork Thu Mar 24 23:27:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8665951 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-renesas-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2D850C0553 for ; Thu, 24 Mar 2016 23:28:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 40D0F20166 for ; Thu, 24 Mar 2016 23:28:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 400C7202B8 for ; Thu, 24 Mar 2016 23:28:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752209AbcCXX2d (ORCPT ); Thu, 24 Mar 2016 19:28:33 -0400 Received: from galahad.ideasonboard.com ([185.26.127.97]:40281 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752087AbcCXX2a (ORCPT ); Thu, 24 Mar 2016 19:28:30 -0400 Received: from avalon.bb.dnainternet.fi (85-23-193-79.bb.dnainternet.fi [85.23.193.79]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id 705CF20096; Fri, 25 Mar 2016 00:27:23 +0100 (CET) From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org Subject: [PATCH 43/51] v4l: vsp1: Factorize media bus codes enumeration code Date: Fri, 25 Mar 2016 01:27:39 +0200 Message-Id: <1458862067-19525-44-git-send-email-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1458862067-19525-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> References: <1458862067-19525-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Most of the entities can't perform format conversion and implement the same media bus enumeration function. Factorize the code into a single implementation. Signed-off-by: Laurent Pinchart --- drivers/media/platform/vsp1/vsp1_bru.c | 26 ++--------------- drivers/media/platform/vsp1/vsp1_entity.c | 46 +++++++++++++++++++++++++++++++ drivers/media/platform/vsp1/vsp1_entity.h | 4 +++ drivers/media/platform/vsp1/vsp1_lif.c | 29 ++----------------- drivers/media/platform/vsp1/vsp1_lut.c | 29 ++----------------- drivers/media/platform/vsp1/vsp1_sru.c | 29 ++----------------- drivers/media/platform/vsp1/vsp1_uds.c | 29 ++----------------- 7 files changed, 60 insertions(+), 132 deletions(-) diff --git a/drivers/media/platform/vsp1/vsp1_bru.c b/drivers/media/platform/vsp1/vsp1_bru.c index fa293ee2829d..835593dd88b3 100644 --- a/drivers/media/platform/vsp1/vsp1_bru.c +++ b/drivers/media/platform/vsp1/vsp1_bru.c @@ -76,31 +76,9 @@ static int bru_enum_mbus_code(struct v4l2_subdev *subdev, MEDIA_BUS_FMT_ARGB8888_1X32, MEDIA_BUS_FMT_AYUV8_1X32, }; - struct vsp1_bru *bru = to_bru(subdev); - - if (code->pad == BRU_PAD_SINK(0)) { - if (code->index >= ARRAY_SIZE(codes)) - return -EINVAL; - - code->code = codes[code->index]; - } else { - struct v4l2_subdev_pad_config *config; - struct v4l2_mbus_framefmt *format; - if (code->index) - return -EINVAL; - - config = vsp1_entity_get_pad_config(&bru->entity, cfg, - code->which); - if (!config) - return -EINVAL; - - format = vsp1_entity_get_pad_format(&bru->entity, config, - BRU_PAD_SINK(0)); - code->code = format->code; - } - - return 0; + return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, + ARRAY_SIZE(codes)); } static int bru_enum_frame_size(struct v4l2_subdev *subdev, diff --git a/drivers/media/platform/vsp1/vsp1_entity.c b/drivers/media/platform/vsp1/vsp1_entity.c index 5030974f3083..b347442bc662 100644 --- a/drivers/media/platform/vsp1/vsp1_entity.c +++ b/drivers/media/platform/vsp1/vsp1_entity.c @@ -141,6 +141,52 @@ int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev, return 0; } +/* + * vsp1_subdev_enum_mbus_code - Subdev pad enum_mbus_code handler + * @subdev: V4L2 subdevice + * @cfg: V4L2 subdev pad configuration + * @code: Media bus code enumeration + * @codes: Array of supported media bus codes + * @ncodes: Number of supported media bus codes + * + * This function implements the subdev enum_mbus_code pad operation for entities + * that do not support format conversion. It enumerates the given supported + * media bus codes on the sink pad and reports a source pad format identical to + * the sink pad. + */ +int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_mbus_code_enum *code, + const unsigned int *codes, unsigned int ncodes) +{ + struct vsp1_entity *entity = to_vsp1_entity(subdev); + + if (code->pad == 0) { + if (code->index >= ncodes) + return -EINVAL; + + code->code = codes[code->index]; + } else { + struct v4l2_subdev_pad_config *config; + struct v4l2_mbus_framefmt *format; + + /* The entity can't perform format conversion, the sink format + * is always identical to the source format. + */ + if (code->index) + return -EINVAL; + + config = vsp1_entity_get_pad_config(entity, cfg, code->which); + if (!config) + return -EINVAL; + + format = vsp1_entity_get_pad_format(entity, config, 0); + code->code = format->code; + } + + return 0; +} + /* ----------------------------------------------------------------------------- * Media Operations */ diff --git a/drivers/media/platform/vsp1/vsp1_entity.h b/drivers/media/platform/vsp1/vsp1_entity.h index 7845e931138f..fbde42256522 100644 --- a/drivers/media/platform/vsp1/vsp1_entity.h +++ b/drivers/media/platform/vsp1/vsp1_entity.h @@ -130,5 +130,9 @@ void vsp1_entity_route_setup(struct vsp1_entity *source, int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_format *fmt); +int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_mbus_code_enum *code, + const unsigned int *codes, unsigned int ncodes); #endif /* __VSP1_ENTITY_H__ */ diff --git a/drivers/media/platform/vsp1/vsp1_lif.c b/drivers/media/platform/vsp1/vsp1_lif.c index db698e7d4884..ded4c5a87d4c 100644 --- a/drivers/media/platform/vsp1/vsp1_lif.c +++ b/drivers/media/platform/vsp1/vsp1_lif.c @@ -45,34 +45,9 @@ static int lif_enum_mbus_code(struct v4l2_subdev *subdev, MEDIA_BUS_FMT_ARGB8888_1X32, MEDIA_BUS_FMT_AYUV8_1X32, }; - struct vsp1_lif *lif = to_lif(subdev); - - if (code->pad == LIF_PAD_SINK) { - if (code->index >= ARRAY_SIZE(codes)) - return -EINVAL; - - code->code = codes[code->index]; - } else { - struct v4l2_subdev_pad_config *config; - struct v4l2_mbus_framefmt *format; - - /* The LIF can't perform format conversion, the sink format is - * always identical to the source format. - */ - if (code->index) - return -EINVAL; - - config = vsp1_entity_get_pad_config(&lif->entity, cfg, - code->which); - if (!config) - return -EINVAL; - format = vsp1_entity_get_pad_format(&lif->entity, config, - LIF_PAD_SINK); - code->code = format->code; - } - - return 0; + return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, + ARRAY_SIZE(codes)); } static int lif_enum_frame_size(struct v4l2_subdev *subdev, diff --git a/drivers/media/platform/vsp1/vsp1_lut.c b/drivers/media/platform/vsp1/vsp1_lut.c index 6a0f10f71dda..781ea99abccf 100644 --- a/drivers/media/platform/vsp1/vsp1_lut.c +++ b/drivers/media/platform/vsp1/vsp1_lut.c @@ -71,34 +71,9 @@ static int lut_enum_mbus_code(struct v4l2_subdev *subdev, MEDIA_BUS_FMT_AHSV8888_1X32, MEDIA_BUS_FMT_AYUV8_1X32, }; - struct vsp1_lut *lut = to_lut(subdev); - - if (code->pad == LUT_PAD_SINK) { - if (code->index >= ARRAY_SIZE(codes)) - return -EINVAL; - - code->code = codes[code->index]; - } else { - struct v4l2_subdev_pad_config *config; - struct v4l2_mbus_framefmt *format; - - /* The LUT can't perform format conversion, the sink format is - * always identical to the source format. - */ - if (code->index) - return -EINVAL; - - config = vsp1_entity_get_pad_config(&lut->entity, cfg, - code->which); - if (!config) - return -EINVAL; - format = vsp1_entity_get_pad_format(&lut->entity, config, - LUT_PAD_SINK); - code->code = format->code; - } - - return 0; + return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, + ARRAY_SIZE(codes)); } static int lut_enum_frame_size(struct v4l2_subdev *subdev, diff --git a/drivers/media/platform/vsp1/vsp1_sru.c b/drivers/media/platform/vsp1/vsp1_sru.c index 38fb4e1e8bae..9dc7c77c74f8 100644 --- a/drivers/media/platform/vsp1/vsp1_sru.c +++ b/drivers/media/platform/vsp1/vsp1_sru.c @@ -116,34 +116,9 @@ static int sru_enum_mbus_code(struct v4l2_subdev *subdev, MEDIA_BUS_FMT_ARGB8888_1X32, MEDIA_BUS_FMT_AYUV8_1X32, }; - struct vsp1_sru *sru = to_sru(subdev); - - if (code->pad == SRU_PAD_SINK) { - if (code->index >= ARRAY_SIZE(codes)) - return -EINVAL; - - code->code = codes[code->index]; - } else { - struct v4l2_subdev_pad_config *config; - struct v4l2_mbus_framefmt *format; - - /* The SRU can't perform format conversion, the sink format is - * always identical to the source format. - */ - if (code->index) - return -EINVAL; - config = vsp1_entity_get_pad_config(&sru->entity, cfg, - code->which); - if (!config) - return -EINVAL; - - format = vsp1_entity_get_pad_format(&sru->entity, config, - SRU_PAD_SINK); - code->code = format->code; - } - - return 0; + return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, + ARRAY_SIZE(codes)); } static int sru_enum_frame_size(struct v4l2_subdev *subdev, diff --git a/drivers/media/platform/vsp1/vsp1_uds.c b/drivers/media/platform/vsp1/vsp1_uds.c index 59432c7c29b9..26f7393d278e 100644 --- a/drivers/media/platform/vsp1/vsp1_uds.c +++ b/drivers/media/platform/vsp1/vsp1_uds.c @@ -119,34 +119,9 @@ static int uds_enum_mbus_code(struct v4l2_subdev *subdev, MEDIA_BUS_FMT_ARGB8888_1X32, MEDIA_BUS_FMT_AYUV8_1X32, }; - struct vsp1_uds *uds = to_uds(subdev); - - if (code->pad == UDS_PAD_SINK) { - if (code->index >= ARRAY_SIZE(codes)) - return -EINVAL; - - code->code = codes[code->index]; - } else { - struct v4l2_subdev_pad_config *config; - struct v4l2_mbus_framefmt *format; - - config = vsp1_entity_get_pad_config(&uds->entity, cfg, - code->which); - if (!config) - return -EINVAL; - - /* The UDS can't perform format conversion, the sink format is - * always identical to the source format. - */ - if (code->index) - return -EINVAL; - format = vsp1_entity_get_pad_format(&uds->entity, config, - UDS_PAD_SINK); - code->code = format->code; - } - - return 0; + return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes, + ARRAY_SIZE(codes)); } static int uds_enum_frame_size(struct v4l2_subdev *subdev,