From patchwork Fri Apr 26 08:05:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lad, Prabhakar" X-Patchwork-Id: 2491291 Return-Path: X-Original-To: patchwork-davinci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from arroyo.ext.ti.com (arroyo.ext.ti.com [192.94.94.40]) by patchwork1.kernel.org (Postfix) with ESMTP id 3E6123FC64 for ; Fri, 26 Apr 2013 08:08:43 +0000 (UTC) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id r3Q85rIT016416; Fri, 26 Apr 2013 03:05:53 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id r3Q85rN2009723; Fri, 26 Apr 2013 03:05:53 -0500 Received: from dlelxv24.itg.ti.com (172.17.1.199) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.2.342.3; Fri, 26 Apr 2013 03:05:53 -0500 Received: from linux.omap.com (dlelxs01.itg.ti.com [157.170.227.31]) by dlelxv24.itg.ti.com (8.13.8/8.13.8) with ESMTP id r3Q85qnc032345; Fri, 26 Apr 2013 03:05:52 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id B148880627; Fri, 26 Apr 2013 03:05:51 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflp53.itg.ti.com (dflp53.itg.ti.com [128.247.5.6]) by linux.omap.com (Postfix) with ESMTP id 3C70580626 for ; Fri, 26 Apr 2013 03:05:50 -0500 (CDT) Received: from white.ext.ti.com (white.ext.ti.com [192.94.93.38]) by dflp53.itg.ti.com (8.13.8/8.13.8) with ESMTP id r3Q85oBF022641 for ; Fri, 26 Apr 2013 03:05:50 -0500 (CDT) Received: from mail6.bemta12.messagelabs.com (mail6.bemta12.messagelabs.com [216.82.250.247]) by white.ext.ti.com (8.13.7/8.13.7) with ESMTP id r3Q85nl6030274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 26 Apr 2013 03:05:49 -0500 Received: from [216.82.250.99:35653] by server-1.bemta-12.messagelabs.com id E5/89-14796-D553A715; Fri, 26 Apr 2013 08:05:49 +0000 X-Env-Sender: prabhakar.csengg@gmail.com X-Msg-Ref: server-16.tower-126.messagelabs.com!1366963546!10519483!1 X-Originating-IP: [209.85.220.51] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG, ML_RADAR_SPEW_LINKS_14,spamassassin: X-StarScan-Received: X-StarScan-Version: 6.8.6.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 2523 invoked from network); 26 Apr 2013 08:05:47 -0000 Received: from mail-pa0-f51.google.com (HELO mail-pa0-f51.google.com) (209.85.220.51) by server-16.tower-126.messagelabs.com with RC4-SHA encrypted SMTP; 26 Apr 2013 08:05:47 -0000 Received: by mail-pa0-f51.google.com with SMTP id jh10so2357717pab.38 for ; Fri, 26 Apr 2013 01:05:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=pM+p1kxgAIysQXcg5edr5HO8rdpVxIWd8sAspHVnz88=; b=tkE49aquaKN7hkbPg3Vq4e/aQxvNRaExRjSxFw5k3e3SpLEGFWmWvMBLI7mqZ4AHOK wZSHgdcKHN8oSXDVNQndJi7KJctuBvyYfSwbScRfxyVJzu+3RKda5h+kxZISel/P4Fh+ 7+tDljp/2yKkXtJSd30r+DM1Cc5yF+3zt9JJkybLuK3v1I7XyW3hteyfu3ntsyKlS7O1 vgfFivsW8j3QX1Q1djOUqHVdzkwNPa4DWIOSVUCAD6SY9NYYcGREGLitshSJRDE90yEJ LDJr1HGukA588+tKrithPr1/XJvBNNN3V1B16NJWX8izYMHZT85G/MgE4sk20wAQLbsc I1oA== X-Received: by 10.68.96.100 with SMTP id dr4mr57106427pbb.172.1366963546715; Fri, 26 Apr 2013 01:05:46 -0700 (PDT) Received: from localhost.localdomain ([59.98.242.2]) by mx.google.com with ESMTPSA id wl5sm11705904pac.18.2013.04.26.01.05.41 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 26 Apr 2013 01:05:45 -0700 (PDT) From: Prabhakar Lad To: LMML Subject: [PATCH] media: i2c: tvp7002: enable TVP7002 decoder for media controller based usage Date: Fri, 26 Apr 2013 13:35:35 +0530 Message-ID: <1366963535-15963-1-git-send-email-prabhakar.csengg@gmail.com> X-Mailer: git-send-email 1.7.4.1 CC: DLOS , Mauro Carvalho Chehab , LKML , Hans Verkuil , Laurent Pinchart , Guennadi Liakhovetski X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com From: Lad, Prabhakar This patch enables tvp7002 decoder driver for media controller based usage by adding v4l2_subdev_pad_ops operations support for enum_mbus_code, set_pad_format, get_pad_format and media_entity_init() on probe and media_entity_cleanup() on remove. The device supports 1 output pad and no input pads. Signed-off-by: Lad, Prabhakar --- drivers/media/i2c/tvp7002.c | 125 +++++++++++++++++++++++++++++++++++++++++-- include/media/tvp7002.h | 2 + 2 files changed, 122 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c index 027809c..b212d41 100644 --- a/drivers/media/i2c/tvp7002.c +++ b/drivers/media/i2c/tvp7002.c @@ -424,6 +424,8 @@ struct tvp7002 { int streaming; const struct tvp7002_timings_definition *current_timings; + struct media_pad pad; + struct v4l2_mbus_framefmt format; }; /* @@ -880,6 +882,93 @@ static const struct v4l2_ctrl_ops tvp7002_ctrl_ops = { .s_ctrl = tvp7002_s_ctrl, }; +/* + * tvp7002_enum_mbus_code() - Enum supported digital video format on pad + * @sd: pointer to standard V4L2 sub-device structure + * @fh: file handle for the subdev + * @code: pointer to subdev enum mbus code struct + * + * Enumerate supported digital video formats for pad. + */ +static int +tvp7002_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, + struct v4l2_subdev_mbus_code_enum *code) +{ + /* Check pad index is valid */ + if (code->pad != 0) + return -EINVAL; + + /* Check requested format index is within range */ + if (code->index != 0) + return -EINVAL; + + code->code = V4L2_MBUS_FMT_YUYV10_1X20; + + return 0; +} + +/* + * tvp7002_set_pad_format() - set video format on pad + * @sd: pointer to standard V4L2 sub-device structure + * @fh: file handle for the subdev + * @fmt: pointer to subdev format struct + * + * set video format for pad. +*/ +static int +tvp7002_set_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, + struct v4l2_subdev_format *fmt) +{ + struct tvp7002 *tvp7002 = to_tvp7002(sd); + + /* Check pad index is valid */ + if (fmt->pad != 0) + return -EINVAL; + + if (fmt->format.field != tvp7002->current_timings->scanmode || + fmt->format.code != V4L2_MBUS_FMT_YUYV10_1X20 || + fmt->format.colorspace != tvp7002->current_timings->color_space || + fmt->format.width != tvp7002->current_timings->timings.bt.width || + fmt->format.height != tvp7002->current_timings->timings.bt.height) + return -EINVAL; + + tvp7002->format = fmt->format; + + return 0; +} + +/* + * tvp7002_get_pad_format() - get video format on pad + * @sd: pointer to standard V4L2 sub-device structure + * @fh: file handle for the subdev + * @fmt: pointer to subdev format struct + * + * get video format for pad. + */ +static int +tvp7002_get_pad_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, + struct v4l2_subdev_format *fmt) +{ + struct tvp7002 *tvp7002 = to_tvp7002(sd); + + /* Check pad index is valid */ + if (fmt->pad != 0) + return -EINVAL; + + if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { + fmt->format = tvp7002->format; + return 0; + } + + fmt->format.code = V4L2_MBUS_FMT_YUYV10_1X20; + fmt->format.width = tvp7002->current_timings->timings.bt.width; + fmt->format.height = tvp7002->current_timings->timings.bt.height; + fmt->format.field = tvp7002->current_timings->scanmode; + fmt->format.colorspace = tvp7002->current_timings->color_space; + + return 0; +} + /* V4L2 core operation handlers */ static const struct v4l2_subdev_core_ops tvp7002_core_ops = { .g_chip_ident = tvp7002_g_chip_ident, @@ -910,10 +999,18 @@ static const struct v4l2_subdev_video_ops tvp7002_video_ops = { .enum_mbus_fmt = tvp7002_enum_mbus_fmt, }; +/* media pad related operation handlers */ +static const struct v4l2_subdev_pad_ops tvp7002_pad_ops = { + .enum_mbus_code = tvp7002_enum_mbus_code, + .get_fmt = tvp7002_get_pad_format, + .set_fmt = tvp7002_set_pad_format, +}; + /* V4L2 top level operation handlers */ static const struct v4l2_subdev_ops tvp7002_ops = { .core = &tvp7002_core_ops, .video = &tvp7002_video_ops, + .pad = &tvp7002_pad_ops, }; /* @@ -993,19 +1090,35 @@ static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id) timings = device->current_timings->timings; error = tvp7002_s_dv_timings(sd, &timings); +#if defined(CONFIG_MEDIA_CONTROLLER) + strlcpy(sd->name, TVP7002_MODULE_NAME, sizeof(sd->name)); + device->pad.flags = MEDIA_PAD_FL_SOURCE; + device->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + device->sd.entity.flags |= MEDIA_ENT_T_V4L2_SUBDEV_DECODER; + + error = media_entity_init(&device->sd.entity, 1, &device->pad, 0); + if (error < 0) + return error; +#endif + v4l2_ctrl_handler_init(&device->hdl, 1); v4l2_ctrl_new_std(&device->hdl, &tvp7002_ctrl_ops, V4L2_CID_GAIN, 0, 255, 1, 0); sd->ctrl_handler = &device->hdl; if (device->hdl.error) { - int err = device->hdl.error; - - v4l2_ctrl_handler_free(&device->hdl); - return err; + error = device->hdl.error; + goto done; } v4l2_ctrl_handler_setup(&device->hdl); return 0; + +done: + v4l2_ctrl_handler_free(&device->hdl); +#if defined(CONFIG_MEDIA_CONTROLLER) + media_entity_cleanup(&device->sd.entity); +#endif + return error; } /* @@ -1022,7 +1135,9 @@ static int tvp7002_remove(struct i2c_client *c) v4l2_dbg(1, debug, sd, "Removing tvp7002 adapter" "on address 0x%x\n", c->addr); - +#if defined(CONFIG_MEDIA_CONTROLLER) + media_entity_cleanup(&device->sd.entity); +#endif v4l2_device_unregister_subdev(sd); v4l2_ctrl_handler_free(&device->hdl); return 0; diff --git a/include/media/tvp7002.h b/include/media/tvp7002.h index ee43534..7123048 100644 --- a/include/media/tvp7002.h +++ b/include/media/tvp7002.h @@ -26,6 +26,8 @@ #ifndef _TVP7002_H_ #define _TVP7002_H_ +#define TVP7002_MODULE_NAME "tvp7002" + /* Platform-dependent data * * clk_polarity: