From patchwork Thu Jun 28 16:20:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 10494395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 401BB60230 for ; Thu, 28 Jun 2018 16:21:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D22502A43A for ; Thu, 28 Jun 2018 16:21:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C64652A4BA; Thu, 28 Jun 2018 16:21:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47CE32A43A for ; Thu, 28 Jun 2018 16:21:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752691AbeF1QVX (ORCPT ); Thu, 28 Jun 2018 12:21:23 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:43923 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751757AbeF1QVW (ORCPT ); Thu, 28 Jun 2018 12:21:22 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fYZfV-0004p5-Dq; Thu, 28 Jun 2018 18:21:13 +0200 Received: from mfe by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1fYZfQ-0007FU-L2; Thu, 28 Jun 2018 18:21:08 +0200 From: Marco Felsch To: mchehab@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: p.zabel@pengutronix.de, afshin.nasser@gmail.com, javierm@redhat.com, sakari.ailus@linux.intel.com, laurent.pinchart@ideasonboard.com, linux-media@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH 07/22] [media] tvp5150: add default format helper Date: Thu, 28 Jun 2018 18:20:39 +0200 Message-Id: <20180628162054.25613-8-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180628162054.25613-1-m.felsch@pengutronix.de> References: <20180628162054.25613-1-m.felsch@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mfe@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-media@vger.kernel.org Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The patch adds three macros to bundle the mbus_framefmt default values and a helper function to set the the default crop and mbus_framefmt values. Signed-off-by: Marco Felsch --- drivers/media/i2c/tvp5150.c | 42 ++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/drivers/media/i2c/tvp5150.c b/drivers/media/i2c/tvp5150.c index 29eaf8166f25..c73536cfcc62 100644 --- a/drivers/media/i2c/tvp5150.c +++ b/drivers/media/i2c/tvp5150.c @@ -28,6 +28,9 @@ #define TVP5150_MAX_CROP_LEFT 511 #define TVP5150_MAX_CROP_TOP 127 #define TVP5150_CROP_SHIFT 2 +#define TVP5150_MBUS_FMT MEDIA_BUS_FMT_UYVY8_2X8 +#define TVP5150_FIELD V4L2_FIELD_ALTERNATE +#define TVP5150_COLORSPACE V4L2_COLORSPACE_SMPTE170M MODULE_DESCRIPTION("Texas Instruments TVP5150A/TVP5150AM1/TVP5151 video decoder driver"); MODULE_AUTHOR("Mauro Carvalho Chehab"); @@ -847,6 +850,18 @@ static v4l2_std_id tvp5150_read_std(struct v4l2_subdev *sd) } } +static void tvp5150_set_default(v4l2_std_id std, struct v4l2_rect *crop) +{ + /* Default is no cropping */ + crop->top = 0; + crop->left = 0; + crop->width = TVP5150_H_MAX; + if (std & V4L2_STD_525_60) + crop->height = TVP5150_V_MAX_525_60; + else + crop->height = TVP5150_V_MAX_OTHERS; +} + static struct v4l2_rect * __tvp5150_get_pad_crop(struct tvp5150 *decoder, struct v4l2_subdev_pad_config *cfg, unsigned int pad, @@ -863,8 +878,8 @@ __tvp5150_get_pad_crop(struct tvp5150 *decoder, } static int tvp5150_fill_fmt(struct v4l2_subdev *sd, - struct v4l2_subdev_pad_config *cfg, - struct v4l2_subdev_format *format) + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *format) { struct v4l2_mbus_framefmt *f; struct v4l2_rect *__crop; @@ -880,12 +895,12 @@ static int tvp5150_fill_fmt(struct v4l2_subdev *sd, f->width = __crop->width; f->height = __crop->height / 2; - f->code = MEDIA_BUS_FMT_UYVY8_2X8; - f->field = V4L2_FIELD_ALTERNATE; - f->colorspace = V4L2_COLORSPACE_SMPTE170M; + f->code = TVP5150_MBUS_FMT; + f->field = TVP5150_FIELD; + f->colorspace = TVP5150_COLORSPACE; dev_dbg_lvl(sd->dev, 1, debug, "width = %d, height = %d\n", f->width, - f->height); + f->height); return 0; } @@ -1026,7 +1041,7 @@ static int tvp5150_enum_mbus_code(struct v4l2_subdev *sd, if (code->pad || code->index) return -EINVAL; - code->code = MEDIA_BUS_FMT_UYVY8_2X8; + code->code = TVP5150_MBUS_FMT; return 0; } @@ -1036,10 +1051,10 @@ static int tvp5150_enum_frame_size(struct v4l2_subdev *sd, { struct tvp5150 *decoder = to_tvp5150(sd); - if (fse->index >= 8 || fse->code != MEDIA_BUS_FMT_UYVY8_2X8) + if (fse->index >= 8 || fse->code != TVP5150_MBUS_FMT) return -EINVAL; - fse->code = MEDIA_BUS_FMT_UYVY8_2X8; + fse->code = TVP5150_MBUS_FMT; fse->min_width = decoder->rect.width; fse->max_width = decoder->rect.width; fse->min_height = decoder->rect.height / 2; @@ -1650,14 +1665,7 @@ static int tvp5150_probe(struct i2c_client *c, goto err; } - /* Default is no cropping */ - core->rect.top = 0; - if (tvp5150_read_std(sd) & V4L2_STD_525_60) - core->rect.height = TVP5150_V_MAX_525_60; - else - core->rect.height = TVP5150_V_MAX_OTHERS; - core->rect.left = 0; - core->rect.width = TVP5150_H_MAX; + tvp5150_set_default(tvp5150_read_std(sd), &core->rect); tvp5150_reset(sd, 0); /* Calls v4l2_ctrl_handler_setup() */