From patchwork Wed Sep 25 15:22:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benoit Parrot X-Patchwork-Id: 11160939 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A7EFB14DB for ; Wed, 25 Sep 2019 15:21:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 85EBF21E6F for ; Wed, 25 Sep 2019 15:21:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="kOlYCLoI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439452AbfIYPU6 (ORCPT ); Wed, 25 Sep 2019 11:20:58 -0400 Received: from lelv0143.ext.ti.com ([198.47.23.248]:49482 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726232AbfIYPU6 (ORCPT ); Wed, 25 Sep 2019 11:20:58 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x8PFKtdp002967; Wed, 25 Sep 2019 10:20:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1569424855; bh=dRdGU5YdcpZPKhHEXUHRHMxUwcKog7yqr8lelxvuiDg=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=kOlYCLoIxXlwm9uSbU7FVjMx2gjBVkshQCF115nzpcq/O5pPKWCRd0Wg5pfhq1fHs buEgGJO3SOnZGfRm9NayZPqoFx020lul++4N977kZIrM4yakvU4JDi0zcOHdb5ypBY S6RzXUiNMjQ2CU3gindvsf404cl4JR9Mf7fCONds= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x8PFKtT9128699 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 25 Sep 2019 10:20:55 -0500 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Wed, 25 Sep 2019 10:20:48 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Wed, 25 Sep 2019 10:20:48 -0500 Received: from uda0869644b.dal.design.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id x8PFKsso047659; Wed, 25 Sep 2019 10:20:55 -0500 From: Benoit Parrot To: Hans Verkuil , Sakari Ailus CC: , , , Benoit Parrot Subject: [Patch 1/3] media: ov5640: add PIXEL_RATE control Date: Wed, 25 Sep 2019 10:22:59 -0500 Message-ID: <20190925152301.21645-2-bparrot@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190925152301.21645-1-bparrot@ti.com> References: <20190925152301.21645-1-bparrot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add v4l2 controls to report the pixel rates of each mode. This is needed by some CSI2 receiver in order to perform proper DPHY configuration. Signed-off-by: Benoit Parrot --- drivers/media/i2c/ov5640.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c index 500d9bbff10b..c2a44f30d56e 100644 --- a/drivers/media/i2c/ov5640.c +++ b/drivers/media/i2c/ov5640.c @@ -193,6 +193,9 @@ struct ov5640_mode_info { struct ov5640_ctrls { struct v4l2_ctrl_handler handler; + struct { + struct v4l2_ctrl *pixel_rate; + }; struct { struct v4l2_ctrl *auto_exp; struct v4l2_ctrl *exposure; @@ -241,6 +244,7 @@ struct ov5640_dev { const struct ov5640_mode_info *last_mode; enum ov5640_frame_rate current_fr; struct v4l2_fract frame_interval; + u64 pixel_rate; struct ov5640_ctrls ctrls; @@ -2202,6 +2206,7 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd, const struct ov5640_mode_info *new_mode; struct v4l2_mbus_framefmt *mbus_fmt = &format->format; struct v4l2_mbus_framefmt *fmt; + u64 rate; int ret; if (format->pad != 0) @@ -2233,6 +2238,12 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd, if (mbus_fmt->code != sensor->fmt.code) sensor->pending_fmt_change = true; + rate = sensor->current_mode->vtot * sensor->current_mode->htot; + rate *= ov5640_framerates[sensor->current_fr]; + sensor->pixel_rate = rate; + + __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate, + sensor->pixel_rate); out: mutex_unlock(&sensor->lock); return ret; @@ -2657,6 +2668,13 @@ static int ov5640_init_controls(struct ov5640_dev *sensor) /* we can use our own mutex for the ctrl lock */ hdl->lock = &sensor->lock; + /* Clock related controls */ + ctrls->pixel_rate = + v4l2_ctrl_new_std(hdl, ops, + V4L2_CID_PIXEL_RATE, 0, INT_MAX, 1, + 55969920); + ctrls->pixel_rate->flags |= V4L2_CTRL_FLAG_READ_ONLY; + /* Auto/manual white balance */ ctrls->auto_wb = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_AUTO_WHITE_BALANCE, @@ -2782,6 +2800,7 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd, struct ov5640_dev *sensor = to_ov5640_dev(sd); const struct ov5640_mode_info *mode; int frame_rate, ret = 0; + u64 rate; if (fi->pad != 0) return -EINVAL; @@ -2816,6 +2835,12 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd, sensor->frame_interval = fi->interval; sensor->current_mode = mode; sensor->pending_mode_change = true; + + rate = sensor->current_mode->vtot * sensor->current_mode->htot; + rate *= ov5640_framerates[sensor->current_fr]; + sensor->pixel_rate = rate; + __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate, + sensor->pixel_rate); } out: mutex_unlock(&sensor->lock);