From patchwork Mon Oct 16 03:14:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou.Yang@microchip.com X-Patchwork-Id: 10007585 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 02399602B3 for ; Mon, 16 Oct 2017 03:19:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB2BB26538 for ; Mon, 16 Oct 2017 03:19:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF48C26E4E; Mon, 16 Oct 2017 03:19:15 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7225026538 for ; Mon, 16 Oct 2017 03:19:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NcH0Vr1+1Yz5yvkzaTvjFJ0G7xVQUW/OmGPf0ykT91c=; b=gZzzKnGv2Ja9qf 0+4/yJ1PpDqr5uR+6CTamwJ9N9TUkY7yHbB1pxEmm4ux5Qd6IE3Rpdz/1rva35EWZMVnIalLc/SCX xrUuF8FWsSq4jy2z/gGV1QHjxXNtSstnTxZd/YeN8B58mM/a0OZe9Sn6yHQROzEXnnZ7LaivP8BS9 /sBmb6zsYrI0WRkHvj+N7ZzMfGnE5H7xswAd63DPCRqvJd2E1FcHR76gNZR4gITuZSdpIlDUeEO6q /mFIShN3k0SnAvZ0390sZA3gYA0W5sdd8YZLPOXBjgBA5IUT/MYd8lAK058rK+9o23cZ5kZS/+DtN HC8Yx4M1KD+LgrzmAOeQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1e3vvX-0005k5-O0; Mon, 16 Oct 2017 03:18:52 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e3vvV-0005je-L6 for linux-arm-kernel@bombadil.infradead.org; Mon, 16 Oct 2017 03:18:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZVmocMANevuzGodNOy7VFx1/h3Lrv9mXMEaThmR0ffw=; b=NwtVz1tpxA6X8dxGPTo3N07cf x8N25xggevD0yTQKX/JVWYNy/7ctT9udlDWAtv2xHglOwBpr+AKmsqDjx8z6XtwQb/1ALg/tEgrax a2EDgBuGU6KFGRQAmxF9m57pawpTGlV33QGC7wnRrQNKO77d/u4uMywZwNwcTPjVOMdbgL2409VRI TKvZ62jumNbDxrPbTdaaThzv6AyFr63kLMLhAXm+RJFMng7f8cFhzgUOOMyPgFH6NE5YtsySZ6Oqm q8tnQrD45AO0jVVb1Pznrxmve5Ta6i3U9+1RjvpqjVKBtmOqMLni1fpRNq4gjAdPIHO48b/tv/aZT pzHD6n0JQ==; Received: from eusmtp01.atmel.com ([212.144.249.242]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e3vvR-00030n-Di for linux-arm-kernel@lists.infradead.org; Mon, 16 Oct 2017 03:18:48 +0000 Received: from apsmtp01.atmel.com (10.168.254.31) by eusmtp01.atmel.com (10.145.145.30) with Microsoft SMTP Server id 14.3.235.1; Mon, 16 Oct 2017 05:18:14 +0200 Received: from shaarm01.corp.atmel.com (10.168.254.13) by apsmtp01.atmel.com (10.168.254.31) with Microsoft SMTP Server id 14.3.235.1; Mon, 16 Oct 2017 11:23:40 +0800 From: Wenyou Yang To: Jonathan Corbet Subject: [PATCH v6 2/3] media: ov7670: Add the get_fmt callback Date: Mon, 16 Oct 2017 11:14:26 +0800 Message-ID: <20171016031427.4194-3-wenyou.yang@microchip.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20171016031427.4194-1-wenyou.yang@microchip.com> References: <20171016031427.4194-1-wenyou.yang@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171016_041845_520476_869D9340 X-CRM114-Status: GOOD ( 19.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wenyou Yang , linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Sakari Ailus , linux-arm-kernel@lists.infradead.org, Linux Media Mailing List Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add the get_fmt callback, also enable V4L2_SUBDEV_FL_HAS_DEVNODE flag to make this subdev has device node. Signed-off-by: Wenyou Yang --- Changes in v6: None Changes in v5: - Fix the build warning on the declaration *mbus_fmt(ISO C90 forbids mixed). Changes in v4: - Fix the build error when not enabling V4L2 sub-device userspace API option. Changes in v3: - Keep tried format info in the try_fmt member of v4l2_subdev__pad_config struct. - Add the internal_ops callback to set default format. Changes in v2: None drivers/media/i2c/ov7670.c | 77 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov7670.c b/drivers/media/i2c/ov7670.c index 553945d4ca28..73ceec63a8ca 100644 --- a/drivers/media/i2c/ov7670.c +++ b/drivers/media/i2c/ov7670.c @@ -232,6 +232,7 @@ struct ov7670_info { struct v4l2_ctrl *saturation; struct v4l2_ctrl *hue; }; + struct v4l2_mbus_framefmt format; struct ov7670_format_struct *fmt; /* Current format */ struct clk *clk; struct gpio_desc *resetb_gpio; @@ -975,6 +976,9 @@ static int ov7670_try_fmt_internal(struct v4l2_subdev *sd, fmt->width = wsize->width; fmt->height = wsize->height; fmt->colorspace = ov7670_formats[index].colorspace; + + info->format = *fmt; + return 0; } @@ -988,6 +992,9 @@ static int ov7670_set_fmt(struct v4l2_subdev *sd, struct ov7670_format_struct *ovfmt; struct ov7670_win_size *wsize; struct ov7670_info *info = to_state(sd); +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + struct v4l2_mbus_framefmt *mbus_fmt; +#endif unsigned char com7; int ret; @@ -998,8 +1005,13 @@ static int ov7670_set_fmt(struct v4l2_subdev *sd, ret = ov7670_try_fmt_internal(sd, &format->format, NULL, NULL); if (ret) return ret; - cfg->try_fmt = format->format; +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad); + *mbus_fmt = format->format; return 0; +#else + return -ENOTTY; +#endif } ret = ov7670_try_fmt_internal(sd, &format->format, &ovfmt, &wsize); @@ -1041,6 +1053,30 @@ static int ov7670_set_fmt(struct v4l2_subdev *sd, return 0; } +static int ov7670_get_fmt(struct v4l2_subdev *sd, + struct v4l2_subdev_pad_config *cfg, + struct v4l2_subdev_format *format) +{ + struct ov7670_info *info = to_state(sd); +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + struct v4l2_mbus_framefmt *mbus_fmt; +#endif + + if (format->which == V4L2_SUBDEV_FORMAT_TRY) { +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + mbus_fmt = v4l2_subdev_get_try_format(sd, cfg, 0); + format->format = *mbus_fmt; + return 0; +#else + return -ENOTTY; +#endif + } else { + format->format = info->format; + } + + return 0; +} + /* * Implement G/S_PARM. There is a "high quality" mode we could try * to do someday; for now, we just do the frame rate tweak. @@ -1508,6 +1544,30 @@ static int ov7670_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_regis } #endif +static void ov7670_get_default_format(struct v4l2_subdev *sd, + struct v4l2_mbus_framefmt *format) +{ + struct ov7670_info *info = to_state(sd); + + format->width = info->devtype->win_sizes[0].width; + format->height = info->devtype->win_sizes[0].height; + format->colorspace = info->fmt->colorspace; + format->code = info->fmt->mbus_code; + format->field = V4L2_FIELD_NONE; +} + +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API +static int ov7670_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +{ + struct v4l2_mbus_framefmt *format = + v4l2_subdev_get_try_format(sd, fh->pad, 0); + + ov7670_get_default_format(sd, format); + + return 0; +} +#endif + /* ----------------------------------------------------------------------- */ static const struct v4l2_subdev_core_ops ov7670_core_ops = { @@ -1528,6 +1588,7 @@ static const struct v4l2_subdev_pad_ops ov7670_pad_ops = { .enum_frame_interval = ov7670_enum_frame_interval, .enum_frame_size = ov7670_enum_frame_size, .enum_mbus_code = ov7670_enum_mbus_code, + .get_fmt = ov7670_get_fmt, .set_fmt = ov7670_set_fmt, }; @@ -1537,6 +1598,12 @@ static const struct v4l2_subdev_ops ov7670_ops = { .pad = &ov7670_pad_ops, }; +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API +static const struct v4l2_subdev_internal_ops ov7670_subdev_internal_ops = { + .open = ov7670_open, +}; +#endif + /* ----------------------------------------------------------------------- */ static const struct ov7670_devtype ov7670_devdata[] = { @@ -1589,6 +1656,11 @@ static int ov7670_probe(struct i2c_client *client, sd = &info->sd; v4l2_i2c_subdev_init(sd, client, &ov7670_ops); +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API + sd->internal_ops = &ov7670_subdev_internal_ops; + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; +#endif + info->clock_speed = 30; /* default: a guess */ if (client->dev.platform_data) { struct ov7670_config *config = client->dev.platform_data; @@ -1645,6 +1717,9 @@ static int ov7670_probe(struct i2c_client *client, info->devtype = &ov7670_devdata[id->driver_data]; info->fmt = &ov7670_formats[0]; + + ov7670_get_default_format(sd, &info->format); + info->clkrc = 0; /* Set default frame rate to 30 fps */