From patchwork Mon Dec 11 17:50:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176850 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230727vqy; Mon, 11 Dec 2023 09:52:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgmLpE56HLSs2l1ml2SJ9BEHEZbZQ8FEkO5PURVkj7Jm3Tu3brmA7i3kMQNcbegbgdpquc X-Received: by 2002:a05:6a20:a125:b0:190:490b:39da with SMTP id q37-20020a056a20a12500b00190490b39damr6503985pzk.59.1702317126316; Mon, 11 Dec 2023 09:52:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317126; cv=none; d=google.com; s=arc-20160816; b=s98kLs3B6zoISmPHaFjC6JE+2fnHdr5YUjqVR/PmpWdUdf1iks3uS4SNiPZxjIb0hS Y33MEE9VdDZ4TM7Nne3AWIWgdSZRVwnzNQl9sX4PkB8AZIbO9ipRuFWJ7m43knwpGtOP MBQTNKRmaBzCzIRocmj2uFidTcyDieMgbc09lxMlj4UU1rsCgXmLRKw3tvfdXNUHpros +xrl/JcjL/SLBAi+OJe2a5DBVxQ37gH2bUPBOBtEEn2TXBmIMTvFL8R7GppqhDVaIJJV Wtv52ztLJ/DyCQIh9EjcCiHpm6xHaoyGe2XdLDnQYXpMVrxtM6mtQV6pCnONPdE5kyCx E5qA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NtvsS5+cD5ElkCe7WN7GeNxLAQrSXFq4ofwLsevoTLU=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=Ft8KpKl2202dS26zsKOk9FnTli00StxA5QepMOPGKKHE1xZhDnUsIUUnaQuGldovjX 8ufu9lXbwvxjPFA/ebrfF4TIE0Ogi/gExghbBgeo9h2/t0sAlqzTzrrvkUEyW0ksI0Jo 3yLdMZO07TAoepjkPfJ5dj5PjSVSN4DSPDKJ31NanLiQhTTAAjyOq4OrwAh25m7Jq3Si SaRhN033UN+YHl9cDwf2btvfbuWCvaHpWcS/AGVgEUAjGoek4kGhvXBShrumDKjsyaC5 3zr9+ovJi6mjFmuiYh2OYC9wZdZxnayI/QDrEojnA67mdOJGXCgJs2A+Hm0k2j05q9B6 pfQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iLtXiiIH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id a13-20020a65418d000000b005c6998804a5si6384390pgq.160.2023.12.11.09.52.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:52:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=iLtXiiIH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id A9EA580A13B2; Mon, 11 Dec 2023 09:52:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235065AbjLKRvp (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345169AbjLKRvY (ORCPT ); Mon, 11 Dec 2023 12:51:24 -0500 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43E2211D; Mon, 11 Dec 2023 09:51:05 -0800 (PST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2ca1e6a94a4so61519651fa.0; Mon, 11 Dec 2023 09:51:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317062; x=1702921862; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NtvsS5+cD5ElkCe7WN7GeNxLAQrSXFq4ofwLsevoTLU=; b=iLtXiiIHrCiYoyz45znkkLJQR8eDQwz4HgSVJ7/SxEyZEVIwmDykW1GRfbbA5qAtmW hR8kVJBPXenltCtbcZDDQ79GlcHQRUX6wFSxcdHtaxf38Dfwpairk603UTJo6eoBzkLV hYpr0MWpGVJFn3imihF45tymfLyj7X6AuACO7x33+5gFeP3Csb5t8H/uT+8bIF/vzoBN r3e2KJxmqafJkprENuPB4D+lZOTps0VqmyrhtcxrB6rfjHVWBPYsTL8DpgCLVDRPwtrL tJzOSQ5nha7YHfK9k8TWN6vLxsJ6vjHYGOpPpTUelYDR7jLA0T1PEtbAxVcLVWcoT/wZ iRYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317062; x=1702921862; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NtvsS5+cD5ElkCe7WN7GeNxLAQrSXFq4ofwLsevoTLU=; b=TxodND3FXDt6WQIzCmQWXF/fU86eUt+BO3QoGrTBmclJjZlcez6zZyn3iF4AMGeGi7 0N4EJTGRYeu3bVdTIAtGTsz0+am+z9ByyFIG0aobqqnP8iCb45QUuKQbEiPkpE9sJxTb UxsqJ/Dv7c/7j1OPeTLwu1ngT74D9CXGPRVQ4RyjjUE1wZJD9cOolsYmNXIiXAZliBJk lpq9tDmV/BlssvxtdpA0SES0nhLO/DLj8DMODqMt6OhpeQF5r8C7sLPZjsg+SoG2AGs6 bSRvbdbfQFF/j5FEKFgAI3yV5CCc/tupELiuIEqfv4MlLSg2Qkz0pgPZZzjuwgnM5Eq/ F0VA== X-Gm-Message-State: AOJu0YzQ/7AyJxlHmnT/FE5Ncn70g0RPJVvbfGpXDerBmCAC+1qte08N NWl23R6lpJFs1LTsC19kZVw+05bCoOwVuOzj X-Received: by 2002:a05:651c:158b:b0:2cc:1eb1:b43f with SMTP id h11-20020a05651c158b00b002cc1eb1b43fmr1884874ljq.68.1702317062572; Mon, 11 Dec 2023 09:51:02 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id r6-20020a2e9946000000b002c9f71e61f3sm1293441ljj.6.2023.12.11.09.51.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:02 -0800 (PST) From: Mikhail Rudenko To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sakari Ailus , Laurent Pinchart , Jacopo Mondi , Tommaso Merciai , Christophe JAILLET , Dave Stevenson , Mauro Carvalho Chehab , Mikhail Rudenko Subject: [PATCH 15/19] media: i2c: ov4689: Set timing registers programmatically Date: Mon, 11 Dec 2023 20:50:18 +0300 Message-ID: <20231211175023.1680247-16-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231211175023.1680247-1-mike.rudenko@gmail.com> References: <20231211175023.1680247-1-mike.rudenko@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:52:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008882897330837 X-GMAIL-MSGID: 1785008882897330837 Set timing-related and BLC anchor registers via cci calls instead of hardcoding them in the register table. This prepares the driver for implementation of configurable analogue crop and binning. No functional change intended. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 82 +++++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 15 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 5acdf9e1b670..9088b4c61cab 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -52,6 +52,15 @@ #define OV4689_TEST_PATTERN_ENABLE 0x80 #define OV4689_TEST_PATTERN_DISABLE 0x0 +#define OV4689_REG_H_CROP_START CCI_REG16(0x3800) +#define OV4689_REG_V_CROP_START CCI_REG16(0x3802) +#define OV4689_REG_H_CROP_END CCI_REG16(0x3804) +#define OV4689_REG_V_CROP_END CCI_REG16(0x3806) +#define OV4689_REG_H_OUTPUT_SIZE CCI_REG16(0x3808) +#define OV4689_REG_V_OUTPUT_SIZE CCI_REG16(0x380a) +#define OV4689_REG_H_WIN_OFF CCI_REG16(0x3810) +#define OV4689_REG_V_WIN_OFF CCI_REG16(0x3812) + #define OV4689_REG_VTS CCI_REG16(0x380e) #define OV4689_VTS_MAX 0x7fff @@ -67,6 +76,17 @@ #define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ OV4689_TIMING_FLIP_DIGITAL) +#define OV4689_REG_ANCHOR_LEFT_START CCI_REG16(0x4020) +#define OV4689_ANCHOR_LEFT_START_DEF 576 +#define OV4689_REG_ANCHOR_LEFT_END CCI_REG16(0x4022) +#define OV4689_ANCHOR_LEFT_END_DEF 831 +#define OV4689_REG_ANCHOR_RIGHT_START CCI_REG16(0x4024) +#define OV4689_ANCHOR_RIGHT_START_DEF 1984 +#define OV4689_REG_ANCHOR_RIGHT_END CCI_REG16(0x4026) +#define OV4689_ANCHOR_RIGHT_END_DEF 2239 + +#define OV4689_REG_VFIFO_CTRL_01 CCI_REG8(0x4601) + #define OV4689_LANES 4 #define OV4689_XVCLK_FREQ 24000000 @@ -199,10 +219,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x3798), 0x1b}, /* Timing control */ - {CCI_REG8(0x3801), 0x08}, /* H_CROP_START_L h_crop_start[7:0] = 0x08 */ - {CCI_REG8(0x3805), 0x97}, /* H_CROP_END_L h_crop_end[7:0] = 0x97 */ - {CCI_REG8(0x3811), 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ - {CCI_REG8(0x3813), 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ {CCI_REG8(0x3819), 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ /* OTP control */ @@ -218,22 +234,11 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x401b), 0x00}, /* DEBUG_MODE */ {CCI_REG8(0x401d), 0x00}, /* DEBUG_MODE */ {CCI_REG8(0x401f), 0x00}, /* DEBUG_MODE */ - {CCI_REG8(0x4020), 0x00}, /* ANCHOR_LEFT_START_H anchor_left_start[11:8] = 0 */ - {CCI_REG8(0x4021), 0x10}, /* ANCHOR_LEFT_START_L anchor_left_start[7:0] = 0x10 */ - {CCI_REG8(0x4022), 0x07}, /* ANCHOR_LEFT_END_H anchor_left_end[11:8] = 0x07 */ - {CCI_REG8(0x4023), 0xcf}, /* ANCHOR_LEFT_END_L anchor_left_end[7:0] = 0xcf */ - {CCI_REG8(0x4024), 0x09}, /* ANCHOR_RIGHT_START_H anchor_right_start[11:8] = 0x09 */ - {CCI_REG8(0x4025), 0x60}, /* ANCHOR_RIGHT_START_L anchor_right_start[7:0] = 0x60 */ - {CCI_REG8(0x4026), 0x09}, /* ANCHOR_RIGHT_END_H anchor_right_end[11:8] = 0x09 */ - {CCI_REG8(0x4027), 0x6f}, /* ANCHOR_RIGHT_END_L anchor_right_end[7:0] = 0x6f */ /* ADC sync control */ {CCI_REG8(0x4500), 0x6c}, /* ADC_SYNC_CTRL */ {CCI_REG8(0x4503), 0x01}, /* ADC_SYNC_CTRL */ - /* VFIFO */ - {CCI_REG8(0x4601), 0xa7}, /* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ - /* Temperature monitor */ {CCI_REG8(0x4d00), 0x04}, /* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ {CCI_REG8(0x4d01), 0x42}, /* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */ @@ -406,6 +411,41 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, return -EINVAL; } +static int ov4689_setup_timings(struct ov4689 *ov4689) +{ + const struct ov4689_mode *mode = ov4689->cur_mode; + struct regmap *rm = ov4689->regmap; + int ret = 0; + + cci_write(rm, OV4689_REG_H_CROP_START, 8, &ret); + cci_write(rm, OV4689_REG_V_CROP_START, 8, &ret); + cci_write(rm, OV4689_REG_H_CROP_END, 2711, &ret); + cci_write(rm, OV4689_REG_V_CROP_END, 1531, &ret); + + cci_write(rm, OV4689_REG_H_OUTPUT_SIZE, mode->width, &ret); + cci_write(rm, OV4689_REG_V_OUTPUT_SIZE, mode->height, &ret); + + cci_write(rm, OV4689_REG_H_WIN_OFF, 8, &ret); + cci_write(rm, OV4689_REG_V_WIN_OFF, 4, &ret); + + cci_write(rm, OV4689_REG_VFIFO_CTRL_01, 167, &ret); + + return ret; +} + +static int ov4689_setup_blc_anchors(struct ov4689 *ov4689) +{ + struct regmap *rm = ov4689->regmap; + int ret = 0; + + cci_write(rm, OV4689_REG_ANCHOR_LEFT_START, 16, &ret); + cci_write(rm, OV4689_REG_ANCHOR_LEFT_END, 1999, &ret); + cci_write(rm, OV4689_REG_ANCHOR_RIGHT_START, 2400, &ret); + cci_write(rm, OV4689_REG_ANCHOR_RIGHT_END, 2415, &ret); + + return ret; +} + static int ov4689_s_stream(struct v4l2_subdev *sd, int on) { struct ov4689 *ov4689 = to_ov4689(sd); @@ -429,6 +469,18 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; } + ret = ov4689_setup_timings(ov4689); + if (ret) { + pm_runtime_put(dev); + goto unlock_and_return; + } + + ret = ov4689_setup_blc_anchors(ov4689); + if (ret) { + pm_runtime_put(dev); + goto unlock_and_return; + } + ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler); if (ret) { pm_runtime_put(dev);