From patchwork Mon Dec 11 17:50:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230224vqy; Mon, 11 Dec 2023 09:51:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOq8oYWjSxirxvWOdsB8IcXCSxGr7hKJDnslX95GA+XczhikZW+mI4iKGiNyfGXXJ/8rlS X-Received: by 2002:a05:6a20:8f14:b0:18f:f955:1ec8 with SMTP id b20-20020a056a208f1400b0018ff9551ec8mr6004358pzk.51.1702317075929; Mon, 11 Dec 2023 09:51:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317075; cv=none; d=google.com; s=arc-20160816; b=Ju4xGxRKeNmnFPhqrd7uMGmrvtOKNwXXzPaYdqlShaJJn5Z1cMZCAM7rXMdX6lKkIM dgqc+6OvS7B6+PPfOkyrvq1ZkU3nxcnTv+FaAVCgBJ2G5re8YYr0xT/0k1DbTYz511OE l32/XCNkqQtCN72oAAtlJvG8HoRQBXc9S40WPZdkS0fPqkni5PWlMBQ9fJc0nGHQd4FP LnOo4f1ha9JnLP8w1/Qt1Qk1bPQNLOh+1pfzZ34zyaUNNJBPFbofDH6QzQ3Dd4k2fRan h/VPr0NXnkyBujdDXJ6+QS8yId3XUG25W+H9oWoA7jFnXGu9Lwq+daDHIVbd+h0DljXU OJiA== 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=QvzWqKWWxtF7t1ieAaxj0+EbNjoeBeyf3ul7f1hfdkU=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=gT+SJc2+mSSDY/Um82e9AhbkXs0Cd57y1WUVoBR8gOITubBDhrX6OXP5I4vhO6A0Dq ZIC3yHNIOwHLrieSmRpbIXT/IQ1CbTCOuX2YZZX5RKIogdq7u386vqIOZfYfSziB9+WQ T/7RBJ31Z0/h49HzKC8lSsv7Yh4FDGv/ofl2NVhd3kynsl7II0FsR5OnCtgF58zNwy8l gKO2jsb753s+PR9pLMpwX/Og/CpQklNODsAWd7FV87OCw2p8JQCwiEfBB7EcWs77IUgZ DWvsBIwiWXHhy0f3iEFAMFWrJ+4llQ0EQD0myXqg6huyaMMDj3AQ3zdF2Tvn7HSAU5QF kXQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bTfyNSyL; 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 h2-20020a655182000000b0058978136247si6274588pgq.483.2023.12.11.09.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:15 -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=bTfyNSyL; 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 CF6068057E26; Mon, 11 Dec 2023 09:51:12 -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 S1345034AbjLKRuz (ORCPT + 99 others); Mon, 11 Dec 2023 12:50:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344959AbjLKRuk (ORCPT ); Mon, 11 Dec 2023 12:50:40 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C46AEC8; Mon, 11 Dec 2023 09:50:45 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-50c0f6b1015so5578847e87.3; Mon, 11 Dec 2023 09:50:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317043; x=1702921843; 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=QvzWqKWWxtF7t1ieAaxj0+EbNjoeBeyf3ul7f1hfdkU=; b=bTfyNSyL2/ApuSkSZWbSga8GmfF0j1R95pnI4x+lrMl5tKZWR6+1/Zj5GPbOsW93LF BE+6+VHSslJoDAxlIMO64iujj+0IfQtVYCWB4giNNICfPifuTSWA4QLbQNzXCBWuua+P uJzCcAw+/lLjn7LAzt/p+m/e6g0bq1czecseirMvMypU8jqa4wWiwoY31y+GJTZTrQAT SXhoo7MDAJvZCAPdFVLXQnp5FX2G0hVD0CaDN5I6mAAMSAIgbFqzWzWBYuFLN2iphCvE SnxA8fwzC+0Ce1l4l5/NYwAPcAre/AmngJzTgLZNWTeXRF/EPeoeXSHjo39hRMYjQ3jZ UOog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317043; x=1702921843; 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=QvzWqKWWxtF7t1ieAaxj0+EbNjoeBeyf3ul7f1hfdkU=; b=Y3YEHCn9wH9Rjp+UJIZcwSsbmaeaEecpfRr4LLGBP4Sj9fp00Kvm0V1KizH6Zruo7z q9wzb1gj8H2NCLn+Uhy3d3LUW0wOLm6FUn6wlJVqsk55+B0uRRXmJC95mNrH/x2YaghP IZoReFLPeKKMFkasfGxFFyIBl6VMYlYKdIrNQbQMRLWihniU2xUtLe38Hvyn4orZHVoD B3VzVNlUl8AvsPIG16ZPa7B4iONUzRUT+2YkzwXT9H86NYFplcWL5V1JSG91gvxBOkZj BEZSLskMS3aPTDNuTWEd18JRrUAM7M7Z/JPND5Jj76owA+Pg9VmxOLaSKo3IMd9roDLr tB3w== X-Gm-Message-State: AOJu0YxOFvhpNLgx4oGmxRA6PEKtlteGR8XJGEosFiOLEN/gQxmbAPyZ W8YlqLJhx69lJhJwic0X6xduv8WhscKqo+Aw X-Received: by 2002:a05:6512:15a0:b0:50b:f05b:3e0c with SMTP id bp32-20020a05651215a000b0050bf05b3e0cmr2430224lfb.79.1702317043047; Mon, 11 Dec 2023 09:50:43 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id e25-20020a196759000000b0050bf8176284sm1163660lfj.117.2023.12.11.09.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:42 -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 01/19] media: i2c: ov4689: Clean up and annotate the register table Date: Mon, 11 Dec 2023 20:50:04 +0300 Message-ID: <20231211175023.1680247-2-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:51:13 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008829771884743 X-GMAIL-MSGID: 1785008829771884743 Many values in the register table are actually power-on defaults. Remove those and also unused HDR exposures and gains. Annotate the remaining values using the publicly available datasheet to facilitate further development. No functional change intended. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 203 +++++++++++++++++++++---------------- 1 file changed, 118 insertions(+), 85 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 403091651885..ff5213862974 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -3,7 +3,7 @@ * ov4689 driver * * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd. - * Copyright (C) 2022 Mikhail Rudenko + * Copyright (C) 2022, 2023 Mikhail Rudenko */ #include @@ -123,90 +123,123 @@ struct ov4689_gain_range { * mipi_datarate per lane 1008Mbps */ static const struct regval ov4689_2688x1520_regs[] = { - {0x0103, 0x01}, {0x3638, 0x00}, {0x0300, 0x00}, - {0x0302, 0x2a}, {0x0303, 0x00}, {0x0304, 0x03}, - {0x030b, 0x00}, {0x030d, 0x1e}, {0x030e, 0x04}, - {0x030f, 0x01}, {0x0312, 0x01}, {0x031e, 0x00}, - {0x3000, 0x20}, {0x3002, 0x00}, {0x3018, 0x72}, - {0x3020, 0x93}, {0x3021, 0x03}, {0x3022, 0x01}, - {0x3031, 0x0a}, {0x303f, 0x0c}, {0x3305, 0xf1}, - {0x3307, 0x04}, {0x3309, 0x29}, {0x3500, 0x00}, - {0x3501, 0x60}, {0x3502, 0x00}, {0x3503, 0x04}, - {0x3504, 0x00}, {0x3505, 0x00}, {0x3506, 0x00}, - {0x3507, 0x00}, {0x3508, 0x00}, {0x3509, 0x80}, - {0x350a, 0x00}, {0x350b, 0x00}, {0x350c, 0x00}, - {0x350d, 0x00}, {0x350e, 0x00}, {0x350f, 0x80}, - {0x3510, 0x00}, {0x3511, 0x00}, {0x3512, 0x00}, - {0x3513, 0x00}, {0x3514, 0x00}, {0x3515, 0x80}, - {0x3516, 0x00}, {0x3517, 0x00}, {0x3518, 0x00}, - {0x3519, 0x00}, {0x351a, 0x00}, {0x351b, 0x80}, - {0x351c, 0x00}, {0x351d, 0x00}, {0x351e, 0x00}, - {0x351f, 0x00}, {0x3520, 0x00}, {0x3521, 0x80}, - {0x3522, 0x08}, {0x3524, 0x08}, {0x3526, 0x08}, - {0x3528, 0x08}, {0x352a, 0x08}, {0x3602, 0x00}, - {0x3603, 0x40}, {0x3604, 0x02}, {0x3605, 0x00}, - {0x3606, 0x00}, {0x3607, 0x00}, {0x3609, 0x12}, - {0x360a, 0x40}, {0x360c, 0x08}, {0x360f, 0xe5}, - {0x3608, 0x8f}, {0x3611, 0x00}, {0x3613, 0xf7}, - {0x3616, 0x58}, {0x3619, 0x99}, {0x361b, 0x60}, - {0x361c, 0x7a}, {0x361e, 0x79}, {0x361f, 0x02}, - {0x3632, 0x00}, {0x3633, 0x10}, {0x3634, 0x10}, - {0x3635, 0x10}, {0x3636, 0x15}, {0x3646, 0x86}, - {0x364a, 0x0b}, {0x3700, 0x17}, {0x3701, 0x22}, - {0x3703, 0x10}, {0x370a, 0x37}, {0x3705, 0x00}, - {0x3706, 0x63}, {0x3709, 0x3c}, {0x370b, 0x01}, - {0x370c, 0x30}, {0x3710, 0x24}, {0x3711, 0x0c}, - {0x3716, 0x00}, {0x3720, 0x28}, {0x3729, 0x7b}, - {0x372a, 0x84}, {0x372b, 0xbd}, {0x372c, 0xbc}, - {0x372e, 0x52}, {0x373c, 0x0e}, {0x373e, 0x33}, - {0x3743, 0x10}, {0x3744, 0x88}, {0x3745, 0xc0}, - {0x374a, 0x43}, {0x374c, 0x00}, {0x374e, 0x23}, - {0x3751, 0x7b}, {0x3752, 0x84}, {0x3753, 0xbd}, - {0x3754, 0xbc}, {0x3756, 0x52}, {0x375c, 0x00}, - {0x3760, 0x00}, {0x3761, 0x00}, {0x3762, 0x00}, - {0x3763, 0x00}, {0x3764, 0x00}, {0x3767, 0x04}, - {0x3768, 0x04}, {0x3769, 0x08}, {0x376a, 0x08}, - {0x376b, 0x20}, {0x376c, 0x00}, {0x376d, 0x00}, - {0x376e, 0x00}, {0x3773, 0x00}, {0x3774, 0x51}, - {0x3776, 0xbd}, {0x3777, 0xbd}, {0x3781, 0x18}, - {0x3783, 0x25}, {0x3798, 0x1b}, {0x3800, 0x00}, - {0x3801, 0x08}, {0x3802, 0x00}, {0x3803, 0x04}, - {0x3804, 0x0a}, {0x3805, 0x97}, {0x3806, 0x05}, - {0x3807, 0xfb}, {0x3808, 0x0a}, {0x3809, 0x80}, - {0x380a, 0x05}, {0x380b, 0xf0}, {0x380c, 0x0a}, - {0x380d, 0x0e}, {0x380e, 0x06}, {0x380f, 0x12}, - {0x3810, 0x00}, {0x3811, 0x08}, {0x3812, 0x00}, - {0x3813, 0x04}, {0x3814, 0x01}, {0x3815, 0x01}, - {0x3819, 0x01}, {0x3820, 0x00}, {0x3821, 0x06}, - {0x3829, 0x00}, {0x382a, 0x01}, {0x382b, 0x01}, - {0x382d, 0x7f}, {0x3830, 0x04}, {0x3836, 0x01}, - {0x3837, 0x00}, {0x3841, 0x02}, {0x3846, 0x08}, - {0x3847, 0x07}, {0x3d85, 0x36}, {0x3d8c, 0x71}, - {0x3d8d, 0xcb}, {0x3f0a, 0x00}, {0x4000, 0xf1}, - {0x4001, 0x40}, {0x4002, 0x04}, {0x4003, 0x14}, - {0x400e, 0x00}, {0x4011, 0x00}, {0x401a, 0x00}, - {0x401b, 0x00}, {0x401c, 0x00}, {0x401d, 0x00}, - {0x401f, 0x00}, {0x4020, 0x00}, {0x4021, 0x10}, - {0x4022, 0x07}, {0x4023, 0xcf}, {0x4024, 0x09}, - {0x4025, 0x60}, {0x4026, 0x09}, {0x4027, 0x6f}, - {0x4028, 0x00}, {0x4029, 0x02}, {0x402a, 0x06}, - {0x402b, 0x04}, {0x402c, 0x02}, {0x402d, 0x02}, - {0x402e, 0x0e}, {0x402f, 0x04}, {0x4302, 0xff}, - {0x4303, 0xff}, {0x4304, 0x00}, {0x4305, 0x00}, - {0x4306, 0x00}, {0x4308, 0x02}, {0x4500, 0x6c}, - {0x4501, 0xc4}, {0x4502, 0x40}, {0x4503, 0x01}, - {0x4601, 0xa7}, {0x4800, 0x04}, {0x4813, 0x08}, - {0x481f, 0x40}, {0x4829, 0x78}, {0x4837, 0x10}, - {0x4b00, 0x2a}, {0x4b0d, 0x00}, {0x4d00, 0x04}, - {0x4d01, 0x42}, {0x4d02, 0xd1}, {0x4d03, 0x93}, - {0x4d04, 0xf5}, {0x4d05, 0xc1}, {0x5000, 0xf3}, - {0x5001, 0x11}, {0x5004, 0x00}, {0x500a, 0x00}, - {0x500b, 0x00}, {0x5032, 0x00}, {0x5040, 0x00}, - {0x5050, 0x0c}, {0x5500, 0x00}, {0x5501, 0x10}, - {0x5502, 0x01}, {0x5503, 0x0f}, {0x8000, 0x00}, - {0x8001, 0x00}, {0x8002, 0x00}, {0x8003, 0x00}, - {0x8004, 0x00}, {0x8005, 0x00}, {0x8006, 0x00}, - {0x8007, 0x00}, {0x8008, 0x00}, {0x3638, 0x00}, + /* System control*/ + {0x0103, 0x01}, /* SC_CTRL0103 software_reset = 1 */ + {0x3000, 0x20}, /* SC_CMMN_PAD_OEN0 FSIN_output_enable = 1 */ + {0x3021, 0x03}, /* + * SC_CMMN_MISC_CTRL fst_stby_ctr = 0, + * sleep_no_latch_enable = 0 + */ + + /* AEC PK */ + {0x3503, 0x04}, /* AEC_MANUAL gain_input_as_sensor_gain_format = 1 */ + {0x352a, 0x08}, /* DIG_GAIN_FRAC_LONG dig_gain_long[14:8] = 0x08 (2x) */ + + /* ADC and analog control*/ + {0x3603, 0x40}, + {0x3604, 0x02}, + {0x3609, 0x12}, + {0x360c, 0x08}, + {0x360f, 0xe5}, + {0x3608, 0x8f}, + {0x3611, 0x00}, + {0x3613, 0xf7}, + {0x3616, 0x58}, + {0x3619, 0x99}, + {0x361b, 0x60}, + {0x361e, 0x79}, + {0x3634, 0x10}, + {0x3635, 0x10}, + {0x3636, 0x15}, + {0x3646, 0x86}, + {0x364a, 0x0b}, + + /* Sensor control */ + {0x3700, 0x17}, + {0x3701, 0x22}, + {0x3703, 0x10}, + {0x370a, 0x37}, + {0x3706, 0x63}, + {0x3709, 0x3c}, + {0x370c, 0x30}, + {0x3710, 0x24}, + {0x3720, 0x28}, + {0x3729, 0x7b}, + {0x372b, 0xbd}, + {0x372c, 0xbc}, + {0x372e, 0x52}, + {0x373c, 0x0e}, + {0x373e, 0x33}, + {0x3743, 0x10}, + {0x3744, 0x88}, + {0x3745, 0xc0}, + {0x374c, 0x00}, + {0x374e, 0x23}, + {0x3751, 0x7b}, + {0x3753, 0xbd}, + {0x3754, 0xbc}, + {0x3756, 0x52}, + {0x376b, 0x20}, + {0x3774, 0x51}, + {0x3776, 0xbd}, + {0x3777, 0xbd}, + {0x3781, 0x18}, + {0x3783, 0x25}, + {0x3798, 0x1b}, + + /* Timing control */ + {0x3801, 0x08}, /* H_CROP_START_L h_crop_start[7:0] = 0x08 */ + {0x3805, 0x97}, /* H_CROP_END_L h_crop_end[7:0] = 0x97 */ + {0x380c, 0x0a}, /* TIMING_HTS_H hts[14:8] = 0x0a */ + {0x380d, 0x0e}, /* TIMING_HTS_L hts[7:0] = 0x0e */ + {0x3811, 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ + {0x3813, 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ + {0x3819, 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ + {0x3821, 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 */ + + /* OTP control */ + {0x3d85, 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1, + * OTP_power_up_load_data_enable = 1, + * OTP_bist_select = 1 (compare with zero) + */ + {0x3d8c, 0x71}, /* OTP_SETTING_STT_ADDRESS_H */ + {0x3d8d, 0xcb}, /* OTP_SETTING_STT_ADDRESS_L */ + + /* BLC registers*/ + {0x4001, 0x40}, /* DEBUG_MODE */ + {0x401b, 0x00}, /* DEBUG_MODE */ + {0x401d, 0x00}, /* DEBUG_MODE */ + {0x401f, 0x00}, /* DEBUG_MODE */ + {0x4020, 0x00}, /* ANCHOR_LEFT_START_H anchor_left_start[11:8] = 0 */ + {0x4021, 0x10}, /* ANCHOR_LEFT_START_L anchor_left_start[7:0] = 0x10 */ + {0x4022, 0x07}, /* ANCHOR_LEFT_END_H anchor_left_end[11:8] = 0x07 */ + {0x4023, 0xcf}, /* ANCHOR_LEFT_END_L anchor_left_end[7:0] = 0xcf */ + {0x4024, 0x09}, /* ANCHOR_RIGHT_START_H anchor_right_start[11:8] = 0x09 */ + {0x4025, 0x60}, /* ANCHOR_RIGHT_START_L anchor_right_start[7:0] = 0x60 */ + {0x4026, 0x09}, /* ANCHOR_RIGHT_END_H anchor_right_end[11:8] = 0x09 */ + {0x4027, 0x6f}, /* ANCHOR_RIGHT_END_L anchor_right_end[7:0] = 0x6f */ + + /* ADC sync control */ + {0x4500, 0x6c}, /* ADC_SYNC_CTRL */ + {0x4503, 0x01}, /* ADC_SYNC_CTRL */ + + /* VFIFO */ + {0x4601, 0xa7}, /* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ + + /* Temperature monitor */ + {0x4d00, 0x04}, /* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ + {0x4d01, 0x42}, /* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */ + {0x4d02, 0xd1}, /* TPM_CTRL_02 tpm_offset[31:24] = 0xd1 */ + {0x4d03, 0x93}, /* TPM_CTRL_03 tpm_offset[23:16] = 0x93 */ + {0x4d04, 0xf5}, /* TPM_CTRL_04 tpm_offset[15:8] = 0xf5 */ + {0x4d05, 0xc1}, /* TPM_CTRL_05 tpm_offset[7:0] = 0xc1 */ + + /* pre-ISP control */ + {0x5050, 0x0c}, /* DEBUG_MODE */ + + /* OTP-DPC control */ + {0x5501, 0x10}, /* OTP_DPC_START_L otp_start_address[7:0] = 0x10 */ + {0x5503, 0x0f}, /* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ {REG_NULL, 0x00}, }; From patchwork Mon Dec 11 17:50:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230115vqy; Mon, 11 Dec 2023 09:51:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IGT8+9pc4oKnQnKFm+G5O3GKJLiK7NO913UWPsqNZxIyCShFyWI5JNGdNjnZno+bHuu/iPM X-Received: by 2002:a05:6a00:139f:b0:6ce:725f:7d9d with SMTP id t31-20020a056a00139f00b006ce725f7d9dmr6041721pfg.14.1702317064499; Mon, 11 Dec 2023 09:51:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317064; cv=none; d=google.com; s=arc-20160816; b=a7Ovj7zeWB2ZpeKDbWbCgOtseNMPcNU6nblGjgp2jrMd6t1PMMfIeuw1UGe8tIhaAB ny+O9nHn0HChY+SouXoh6G8NXU6uwQQr5ySsyOHyzrGoxzQmYhD0gOxpM5WROsxL1jBF 9HYqZdqrELUbwAUhLiSkLWWGeIRexYvmyudpi3ZmvZ7qi8Nrf9zZGrIVfWyiSenMkV+1 AKeXuZGSNHOUKCmnv3LueMMl7MYRmauCKei2rEEZCqSfyJEsQ5y6Ot14paKutBRlt+jz Rz6clup1H1034TQkwQUFuWUl/FNWljzlRPo5StaQ5XDclO7Ff3HgwnHlZOjxPutZpyNA LUfA== 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=tVL1A/XuQPswwKjRrHcQ3Q+mQNKL8W1neWWaIk0mGMo=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=oTbL3D1/uBV7r6mWv4p8NqVoDOEIjSusAypuejNJ5DxBmUWXmsX5oZKv9jgcLp/NA2 JkJfEIZSWmNVK0VuAK5GGDp7RylN9fg/Plel2t5lN+uq9iX7xerB885lU3W4LgxEwhQG PY3veCAIJ3yBHpFWa2sI6t0ilWPTJKrpBP0osMDFiFPAvEQuj5fx20eNj2rHTqF+XuSI EdfExbFoJBJxKyKjn/DFieLhz+aJ/V3W/W7f2WtrbPuu0B2OpMdHdG/ijmBaDpLlVige LGLxG+puhPY0mtZVRc3E9IHF+4Bta/pnBEQs7JPSYP2uWzTXpWBqaAJczOmcEdVElRvP oTow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hShG54bi; 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 fa1-20020a056a002d0100b006be55174f3fsi6445607pfb.28.2023.12.11.09.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:04 -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=hShG54bi; 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 57C838057E7E; Mon, 11 Dec 2023 09:51:02 -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 S1344954AbjLKRuw (ORCPT + 99 others); Mon, 11 Dec 2023 12:50:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344963AbjLKRuk (ORCPT ); Mon, 11 Dec 2023 12:50:40 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD19793; Mon, 11 Dec 2023 09:50:46 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-50bf69afa99so6052929e87.3; Mon, 11 Dec 2023 09:50:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317044; x=1702921844; 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=tVL1A/XuQPswwKjRrHcQ3Q+mQNKL8W1neWWaIk0mGMo=; b=hShG54bigAXEIv7Qbg2NHieK/LptHaQj8iXPKw2ocIY0kY/OBsIWqHrHBzmLsHg4gd NkyLrxpJ54CsJr0MLtzZy3tFJXlOuBJ6bx032Do6iuV9yyZh0zSh79QIUwMhFQ/Jy+AI uSpFC6hrYoF9fhNaGokKovO15he3hcTD/27esxBxVdJk9p16GFllz5RNLef7uQyUQdzj PrMVzXPCtXnxhK2EwxPQhGzYWaWMdDoqLakqcY5QObQ9gLShlTeNNL1rtWC9zqlrwl58 wJcL1vOuiEzRSmhre9kzXpQ4pEh67u0SeO5OBf3N2V1Lxi6hpHs+2J7sNS5J/dWlUKzJ uZog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317044; x=1702921844; 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=tVL1A/XuQPswwKjRrHcQ3Q+mQNKL8W1neWWaIk0mGMo=; b=B2v098CaDzrLzX2w0Ml1i97cc7+6Gw8JmWKu91MpDPoB7ZDCS8LjtonoJ0J8XoUYbe BYwyG+AN488gWHz0ryvORyyhjA19UeA28ArW56UFrL/Eydv1e9I9Dy+2Fvct5v0PkT5q 82FxyD6coghrnus0itdZ75IgAbgm4zIJgfAKsPzH2pXYFdMLd6HkhMCS2npyybXU/OF1 c134/4NqSAa3zNBaetR1tZmY1ONtq31VlIyJ8DZgFpaf7hwwvDjt9iHwMKLhWHuhJj9T ND+s7tLUw4LDIbqsxuTATBT+p7vqnRXq638qw7gHK7XIr8XR60+/335h5UYjTCYbcXq6 NqEw== X-Gm-Message-State: AOJu0Ywg5SsM98QQ78B4BmtTN/dCUF//TPG78A5r8JUWslTPiVgfo68n kRXphV0qXKIASDqiJMsR4272yPTUbRo+v9R0 X-Received: by 2002:a05:6512:2316:b0:50b:f30b:5499 with SMTP id o22-20020a056512231600b0050bf30b5499mr3065839lfu.80.1702317044420; Mon, 11 Dec 2023 09:50:44 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id h4-20020a056512350400b0050d14ce3958sm1077170lfs.81.2023.12.11.09.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:43 -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 02/19] media: i2c: ov4689: Fix typo in a comment Date: Mon, 11 Dec 2023 20:50:05 +0300 Message-ID: <20231211175023.1680247-3-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=ham 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:51:02 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008818291839730 X-GMAIL-MSGID: 1785008818291839730 Fix a spelling error in a comment. Signed-off-by: Mikhail Rudenko Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index ff5213862974..53dcfc8685d4 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -692,7 +692,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case V4L2_CID_EXPOSURE: - /* 4 least significant bits of expsoure are fractional part */ + /* 4 least significant bits of exposure are fractional part */ ret = ov4689_write_reg(ov4689->client, OV4689_REG_EXPOSURE, OV4689_REG_VALUE_24BIT, ctrl->val << 4); break; From patchwork Mon Dec 11 17:50:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176844 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230402vqy; Mon, 11 Dec 2023 09:51:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGU8aDZOzRFXstcsA0pNF+h67Xj8fI91AWFtjwcWf5Q9I3TOgBGQbobv+lgwPFWQM/YfvUG X-Received: by 2002:a05:6a20:429f:b0:18f:97c:4f4c with SMTP id o31-20020a056a20429f00b0018f097c4f4cmr2694642pzj.88.1702317096785; Mon, 11 Dec 2023 09:51:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317096; cv=none; d=google.com; s=arc-20160816; b=wRlM3/aWO7DUrHS1aqdPGzbRFuiAbfXdcrJvoe4e8JXzoYrpfw6rcY6Uhrn3mN4yr3 OMIa68HANZkbZDM6tn+fS7eBMh1YjM4MY5+CLnnvbuihFdRofSg/Y9/oeJhx0lubNMbu etQDcWsEuPGZLUvT3u58Zko0QrcJYo/35kvMGSa7jsC8m0nudrbMLsnWDLy30ida1M2Y UvKOy7U9yfDZHtxUSkaNkt2eOvXKxAueRMylUEHeqwEojVQ+QPuCR35HLcEQ6cpe4yrY TsRYpKv6y3PGBnnK3J9OQ69W6OsSMtYQmKbqxG2sCcHhU4AD6SHSmykktvMXYEJHfHuI Yqcw== 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=5aS1x6VnzG7ul/dczzaIUU7WHV34y2x/02/ro4MEmKE=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=eENQbtHId2hU3if7PzIA7HxbgDN+yYDqW6gzeNag37Ox3UZ+bU8agzPGnVqmivGm3t EW4GuiEbnRf/n7aIUcf1Im6JcJxC0TadVHVlMM1KtaiB3X65TIuAnDlbZGz4VsOJAFFI xfXNHM41FgWlK5KxBbnTBwZJvOj62BLN9hW8kTHeGQn24O28cA/tKPF5PkIPpe3wvVmx HYIBw3fnUAkycZOtWaCJV9+WDf+047R7uxIsLk3VtXSj2m6eeC6ccYrofE/7QtgkR/+L au5ORhpLN0XGyxq/lFSr+fPs1d8UxXwa7pLATJeNDLrCM/yKZlgIQAD9HiDUBjBh/sFD MjKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lClXnxi7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id v18-20020a631512000000b005c623037c10si6409567pgl.96.2023.12.11.09.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lClXnxi7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 19430806037C; Mon, 11 Dec 2023 09:51:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345067AbjLKRu7 (ORCPT + 99 others); Mon, 11 Dec 2023 12:50:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345092AbjLKRuo (ORCPT ); Mon, 11 Dec 2023 12:50:44 -0500 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B782ECD; Mon, 11 Dec 2023 09:50:48 -0800 (PST) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2cc2683fdaaso7667281fa.0; Mon, 11 Dec 2023 09:50:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317046; x=1702921846; 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=5aS1x6VnzG7ul/dczzaIUU7WHV34y2x/02/ro4MEmKE=; b=lClXnxi7WyJ8KSCXrx35k2Pfsd7/R4KsMbHxH9SHAAlgZzQm9LrtUY2jt9x/2OhhgV QCFYY4rlxsv+oeNICFgn32rbaRU8uj75QkpmjDBPA4QRHozKdTFhknn8miCZfs80yK56 EpYe1Rq8tUhRzgmUb9sBXuAqBO3YqwUz4sLroO6pWulu6WkqLQN1hAIGEYN7ZubYZMH9 sVC/5sKb4WkU6oW2XdynvNUaiMgMqXHQAM6iMTYapyQaLHDvgLCD9fQ5C785UshwwiRM feLc7BZLr4SQxAg+P3arX7J4ouaPPSRj9cQ5sRxqLEOp4FO8X7iInBb8ZNoi30ojlYbD 71IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317046; x=1702921846; 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=5aS1x6VnzG7ul/dczzaIUU7WHV34y2x/02/ro4MEmKE=; b=KSgE6vnyN/8n8khXRz6hI0UNMqyaIfKQT9PApHieYSt3HInZDh9AEFf66m7UYgH/d9 0i/OhEIHejcDxwKOz6+F56vtWrkODxAHta5NlASBlFRky2HGDP75/rYFTFhn0szljr5f PaJGNkFInQ4tIMvyvqycetxQrdgeX5wCJL8rQCCV8q94jlN++vDTIUG49W6ChOiR9QZh UpQIMJ33KYRH//GJp6PF7B7xvsY1gA6H3r/KG4iCS71+Rb5vZfRueETFY+2baCDkOXn0 WOWFlUHaXojui11a6bcjQnLbhtmN7Tq7cPqO0JvC44i6fvJAxwZYS42CyrjS00uWOIzZ 2pYw== X-Gm-Message-State: AOJu0YxdXUrotTEcZJaEaNsjm/vISLl0J6/CT2Uum5nX+cHmQ6aib7ja yQOLA1I+TvrnMKB9Djw6m5ftHHzJIWeihEj/ X-Received: by 2002:a05:651c:987:b0:2cb:29f4:c96e with SMTP id b7-20020a05651c098700b002cb29f4c96emr3690639ljq.21.1702317045787; Mon, 11 Dec 2023 09:50:45 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id b7-20020a2e9887000000b002ca0050bf36sm1285472ljj.73.2023.12.11.09.50.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:45 -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 03/19] media: i2c: ov4689: CCI conversion Date: Mon, 11 Dec 2023 20:50:06 +0300 Message-ID: <20231211175023.1680247-4-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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:51:31 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008852064889588 X-GMAIL-MSGID: 1785008852064889588 Convert the i2c register accesses to utilize the CCI helper library rather than relying on driver-specific functions. There are no intended functional changes. Signed-off-by: Mikhail Rudenko Reviewed-by: Laurent Pinchart --- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/ov4689.c | 361 ++++++++++++++----------------------- 2 files changed, 140 insertions(+), 222 deletions(-) diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 59ee0ca2c978..adf71d2b3b03 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -374,6 +374,7 @@ config VIDEO_OV2740 config VIDEO_OV4689 tristate "OmniVision OV4689 sensor support" depends on GPIOLIB + select V4L2_CCI_I2C help This is a Video4Linux2 sensor-level driver for the OmniVision OV4689 camera. diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 53dcfc8685d4..51a15810cb1d 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -15,45 +15,39 @@ #include #include #include +#include #include #include #include +#define OV4689_REG_CHIP_ID CCI_REG16(0x300a) #define CHIP_ID 0x004688 -#define OV4689_REG_CHIP_ID 0x300a -#define OV4689_XVCLK_FREQ 24000000 - -#define OV4689_REG_CTRL_MODE 0x0100 +#define OV4689_REG_CTRL_MODE CCI_REG8(0x0100) #define OV4689_MODE_SW_STANDBY 0x0 #define OV4689_MODE_STREAMING BIT(0) -#define OV4689_REG_EXPOSURE 0x3500 +#define OV4689_REG_EXPOSURE CCI_REG24(0x3500) #define OV4689_EXPOSURE_MIN 4 #define OV4689_EXPOSURE_STEP 1 #define OV4689_VTS_MAX 0x7fff -#define OV4689_REG_GAIN_H 0x3508 -#define OV4689_REG_GAIN_L 0x3509 +#define OV4689_REG_GAIN_H CCI_REG8(0x3508) +#define OV4689_REG_GAIN_L CCI_REG8(0x3509) #define OV4689_GAIN_H_MASK 0x07 #define OV4689_GAIN_H_SHIFT 8 #define OV4689_GAIN_L_MASK 0xff #define OV4689_GAIN_STEP 1 #define OV4689_GAIN_DEFAULT 0x80 -#define OV4689_REG_TEST_PATTERN 0x5040 +#define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040) #define OV4689_TEST_PATTERN_ENABLE 0x80 #define OV4689_TEST_PATTERN_DISABLE 0x0 -#define OV4689_REG_VTS 0x380e - -#define REG_NULL 0xFFFF - -#define OV4689_REG_VALUE_08BIT 1 -#define OV4689_REG_VALUE_16BIT 2 -#define OV4689_REG_VALUE_24BIT 3 +#define OV4689_REG_VTS CCI_REG16(0x380e) #define OV4689_LANES 4 +#define OV4689_XVCLK_FREQ 24000000 static const char *const ov4689_supply_names[] = { "avdd", /* Analog power */ @@ -61,11 +55,6 @@ static const char *const ov4689_supply_names[] = { "dvdd", /* Digital core power */ }; -struct regval { - u16 addr; - u8 val; -}; - enum ov4689_mode_id { OV4689_MODE_2688_1520 = 0, OV4689_NUM_MODES, @@ -84,11 +73,13 @@ struct ov4689_mode { u32 sensor_height; u32 crop_top; u32 crop_left; - const struct regval *reg_list; + const struct cci_reg_sequence *reg_list; + unsigned int num_regs; }; struct ov4689 { struct i2c_client *client; + struct regmap *regmap; struct clk *xvclk; struct gpio_desc *reset_gpio; struct gpio_desc *pwdn_gpio; @@ -122,125 +113,124 @@ struct ov4689_gain_range { * max_framerate 30fps * mipi_datarate per lane 1008Mbps */ -static const struct regval ov4689_2688x1520_regs[] = { +static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { /* System control*/ - {0x0103, 0x01}, /* SC_CTRL0103 software_reset = 1 */ - {0x3000, 0x20}, /* SC_CMMN_PAD_OEN0 FSIN_output_enable = 1 */ - {0x3021, 0x03}, /* - * SC_CMMN_MISC_CTRL fst_stby_ctr = 0, - * sleep_no_latch_enable = 0 - */ + {CCI_REG8(0x0103), 0x01}, /* SC_CTRL0103 software_reset = 1 */ + {CCI_REG8(0x3000), 0x20}, /* SC_CMMN_PAD_OEN0 FSIN_output_enable = 1 */ + {CCI_REG8(0x3021), 0x03}, /* + * SC_CMMN_MISC_CTRL fst_stby_ctr = 0, + * sleep_no_latch_enable = 0 + */ /* AEC PK */ - {0x3503, 0x04}, /* AEC_MANUAL gain_input_as_sensor_gain_format = 1 */ - {0x352a, 0x08}, /* DIG_GAIN_FRAC_LONG dig_gain_long[14:8] = 0x08 (2x) */ + {CCI_REG8(0x3503), 0x04}, /* AEC_MANUAL gain_input_as_sensor_gain_format = 1 */ + {CCI_REG8(0x352a), 0x08}, /* DIG_GAIN_FRAC_LONG dig_gain_long[14:8] = 0x08 (2x) */ /* ADC and analog control*/ - {0x3603, 0x40}, - {0x3604, 0x02}, - {0x3609, 0x12}, - {0x360c, 0x08}, - {0x360f, 0xe5}, - {0x3608, 0x8f}, - {0x3611, 0x00}, - {0x3613, 0xf7}, - {0x3616, 0x58}, - {0x3619, 0x99}, - {0x361b, 0x60}, - {0x361e, 0x79}, - {0x3634, 0x10}, - {0x3635, 0x10}, - {0x3636, 0x15}, - {0x3646, 0x86}, - {0x364a, 0x0b}, + {CCI_REG8(0x3603), 0x40}, + {CCI_REG8(0x3604), 0x02}, + {CCI_REG8(0x3609), 0x12}, + {CCI_REG8(0x360c), 0x08}, + {CCI_REG8(0x360f), 0xe5}, + {CCI_REG8(0x3608), 0x8f}, + {CCI_REG8(0x3611), 0x00}, + {CCI_REG8(0x3613), 0xf7}, + {CCI_REG8(0x3616), 0x58}, + {CCI_REG8(0x3619), 0x99}, + {CCI_REG8(0x361b), 0x60}, + {CCI_REG8(0x361e), 0x79}, + {CCI_REG8(0x3634), 0x10}, + {CCI_REG8(0x3635), 0x10}, + {CCI_REG8(0x3636), 0x15}, + {CCI_REG8(0x3646), 0x86}, + {CCI_REG8(0x364a), 0x0b}, /* Sensor control */ - {0x3700, 0x17}, - {0x3701, 0x22}, - {0x3703, 0x10}, - {0x370a, 0x37}, - {0x3706, 0x63}, - {0x3709, 0x3c}, - {0x370c, 0x30}, - {0x3710, 0x24}, - {0x3720, 0x28}, - {0x3729, 0x7b}, - {0x372b, 0xbd}, - {0x372c, 0xbc}, - {0x372e, 0x52}, - {0x373c, 0x0e}, - {0x373e, 0x33}, - {0x3743, 0x10}, - {0x3744, 0x88}, - {0x3745, 0xc0}, - {0x374c, 0x00}, - {0x374e, 0x23}, - {0x3751, 0x7b}, - {0x3753, 0xbd}, - {0x3754, 0xbc}, - {0x3756, 0x52}, - {0x376b, 0x20}, - {0x3774, 0x51}, - {0x3776, 0xbd}, - {0x3777, 0xbd}, - {0x3781, 0x18}, - {0x3783, 0x25}, - {0x3798, 0x1b}, + {CCI_REG8(0x3700), 0x17}, + {CCI_REG8(0x3701), 0x22}, + {CCI_REG8(0x3703), 0x10}, + {CCI_REG8(0x370a), 0x37}, + {CCI_REG8(0x3706), 0x63}, + {CCI_REG8(0x3709), 0x3c}, + {CCI_REG8(0x370c), 0x30}, + {CCI_REG8(0x3710), 0x24}, + {CCI_REG8(0x3720), 0x28}, + {CCI_REG8(0x3729), 0x7b}, + {CCI_REG8(0x372b), 0xbd}, + {CCI_REG8(0x372c), 0xbc}, + {CCI_REG8(0x372e), 0x52}, + {CCI_REG8(0x373c), 0x0e}, + {CCI_REG8(0x373e), 0x33}, + {CCI_REG8(0x3743), 0x10}, + {CCI_REG8(0x3744), 0x88}, + {CCI_REG8(0x3745), 0xc0}, + {CCI_REG8(0x374c), 0x00}, + {CCI_REG8(0x374e), 0x23}, + {CCI_REG8(0x3751), 0x7b}, + {CCI_REG8(0x3753), 0xbd}, + {CCI_REG8(0x3754), 0xbc}, + {CCI_REG8(0x3756), 0x52}, + {CCI_REG8(0x376b), 0x20}, + {CCI_REG8(0x3774), 0x51}, + {CCI_REG8(0x3776), 0xbd}, + {CCI_REG8(0x3777), 0xbd}, + {CCI_REG8(0x3781), 0x18}, + {CCI_REG8(0x3783), 0x25}, + {CCI_REG8(0x3798), 0x1b}, /* Timing control */ - {0x3801, 0x08}, /* H_CROP_START_L h_crop_start[7:0] = 0x08 */ - {0x3805, 0x97}, /* H_CROP_END_L h_crop_end[7:0] = 0x97 */ - {0x380c, 0x0a}, /* TIMING_HTS_H hts[14:8] = 0x0a */ - {0x380d, 0x0e}, /* TIMING_HTS_L hts[7:0] = 0x0e */ - {0x3811, 0x08}, /* H_WIN_OFF_L h_win_off[7:0] = 0x08*/ - {0x3813, 0x04}, /* V_WIN_OFF_L v_win_off[7:0] = 0x04 */ - {0x3819, 0x01}, /* VSYNC_END_L vsync_end_point[7:0] = 0x01 */ - {0x3821, 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 */ + {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(0x380c), 0x0a}, /* TIMING_HTS_H hts[14:8] = 0x0a */ + {CCI_REG8(0x380d), 0x0e}, /* TIMING_HTS_L hts[7:0] = 0x0e */ + {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 */ + {CCI_REG8(0x3821), 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 */ /* OTP control */ - {0x3d85, 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1, - * OTP_power_up_load_data_enable = 1, - * OTP_bist_select = 1 (compare with zero) - */ - {0x3d8c, 0x71}, /* OTP_SETTING_STT_ADDRESS_H */ - {0x3d8d, 0xcb}, /* OTP_SETTING_STT_ADDRESS_L */ + {CCI_REG8(0x3d85), 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1, + * OTP_power_up_load_data_enable = 1, + * OTP_bist_select = 1 (compare with zero) + */ + {CCI_REG8(0x3d8c), 0x71}, /* OTP_SETTING_STT_ADDRESS_H */ + {CCI_REG8(0x3d8d), 0xcb}, /* OTP_SETTING_STT_ADDRESS_L */ /* BLC registers*/ - {0x4001, 0x40}, /* DEBUG_MODE */ - {0x401b, 0x00}, /* DEBUG_MODE */ - {0x401d, 0x00}, /* DEBUG_MODE */ - {0x401f, 0x00}, /* DEBUG_MODE */ - {0x4020, 0x00}, /* ANCHOR_LEFT_START_H anchor_left_start[11:8] = 0 */ - {0x4021, 0x10}, /* ANCHOR_LEFT_START_L anchor_left_start[7:0] = 0x10 */ - {0x4022, 0x07}, /* ANCHOR_LEFT_END_H anchor_left_end[11:8] = 0x07 */ - {0x4023, 0xcf}, /* ANCHOR_LEFT_END_L anchor_left_end[7:0] = 0xcf */ - {0x4024, 0x09}, /* ANCHOR_RIGHT_START_H anchor_right_start[11:8] = 0x09 */ - {0x4025, 0x60}, /* ANCHOR_RIGHT_START_L anchor_right_start[7:0] = 0x60 */ - {0x4026, 0x09}, /* ANCHOR_RIGHT_END_H anchor_right_end[11:8] = 0x09 */ - {0x4027, 0x6f}, /* ANCHOR_RIGHT_END_L anchor_right_end[7:0] = 0x6f */ + {CCI_REG8(0x4001), 0x40}, /* DEBUG_MODE */ + {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 */ - {0x4500, 0x6c}, /* ADC_SYNC_CTRL */ - {0x4503, 0x01}, /* ADC_SYNC_CTRL */ + {CCI_REG8(0x4500), 0x6c}, /* ADC_SYNC_CTRL */ + {CCI_REG8(0x4503), 0x01}, /* ADC_SYNC_CTRL */ /* VFIFO */ - {0x4601, 0xa7}, /* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ + {CCI_REG8(0x4601), 0xa7}, /* VFIFO_CTRL_01 r_vfifo_read_start[7:0] = 0xa7 */ /* Temperature monitor */ - {0x4d00, 0x04}, /* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ - {0x4d01, 0x42}, /* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */ - {0x4d02, 0xd1}, /* TPM_CTRL_02 tpm_offset[31:24] = 0xd1 */ - {0x4d03, 0x93}, /* TPM_CTRL_03 tpm_offset[23:16] = 0x93 */ - {0x4d04, 0xf5}, /* TPM_CTRL_04 tpm_offset[15:8] = 0xf5 */ - {0x4d05, 0xc1}, /* TPM_CTRL_05 tpm_offset[7:0] = 0xc1 */ + {CCI_REG8(0x4d00), 0x04}, /* TPM_CTRL_00 tmp_slope[15:8] = 0x04 */ + {CCI_REG8(0x4d01), 0x42}, /* TPM_CTRL_01 tmp_slope[7:0] = 0x42 */ + {CCI_REG8(0x4d02), 0xd1}, /* TPM_CTRL_02 tpm_offset[31:24] = 0xd1 */ + {CCI_REG8(0x4d03), 0x93}, /* TPM_CTRL_03 tpm_offset[23:16] = 0x93 */ + {CCI_REG8(0x4d04), 0xf5}, /* TPM_CTRL_04 tpm_offset[15:8] = 0xf5 */ + {CCI_REG8(0x4d05), 0xc1}, /* TPM_CTRL_05 tpm_offset[7:0] = 0xc1 */ /* pre-ISP control */ - {0x5050, 0x0c}, /* DEBUG_MODE */ + {CCI_REG8(0x5050), 0x0c}, /* DEBUG_MODE */ /* OTP-DPC control */ - {0x5501, 0x10}, /* OTP_DPC_START_L otp_start_address[7:0] = 0x10 */ - {0x5503, 0x0f}, /* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ - {REG_NULL, 0x00}, + {CCI_REG8(0x5501), 0x10}, /* OTP_DPC_START_L otp_start_address[7:0] = 0x10 */ + {CCI_REG8(0x5503), 0x0f}, /* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ }; static const struct ov4689_mode supported_modes[] = { @@ -258,6 +248,7 @@ static const struct ov4689_mode supported_modes[] = { .vts_def = 1554, .pixel_rate = 480000000, .reg_list = ov4689_2688x1520_regs, + .num_regs = ARRAY_SIZE(ov4689_2688x1520_regs), }, }; @@ -310,83 +301,6 @@ static const struct ov4689_gain_range ov4689_gain_ranges[] = { }, }; -/* Write registers up to 4 at a time */ -static int ov4689_write_reg(struct i2c_client *client, u16 reg, u32 len, - u32 val) -{ - u32 buf_i, val_i; - __be32 val_be; - u8 *val_p; - u8 buf[6]; - - if (len > 4) - return -EINVAL; - - buf[0] = reg >> 8; - buf[1] = reg & 0xff; - - val_be = cpu_to_be32(val); - val_p = (u8 *)&val_be; - buf_i = 2; - val_i = 4 - len; - - while (val_i < 4) - buf[buf_i++] = val_p[val_i++]; - - if (i2c_master_send(client, buf, len + 2) != len + 2) - return -EIO; - - return 0; -} - -static int ov4689_write_array(struct i2c_client *client, - const struct regval *regs) -{ - int ret = 0; - u32 i; - - for (i = 0; ret == 0 && regs[i].addr != REG_NULL; i++) - ret = ov4689_write_reg(client, regs[i].addr, - OV4689_REG_VALUE_08BIT, regs[i].val); - - return ret; -} - -/* Read registers up to 4 at a time */ -static int ov4689_read_reg(struct i2c_client *client, u16 reg, unsigned int len, - u32 *val) -{ - __be16 reg_addr_be = cpu_to_be16(reg); - struct i2c_msg msgs[2]; - __be32 data_be = 0; - u8 *data_be_p; - int ret; - - if (len > 4 || !len) - return -EINVAL; - - data_be_p = (u8 *)&data_be; - /* Write register address */ - msgs[0].addr = client->addr; - msgs[0].flags = 0; - msgs[0].len = 2; - msgs[0].buf = (u8 *)®_addr_be; - - /* Read data from register */ - msgs[1].addr = client->addr; - msgs[1].flags = I2C_M_RD; - msgs[1].len = len; - msgs[1].buf = &data_be_p[4 - len]; - - ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); - if (ret != ARRAY_SIZE(msgs)) - return -EIO; - - *val = be32_to_cpu(data_be); - - return 0; -} - static void ov4689_fill_fmt(const struct ov4689_mode *mode, struct v4l2_mbus_framefmt *fmt) { @@ -460,8 +374,8 @@ static int ov4689_enable_test_pattern(struct ov4689 *ov4689, u32 pattern) else val = OV4689_TEST_PATTERN_DISABLE; - return ov4689_write_reg(ov4689->client, OV4689_REG_TEST_PATTERN, - OV4689_REG_VALUE_08BIT, val); + return cci_write(ov4689->regmap, OV4689_REG_TEST_PATTERN, + val, NULL); } static int ov4689_get_selection(struct v4l2_subdev *sd, @@ -505,8 +419,10 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) if (ret < 0) goto unlock_and_return; - ret = ov4689_write_array(ov4689->client, - ov4689->cur_mode->reg_list); + ret = cci_multi_reg_write(ov4689->regmap, + ov4689->cur_mode->reg_list, + ov4689->cur_mode->num_regs, + NULL); if (ret) { pm_runtime_put(&client->dev); goto unlock_and_return; @@ -518,17 +434,15 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; } - ret = ov4689_write_reg(ov4689->client, OV4689_REG_CTRL_MODE, - OV4689_REG_VALUE_08BIT, - OV4689_MODE_STREAMING); + ret = cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, + OV4689_MODE_STREAMING, NULL); if (ret) { pm_runtime_put(&client->dev); goto unlock_and_return; } } else { - ov4689_write_reg(ov4689->client, OV4689_REG_CTRL_MODE, - OV4689_REG_VALUE_08BIT, - OV4689_MODE_SW_STANDBY); + cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, + OV4689_MODE_SW_STANDBY, NULL); pm_runtime_put(&client->dev); } @@ -693,26 +607,23 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case V4L2_CID_EXPOSURE: /* 4 least significant bits of exposure are fractional part */ - ret = ov4689_write_reg(ov4689->client, OV4689_REG_EXPOSURE, - OV4689_REG_VALUE_24BIT, ctrl->val << 4); + ret = cci_write(ov4689->regmap, OV4689_REG_EXPOSURE, + ctrl->val << 4, NULL); break; case V4L2_CID_ANALOGUE_GAIN: ret = ov4689_map_gain(ov4689, ctrl->val, &sensor_gain); - ret = ret ?: - ov4689_write_reg(ov4689->client, OV4689_REG_GAIN_H, - OV4689_REG_VALUE_08BIT, - (sensor_gain >> OV4689_GAIN_H_SHIFT) & - OV4689_GAIN_H_MASK); - ret = ret ?: - ov4689_write_reg(ov4689->client, OV4689_REG_GAIN_L, - OV4689_REG_VALUE_08BIT, - sensor_gain & OV4689_GAIN_L_MASK); + cci_write(ov4689->regmap, OV4689_REG_GAIN_H, + (sensor_gain >> OV4689_GAIN_H_SHIFT) & + OV4689_GAIN_H_MASK, &ret); + + cci_write(ov4689->regmap, OV4689_REG_GAIN_L, + sensor_gain & OV4689_GAIN_L_MASK, + &ret); break; case V4L2_CID_VBLANK: - ret = ov4689_write_reg(ov4689->client, OV4689_REG_VTS, - OV4689_REG_VALUE_16BIT, - ctrl->val + ov4689->cur_mode->height); + ret = cci_write(ov4689->regmap, OV4689_REG_VTS, + ctrl->val + ov4689->cur_mode->height, NULL); break; case V4L2_CID_TEST_PATTERN: ret = ov4689_enable_test_pattern(ov4689, ctrl->val); @@ -817,18 +728,17 @@ static int ov4689_check_sensor_id(struct ov4689 *ov4689, struct i2c_client *client) { struct device *dev = &ov4689->client->dev; - u32 id = 0; + u64 id = 0; int ret; - ret = ov4689_read_reg(client, OV4689_REG_CHIP_ID, - OV4689_REG_VALUE_16BIT, &id); + ret = cci_read(ov4689->regmap, OV4689_REG_CHIP_ID, &id, NULL); if (ret) { dev_err(dev, "Cannot read sensor ID\n"); return ret; } if (id != CHIP_ID) { - dev_err(dev, "Unexpected sensor ID %06x, expected %06x\n", + dev_err(dev, "Unexpected sensor ID %06llx, expected %06x\n", id, CHIP_ID); return -ENODEV; } @@ -938,6 +848,13 @@ static int ov4689_probe(struct i2c_client *client) return -EINVAL; } + ov4689->regmap = devm_cci_regmap_init_i2c(client, 16); + if (IS_ERR(ov4689->regmap)) { + ret = PTR_ERR(ov4689->regmap); + dev_err(dev, "failed to initialize CCI: %d\n", ret); + return ret; + } + ov4689->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); if (IS_ERR(ov4689->reset_gpio)) { From patchwork Mon Dec 11 17:50:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176841 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230303vqy; Mon, 11 Dec 2023 09:51:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHSfrNXQwGSNHMi2XwuUG94TWC9ImEwZzOJpG7PYfRDCunV0NIef0co9dtIS0XzJ8OuadI X-Received: by 2002:a17:90a:3dc5:b0:285:9ec0:892a with SMTP id i63-20020a17090a3dc500b002859ec0892amr2020910pjc.33.1702317084076; Mon, 11 Dec 2023 09:51:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317084; cv=none; d=google.com; s=arc-20160816; b=bvfPLpNXDKioI0g2743s70+NMGzcqVI+nmJY+BXtk2UpicKxLuagyBqP8nt6/q1kI/ 4is0JMiu0ghe91SDZ60O6WOB9tPpsBFWSQx8a7UaS1OjLryGGgs7ATW+Vkd1Ju2Ddm33 KeHLqKaWjDuMDfORnvdyEwaCDDNWLveeugUFo6wncj6jmqWZmByKop7fDK3H4ohC8FRT q58evz26z/HoykzVz9j8gUGuskr/PTIECbbkMj6a8eooBQEbiscCEZq+zWvRpWoBvdhm kOFmJRgy8mi8b3TBa3v/fWFOIBsU4HK8cx7XZ1pgNCqsFEKJQr7rtEqM45nMZOO48wBm RijQ== 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=Jt3HgKogia1ukkriZaYijzD0Deb4LMT0CLdQl1sk2DA=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=jDfu9NUpxNMRqY8ZQeZKRPnPEFL6WE8Dbo5LxGMbKPETI+43rsXRGVS1/tlPjjhPVW zSTeryibvyt7g00t5VjLghN7Briw1FOIwoLLVY2qaGoKa1FeGsrxevQAsyjy1yfMcqk9 BKR9LDyipRLEG1aLH4433NUVGSMFZHnRXl5ZQb4ac7Hp4Pk48eahUyTaU0hTWfRWV44B vx1MdYKVBNA7YXlS+D1cOCZoKws02ZAPsPHy6xxP9Q+VM1GQqAnZrTyq7txX5G67Hs3q 8BO8nG+26m9l3VtH24+u5PL2uZBQvX3WYVsRCJB0GPENfmk8Y4VLf+4Kllf5eJyxZ/B9 viUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hHPlHfyw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id iq13-20020a17090afb4d00b0028665a20c0asi6457916pjb.4.2023.12.11.09.51.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hHPlHfyw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 89E7180564BD; Mon, 11 Dec 2023 09:51:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345113AbjLKRvH (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345103AbjLKRup (ORCPT ); Mon, 11 Dec 2023 12:50:45 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34AFF93; Mon, 11 Dec 2023 09:50:50 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-50be4f03b06so4519835e87.0; Mon, 11 Dec 2023 09:50:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317047; x=1702921847; 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=Jt3HgKogia1ukkriZaYijzD0Deb4LMT0CLdQl1sk2DA=; b=hHPlHfyw0AzvWUbPe8NBRnzUX0bJ2b0jN/eXDf5ikcbLDplZlZkaNcBuMnx5R0RiN7 n8QT/9aOgZ/JwfQ/6fwM4E6KquAdwk6FjS1KapIrQ5T3tAhBNoWJL7JZgo+s7TpbHGq7 fun6BBDgGSN5UFf8p7Jl/XVKRM4j5DGfUSKh+pDfVV0xWb4+gZe9GmQY/wZA2rqUO6Gt 75JnzSVWloqDEgg7CMLB1YPf9/4soNSu+bi8dcizsA1QNE2enHfoAUw8Ytm1YUOH6/U+ 7gH13IcpJtEs4DkdEO2AmPABprukI0GRoRdL9yaJCkmGHwjZPXkbwCqHhSIqwCGeocLU 3G2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317047; x=1702921847; 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=Jt3HgKogia1ukkriZaYijzD0Deb4LMT0CLdQl1sk2DA=; b=uwZ3f+Iim/pnlyckCHXK7D4VPQDIZGoORRbdho2rr7gvGPVayyBCIIfV85M0v5FH6E vQG2DQ4beOGHMBDOi6/Ahtzm7z4oBcXw8CvrlxLtxrXc9wFJ2H5yGYzm515+/hOevO30 fBvZw/FWjL5cLGLpk7nHHVY7b9LrfaYnhfDrdBdwoPP0oSwRt+zjbIZJRx4x04iILDEm JATljndpdjGEM0naUziacI/gSuVtG0lcy+W0j+khnl06lALZut06M+xIsPuHCu+SLldJ AtD74XitGRydWgp6q//f13HyTYs0aHvyWsYXxlWoWfcI1vF5qMiLYgdkvF3PhaLI4Zsv GE0g== X-Gm-Message-State: AOJu0YznVG4IdJ/iNLH3aEhVjLodC4u6mOy9irNVqPrA37TWM/lrmS6B 9XS37Cwhc8PqMG3sguc1H5w0JJCXlIxiHOVN X-Received: by 2002:ac2:5e3a:0:b0:50b:f30b:534d with SMTP id o26-20020ac25e3a000000b0050bf30b534dmr1323845lfg.57.1702317047409; Mon, 11 Dec 2023 09:50:47 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id i24-20020a0565123e1800b0050bfdc711b8sm1088996lfv.15.2023.12.11.09.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:46 -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 04/19] media: i2c: ov4689: Remove i2c_client from ov4689 struct Date: Mon, 11 Dec 2023 20:50:07 +0300 Message-ID: <20231211175023.1680247-5-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:51:22 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008838532478617 X-GMAIL-MSGID: 1785008838532478617 The 'client' field within the 'ov4689' structure is solely used to access its 'dev' member. This commit removes the 'client' field and directly stores a pointer to the 'struct device'. Signed-off-by: Mikhail Rudenko Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 51a15810cb1d..8c120d7f7830 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -78,7 +78,7 @@ struct ov4689_mode { }; struct ov4689 { - struct i2c_client *client; + struct device *dev; struct regmap *regmap; struct clk *xvclk; struct gpio_desc *reset_gpio; @@ -409,13 +409,13 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, static int ov4689_s_stream(struct v4l2_subdev *sd, int on) { struct ov4689 *ov4689 = to_ov4689(sd); - struct i2c_client *client = ov4689->client; + struct device *dev = ov4689->dev; int ret = 0; mutex_lock(&ov4689->mutex); if (on) { - ret = pm_runtime_resume_and_get(&client->dev); + ret = pm_runtime_resume_and_get(dev); if (ret < 0) goto unlock_and_return; @@ -424,26 +424,26 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL); if (ret) { - pm_runtime_put(&client->dev); + pm_runtime_put(dev); goto unlock_and_return; } ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler); if (ret) { - pm_runtime_put(&client->dev); + pm_runtime_put(dev); goto unlock_and_return; } ret = cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, OV4689_MODE_STREAMING, NULL); if (ret) { - pm_runtime_put(&client->dev); + pm_runtime_put(dev); goto unlock_and_return; } } else { cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, OV4689_MODE_SW_STANDBY, NULL); - pm_runtime_put(&client->dev); + pm_runtime_put(dev); } unlock_and_return: @@ -557,7 +557,6 @@ static const struct v4l2_subdev_ops ov4689_subdev_ops = { */ static int ov4689_map_gain(struct ov4689 *ov4689, int logical_gain, int *result) { - const struct device *dev = &ov4689->client->dev; const struct ov4689_gain_range *range; unsigned int n; @@ -568,7 +567,8 @@ static int ov4689_map_gain(struct ov4689 *ov4689, int logical_gain, int *result) } if (n == ARRAY_SIZE(ov4689_gain_ranges)) { - dev_warn_ratelimited(dev, "no mapping found for gain %d\n", + dev_warn_ratelimited(ov4689->dev, + "no mapping found for gain %d\n", logical_gain); return -EINVAL; } @@ -584,7 +584,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) { struct ov4689 *ov4689 = container_of(ctrl->handler, struct ov4689, ctrl_handler); - struct i2c_client *client = ov4689->client; + struct device *dev = ov4689->dev; int sensor_gain; s64 max_expo; int ret; @@ -601,7 +601,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) break; } - if (!pm_runtime_get_if_in_use(&client->dev)) + if (!pm_runtime_get_if_in_use(dev)) return 0; switch (ctrl->id) { @@ -629,13 +629,13 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) ret = ov4689_enable_test_pattern(ov4689, ctrl->val); break; default: - dev_warn(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n", + dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", __func__, ctrl->id, ctrl->val); ret = -EINVAL; break; } - pm_runtime_put(&client->dev); + pm_runtime_put(dev); return ret; } @@ -700,8 +700,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) if (handler->error) { ret = handler->error; - dev_err(&ov4689->client->dev, "Failed to init controls(%d)\n", - ret); + dev_err(ov4689->dev, "Failed to init controls(%d)\n", ret); goto err_free_handler; } @@ -727,7 +726,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) static int ov4689_check_sensor_id(struct ov4689 *ov4689, struct i2c_client *client) { - struct device *dev = &ov4689->client->dev; + struct device *dev = ov4689->dev; u64 id = 0; int ret; @@ -755,7 +754,7 @@ static int ov4689_configure_regulators(struct ov4689 *ov4689) for (i = 0; i < ARRAY_SIZE(ov4689_supply_names); i++) ov4689->supplies[i].supply = ov4689_supply_names[i]; - return devm_regulator_bulk_get(&ov4689->client->dev, + return devm_regulator_bulk_get(ov4689->dev, ARRAY_SIZE(ov4689_supply_names), ov4689->supplies); } @@ -824,7 +823,8 @@ static int ov4689_probe(struct i2c_client *client) if (!ov4689) return -ENOMEM; - ov4689->client = client; + ov4689->dev = dev; + ov4689->cur_mode = &supported_modes[OV4689_MODE_2688_1520]; ov4689->xvclk = devm_clk_get_optional(dev, NULL); From patchwork Mon Dec 11 17:50:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230286vqy; Mon, 11 Dec 2023 09:51:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IESsdP+WCZo1soRJ9kGKXnjfe5+iakHAi6wcA/OD6gSsgDcSQl2VljYNSFBIB73fXttCtDs X-Received: by 2002:a05:6a00:2d9e:b0:6ce:2731:5f70 with SMTP id fb30-20020a056a002d9e00b006ce27315f70mr2495945pfb.47.1702317081028; Mon, 11 Dec 2023 09:51:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317081; cv=none; d=google.com; s=arc-20160816; b=tw8QPRxg/TnNgJkkFvFb+msgLVvpHzX+miSo+RsjQSoW5CWIi8GtoUFJV7YSKu9zs4 R/e+qcW5mGL84TfI/AIlGTb/O7FQz8/prHtak6P6s/jTLu5G1YZcfoF8ioOiz/5w5eVT IsnxtYs02Ne1OCzFYvsSSRpKUwXY4VMZiLk4TW6IuKweeDKbZbaxJd7xCsneF8xeBGBu +zZd/46j4/VCZTG+PU7woermF5ZkuGnyCeUVD1tTXH+yzYL1Eq4UisfHgsp4oLuYHMlL pDCsBZCF63MYWu/9qHGfy5UADU19XIBCDWWPsxUxu2gtS9DpoeWvvPE2n24SPqvbZWZY tPhQ== 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=e4fte2YHRSrHHN42OBWruBtaIGZ/SFtVFuhUHEuhcX8=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=cNUzJWASUyIH/Q2KndBC68/lgQOF6hpuNqVNrhiOWdEVvdLYC0hMDWbnjvT8sxOFmd rY3LDf69nRJ/uVTAluac0AMwqFxFC8RjonkgmqhtHxPcZ87p4/JwetpJiCzHgMd+U7ms CKT8+1KKsEUheHWWNFfltW4p5h3r9QkDXISNk7A7jiOnunKkDn8DO8U/SXUWWrxhw0U1 3F1JVrpnRGnHS31MAWcVrrSStwgOMRE7iK7GVfZ3u9erVgm4dmrA82eUtcZllYYTRtem WQ//vpYOFuY8RkS+xCwugzNZkY9gzxFMPimgBenaitH6o13+DWKEDcmKbzwHheZqIvOO jpEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=IqFLlH4h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c29-20020a631c1d000000b005657ba564bdsi6161300pgc.826.2023.12.11.09.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=IqFLlH4h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 9A02A80564BE; Mon, 11 Dec 2023 09:51:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344965AbjLKRvC (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345104AbjLKRup (ORCPT ); Mon, 11 Dec 2023 12:50:45 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA29AD0; Mon, 11 Dec 2023 09:50:51 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50bf1e32571so5581961e87.2; Mon, 11 Dec 2023 09:50:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317049; x=1702921849; 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=e4fte2YHRSrHHN42OBWruBtaIGZ/SFtVFuhUHEuhcX8=; b=IqFLlH4hfcQN+nVLz+K238zJs287ZHvR6ddocANW7MKwC1bTrAp5lE/ASgXEyoUvQl oqEn1zXb5ta+5RjuYRJYTslbWIF26fWJwIcL6ap/MP/12dMZ0yHjQWgvRgygRFfwRMlX AYglRkXztW9Xk/JY6ZzssxWLtktBFOMc0oGesNzaD81QSLZ6Yr1FIV9YlZJ4ZROc6PaC 5Naf2893cI63+ICan4gDM8BnyZ8e1tGTkQzOVOrC0/B/UPw8Y34mU1ow4s0Idtw0hdoO 1rQd0Lr1voyFVAixcFPoObmOuywWf0qbZBlGPd6L/T9WI18C7t0ShOyOvhAhzYTqiBWZ hKvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317049; x=1702921849; 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=e4fte2YHRSrHHN42OBWruBtaIGZ/SFtVFuhUHEuhcX8=; b=NtReQpCWkpf0gtZGwIPsPKvbmE8UgIlP1rvFea3DF+R4WWiw1xFsrmOLXN7T4yJYVg QRlEZkXI/q5UZP0zLiVgWGdO6vzYxSEEgwH4r2rulSMBTtEd8qqAJj6/ecHu+Ds1/WY1 XlrUgCh+6mxSXthzasazIq/RBhsFh/+Czf8QFUN/G/33U9rroJf6SDzK8dON87ILJUle CP7M0R5c9NqwN9nRW+9LNjJ4feUAwAogal/O+UoaJnXwZmu0+gpKfOniIesJTPbxh+6C w7J3J0BmmqZSLAtD9tdbyyNRWoK13Za+qHLQEauB4LfWVN4wSbEe3fCoPm0sjhcDiTyT pxew== X-Gm-Message-State: AOJu0YxuayilUJAFgHP0X0XA3uephF625qxtVnmVo9znGjKcLHwTbxfc IDGX91YZ6XrJV/IGMnELR3iNUtgtXch1/ozV X-Received: by 2002:ac2:5328:0:b0:50d:ff76:61ee with SMTP id f8-20020ac25328000000b0050dff7661eemr767800lfh.134.1702317049431; Mon, 11 Dec 2023 09:50:49 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id k4-20020a05651210c400b0050bef21a012sm1141582lfg.191.2023.12.11.09.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:48 -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 05/19] media: i2c: ov4689: Refactor ov4689_set_ctrl Date: Mon, 11 Dec 2023 20:50:08 +0300 Message-ID: <20231211175023.1680247-6-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:51:19 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008835514968282 X-GMAIL-MSGID: 1785008835514968282 Introduces local variables for regmap and the control value within the ov4689_set_ctrl function. This adjustment eliminates repetition within the function. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 8c120d7f7830..42700ecfbe0e 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -584,7 +584,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) { struct ov4689 *ov4689 = container_of(ctrl->handler, struct ov4689, ctrl_handler); + struct regmap *regmap = ov4689->regmap; struct device *dev = ov4689->dev; + s32 val = ctrl->val; int sensor_gain; s64 max_expo; int ret; @@ -593,7 +595,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case V4L2_CID_VBLANK: /* Update max exposure while meeting expected vblanking */ - max_expo = ov4689->cur_mode->height + ctrl->val - 4; + max_expo = ov4689->cur_mode->height + val - 4; __v4l2_ctrl_modify_range(ov4689->exposure, ov4689->exposure->minimum, max_expo, ov4689->exposure->step, @@ -607,36 +609,34 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case V4L2_CID_EXPOSURE: /* 4 least significant bits of exposure are fractional part */ - ret = cci_write(ov4689->regmap, OV4689_REG_EXPOSURE, - ctrl->val << 4, NULL); + cci_write(regmap, OV4689_REG_EXPOSURE, val << 4, &ret); break; case V4L2_CID_ANALOGUE_GAIN: - ret = ov4689_map_gain(ov4689, ctrl->val, &sensor_gain); + ret = ov4689_map_gain(ov4689, val, &sensor_gain); - cci_write(ov4689->regmap, OV4689_REG_GAIN_H, + cci_write(regmap, OV4689_REG_GAIN_H, (sensor_gain >> OV4689_GAIN_H_SHIFT) & OV4689_GAIN_H_MASK, &ret); - cci_write(ov4689->regmap, OV4689_REG_GAIN_L, + cci_write(regmap, OV4689_REG_GAIN_L, sensor_gain & OV4689_GAIN_L_MASK, &ret); break; case V4L2_CID_VBLANK: - ret = cci_write(ov4689->regmap, OV4689_REG_VTS, - ctrl->val + ov4689->cur_mode->height, NULL); + cci_write(regmap, OV4689_REG_VTS, + val + ov4689->cur_mode->height, &ret); break; case V4L2_CID_TEST_PATTERN: - ret = ov4689_enable_test_pattern(ov4689, ctrl->val); + ret = ov4689_enable_test_pattern(ov4689, val); break; default: dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", - __func__, ctrl->id, ctrl->val); + __func__, ctrl->id, val); ret = -EINVAL; break; } pm_runtime_put(dev); - return ret; } From patchwork Mon Dec 11 17:50:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176876 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7269655vqy; Mon, 11 Dec 2023 10:57:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IFci8Y3hPHjeogVXa1GuDhMCr79d1oxNdKSNtKz1xy9hciMYVNe2MIpg2niHCWIhJ4TRuwh X-Received: by 2002:a05:6a00:460f:b0:6ce:4866:f388 with SMTP id ko15-20020a056a00460f00b006ce4866f388mr2861430pfb.24.1702321031324; Mon, 11 Dec 2023 10:57:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702321031; cv=none; d=google.com; s=arc-20160816; b=vpAa/ByOH/IRXMU0wzVKBWKrxTMdCpgdI6iwYp1T7Z0zKe65MyfLOFbDPLnVoKOknN VLvNVILp9FwMs+u/S4kTP+OdMyJBCjxRoKdAXUsGXFFeisSSPepjA2Q2c+ywZw+ctC+V RyRqycFvVlxaXtb7lupT32npled2ausEK/lwJXgrhM81d1V7sa/pSDusyAfOQoO0wMZN BGweJwpmPXeRxO/tbt+MyIshdL7vxC3nrHcnEqEwgmc+AOWIrrJ9HSI6Qg2L22sE8kz7 C3DuHCyvwJUff7mvjEnWuay+bpc/yQi7h6ePROW6XTK9F16+e1gP21sGwwUHedyMR1h7 WIJQ== 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=vPJtRqKNEOg0N5Ytto1LWF17klynRrR8m/oK9rsOY4A=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=lQxvmHsRr19TTR8vijAE8tjeSESoVc+pVaEWxCX88+FCrzoKrbg+t+pGYuyas2hJaD XFMlvlSQnD57eS9e0HlOvLyrIZzYRzVuT0uGzwPWoAOLypc0X/4eHjiLkUNxqOQyXdTq nbL32p5O+2KrO3h43/bEbbPcPyvTYLnnFzLhhS03la6g/PpW6tClJ9goTdqNEcG5IFBU 9oLu+KRzab3dr0Pa7t11pu43jR8Pjdrj0XEVWNVnPNxxU267LHuag+qYRQ7rgXGV2/i6 /ulMT+1FtB5gn/SAbbl8FFlkkVD9p33gWzdyuuWr/s44VSu3r/IqjB0HuklajVYkWUPh sJJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="hg/i0+kd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id fi26-20020a056a00399a00b006cb8cbc9bb8si6498860pfb.284.2023.12.11.10.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 10:57:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="hg/i0+kd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 9144E80BEDF0; Mon, 11 Dec 2023 10:57:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344632AbjLKS4o (ORCPT + 99 others); Mon, 11 Dec 2023 13:56:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345116AbjLKRuq (ORCPT ); Mon, 11 Dec 2023 12:50:46 -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 BFA9BC7; Mon, 11 Dec 2023 09:50:52 -0800 (PST) Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2c9ea37ac87so65520551fa.3; Mon, 11 Dec 2023 09:50:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317050; x=1702921850; 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=vPJtRqKNEOg0N5Ytto1LWF17klynRrR8m/oK9rsOY4A=; b=hg/i0+kdPHNu4Q1yaFRuUqpcqAmXiphnA43I6syZ/t3dKBwF5WDgXypTfxuTC9CB/g 4c60x43Z7nQVGftfs+kIiYXGLStgTPpFvduztz5Al+x8ZINUQKBu2Lu9IPCRZINMjjY0 6rw35P5UUifAZqI03SufKRWGB6BAw/JAVQwx71HAoCBympbN+qKOAXp1tvW4fyWKK+GK ARZn305BwYElt3tH3mk/+4hYxGseF+SrZijo7UV9Lf5a8pyQKdoTi99JQukev4B6FAbQ wOcG45M2qKBMxebAi7B/bRttzcQfYCiiQFZ4oG9VoVDaNYi81m9Ox/SqlUL1R2aH9aUh vAdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317050; x=1702921850; 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=vPJtRqKNEOg0N5Ytto1LWF17klynRrR8m/oK9rsOY4A=; b=RcUT+AeH5QnwMiCw8o6/EY9f7aD6tkAGhcbMLuqZXWU4NwQgAWrCjBEINsKQYQb6sq dq3ON0zZfEuJl7f4As2odd5+FpcY14RqfPRALBxiTEgNEae+G2XvDSEr3NYpTyPz7CDr iQgL0hI5EtGZ+8VXYKNVM2UbtB7z7Xw5c5uNTgS3o4Y54povhTKdiTK6fZD5RFDP0Onn 8QPZMc/hWm2APRgYbDQV//46k5LD6nbPd75xRGeS+uZfNktQG4kIZ22F+KDSp0oZnCAp Y3+r5gy+P2ZKzA3Yv9qYvglw6YpDznpdYs5sXmR99NDY/eHb3ealafDefof7JWIxI0af 6Jyg== X-Gm-Message-State: AOJu0YyFifiEAXI2rbr0K8qlUhpEHQrGfQ7fujQJm9UlgGm+tC6sYM/8 cyMZODGXl8YcSW48PJbRf/xCcnp68i2ZivNr X-Received: by 2002:a2e:a907:0:b0:2cc:2751:a6b7 with SMTP id j7-20020a2ea907000000b002cc2751a6b7mr815528ljq.21.1702317050576; Mon, 11 Dec 2023 09:50:50 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id h23-20020a2ea497000000b002c9c21d01c2sm1261702lji.101.2023.12.11.09.50.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:50 -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 06/19] media: i2c: ov4689: Set gain in one 16 bit write Date: Mon, 11 Dec 2023 20:50:09 +0300 Message-ID: <20231211175023.1680247-7-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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 11 Dec 2023 10:57:08 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785010129839566327 X-GMAIL-MSGID: 1785012977817653355 According to the datasheet, bits 0-7 of the AEC LONG GAIN register (0x3508) map to bits 8-15 of the gain value and no masking is required. Thus set analogue gain in a single 16-bit write instead of two 8-bit writes. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 42700ecfbe0e..5392f650960c 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -32,11 +32,7 @@ #define OV4689_EXPOSURE_STEP 1 #define OV4689_VTS_MAX 0x7fff -#define OV4689_REG_GAIN_H CCI_REG8(0x3508) -#define OV4689_REG_GAIN_L CCI_REG8(0x3509) -#define OV4689_GAIN_H_MASK 0x07 -#define OV4689_GAIN_H_SHIFT 8 -#define OV4689_GAIN_L_MASK 0xff +#define OV4689_REG_GAIN CCI_REG16(0x3508) #define OV4689_GAIN_STEP 1 #define OV4689_GAIN_DEFAULT 0x80 @@ -613,14 +609,7 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) break; case V4L2_CID_ANALOGUE_GAIN: ret = ov4689_map_gain(ov4689, val, &sensor_gain); - - cci_write(regmap, OV4689_REG_GAIN_H, - (sensor_gain >> OV4689_GAIN_H_SHIFT) & - OV4689_GAIN_H_MASK, &ret); - - cci_write(regmap, OV4689_REG_GAIN_L, - sensor_gain & OV4689_GAIN_L_MASK, - &ret); + cci_write(regmap, OV4689_REG_GAIN, sensor_gain, &ret); break; case V4L2_CID_VBLANK: cci_write(regmap, OV4689_REG_VTS, From patchwork Mon Dec 11 17:50:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230335vqy; Mon, 11 Dec 2023 09:51:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGhvVuFfJjENk8ME9ySNcfZ/Os+3HzvNcJzSZ/wJPO5Z3JnFePjwf8PB8el5R+AYXZPjf7t X-Received: by 2002:a05:6a00:21c3:b0:68f:c078:b0c9 with SMTP id t3-20020a056a0021c300b0068fc078b0c9mr4753794pfj.11.1702317088224; Mon, 11 Dec 2023 09:51:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317088; cv=none; d=google.com; s=arc-20160816; b=PhME7vu4Lzy39/4DuY+G+qQG2qEq8bhTWUjfPwGzCDq94TOOnSpSA4Ob02+07k9Q5v gFkM9r9+0ysRCp/ud8TNXgV0UoSHro362x5zm0UVK4su8ELHqKUbGD3/Of4G6vY/LASW DlLvfb+bJEwM51f/xpvG+2ptn0/YdDWPWeHYQGXuHnBVvP/90TkhpfAXbetcZzeMuHjf aqdy/ofBSGCmIwvrT3JihIp3o64EocrX2ShhtuNqXsYzGoVBJ0Ts4oe4pqeXnQ9W8ZDT 2M5YAbUKxOGDbZiy93GMXpddbHE/Y1d2yhuxBBqcrUg4j64k8UJontlDrvrto+omTvLb gVGA== 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=wNY858fptfzHBCj2MypAYw/Wf6IpNmLWS0ucyNJkm2A=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=cQsISFJUa0jJFNXa7nRjn5kuDKxYR4k26GA1kbrsE+KZjfiTV51UDZogSJq38lSMiq 9yjAvEjJCMGkLc+4ncIWVfI1KuFtV1afZAXJs2s+cM5wLTXBb4U2sPkLKeapWd5/MVn+ CnTJiPHC+abQP25zPcb08SYVnAGu1JVKrmVhJiNDz7hbmBRdJGv+5oalyQVkpMOiWHuR VYYC4cTRwfUCG0wNkzUzOfys1dNfFIpiP1JBVtEzd0H0knJd9sCov6E+M4RDfQCxHRDK Ash1nNXLFonv1TSTAHoMZyo5nXV6TBFz0cvbMS4vWcCGqSu4Bb7RMygy3uTlQ7NUpwhK 4lgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eWLScynt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t21-20020a056a0021d500b006ced275c406si6260782pfj.309.2023.12.11.09.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=eWLScynt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 1C3E2805F94C; Mon, 11 Dec 2023 09:51:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345126AbjLKRvK (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344797AbjLKRus (ORCPT ); Mon, 11 Dec 2023 12:50:48 -0500 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21ACFD8; Mon, 11 Dec 2023 09:50:54 -0800 (PST) Received: by mail-lj1-x22c.google.com with SMTP id 38308e7fff4ca-2c9f7fe6623so59317491fa.3; Mon, 11 Dec 2023 09:50:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317052; x=1702921852; 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=wNY858fptfzHBCj2MypAYw/Wf6IpNmLWS0ucyNJkm2A=; b=eWLScynttCeFKklww37oAkdqxr3wBwT2+pBCyDOTRqUKxPoOrXq1EUt+zdFnqAx6Zc 6Zp8BwLzCM1tkBUew7uqhtEDSsB+xYOt9a5KnfwyrZMslxfihiroXdpQiMLzLNE6IwPN XVeJ1aQ9gLDxAEDCq2sb4/Il/wqIrZ3ZXzdH4AjlQrBoL2pJuZOUAqgNKYIg9FEBFQDd p99ydF7l5qcqrnBRBsJk91Wt32Xh787GT1PMIPef8WRaa65MqTUSJQDwQRZrOrOQPnCR HrGzCpAbC4PHiecnJtXuamTvpcMTNDdzZn0Ywf//tvYzikEmBOE5vBQpCP7bwBebpMiG OZFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317052; x=1702921852; 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=wNY858fptfzHBCj2MypAYw/Wf6IpNmLWS0ucyNJkm2A=; b=HmFBsbMi56YrGIICwnCndgUSCuCx0E38Ac4a6p9J1W6/sb3mT98x4O2Cexulo0QTdC nvMAdHWfUeUj76ZVUsskSy/Fjg0m0vVlQrOdczKsSS+mMaWMwbr4SaaYzGcXIuK1ja1F oa01saVB3q9HvujK3y+5Gur8lEAFrjd70JLb+vXFzJUCy18tadaUwL+W44YklR3LxMaF CEFCJ0uDooCtBcHpQKSo0fmd420SW1ab/d+l/Q3FlOeCe0cJv5cJkrF0Wqau3rmtWbUk uawJYq/t4fhMr6KWKVyE7YjUVaVLKoXsbod0O7uBbhbff2AK2CegwoKw/rUuZX88iUUa uyUA== X-Gm-Message-State: AOJu0YyCm5547Stu1AZ59ZM7SvWJ33ZRh9pFCcdo9PHfNoWIS3etPbfQ eEWL2FS7uRU7vR4r1EkZzvn0M0ZRH2cnHxIZ X-Received: by 2002:a19:655a:0:b0:50b:fe63:ef9 with SMTP id c26-20020a19655a000000b0050bfe630ef9mr1413617lfj.73.1702317051775; Mon, 11 Dec 2023 09:50:51 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id b4-20020a056512060400b0050bfdb13929sm1130734lfe.73.2023.12.11.09.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:51 -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 07/19] media: i2c: ov4689: Use sub-device active state Date: Mon, 11 Dec 2023 20:50:10 +0300 Message-ID: <20231211175023.1680247-8-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:51:27 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008842777334694 X-GMAIL-MSGID: 1785008842777334694 Use sub-device active state. Employ control handler lock to synchronize access to the active state and s_stream. Signed-off-by: Mikhail Rudenko Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 68 +++++++++++++++----------------------- 1 file changed, 27 insertions(+), 41 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 5392f650960c..2eef64cd0070 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -86,7 +86,6 @@ struct ov4689 { u32 clock_rate; - struct mutex mutex; /* lock to protect ctrls and cur_mode */ struct v4l2_ctrl_handler ctrl_handler; struct v4l2_ctrl *exposure; @@ -319,19 +318,6 @@ static int ov4689_set_fmt(struct v4l2_subdev *sd, return 0; } -static int ov4689_get_fmt(struct v4l2_subdev *sd, - struct v4l2_subdev_state *sd_state, - struct v4l2_subdev_format *fmt) -{ - struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format; - struct ov4689 *ov4689 = to_ov4689(sd); - - /* only one mode supported for now */ - ov4689_fill_fmt(ov4689->cur_mode, mbus_fmt); - - return 0; -} - static int ov4689_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_mbus_code_enum *code) @@ -405,10 +391,11 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, static int ov4689_s_stream(struct v4l2_subdev *sd, int on) { struct ov4689 *ov4689 = to_ov4689(sd); + struct v4l2_subdev_state *sd_state; struct device *dev = ov4689->dev; int ret = 0; - mutex_lock(&ov4689->mutex); + sd_state = v4l2_subdev_lock_and_get_active_state(&ov4689->subdev); if (on) { ret = pm_runtime_resume_and_get(dev); @@ -443,7 +430,7 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) } unlock_and_return: - mutex_unlock(&ov4689->mutex); + v4l2_subdev_unlock_state(sd_state); return ret; } @@ -506,19 +493,15 @@ static int __maybe_unused ov4689_power_off(struct device *dev) return 0; } -static int ov4689_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) +static int ov4689_init_cfg(struct v4l2_subdev *sd, + struct v4l2_subdev_state *sd_state) { - struct ov4689 *ov4689 = to_ov4689(sd); - struct v4l2_mbus_framefmt *try_fmt; - - mutex_lock(&ov4689->mutex); + struct v4l2_mbus_framefmt *try_fmt = + v4l2_subdev_state_get_format(sd_state, 0); - try_fmt = v4l2_subdev_state_get_format(fh->state, 0); /* Initialize try_fmt */ ov4689_fill_fmt(&supported_modes[OV4689_MODE_2688_1520], try_fmt); - mutex_unlock(&ov4689->mutex); - return 0; } @@ -526,18 +509,15 @@ static const struct dev_pm_ops ov4689_pm_ops = { SET_RUNTIME_PM_OPS(ov4689_power_off, ov4689_power_on, NULL) }; -static const struct v4l2_subdev_internal_ops ov4689_internal_ops = { - .open = ov4689_open, -}; - static const struct v4l2_subdev_video_ops ov4689_video_ops = { .s_stream = ov4689_s_stream, }; static const struct v4l2_subdev_pad_ops ov4689_pad_ops = { + .init_cfg = ov4689_init_cfg, .enum_mbus_code = ov4689_enum_mbus_code, .enum_frame_size = ov4689_enum_frame_sizes, - .get_fmt = ov4689_get_fmt, + .get_fmt = v4l2_subdev_get_fmt, .set_fmt = ov4689_set_fmt, .get_selection = ov4689_get_selection, }; @@ -649,7 +629,6 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) ret = v4l2_ctrl_handler_init(handler, 10); if (ret) return ret; - handler->lock = &ov4689->mutex; ctrl = v4l2_ctrl_new_int_menu(handler, NULL, V4L2_CID_LINK_FREQ, 0, 0, link_freq_menu_items); @@ -862,13 +841,14 @@ static int ov4689_probe(struct i2c_client *client) return dev_err_probe(dev, ret, "Failed to get power regulators\n"); - mutex_init(&ov4689->mutex); - sd = &ov4689->subdev; v4l2_i2c_subdev_init(sd, client, &ov4689_subdev_ops); + ret = ov4689_initialize_controls(ov4689); - if (ret) - goto err_destroy_mutex; + if (ret) { + dev_err(dev, "Failed to initialize controls\n"); + return ret; + } ret = ov4689_power_on(dev); if (ret) @@ -878,19 +858,26 @@ static int ov4689_probe(struct i2c_client *client) if (ret) goto err_power_off; - sd->internal_ops = &ov4689_internal_ops; sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; ov4689->pad.flags = MEDIA_PAD_FL_SOURCE; - sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; ret = media_entity_pads_init(&sd->entity, 1, &ov4689->pad); if (ret < 0) goto err_power_off; + sd->state_lock = ov4689->ctrl_handler.lock; + ret = v4l2_subdev_init_finalize(sd); + + if (ret) { + dev_err(dev, "Could not register v4l2 device\n"); + goto err_clean_entity; + } + ret = v4l2_async_register_subdev_sensor(sd); if (ret) { dev_err(dev, "v4l2 async register subdev failed\n"); - goto err_clean_entity; + goto err_clean_subdev; } pm_runtime_set_active(dev); @@ -899,14 +886,14 @@ static int ov4689_probe(struct i2c_client *client) return 0; +err_clean_subdev: + v4l2_subdev_cleanup(sd); err_clean_entity: media_entity_cleanup(&sd->entity); err_power_off: ov4689_power_off(dev); err_free_handler: v4l2_ctrl_handler_free(&ov4689->ctrl_handler); -err_destroy_mutex: - mutex_destroy(&ov4689->mutex); return ret; } @@ -918,9 +905,8 @@ static void ov4689_remove(struct i2c_client *client) v4l2_async_unregister_subdev(sd); media_entity_cleanup(&sd->entity); - + v4l2_subdev_cleanup(sd); v4l2_ctrl_handler_free(&ov4689->ctrl_handler); - mutex_destroy(&ov4689->mutex); pm_runtime_disable(&client->dev); if (!pm_runtime_status_suspended(&client->dev)) From patchwork Mon Dec 11 17:50:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230810vqy; Mon, 11 Dec 2023 09:52:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6GqVKGVX86LUTXcTQyM9njEWWW+W6WqGBQizyu9UFTKOcqq1+BL4D5nEGyaXvaG0nlc0+ X-Received: by 2002:a17:902:ab84:b0:1d0:6ffe:1e6d with SMTP id f4-20020a170902ab8400b001d06ffe1e6dmr2100240plr.80.1702317133216; Mon, 11 Dec 2023 09:52:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317133; cv=none; d=google.com; s=arc-20160816; b=oaVL9yjeXYT4/bM6zB+1rzUIr4epzQkvwl0A+JiLPglvPFlHVzo3sr1PiVGGvsomRF q1rRATuQ0yRIr5Haj6BpkEA8nk/Jm/ucQFO4owL9gdj7nMWMBJF6pkN9e/Yh/shXGfma EKWEilcuwvMcuGgItFgzwb1r+Px650VcPsNlcFBbHIVOdm88aA9NXdBq1xK5XhxFy9Ed Y8EbyDgvCaOn8b/rOwS6gqpyRwbyTDQtxL8/U7DdJmazO1tzXsDqKoejRoBswg0HL0xC ANEeO0Qmh48grykZRiZHjna842O4MIsOeOdfLaRx4jUcUju+seu5LsemTxVYwbytuCzh YqPA== 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=tsJX+Qboa5vi8f2nlAdje7XxRx8QzHIYwHcUKKyZ1AE=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=F+iPuXVqqL3KFfNOTU/FNd5j5m1FL1w6I3RhBf/t30/xuqsSrCwcaPRMKPPQuDdH/s rcuG0r6R2w2PEowpFR43FM1vpQ1C1yhkkIKNT38oPgjbd2JRc4ySlF9BcIKi3fZVesRJ 39FUkk2JacxEVJxvcNLZyHSQDAU5dulL+fR/1tFBYCSX5VQABhw/ffaiHljIz5pw9zvN Aq+sZO03OSLuHRe6ymdbhYkkG2/B/+ihzCfDH20jk5sjgff10TFp8T/k4f4LiBE+EPb6 wtyriJgBVJ1yelccJqhXxYEx39oSp618mIEm5aw+pCO/aoQ3lUruhDqgbxODY/QO6zG4 X8FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FHW5Q7Ge; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id x19-20020a1709027c1300b001cff7628fd4si6289892pll.595.2023.12.11.09.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:52:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FHW5Q7Ge; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id CF1A5807649D; Mon, 11 Dec 2023 09:52:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345133AbjLKRvM (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344578AbjLKRut (ORCPT ); Mon, 11 Dec 2023 12:50:49 -0500 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4012493; Mon, 11 Dec 2023 09:50:55 -0800 (PST) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-50d176eb382so4042209e87.2; Mon, 11 Dec 2023 09:50:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317053; x=1702921853; 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=tsJX+Qboa5vi8f2nlAdje7XxRx8QzHIYwHcUKKyZ1AE=; b=FHW5Q7Ge8RTNlxvNzMIVT9FHiIz+3+KLPU9iaku/akVCwWCXOovSH99NRX2uE2EptN BtV42L1xZZZNYjbwNKr4mlc6uVGxj/1837PsA+1DVdl9z0G5DHKCQBjuZJIZILWuGdYk gZPfvQ27RXfGCutmBTg4iAHnIqzPH4fHyeoNvH7Q1c+a7LCkMR2vRFjkp7YvSkvvxih5 2x9KFPVYgUNxkiDNXYPcCSe+tMzRgwyc9cd/9ke6c+2N+hwIfwwwMDYufyUIXzt4KK+O bqiZjNlnJIv09rFOweasHRmHfbRb7NaS+EmtmAnboeJAV/AfVu5bSCpV3JG0MXngK+Nx 4RxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317053; x=1702921853; 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=tsJX+Qboa5vi8f2nlAdje7XxRx8QzHIYwHcUKKyZ1AE=; b=QmzCt5MErbktnaW6E0CaBQeNntLk2jp0BIm67DampV8xZOE97kOB7Y2XYjNjfn/h+S axxVsDlq+X9jIqRMCWqMVojyEe4vkgBSD0PE/W5k2AwfzXOlRfPhfMvGHA/AfiVFZMVn pOUaO7AhAf1b8LBh4AbyQK++zEkVAcIsXQU7luitRceDoHQyPF0qB8Wzo/fru9lZEeFE T0LR72h+gQygNRXkveAmIW+SikBEBdNBRSsQPZobCtKeIzh68y/TZxq9ftuKRk6sHFgl q1mZ4RaK/WhSg6hIFg8l7kNshiWZZ5te7HyeTEw4BCgMWzBk57KuqQSpty/cPjG6lsiJ Y7nw== X-Gm-Message-State: AOJu0Yy2enAMxwajp7tpZs4oK5GffwRj/ofNxhwhd9gSzIR1uQIv2bdA Fd8lPxkRtN637UgXE571mnWYfXrHvtLM0/qT X-Received: by 2002:a05:6512:1308:b0:50d:1a14:2f78 with SMTP id x8-20020a056512130800b0050d1a142f78mr3033484lfu.86.1702317052809; Mon, 11 Dec 2023 09:50:52 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id k18-20020ac24572000000b0050bfdfe0133sm1127334lfm.134.2023.12.11.09.50.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:52 -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 08/19] media: i2c: ov4689: Enable runtime PM before registering sub-device Date: Mon, 11 Dec 2023 20:50:11 +0300 Message-ID: <20231211175023.1680247-9-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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:52:04 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008889845094862 X-GMAIL-MSGID: 1785008889845094862 As the sensor may be accessible right after its async sub-device is registered, enable runtime PM before doing so. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 2eef64cd0070..ba33b0ced532 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -874,16 +874,16 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_entity; } + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + pm_runtime_idle(dev); + ret = v4l2_async_register_subdev_sensor(sd); if (ret) { dev_err(dev, "v4l2 async register subdev failed\n"); goto err_clean_subdev; } - pm_runtime_set_active(dev); - pm_runtime_enable(dev); - pm_runtime_idle(dev); - return 0; err_clean_subdev: From patchwork Mon Dec 11 17:50:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176847 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230468vqy; Mon, 11 Dec 2023 09:51:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGteFZ7ai8Pq360ur5+IbY2STZKIsuHpK5SQTgy3wez8xHwISWuU8XAXJs/cd+ghf7GJtP X-Received: by 2002:aa7:8706:0:b0:6ce:2732:590 with SMTP id b6-20020aa78706000000b006ce27320590mr3943504pfo.65.1702317103114; Mon, 11 Dec 2023 09:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317103; cv=none; d=google.com; s=arc-20160816; b=dR0d0EHAaCr+CmW2205sNu0xbgtFk3/b6FfR9XEnDMEg5mxtOaRIhts/DUMX6C9j80 6ZPawkN3QpG5WhxC7UbdFW6/qhLe1tVxLeCMGOR/7UnzLAJARF918aPR/H1AY/1e4Ehb LEOTK25FncH83k6cuM9oEGnhsCmaAkrlRwbU4LjoqVoszTQstZUgu2I0Wxcg4TgO+Xz8 rFv0ijm8XNIbsDTNY6NIEHbckCzz7t/Jwh5M6D/SaxFX7OJ6XLPDAK3yTz9O2M6kK1bM DxPPDUcTJSm+Wk/jjes3CZ9wLgD5/6aAOefa/N3X76n+zu4OiUKlWawj/+xiafs+qgxg xD/w== 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=SSLorSrmwJkpM8Qw+vtX+TJSDohLzn/aN7e/ge7Qmsg=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=ub6nnCVa/j8aILIaso9zvo14JjpxMx6+bqNbm6FYHliSUQHKKMf6H3bmRUzF+AQU8T ADBP/MqQTq06OAnVw2ru9kk9oUbwaCnLW9cf3B+Yf6WwmMXc04ducURKV2P2pIWczA0/ 76ebbVzKDOyM5jL/SLoh/nIRZPX1Bzh5orxjCugQbxlnkN+pMMZjArBTi0icSSYILy8o s+zsBCYk/WzZCNDIH02EB24Ciqk7nwgII4pEWGMJDWosQSb9UKmGPGRb7Q25mNrdL/li Ou+NV/l42BtLj2g0ZPavFQ7QMjpA+5bwjAwe11csvXOfKzvQ+LRinp3HdYeVxBj8KTVc VRig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ikL22BnH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id y16-20020a056a00191000b006cbbacf7aaasi6486893pfi.29.2023.12.11.09.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ikL22BnH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id D2749805917A; Mon, 11 Dec 2023 09:51:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345034AbjLKRvR (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344796AbjLKRuu (ORCPT ); Mon, 11 Dec 2023 12:50:50 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6700FC7; Mon, 11 Dec 2023 09:50:56 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2ca0d14976aso63332731fa.2; Mon, 11 Dec 2023 09:50:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317054; x=1702921854; 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=SSLorSrmwJkpM8Qw+vtX+TJSDohLzn/aN7e/ge7Qmsg=; b=ikL22BnHK4Vla7jiqEVbE/smiIIHLZ3A/hqmCsK+cJyfFWOhctUEqM/wjeYybnoYHP dNuCmlnNdd6bD194+Fga/ywjzgWc7qYQP3AHQvDA9Ik2NrbtHllzfQwUTcpw/GvRZxTv vK5IqUS6wAbM4VAdgg9znPclUkE1RalM5z8Yecu/Opy/wGgtcwUaDrxGLlHcWOUPg2OH kfON1bTySuaJ1DaznrzpTWOiOJXW9jhG3xmvKlM5LSUVUpFfC1hrMVILpZuRiYVDwjQS HN9PT2m7FcEi4WwodP2UM5gfZcEOz9A/uD2Dv79vg3/UVD5M1IsiEG23HYlcvaWuWneK pKRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317054; x=1702921854; 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=SSLorSrmwJkpM8Qw+vtX+TJSDohLzn/aN7e/ge7Qmsg=; b=jSF/WLgy47mp5bQPtQu44LhO+ElRgfTvZ2zlQ2Dy1JJa8XnSPu81JKufBx9903ro56 q7dFYHYE2bodKl2FBK2Im0qPeDFfTaoMuEf9a63bWhSOePkT9icH0XUcknrlJeE3SwE1 ZJ4e9Ul/2nbC5gGrB6ZiYwj12DUxVvTXKzEMvbB2vudG1q0yHyfYReUnFkQqQFOgSqpW JjnlEkAhbrZjxGnIJ46Eqtff/4nmAwp2SUEp/vvTatfvNJH/RjTdQEbD0eznbE1ZUOYA SGA6Ijo7w5AW1d2HqjQsbrdfq4tEPrVQZZlohrIz4NUryGJlvocCqTZA/koHmUV7FhCO sz5g== X-Gm-Message-State: AOJu0Yw8ejmhunmZ4c3lUvHSxB0skgTFpXN5soE0Sns82JX6O5XBh68V hrVAavrdsdSDntEOWJs3lSLm0Tgl6tcF7sT7 X-Received: by 2002:a2e:a545:0:b0:2cc:202f:6266 with SMTP id e5-20020a2ea545000000b002cc202f6266mr917704ljn.96.1702317053973; Mon, 11 Dec 2023 09:50:53 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id 13-20020a2e154d000000b002ca03d01360sm1360796ljv.23.2023.12.11.09.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:53 -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 09/19] media: i2c: ov4689: Remove max_fps field from struct ov4689_mode Date: Mon, 11 Dec 2023 20:50:12 +0300 Message-ID: <20231211175023.1680247-10-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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:51:33 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008858175936950 X-GMAIL-MSGID: 1785008858175936950 max_fps field of struct ov4689_mode is unused in this driver, so remove it. Signed-off-by: Mikhail Rudenko Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index ba33b0ced532..9fa06941a0e5 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -60,7 +60,6 @@ struct ov4689_mode { enum ov4689_mode_id id; u32 width; u32 height; - u32 max_fps; u32 hts_def; u32 vts_def; u32 exp_def; @@ -237,7 +236,6 @@ static const struct ov4689_mode supported_modes[] = { .sensor_height = 1536, .crop_top = 8, .crop_left = 16, - .max_fps = 30, .exp_def = 1536, .hts_def = 4 * 2574, .vts_def = 1554, From patchwork Mon Dec 11 17:50:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176843 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230379vqy; Mon, 11 Dec 2023 09:51:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IF++xaJuKMZvc5TRbb1Xj63YTESo5u1AkQlPAdLFhUYLVXWzNev0eBNi7RKdGN4Z1Cpyvck X-Received: by 2002:a05:6a20:748f:b0:18c:f734:64e5 with SMTP id p15-20020a056a20748f00b0018cf73464e5mr2459867pzd.44.1702317093599; Mon, 11 Dec 2023 09:51:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317093; cv=none; d=google.com; s=arc-20160816; b=C+ZjJP21JmKzi/YynUTlrZ0xz6uXbBO8cY3yca8/8TM8eSnE19r6SGHJb2QarOiXxK FKIoOmE9ZXTFRdKKd01t75JMI6LTaGFAvFTFn15UUKgOS6JuN9t/id/qlE4yhQTXhBdE 7z7vXKE3O8TeII9BdnzScI1TmSfmRu/gIehcXzThBCQKQ0w8Or59Mw6xIeL76rS4dyDe JKvca58Hg52U4Zlg3emoW6jp2nJNfgHgKlbMy4LfbooWbt0UigK8m0dEsJGi2cBUG1RV rQTKMNJsoaN7e96mdAT8Z6DC+aq6se4pS0U24t8dwMD/+x95wWsuyt73ulvo7/Any4B7 EY7g== 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=cRYPXlKC8fxVqZOLpMO9mgZ04bcZLhSPp5xxyRwBBIg=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=x63L0E5eKur3p66cWcEejLOVTw8aKhy/rFbl3P5biCZ2g0YpQIQxyaDv9+sGp+s6wp +34Qg88uscel9+tC/PMqKRjhoTsDlylCVps967HSMOIO06g4DT9mlgDJTWY8B4tVO1Rv QY/cg3WqRQKc0XjYF33cv91igjR7LaQKAc0CbkjUAwmtACyPBaaAGunQ2ITAx/yV4gS/ YyM/zF+IRPjI4Jwn+gSYGTi3v1Vu8ydg9jQqNTukwVm+KhzAC8GBTr1P94C1E5cgPBKC N+KndkJ1Lov0UGTMycIkGBbGKcKHTX2E4ggYZ5GX3ZFp9Rntlr3zsR9DJknH6FJP5xPL DT2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mVvyEERY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id b13-20020a630c0d000000b005c65eb2bc62si6155180pgl.237.2023.12.11.09.51.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mVvyEERY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id CA67F80A30F4; Mon, 11 Dec 2023 09:51:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345147AbjLKRvU (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344952AbjLKRuw (ORCPT ); Mon, 11 Dec 2023 12:50:52 -0500 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE62FE3; Mon, 11 Dec 2023 09:50:57 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2ca0715f0faso65825371fa.0; Mon, 11 Dec 2023 09:50:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317055; x=1702921855; 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=cRYPXlKC8fxVqZOLpMO9mgZ04bcZLhSPp5xxyRwBBIg=; b=mVvyEERYOK8hWlNpLlOjY/CYVkWA/3QEhiZ6MVvCCqbmKnLt/te6GRyhDCQegdNqkI cl1SsPQoQG1kwjXevalIZCQeAROePdlt3ctnO+Bz5wmjjSW9eMHMXku+iR3uxa8NEiuW aR9iKoZEH7yzG7JznKbrNVv6+dIME7mvWVqaAuGq3S0GMljLoouocApUkgG4qNKdcbnI Lawml4fC1z1izWtLQzLCTTlALDMNl6XlXzX8euy6CbOu4RxeOcfi05EfDE1oDt+VSCai /oJa+d+VSw+sJSQCCtPy66K/0/0ERL8zFb7eOnUAiwyrnKyYeY0DKfivaBZqDoyeSzKZ NS8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317055; x=1702921855; 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=cRYPXlKC8fxVqZOLpMO9mgZ04bcZLhSPp5xxyRwBBIg=; b=W02CPBSrcnA6TlCkYez8B1z2OlguZS961ezdH8ioBDSAA1/G5NuXVvI2xIzwF4P6/0 89yrv1LJbqYo5JABCT9SY3uLPfziq+X4QOHSmCMf+i8ePkH1BAkI0HLGfJXIkpLgHJMQ RQ6WseiJYsk46vE/dKa4jUcAFLorOss5LNPGdaKi70fubcb6KZHV+RhF1Ktutk60RnZU J71uZsr8ZFTotWMsdTnHfpPzFA8XOhaJ6+hiOgasvnLhGKUslBuUzCHx5wQNAahagt3C bYU/2Y86cEaId+rrkbMAtA64qlt+EiVMGVS6kQdnWxv1D7q+66hVhG+XT8s7/C/pWBXu VoOw== X-Gm-Message-State: AOJu0Yx5JxLxThJGz3Ar4o4zoEfBDcIm+HKJnLvGo/cwM/4ZfYfWVytA OGbtWu2I/RsgtJugPvB/rhzqhOTMcw6k+LCY X-Received: by 2002:a2e:3909:0:b0:2cc:1fc1:e209 with SMTP id g9-20020a2e3909000000b002cc1fc1e209mr993981lja.88.1702317055474; Mon, 11 Dec 2023 09:50:55 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id f7-20020a05651c03c700b002ca0192dad7sm1310294ljp.44.2023.12.11.09.50.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:55 -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 10/19] media: i2c: ov4689: Make horizontal blanking configurable Date: Mon, 11 Dec 2023 20:50:13 +0300 Message-ID: <20231211175023.1680247-11-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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:51:31 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008848683957697 X-GMAIL-MSGID: 1785008848683957697 Make horizontal blanking configurable. To do so, set HTS register according to the requested horizontal blanking in ov4689_set_ctrl instead of the register table. Default HTS value is not changed by this patch. Minimal HTS value is found experimentally and corresponds to 90 fps framerate at minimum vertical blanking. Real HTS value is the register value multiplied by 4. Signed-off-by: Mikhail Rudenko Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 9fa06941a0e5..67d4004bdcfb 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -30,7 +30,6 @@ #define OV4689_REG_EXPOSURE CCI_REG24(0x3500) #define OV4689_EXPOSURE_MIN 4 #define OV4689_EXPOSURE_STEP 1 -#define OV4689_VTS_MAX 0x7fff #define OV4689_REG_GAIN CCI_REG16(0x3508) #define OV4689_GAIN_STEP 1 @@ -41,6 +40,11 @@ #define OV4689_TEST_PATTERN_DISABLE 0x0 #define OV4689_REG_VTS CCI_REG16(0x380e) +#define OV4689_VTS_MAX 0x7fff + +#define OV4689_REG_HTS CCI_REG16(0x380c) +#define OV4689_HTS_DIVIDER 4 +#define OV4689_HTS_MAX 0x7fff #define OV4689_LANES 4 #define OV4689_XVCLK_FREQ 24000000 @@ -61,6 +65,7 @@ struct ov4689_mode { u32 width; u32 height; u32 hts_def; + u32 hts_min; u32 vts_def; u32 exp_def; u32 pixel_rate; @@ -104,7 +109,7 @@ struct ov4689_gain_range { /* * Xclk 24Mhz - * max_framerate 30fps + * max_framerate 90fps * mipi_datarate per lane 1008Mbps */ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { @@ -175,8 +180,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { /* 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(0x380c), 0x0a}, /* TIMING_HTS_H hts[14:8] = 0x0a */ - {CCI_REG8(0x380d), 0x0e}, /* TIMING_HTS_L hts[7:0] = 0x0e */ {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 */ @@ -237,7 +240,8 @@ static const struct ov4689_mode supported_modes[] = { .crop_top = 8, .crop_left = 16, .exp_def = 1536, - .hts_def = 4 * 2574, + .hts_def = 10296, + .hts_min = 3432, .vts_def = 1554, .pixel_rate = 480000000, .reg_list = ov4689_2688x1520_regs, @@ -596,6 +600,11 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_TEST_PATTERN: ret = ov4689_enable_test_pattern(ov4689, val); break; + case V4L2_CID_HBLANK: + cci_write(regmap, OV4689_REG_HTS, + (val + ov4689->cur_mode->width) / + OV4689_HTS_DIVIDER, &ret); + break; default: dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", __func__, ctrl->id, val); @@ -618,13 +627,13 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) struct v4l2_ctrl_handler *handler; const struct ov4689_mode *mode; s64 exposure_max, vblank_def; + s64 hblank_def, hblank_min; struct v4l2_ctrl *ctrl; - s64 h_blank_def; int ret; handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret = v4l2_ctrl_handler_init(handler, 10); + ret = v4l2_ctrl_handler_init(handler, 11); if (ret) return ret; @@ -636,11 +645,11 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE, 0, mode->pixel_rate, 1, mode->pixel_rate); - h_blank_def = mode->hts_def - mode->width; - ctrl = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK, h_blank_def, - h_blank_def, 1, h_blank_def); - if (ctrl) - ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; + hblank_def = mode->hts_def - mode->width; + hblank_min = mode->hts_min - mode->width; + v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_HBLANK, + hblank_min, OV4689_HTS_MAX - mode->width, + OV4689_HTS_DIVIDER, hblank_def); vblank_def = mode->vts_def - mode->height; v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_VBLANK, From patchwork Mon Dec 11 17:50:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176845 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230461vqy; Mon, 11 Dec 2023 09:51:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfgayUB95WDHrG3AlVEIZbMfQlNSzr9SCznqnOq2EE1pY0wvng1ZKmeRMLqqZZA1W8v7Pw X-Received: by 2002:a05:6a20:7d86:b0:18f:f86f:bcdb with SMTP id v6-20020a056a207d8600b0018ff86fbcdbmr5823852pzj.93.1702317103858; Mon, 11 Dec 2023 09:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317103; cv=none; d=google.com; s=arc-20160816; b=vlnlq8MtH/gmLE5uj7r7mrRl3J5C8UpGiuX2qk5H5n/8L6M5fzKHw3p9YZQh2Ziz7M G0W8yYxYGZznffUgJigi9bJS3kSaCJXTq0PGreNnDSCwRaMFiIB6GiDkxMQo/JPAuA3N /fByItihOXiqUREiwPxDUoFs2j66CAyWEvnGwXIDDzUd6t+tQlkSOMya/px+lo88y8fY 8hFbXNSWpwMkdPttu9yEqHOxnTgOW1L5VQf8iNQ5fO9ngkR21jdj8UXEM22eaw1uxeZ6 2lfKA+6OVH7eQAZB0GDAc41VgZiSoTA1WXN9W3GSKMZsMJ1B0O4EV0ZV0YUmR6SRrJzj QKNw== 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=lRa38RGEmz27i+dqJIZM7KN8VTKbmG28KhKh8WuCaJ4=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=NLCaWbcdFuPPkeQQCOmk4WR0wRUN7IDDT6SY8IFdz5v2r9tkKViEDUeOLEPW9E1ZQt Luh15ZiLtG9corUbgusn2Voh8LChduyz4Q64AP4hTvB/Rf7qLKUCYvw9qMP+I5Qt+SB3 IsADxouXTOCeSgSqzuxRZes6jk8KHhUUbe87HhEDze7+/IaoNkDmXcdbKhQbGoLQ4gco 1ly0svRyvTjkV+JFY+m8YA/2QLexuBGSkqR1d7bthXH6oDc912iC/yFRkA1Cs7Sv1xtZ lmg+iD6P3Jobztu7Qu7b+nW4LyGo4GXe+WbIqEx7kRnsESUXTfp1Q5OkBdgucbD55Lnm BG+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jstO4TdZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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. [23.128.96.33]) by mx.google.com with ESMTPS id bx2-20020a056a02050200b005be1e55546esi6688150pgb.51.2023.12.11.09.51.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=jstO4TdZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 8A4CA80A1394; Mon, 11 Dec 2023 09:51:37 -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 S1345155AbjLKRvY (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345065AbjLKRu7 (ORCPT ); Mon, 11 Dec 2023 12:50:59 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 368A8C3; Mon, 11 Dec 2023 09:50:59 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50bf8843a6fso4723373e87.0; Mon, 11 Dec 2023 09:50:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317057; x=1702921857; 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=lRa38RGEmz27i+dqJIZM7KN8VTKbmG28KhKh8WuCaJ4=; b=jstO4TdZZqBVGzJ5soti4kqLyfE9JLFOqDNGcG5tSa9CvL3Ke5Pr9VKIucgIkd552d Gp7hIMTJt9DK/UhNuJkm0Iqjuf4TEqo7VdC5DkiU/uBX7o3JnZgRmdvf0EfKbSPOtnf5 nUfUu5OI8fSQKNm/Y+VIwPIvMYiloNzBZV8NGIMXtaxzM801ckaRGoXYIL+bsXUkwJER 5DIzdH8+0lI7v3EYyrqkInMRUc9RB1DxqMNf49751HMFqVJij2J/5eQurwVaTsJr8VNM hWnOoSEBshmyHzTVcEf47gl+rQKH9/Ha87LFZDEzX9n2hz4E7bwHtMKk0Zannl09kWpm LQ0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317057; x=1702921857; 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=lRa38RGEmz27i+dqJIZM7KN8VTKbmG28KhKh8WuCaJ4=; b=M5GC+oG610jNrBFI/05HRPYMAM5PNyOUaSYOyktZVSZnB487V4bS+NSEfE0YdcZpov z/h2Dtmv9g1SVCBi3YRObvgdrsGaFXqSnmUtGnLn1SDlrKyIEm6OTc3F4AsC6SD1tLna EakJJgVP7gb4EuajcmEYby9oh1gLX6EowwBWPr0Xd+wkXb17GGxMQR3ynmv9MqZ5tNA+ EQHcjH+hO86S+yi2/5m7LCCJeyvBs5hBRlifMaol1Y+tvHjhofYcGFSaBLXugW7l4vjL T9mO9j2m+qXkh62k8xp4Lc31SbZ5oR3e+VhSvk/uZ7tpw8D34yGVLtfRTqu97/xLPA19 HbFw== X-Gm-Message-State: AOJu0YygqOcQB3cmQaI5unqd/40a5febeQwmUVUEV5zFOM117gXlrxMt WEpFhMtxfjiHHeAC3nWH78zJ7AU6E7IADVSU X-Received: by 2002:ac2:548d:0:b0:50b:f706:81cd with SMTP id t13-20020ac2548d000000b0050bf70681cdmr2409825lfk.19.1702317056754; Mon, 11 Dec 2023 09:50:56 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id r14-20020ac25a4e000000b0050bfd883f56sm1141079lfn.129.2023.12.11.09.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:56 -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 11/19] media: i2c: ov4689: Implement vflip/hflip controls Date: Mon, 11 Dec 2023 20:50:14 +0300 Message-ID: <20231211175023.1680247-12-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:51:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008859460801183 X-GMAIL-MSGID: 1785008859460801183 The OV4689 sensor supports horizontal and vertical flipping. Add appropriate controls to the driver. Toggling both array flip and digital flip bits allows to achieve flipping while maintaining output Bayer order. Note that the default value of hflip control corresponds to both bits set, as it was before this patch. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 67d4004bdcfb..62aeae43d749 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -46,6 +46,14 @@ #define OV4689_HTS_DIVIDER 4 #define OV4689_HTS_MAX 0x7fff +#define OV4689_REG_TIMING_FORMAT1 CCI_REG8(0x3820) +#define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821) +#define OV4689_TIMING_FLIP_MASK GENMASK(2, 1) +#define OV4689_TIMING_FLIP_ARRAY BIT(1) +#define OV4689_TIMING_FLIP_DIGITAL BIT(2) +#define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ + OV4689_TIMING_FLIP_DIGITAL) + #define OV4689_LANES 4 #define OV4689_XVCLK_FREQ 24000000 @@ -183,7 +191,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {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 */ - {CCI_REG8(0x3821), 0x06}, /* TIMING_FORMAT2 array_h_mirror = 1, digital_h_mirror = 1 */ /* OTP control */ {CCI_REG8(0x3d85), 0x36}, /* OTP_REG85 OTP_power_up_load_setting_enable = 1, @@ -605,6 +612,16 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) (val + ov4689->cur_mode->width) / OV4689_HTS_DIVIDER, &ret); break; + case V4L2_CID_VFLIP: + cci_update_bits(regmap, OV4689_REG_TIMING_FORMAT1, + OV4689_TIMING_FLIP_MASK, + val ? OV4689_TIMING_FLIP_BOTH : 0, &ret); + break; + case V4L2_CID_HFLIP: + cci_update_bits(regmap, OV4689_REG_TIMING_FORMAT2, + OV4689_TIMING_FLIP_MASK, + val ? 0 : OV4689_TIMING_FLIP_BOTH, &ret); + break; default: dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", __func__, ctrl->id, val); @@ -633,7 +650,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret = v4l2_ctrl_handler_init(handler, 11); + ret = v4l2_ctrl_handler_init(handler, 13); if (ret) return ret; @@ -673,6 +690,9 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) ARRAY_SIZE(ov4689_test_pattern_menu) - 1, 0, 0, ov4689_test_pattern_menu); + v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_VFLIP, 0, 1, 1, 0); + v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_HFLIP, 0, 1, 1, 0); + if (handler->error) { ret = handler->error; dev_err(ov4689->dev, "Failed to init controls(%d)\n", ret); From patchwork Mon Dec 11 17:50:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176846 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230467vqy; Mon, 11 Dec 2023 09:51:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMYflX51QqbJNqlx1EIlFmmhPyqQaocffXOHEzeVfXXRRU1MMS9dtmDJOdpHNK5NW9aX5a X-Received: by 2002:a05:6a00:1889:b0:6ce:64e1:486b with SMTP id x9-20020a056a00188900b006ce64e1486bmr2165234pfh.6.1702317103859; Mon, 11 Dec 2023 09:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317103; cv=none; d=google.com; s=arc-20160816; b=QuFwxdPP6RWZvjLU89srjxVezgCyDh+a8YiT65ejOF5ayQmo/QQh3Xjq3mNybPB3l1 bG3nIYEdVV9xhtgVbZkQfayI06eBiqq297MN6AAX4qOaQ/MJ2No9zyEML1pkCFdAcGhj LaN0gzaayi9g8bDDiLHC0qvEM2ExUbI1K83cbbOz1uqd+CzLehmHwBjBX/EsC/SOUKKa oG7tdhPIG7lbOeO8vL45N5mNLomc9rHq8cm5RtTc6sLriY7ad915mWO2/ldQTswsJ9Xm atOIsfshNkjO6cBtvjhWdSCsoiHRQyz+gKzOhCTQJe6iZfQ/jOUKLn6YynQVWtElGAdl TYTg== 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=O3YUfzGsaBsOQXR1nI75uclXXzs9bCDdUPhKf4IBE2Q=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=FlLptR8kPH+FRukpk3gE/PfosTMJjG2rvVrZbqus7zGcn/CLEG+ebrSSWerwQGZ2gX r58BY6ZisGrllpl1zXiLDz1I0tyD7O6Ffoi1IBS9z7vEBpNTRQSlRdpZhw46uWE+RmZn 6qKAi8sTIzq7dhB7R5TGR2WM4+Z1M/M6vFPy7r2cfeiXcPGonWQSDKhlMTdvIibM6A+O ECr96tNonsX6HNMO3uZ5oPraEijdAblrbR8bX7SScqnRmdXqj0HDvrKVJbdYSpH0PkmL M3VKAiny9/X/rTgZyfeEJgE6ZazLHc8qG9SHWNTJC+AtJ1DqkPsAchC4IDisXtS1ZJiJ 7LFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GvFMWsSq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id bz25-20020a056a02061900b005be109a793csi6587271pgb.444.2023.12.11.09.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GvFMWsSq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id E10C4806036A; Mon, 11 Dec 2023 09:51:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345178AbjLKRv1 (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345066AbjLKRu7 (ORCPT ); Mon, 11 Dec 2023 12:50:59 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04CC5CD; Mon, 11 Dec 2023 09:51:01 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2c9f7fe6623so59319011fa.3; Mon, 11 Dec 2023 09:51:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317058; x=1702921858; 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=O3YUfzGsaBsOQXR1nI75uclXXzs9bCDdUPhKf4IBE2Q=; b=GvFMWsSqknLhstpCt60WroNMg+GRrecTOd7anjl1ExvUwRNmXGWRcmL41L+pNYNE0h +FCDjqk4vSrnqH+XfCEgMwcKYvv7FXxFAlOOspRjNFkXyFNaz+E5FrXrww//TscEE+PX yMmcWuMmU/zMY50y7DLfJ98D9xxcG0Vs0ci5nXhDCX5f9wb25FabbmoofCHCf50WnqLT gtqmayDLc6eJuAArqwW3Gqd9p/ICalpLTCAqcuTOXy2SMQ0CWM2YQXn2+KoB0WPDkQZy 6bscfGTdXENY/BzJ9Dal/fQQXjZ6xl9Jmyx2OQLk7LSc7lymnnOiTb0y9c9515CO1Egn YDmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317058; x=1702921858; 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=O3YUfzGsaBsOQXR1nI75uclXXzs9bCDdUPhKf4IBE2Q=; b=wkbgjaYZTfhjagHTPJdphRAA1itv/UiaabuurMw63L5DCpqidUanw790IYFsuEjrwW oKkxq15As0tA6Y4eOZT4E2Icvei1Z7yISgUBcBbf6M1oxZBH/LsYtNPx8QaJhxvuK42G IMKEVxQIpnIJ8Dd7GS2Bc0KtKo/OBEHHk2hD/1Cww1+8gCLpwMmfcmOKTRFh4FcQtlrV svcvTvlFC0Cf4QQCEVZIn29FQjFosZYMIgh7lIYVq8TBGOh+3o15ScF1PDxZvNv0XwcX +0ND0r8wolmwQJI+isMvsFIGriQElJtec/27OkbHTkcPPrSiDXBkbkdSLpHWsdKLbDcO Xlzw== X-Gm-Message-State: AOJu0Yz95qHl/OF4Fl1Vc3QFX1mr9kMKu8tpWZNilxaNhBAS/QqJg+yB bGp1QCXB63i9JBo5V4QEmMal80EazvsjxvId X-Received: by 2002:a2e:5309:0:b0:2cc:275c:3dd1 with SMTP id h9-20020a2e5309000000b002cc275c3dd1mr314444ljb.57.1702317058477; Mon, 11 Dec 2023 09:50:58 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id r17-20020a2eb611000000b002c9f5039a86sm1280249ljn.87.2023.12.11.09.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:58 -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 12/19] media: i2c: ov4689: Implement digital gain control Date: Mon, 11 Dec 2023 20:50:15 +0300 Message-ID: <20231211175023.1680247-13-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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:51:37 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008859638124346 X-GMAIL-MSGID: 1785008859638124346 The OV4689 sensor supports digital gain up to 16x. Implement corresponding control in the driver. Default digital gain value is not modified by this patch. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 62aeae43d749..ed0ce1b9e55b 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -35,6 +35,12 @@ #define OV4689_GAIN_STEP 1 #define OV4689_GAIN_DEFAULT 0x80 +#define OV4689_REG_DIG_GAIN CCI_REG16(0x352A) +#define OV4689_DIG_GAIN_MIN 1 +#define OV4689_DIG_GAIN_MAX 0x7fff +#define OV4689_DIG_GAIN_STEP 1 +#define OV4689_DIG_GAIN_DEFAULT 0x800 + #define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040) #define OV4689_TEST_PATTERN_ENABLE 0x80 #define OV4689_TEST_PATTERN_DISABLE 0x0 @@ -131,7 +137,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { /* AEC PK */ {CCI_REG8(0x3503), 0x04}, /* AEC_MANUAL gain_input_as_sensor_gain_format = 1 */ - {CCI_REG8(0x352a), 0x08}, /* DIG_GAIN_FRAC_LONG dig_gain_long[14:8] = 0x08 (2x) */ /* ADC and analog control*/ {CCI_REG8(0x3603), 0x40}, @@ -622,6 +627,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) OV4689_TIMING_FLIP_MASK, val ? 0 : OV4689_TIMING_FLIP_BOTH, &ret); break; + case V4L2_CID_DIGITAL_GAIN: + cci_write(regmap, OV4689_REG_DIG_GAIN, val, &ret); + break; default: dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", __func__, ctrl->id, val); @@ -650,7 +658,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret = v4l2_ctrl_handler_init(handler, 13); + ret = v4l2_ctrl_handler_init(handler, 14); if (ret) return ret; @@ -693,6 +701,10 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_VFLIP, 0, 1, 1, 0); v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_HFLIP, 0, 1, 1, 0); + v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_DIGITAL_GAIN, + OV4689_DIG_GAIN_MIN, OV4689_DIG_GAIN_MAX, + OV4689_DIG_GAIN_STEP, OV4689_DIG_GAIN_DEFAULT); + if (handler->error) { ret = handler->error; dev_err(ov4689->dev, "Failed to init controls(%d)\n", ret); From patchwork Mon Dec 11 17:50:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176851 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230748vqy; Mon, 11 Dec 2023 09:52:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVDcgn7NFflyENcBvQGDS/I+0/riSkcV8At01ATzSy0GsfYGhvJFmpM5waZ2Rvxg1MaWY1 X-Received: by 2002:a05:6e02:1d92:b0:35d:59a2:1278 with SMTP id h18-20020a056e021d9200b0035d59a21278mr6832851ila.36.1702317127389; Mon, 11 Dec 2023 09:52:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317127; cv=none; d=google.com; s=arc-20160816; b=TYwaNvwCu48JIEsjb8KGqiTfKmwcb/duxAcyTlaEMMiSTaBcfx0NeKV+8WHyKkRgXA 0lTWeftVVH5WdxMmsbhSpHcl7Cz0cosY23whh51doJTKluq2z9FU4rI1fRke/7gNrZzC ts6JTWtBO8zJp7oE72Qnz7FOk7v7fcJ2q7pe36M4od5TmgAUtp7UhEDv8OPjVNWlgpmp qyMsTCwj8Os1at5DyTGQh0FSbrsgJXnyI3Uj+sXoZYFD6ozYiOT9aQoV1iM9LrDGKNWO 88Q9eSEHh4HeiiGKQCYDSTyDzXywMUkw2dIQ0NKjSSLli8brRM2lHXP1QoRan0b6PH3o EKIw== 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=ZV+qykvCHEWTicA8pud0kxh1xP8XT+s6VE1pgxnwgAs=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=yyaoWSR/QoRGb5eW/gFcE57HzWccZkSXvcifN5/7htiGzh3nmzT1AScjXVJ3+wg8Zc Yso1SzPgGw2De5egiqdfZkNXBhsCNm8D9OxCvUZgUtmlnn7ORYdQrM63VxojL3TLiotw M8wW/RBBpkimrCACXKQ0YeeYKtMv1LIESwiGpYoxSmLbXJqv3GEnfRP1OX6CJTAp721F FcsSQsqRYFef+NNHVQdRh9fjqb+ccGfw7cp+50K+1E1ERDiBgX5U0m5tw60zYeKdGjyW 3K0q9dZOapKSonTrmZ9uIkskWk0T1eOuaLoGyF5IgOG7sb8U5l1glxpw6qxft8+D9nNU XIzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nXddlOjK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id c31-20020a630d1f000000b00577475ee5f6si6188947pgl.618.2023.12.11.09.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:52:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nXddlOjK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id A65EA8098FC3; Mon, 11 Dec 2023 09:52:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345198AbjLKRvb (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344962AbjLKRu7 (ORCPT ); Mon, 11 Dec 2023 12:50:59 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D41A4F4; Mon, 11 Dec 2023 09:51:02 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2c9bd3ec4f6so59262231fa.2; Mon, 11 Dec 2023 09:51:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317060; x=1702921860; 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=ZV+qykvCHEWTicA8pud0kxh1xP8XT+s6VE1pgxnwgAs=; b=nXddlOjKA7x/J0WEj/achhmSAow85xddAX76If+PlbriwksNZ194VYPuAJgnIPY00u H0HCZX0YCZlB9VsezCuazu/Ru6fS8z887AcTy48Tr7fZxVEirHLp0kthBgH4SAfczUMf LpeY/3GyULA/FC1C26QoiDLE6J78P8KElouljtsV4NhzaT7A+jcE+/ohsBP/ydm0T2V6 3y3LbfhY17p6fxL5hKZrdDWbVDPKUxsBaKIaXmKGhzCjq3NDubt2oDxSZ1Fd/Gs/Fovz eu61bRQhVOmef/pPklBhI5GAPHhI7nVovhFlYzn0QoNuqgkj9ObnBFCQxfkNs0uWkp7D 1DOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317060; x=1702921860; 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=ZV+qykvCHEWTicA8pud0kxh1xP8XT+s6VE1pgxnwgAs=; b=URr/RQAcwL3t+ClsjbKcGBY8EM0hBvQgRBh8WSZ1rIb0HAXpGRSacsFFoH0Pks/RIq HktgDl3gcK5WBtQkQb4xjGQuESbjbc7F5RLovkOx7bkMb9XHFLcCkh0IR0/etRjU9Q1G vRwoXJQar14Hb5E77CRrTrXyfZDWMc4d8z0mh1zz0Z35GLNClsCMzKI9uiUwQX3mwnue 3m/R4TPKhFXMNK3Od+P4w87jlgtckwCaCgKY58W+7aBLVHZOaP5XEuiWKty3rJlPI1Jc Hh/fUosu08FLWXCeR1zD+jFUZKOafPNlQJrAFDhgqeCIJATSN7TcuqrRH38OHrWbGI5x BpSg== X-Gm-Message-State: AOJu0YwLFfqEPVqkMMkFCSO8k694ItczbQL/XCFcGcachrSNBkdteG1S FIWXqqXH9WI58ll4OkVXR6lm5V2L8jwDSwIV X-Received: by 2002:a2e:a178:0:b0:2c9:fa32:4261 with SMTP id u24-20020a2ea178000000b002c9fa324261mr1222745ljl.60.1702317059731; Mon, 11 Dec 2023 09:50:59 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id s14-20020a05651c200e00b002c9f3e0a075sm1296088ljo.55.2023.12.11.09.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:50:59 -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 13/19] media: i2c: ov4689: Implement manual color balance controls Date: Mon, 11 Dec 2023 20:50:16 +0300 Message-ID: <20231211175023.1680247-14-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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:52:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008884073181014 X-GMAIL-MSGID: 1785008884073181014 The OV4689 sensor has separate red and blue gain settings (up to 4x). Implement appropriate controls in the driver. Default gain values are not modified. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index ed0ce1b9e55b..18e1fd564ec0 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -41,6 +41,13 @@ #define OV4689_DIG_GAIN_STEP 1 #define OV4689_DIG_GAIN_DEFAULT 0x800 +#define OV4689_REG_WB_GAIN_RED CCI_REG16(0x500c) +#define OV4689_REG_WB_GAIN_BLUE CCI_REG16(0x5010) +#define OV4689_WB_GAIN_MIN 1 +#define OV4689_WB_GAIN_MAX 0xfff +#define OV4689_WB_GAIN_STEP 1 +#define OV4689_WB_GAIN_DEFAULT 0x400 + #define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040) #define OV4689_TEST_PATTERN_ENABLE 0x80 #define OV4689_TEST_PATTERN_DISABLE 0x0 @@ -630,6 +637,12 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_DIGITAL_GAIN: cci_write(regmap, OV4689_REG_DIG_GAIN, val, &ret); break; + case V4L2_CID_RED_BALANCE: + cci_write(regmap, OV4689_REG_WB_GAIN_RED, val, &ret); + break; + case V4L2_CID_BLUE_BALANCE: + cci_write(regmap, OV4689_REG_WB_GAIN_BLUE, val, &ret); + break; default: dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", __func__, ctrl->id, val); @@ -658,7 +671,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret = v4l2_ctrl_handler_init(handler, 14); + ret = v4l2_ctrl_handler_init(handler, 16); if (ret) return ret; @@ -705,6 +718,14 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) OV4689_DIG_GAIN_MIN, OV4689_DIG_GAIN_MAX, OV4689_DIG_GAIN_STEP, OV4689_DIG_GAIN_DEFAULT); + v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_RED_BALANCE, + OV4689_WB_GAIN_MIN, OV4689_WB_GAIN_MAX, + OV4689_WB_GAIN_STEP, OV4689_WB_GAIN_DEFAULT); + + v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_BLUE_BALANCE, + OV4689_WB_GAIN_MIN, OV4689_WB_GAIN_MAX, + OV4689_WB_GAIN_STEP, OV4689_WB_GAIN_DEFAULT); + if (handler->error) { ret = handler->error; dev_err(ov4689->dev, "Failed to init controls(%d)\n", ret); From patchwork Mon Dec 11 17:50:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176848 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230579vqy; Mon, 11 Dec 2023 09:51:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIm7DpZBm3SbHOMR10maQ/Hs3BETRdF4QL1xZOv+6Qq+Ivpo0oyKyBCr0led4xf58zBuvV X-Received: by 2002:a05:6a20:1606:b0:191:5fe1:1c67 with SMTP id l6-20020a056a20160600b001915fe11c67mr258751pzj.0.1702317113725; Mon, 11 Dec 2023 09:51:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317113; cv=none; d=google.com; s=arc-20160816; b=Z+R/4jSRL7R9UHXqZnf55MWgzV9ElBlqaLDBzgVSEXMRgkupNR0ETQoKDC5jJzio0a HywCJP/DLqCC18Cbyse68mGuKfgy4Edt98iimOqme7+wXZUjpbt2XjC2bJyPJYMucNif /q0mmsAiAUqOe5ZlUttf6EneMEDdZApUCL2b74rNihVmRcB19KOZcdT3Nm3TqxlFgY8h FUmpSlGxT6DDmEdNSu1oVg8ZmHFcbfS+YcocamcFepWS/s0Yh0w7wrOu67FWlKs5MSBz 46NIGF69sEKQhilLuvRuMaN7EkOezmz+ZrJeRiVZwgRKXaFxaWrtWX6+7S2dkioDyqnc Ijiw== 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=rk40BFqdM79fk23xCLVJrMhVtoRWFhktaIF9x7isDYY=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=ihKyVkiXK0viAg9jlb8YneQnP9r76Im2N9t89necxNvb9IiuSg+7+bZi/LgGiCT+Cb PEMr/QpHWe/xwHpbtzm58IXJncq0s+7gv92aBQcCQ3s1+vYr9gEMpqeG6anAITSh5qf6 O7F667VDDVzFMyi2WnIvmlO4hbkQvF5Ex4cpdwzWxvjV4/8SVahjoL/Twmg9s16n3lIT 3A1p6YkMxj5vE6LikXtrCN2lXp2Itl7HenRnALMfdEpEfw69GQx40sxZqSrUARsRPZnk 0b9DasOuAkJlQcmBCRB/7K/vP+B+TMc/mYSNwbU5q9PLYwHG736CZE2ldrTWyEK/kM0H /aAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HdHtrTjc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id v4-20020a655684000000b005b7160263efsi6303467pgs.489.2023.12.11.09.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HdHtrTjc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 397758059D80; Mon, 11 Dec 2023 09:51:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345098AbjLKRvd (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345094AbjLKRvA (ORCPT ); Mon, 11 Dec 2023 12:51:00 -0500 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43D6D10A; Mon, 11 Dec 2023 09:51:04 -0800 (PST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-50bce78f145so5436684e87.0; Mon, 11 Dec 2023 09:51:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317061; x=1702921861; 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=rk40BFqdM79fk23xCLVJrMhVtoRWFhktaIF9x7isDYY=; b=HdHtrTjceu0y62/Z5hRTF96op5Gr+rIXq7tgU3EVHD9/bjxf1x0/bD1uqBnRoO2EAU 41QjMpShVtJmwYc5gNqaOrQKhfh/SuPD7D7W2lrblmtscLrCpNexm0cseAumXY5Je0aq gfp3aopdeaW3TWsTqOWz0doDK1bmed0miGinr68608kic30+cOEA78sUv8jCGr/TVvCI uaz/GkgZlWJC8uj0OdeNeLc8rno+Mokn5lCQq1NOw4h6CkUJjVOtt/eScozWTYjoaoqa ShJBgibm7jF5RlG2GcYzO71gKFuNmN93UG8LpSgbOvVHZ8IkekVW7/3qrUk/Mmso1Mx/ GyIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317061; x=1702921861; 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=rk40BFqdM79fk23xCLVJrMhVtoRWFhktaIF9x7isDYY=; b=HNq7DaroZrIJOfhLOoMhyX2dMIsXcFU/UttMwnZ2GXMiEqGtW+v2x1DBf4XqOQ2xQn PQS+mPa2IEbG+AGVE8HtNqk2nBap1cpMX+XMJsFuQAlrKdazJ3CtrlYXy6eVU7iq5A8B cm7LpkM04oYvkLK0dH/RKqX49II59+9B7Ys/AxyVpB2tWLWPghFFCwJ8UEOFD/ZQvOB/ 5RdmIzJVejBAt2OjEEbIzcANbMJFdFf1Pz9Guh2F1N1kulLT85QjBSNzwGirTG/ZtjMx inPd6LJmn/IMmrw/Mgm40sw144G+ufAqhRz4bd6xFahslflvizw8gKFqB7QvfDTWlR77 Bosw== X-Gm-Message-State: AOJu0YwZKtNcnxNK8/Yw8BoJE6ee9Y886ZHRDcymWCZQwlK8g+MBkRMx rlPOHsQA7DAetBnEAcsOThjm+4pJAAwZ5uqv X-Received: by 2002:a05:6512:3a88:b0:50b:d944:bfe1 with SMTP id q8-20020a0565123a8800b0050bd944bfe1mr1234818lfu.163.1702317061343; Mon, 11 Dec 2023 09:51:01 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id cf16-20020a056512281000b0050df1c4149asm605479lfb.273.2023.12.11.09.51.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:01 -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 14/19] media: i2c: ov4689: Move pixel array size out of struct ov4689_mode Date: Mon, 11 Dec 2023 20:50:17 +0300 Message-ID: <20231211175023.1680247-15-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=1.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,PDS_OTHER_BAD_TLD, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:51:51 -0800 (PST) X-Spam-Level: * X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008869665526809 X-GMAIL-MSGID: 1785008869665526809 Pixel array dimensions and default crop size do not belong to the ov4689_mode structure, since they are mode independent. Make them defines instead. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 18e1fd564ec0..5acdf9e1b670 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -70,6 +70,11 @@ #define OV4689_LANES 4 #define OV4689_XVCLK_FREQ 24000000 +#define OV4689_PIXEL_ARRAY_WIDTH 2720 +#define OV4689_PIXEL_ARRAY_HEIGHT 1536 +#define OV4689_DUMMY_ROWS 8 +#define OV4689_DUMMY_COLUMNS 16 + static const char *const ov4689_supply_names[] = { "avdd", /* Analog power */ "dovdd", /* Digital I/O power */ @@ -90,10 +95,6 @@ struct ov4689_mode { u32 vts_def; u32 exp_def; u32 pixel_rate; - u32 sensor_width; - u32 sensor_height; - u32 crop_top; - u32 crop_left; const struct cci_reg_sequence *reg_list; unsigned int num_regs; }; @@ -254,10 +255,6 @@ static const struct ov4689_mode supported_modes[] = { .id = OV4689_MODE_2688_1520, .width = 2688, .height = 1520, - .sensor_width = 2720, - .sensor_height = 1536, - .crop_top = 8, - .crop_left = 16, .exp_def = 1536, .hts_def = 10296, .hts_min = 3432, @@ -385,8 +382,6 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) { - const struct ov4689_mode *mode = to_ov4689(sd)->cur_mode; - if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) return -EINVAL; @@ -394,15 +389,17 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, case V4L2_SEL_TGT_CROP_BOUNDS: sel->r.top = 0; sel->r.left = 0; - sel->r.width = mode->sensor_width; - sel->r.height = mode->sensor_height; + sel->r.width = OV4689_PIXEL_ARRAY_WIDTH; + sel->r.height = OV4689_PIXEL_ARRAY_HEIGHT; return 0; case V4L2_SEL_TGT_CROP: case V4L2_SEL_TGT_CROP_DEFAULT: - sel->r.top = mode->crop_top; - sel->r.left = mode->crop_left; - sel->r.width = mode->width; - sel->r.height = mode->height; + sel->r.top = OV4689_DUMMY_ROWS; + sel->r.left = OV4689_DUMMY_COLUMNS; + sel->r.width = + OV4689_PIXEL_ARRAY_WIDTH - 2 * OV4689_DUMMY_COLUMNS; + sel->r.height = + OV4689_PIXEL_ARRAY_WIDTH - 2 * OV4689_DUMMY_ROWS; return 0; } 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); From patchwork Mon Dec 11 17:50:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176849 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230704vqy; Mon, 11 Dec 2023 09:52:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEme/vnov80in5bCweMlTNFBPVA12eELiXcVKEfG0d1iRb1FkUP3rzW7D7+wv333BGcUuIc X-Received: by 2002:a17:90b:3ec7:b0:286:860e:162c with SMTP id rm7-20020a17090b3ec700b00286860e162cmr2108042pjb.34.1702317124331; Mon, 11 Dec 2023 09:52:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317124; cv=none; d=google.com; s=arc-20160816; b=nIkGSL+DRmiH+Q8Metlf/KFAJTtcWZKRxKQ0jKWwIL8qbDOwYl/ttMkQDhv3pzujZ5 fKWNaIj2vhMp8OXuOs4ay+nqDHIFqBub80nWP34kmyILqoLwZYUauLxhqPPYup3DEeeY gQyRDXQnZgoH8mGeMjhAGXF4h/2V8vJdZK7Bl5RgaFgIx0HnETcYFK2YbiIjGh0nvDer 116dx9H3EOrxqkXHiDD7NnlMi174X3KQLTIvBJIp/DY2iAAFpAt+CCyPVPNse309lmVh 89OCp7rxtiXfuvaN7Ez3FvUYhkQLZdlMIn9DnFB3+75JaabOFtlzPxqbmqhDRmH7BDDq NV2A== 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=Szd3tCJq3BzuFOQAHr0j38m73gmT9ejF3aS5J8pZX5s=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=yZqfla43DqVi/tF65+WUauz0OnaFJ3Pea+ekYOtDCRcHHbaY6ASZTP/0CTI2yI98qW 1RksDvvvOJa43OrKQg15PeLLG9Er5Q8K9LqPBV5gLbqecB6trbY20IjxIBq7hIDl88EK mS4WJxCJoAmyzjq5/UcYuq6Pduf9R9C6FCdy1Hu9y2/yG9+vp5hl3r8XG7Spnln0OvpJ UFV2kjkpBn2QIIn5av1rrYpbjHnE5o3qvtt0qagjSV87PSPwke3ppP/9KBvcdnzJWv2F bvU0ZNqIeUAgM1HxPXXhgtrC6XYnxmTr6h/KPyYyzsqzR09hghZlcU9JBkvc4UhREQ+E K1vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="iB5pY8/f"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id h22-20020a17090adb9600b00286adc9fd7fsi7626795pjv.60.2023.12.11.09.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:52:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="iB5pY8/f"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id E737480AEB36; Mon, 11 Dec 2023 09:51:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344954AbjLKRvt (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345185AbjLKRva (ORCPT ); Mon, 11 Dec 2023 12:51:30 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EB4C107; Mon, 11 Dec 2023 09:51:06 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-50bf2d9b3fdso6227780e87.3; Mon, 11 Dec 2023 09:51:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317064; x=1702921864; 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=Szd3tCJq3BzuFOQAHr0j38m73gmT9ejF3aS5J8pZX5s=; b=iB5pY8/fEWLd+CMZhUfZY0IUZscXbjk91jxThziFGjpyPMDZY8LcdvrAXL28wqr/+1 IHGNmYV40fQuwv7e62aKMD8otcFn4z6UHicwabB5suSkGErkraU3IFG+EEoqU5pigWwP vRGfdNO5oq29nJ+414/xzQSioXSv0wMrfAbUgHf3cHAGvnvdhA6STBXYWkKaRgDT/bxw N7g9hd4liQpkJTiSmXK0LDGNCyVhQQYXDd/xAiSoPhSqhrcgkwWmNz7L+MgvUdf4sup+ GgnVfI0ob1ib0cWQhkrd9EJp/174P49hKXRwYVn362f+/jD1i8zNXda+R9besiydVgTi UwDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317064; x=1702921864; 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=Szd3tCJq3BzuFOQAHr0j38m73gmT9ejF3aS5J8pZX5s=; b=H/0tiN281/Hfk7bb8gjtrqurO1wJaUPV3R6AsPYDsdCWt1ZydmdlCNgcTNwQMFkhYW YHtBug3GQT+w8Z1LQuV15DJ8NrZ+PMbadmt2C1ldZf+ZzGZK1aYsK6vD1KYhxgDO4ChW jReAqzhMoNNGWqZUMTKOCVzPKfykluieE8XS66z3jjfkyo3x5pVNIStCTC2k5AMuIPjX fiFjY78N9wSCTidsCM78lI9DQH2XeDyYJ5jhJuF4pcjnyDY6LEES5A3H+RS8Bxu3Y2Xl /dhwOaKe9uldmululiZfR20w49/cIWkGaqz8HW0pbAGvUtM3KWuvIBCSV3wU34n15HMn TmJQ== X-Gm-Message-State: AOJu0Ywhau/O7FB5qxgLsGKfkDlkyyPaoIVLiNwdzGzxBBVd775vu8mF yMieLKf4ecq9Sy+Ob0UCUVbTM4xvy9FQOC/L X-Received: by 2002:ac2:4f90:0:b0:50b:f7fe:bc11 with SMTP id z16-20020ac24f90000000b0050bf7febc11mr1956528lfs.54.1702317063971; Mon, 11 Dec 2023 09:51:03 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id w22-20020ac254b6000000b0050bf273a895sm1130193lfk.240.2023.12.11.09.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:03 -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 16/19] media: i2c: ov4689: Configurable analogue crop Date: Mon, 11 Dec 2023 20:50:19 +0300 Message-ID: <20231211175023.1680247-17-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=1.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,PDS_OTHER_BAD_TLD, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:51:59 -0800 (PST) X-Spam-Level: * X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008881192566342 X-GMAIL-MSGID: 1785008881192566342 Implement configurable analogue crop via .set_selectiong call. ov4689_init_cfg is modified to initialize default subdev selection. Offsets are aligned to 2 to preserve Bayer order, selection width is aligned to 4 and height to 2 to meet hardware requirements. Experimentally discovered values of the cropping-related registers and vfifo_read_start for various output sizes are used. Default BLC anchor positions are used for the default analogue crop, scaling down proportionally for the smaller crop sizes. When analogue crop is adjusted, several consequential actions take place: the output format is reset, exposure/vblank/hblank control ranges and default values are adjusted accordingly. Additionally, ov4689_set_ctrl utilizes pad crop instead of cur_mode width and height for HTS and VTS calculation. Also, ov4689_enum_frame_sizes is modified to report crop size as available frame size. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 278 ++++++++++++++++++++++++++++--------- 1 file changed, 213 insertions(+), 65 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 9088b4c61cab..f3071e661f4a 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -56,8 +56,13 @@ #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_H_OUTPUT_SIZE_DEFAULT 2688 + #define OV4689_REG_V_OUTPUT_SIZE CCI_REG16(0x380a) +#define OV4689_V_OUTPUT_SIZE_DEFAULT 1520 + #define OV4689_REG_H_WIN_OFF CCI_REG16(0x3810) #define OV4689_REG_V_WIN_OFF CCI_REG16(0x3812) @@ -95,6 +100,19 @@ #define OV4689_DUMMY_ROWS 8 #define OV4689_DUMMY_COLUMNS 16 +/* + * These values are not hardware limits, but rather the minimums that + * the driver has been tested to. + */ +#define OV4689_H_CROP_MIN 128 +#define OV4689_V_CROP_MIN 128 + +/* + * Minimum working vertical blanking value. Found experimentally at + * minimum HTS values. + */ +#define OV4689_VBLANK_MIN 31 + static const char *const ov4689_supply_names[] = { "avdd", /* Analog power */ "dovdd", /* Digital I/O power */ @@ -133,7 +151,7 @@ struct ov4689 { u32 clock_rate; struct v4l2_ctrl_handler ctrl_handler; - struct v4l2_ctrl *exposure; + struct v4l2_ctrl *exposure, *hblank, *vblank; const struct ov4689_mode *cur_mode; }; @@ -319,24 +337,27 @@ static const struct ov4689_gain_range ov4689_gain_ranges[] = { }, }; -static void ov4689_fill_fmt(const struct ov4689_mode *mode, - struct v4l2_mbus_framefmt *fmt) -{ - fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10; - fmt->width = mode->width; - fmt->height = mode->height; - fmt->field = V4L2_FIELD_NONE; -} - static int ov4689_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { - struct v4l2_mbus_framefmt *mbus_fmt = &fmt->format; - struct ov4689 *ov4689 = to_ov4689(sd); + struct v4l2_mbus_framefmt *format; + struct v4l2_rect *crop; + + crop = v4l2_subdev_state_get_crop(sd_state, fmt->pad); + format = v4l2_subdev_state_get_format(sd_state, fmt->pad); - /* only one mode supported for now */ - ov4689_fill_fmt(ov4689->cur_mode, mbus_fmt); + format->width = crop->width; + format->height = crop->height; + + format->code = MEDIA_BUS_FMT_SBGGR10_1X10; + format->field = V4L2_FIELD_NONE; + format->colorspace = V4L2_COLORSPACE_RAW; + format->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT; + format->quantization = V4L2_QUANTIZATION_FULL_RANGE; + format->xfer_func = V4L2_XFER_FUNC_NONE; + + fmt->format = *format; return 0; } @@ -356,16 +377,20 @@ static int ov4689_enum_frame_sizes(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_frame_size_enum *fse) { - if (fse->index >= ARRAY_SIZE(supported_modes)) + const struct v4l2_rect *crop; + + if (fse->index >= 1) return -EINVAL; if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10) return -EINVAL; - fse->min_width = supported_modes[fse->index].width; - fse->max_width = supported_modes[fse->index].width; - fse->max_height = supported_modes[fse->index].height; - fse->min_height = supported_modes[fse->index].height; + crop = v4l2_subdev_state_get_crop(sd_state, 0); + + fse->min_width = crop->width; + fse->max_width = crop->width; + fse->max_height = crop->height; + fse->min_height = crop->height; return 0; } @@ -387,20 +412,14 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) { - if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) - return -EINVAL; - switch (sel->target) { - case V4L2_SEL_TGT_CROP_BOUNDS: - sel->r.top = 0; - sel->r.left = 0; - sel->r.width = OV4689_PIXEL_ARRAY_WIDTH; - sel->r.height = OV4689_PIXEL_ARRAY_HEIGHT; - return 0; case V4L2_SEL_TGT_CROP: + sel->r = *v4l2_subdev_state_get_crop(state, sel->pad); + return 0; + case V4L2_SEL_TGT_CROP_BOUNDS: case V4L2_SEL_TGT_CROP_DEFAULT: - sel->r.top = OV4689_DUMMY_ROWS; sel->r.left = OV4689_DUMMY_COLUMNS; + sel->r.top = OV4689_DUMMY_ROWS; sel->r.width = OV4689_PIXEL_ARRAY_WIDTH - 2 * OV4689_DUMMY_COLUMNS; sel->r.height = @@ -411,37 +430,141 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, return -EINVAL; } -static int ov4689_setup_timings(struct ov4689 *ov4689) +/* + * Minimum working HTS value for given output width (found + * experimentally). + */ +static unsigned int ov4689_hts_min(unsigned int width) { - const struct ov4689_mode *mode = ov4689->cur_mode; + return max_t(unsigned int, 3156, 224 + width * 19 / 16); +} + +static void ov4689_update_ctrl_ranges(struct ov4689 *ov4689, + struct v4l2_rect *crop) +{ + struct v4l2_ctrl *exposure = ov4689->exposure; + struct v4l2_ctrl *vblank = ov4689->vblank; + struct v4l2_ctrl *hblank = ov4689->hblank; + s64 def_val, min_val, max_val; + + min_val = ov4689_hts_min(crop->width) - crop->width; + max_val = OV4689_HTS_MAX - crop->width; + def_val = clamp_t(s64, hblank->default_value, min_val, max_val); + __v4l2_ctrl_modify_range(hblank, min_val, max_val, hblank->step, + def_val); + + min_val = OV4689_VBLANK_MIN; + max_val = OV4689_HTS_MAX - crop->width; + def_val = clamp_t(s64, vblank->default_value, min_val, max_val); + __v4l2_ctrl_modify_range(vblank, min_val, max_val, vblank->step, + def_val); + + min_val = exposure->minimum; + max_val = crop->height + vblank->val - 4; + def_val = clamp_t(s64, exposure->default_value, min_val, max_val); + __v4l2_ctrl_modify_range(exposure, min_val, max_val, exposure->step, + def_val); +} + +static int ov4689_set_selection(struct v4l2_subdev *sd, + struct v4l2_subdev_state *state, + struct v4l2_subdev_selection *sel) +{ + struct ov4689 *ov4689 = to_ov4689(sd); + struct v4l2_mbus_framefmt *format; + struct v4l2_rect *crop; + struct v4l2_rect rect; + + if (sel->target != V4L2_SEL_TGT_CROP) + return -EINVAL; + + rect.left = clamp(ALIGN(sel->r.left, 2), OV4689_DUMMY_COLUMNS, + OV4689_PIXEL_ARRAY_WIDTH); + rect.top = clamp(ALIGN(sel->r.top, 2), OV4689_DUMMY_ROWS, + OV4689_PIXEL_ARRAY_HEIGHT); + + rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 4), + OV4689_H_CROP_MIN, OV4689_PIXEL_ARRAY_WIDTH - + 2 * OV4689_DUMMY_COLUMNS); + rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2), + OV4689_V_CROP_MIN, OV4689_PIXEL_ARRAY_HEIGHT - + 2 * OV4689_DUMMY_ROWS); + + crop = v4l2_subdev_state_get_crop(state, sel->pad); + + if (rect.width != crop->width || rect.height != crop->height) { + /* + * Reset the output image size if the crop rectangle size has + * been modified. + */ + format = v4l2_subdev_state_get_format(state, sel->pad); + format->width = rect.width; + format->height = rect.height; + + if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) + ov4689_update_ctrl_ranges(ov4689, &rect); + } + + *crop = rect; + sel->r = rect; + + return 0; +} + +static int ov4689_setup_timings(struct ov4689 *ov4689, + struct v4l2_subdev_state *state) +{ + const struct v4l2_mbus_framefmt *format; struct regmap *rm = ov4689->regmap; + const struct v4l2_rect *crop; 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); + format = v4l2_subdev_state_get_format(state, 0); + crop = v4l2_subdev_state_get_crop(state, 0); + + cci_write(rm, OV4689_REG_H_CROP_START, crop->left, &ret); + cci_write(rm, OV4689_REG_V_CROP_START, crop->top, &ret); + cci_write(rm, OV4689_REG_H_CROP_END, crop->left + crop->width + 1, &ret); + cci_write(rm, OV4689_REG_V_CROP_END, crop->top + crop->height + 1, &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_OUTPUT_SIZE, format->width, &ret); + cci_write(rm, OV4689_REG_V_OUTPUT_SIZE, format->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_H_WIN_OFF, 0, &ret); + cci_write(rm, OV4689_REG_V_WIN_OFF, 0, &ret); - cci_write(rm, OV4689_REG_VFIFO_CTRL_01, 167, &ret); + /* + * Maximum working value of vfifo_read_start for given output + * width (found experimentally). + */ + cci_write(rm, OV4689_REG_VFIFO_CTRL_01, format->width / 16 - 1, &ret); return ret; } -static int ov4689_setup_blc_anchors(struct ov4689 *ov4689) +/* + * Setup black level compensation anchors. For the default frame width + * default anchors positions are used. For smaller crop sizes they are + * scaled accordingly. + */ +static int ov4689_setup_blc_anchors(struct ov4689 *ov4689, + struct v4l2_subdev_state *state) { + unsigned int width_def = OV4689_H_OUTPUT_SIZE_DEFAULT; struct regmap *rm = ov4689->regmap; + const struct v4l2_rect *crop; 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); + crop = v4l2_subdev_state_get_crop(state, 0); + + cci_write(rm, OV4689_REG_ANCHOR_LEFT_START, + OV4689_ANCHOR_LEFT_START_DEF * crop->width / width_def, &ret); + cci_write(rm, OV4689_REG_ANCHOR_LEFT_END, + OV4689_ANCHOR_LEFT_END_DEF * crop->width / width_def, &ret); + cci_write(rm, OV4689_REG_ANCHOR_RIGHT_START, + OV4689_ANCHOR_RIGHT_START_DEF * crop->width / width_def, &ret); + cci_write(rm, OV4689_REG_ANCHOR_RIGHT_END, + OV4689_ANCHOR_RIGHT_END_DEF * crop->width / width_def, &ret); return ret; } @@ -469,13 +592,13 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; } - ret = ov4689_setup_timings(ov4689); + ret = ov4689_setup_timings(ov4689, sd_state); if (ret) { pm_runtime_put(dev); goto unlock_and_return; } - ret = ov4689_setup_blc_anchors(ov4689); + ret = ov4689_setup_blc_anchors(ov4689, sd_state); if (ret) { pm_runtime_put(dev); goto unlock_and_return; @@ -566,11 +689,25 @@ static int __maybe_unused ov4689_power_off(struct device *dev) static int ov4689_init_cfg(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state) { - struct v4l2_mbus_framefmt *try_fmt = - v4l2_subdev_state_get_format(sd_state, 0); + u32 width_def = OV4689_H_OUTPUT_SIZE_DEFAULT; + u32 height_def = OV4689_V_OUTPUT_SIZE_DEFAULT; + + struct v4l2_subdev_selection sel = { + .target = V4L2_SEL_TGT_CROP, + .r.left = OV4689_DUMMY_COLUMNS, + .r.top = OV4689_DUMMY_ROWS, + .r.width = width_def, + .r.height = height_def, + }; + struct v4l2_subdev_format format = { + .format = { + .width = width_def, + .height = height_def, + }, + }; - /* Initialize try_fmt */ - ov4689_fill_fmt(&supported_modes[OV4689_MODE_2688_1520], try_fmt); + ov4689_set_selection(sd, sd_state, &sel); + ov4689_set_fmt(sd, sd_state, &format); return 0; } @@ -590,6 +727,7 @@ static const struct v4l2_subdev_pad_ops ov4689_pad_ops = { .get_fmt = v4l2_subdev_get_fmt, .set_fmt = ov4689_set_fmt, .get_selection = ov4689_get_selection, + .set_selection = ov4689_set_selection, }; static const struct v4l2_subdev_ops ov4689_subdev_ops = { @@ -631,21 +769,29 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) struct ov4689 *ov4689 = container_of(ctrl->handler, struct ov4689, ctrl_handler); struct regmap *regmap = ov4689->regmap; + struct v4l2_subdev_state *sd_state; struct device *dev = ov4689->dev; + struct v4l2_rect *crop; s32 val = ctrl->val; int sensor_gain; - s64 max_expo; + s64 max_expo, def_expo; int ret; + sd_state = v4l2_subdev_get_locked_active_state(&ov4689->subdev); + crop = v4l2_subdev_state_get_crop(sd_state, 0); + /* Propagate change of current control to all related controls */ switch (ctrl->id) { case V4L2_CID_VBLANK: /* Update max exposure while meeting expected vblanking */ - max_expo = ov4689->cur_mode->height + val - 4; - __v4l2_ctrl_modify_range(ov4689->exposure, - ov4689->exposure->minimum, max_expo, - ov4689->exposure->step, - ov4689->exposure->default_value); + max_expo = crop->height + val - 4; + def_expo = clamp_t(s64, ov4689->exposure->default_value, + ov4689->exposure->minimum, max_expo); + + ret = __v4l2_ctrl_modify_range(ov4689->exposure, + ov4689->exposure->minimum, + max_expo, ov4689->exposure->step, + def_expo); break; } @@ -663,14 +809,14 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) break; case V4L2_CID_VBLANK: cci_write(regmap, OV4689_REG_VTS, - val + ov4689->cur_mode->height, &ret); + val + crop->height, &ret); break; case V4L2_CID_TEST_PATTERN: ret = ov4689_enable_test_pattern(ov4689, val); break; case V4L2_CID_HBLANK: cci_write(regmap, OV4689_REG_HTS, - (val + ov4689->cur_mode->width) / + (val + crop->width) / OV4689_HTS_DIVIDER, &ret); break; case V4L2_CID_VFLIP: @@ -734,14 +880,16 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) hblank_def = mode->hts_def - mode->width; hblank_min = mode->hts_min - mode->width; - v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_HBLANK, - hblank_min, OV4689_HTS_MAX - mode->width, - OV4689_HTS_DIVIDER, hblank_def); + ov4689->hblank = v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, + V4L2_CID_HBLANK, hblank_min, + OV4689_HTS_MAX - mode->width, + OV4689_HTS_DIVIDER, hblank_def); vblank_def = mode->vts_def - mode->height; - v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_VBLANK, - vblank_def, OV4689_VTS_MAX - mode->height, 1, - vblank_def); + ov4689->vblank = v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, + V4L2_CID_VBLANK, OV4689_VBLANK_MIN, + OV4689_VTS_MAX - mode->height, 1, + vblank_def); exposure_max = mode->vts_def - 4; ov4689->exposure = From patchwork Mon Dec 11 17:50:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176852 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230765vqy; Mon, 11 Dec 2023 09:52:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwoDv09J1Ln/uoB0vJ4GZ1gf9HdpL2SWBCan4UZfg3kSnKSPwz6m0FK2ovS9mJKR/fxMOL X-Received: by 2002:a17:90a:4e47:b0:286:db0a:129b with SMTP id t7-20020a17090a4e4700b00286db0a129bmr2136098pjl.43.1702317128530; Mon, 11 Dec 2023 09:52:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317128; cv=none; d=google.com; s=arc-20160816; b=jWIT862X5pamepsAa1oY9XeN1/xkNlHp4N7yyl2yursZFQC+ReTfTjQjpCqIDboXGQ UJzYLgKWNR2Mb7idAZD/Z4CoWYWy7j9DJZ6YYl4u+ZS70eiOSEfE9pK8LZrFEfgpFSrr LYQnAG6+S56gu0zkIf3ocw7rf3I4+hUvEhXfWrMoxnHvE4921mlXbf11C6BYxA9XEgKk T6PzftVeCkn/rke2hB8/5FsZHkz+eG8YE/c5tfKHyOl7DvDrDFNjFlsSjwxpsav1Zy3U 5Y30B1BxwqSqtxE2CoyK+NjDbR5irtqzVG1uyITfcOIACBTjC14LVRS/caPlM8KiRq2C iRlA== 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=/C0YbxXisOYuGkb4hmqJPNMzEyl5yI/OtRTBBpCRGRE=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=bFERKHsTH7gjuqox+t/cBK5r/Jvbs3N2LOf5saiSw0xajmLQWeN2QKzTsE1SR2aCeY DmEFlEUzGfPrSfDEaq78WhO3MQuC9QDm93OjvRld2mswkbVvHD3uKEqcuvicy0RirN3E iQble1GuOBp2sxICT0i1XD1pFz2s2KsrzgBvoDXQbYZvfcDFFC1v0hASbXAQoJDbvJhk N7/OmTONzhVgWBTH3pfEy/PDfZJHTDPqIiYKwbgB9tmX9Cujdv2J40rH01Aey6atv4mQ eEf5qvHxv8tdMD5A+/nyVzJC5m9oXM5v5apBX5TdPWJW1jEcocXO+H4+z4sR1oWsR931 TYog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nR1cUa+6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id h22-20020a17090ac39600b0028688bdbcc4si7816181pjt.161.2023.12.11.09.52.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:52:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nR1cUa+6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id C15C78098FCB; Mon, 11 Dec 2023 09:52:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345185AbjLKRvx (ORCPT + 99 others); Mon, 11 Dec 2023 12:51:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345206AbjLKRvb (ORCPT ); Mon, 11 Dec 2023 12:51:31 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 397B793; Mon, 11 Dec 2023 09:51:08 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-50bf8843a6fso4723550e87.0; Mon, 11 Dec 2023 09:51:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317065; x=1702921865; 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=/C0YbxXisOYuGkb4hmqJPNMzEyl5yI/OtRTBBpCRGRE=; b=nR1cUa+6WZo2E9ss+pRTKFpsiycvFZyTfqS5Yh1E5F2yT+Lnx5Gyh9f/q29dTHnGSd g1zShF9IYc0Vp+LDreFI8rXOh55R7lrR0PBwR/ZrkI/lcZRokIIDih4qRe1EAbJbTe+G mZnJSPawgcFMWTuvgCtZpOrTt6qy3DsrrxeD0JYU0hoV3S/dBSQxYfL1E2JotM7Cyc4Y gleyvONvuJErwOUIg0/K3MpZ81TBFGPslzr3Q5VeYTSqS9h2ZNWnx42QLWJ2zJaXIL8B RGr8dgu/tp0moqlBRZZWqM/62vSgOGRuBvRhSZOVcxt6f/AaaVnpBp2Ua5Xpf3HbJ7vd zm3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317065; x=1702921865; 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=/C0YbxXisOYuGkb4hmqJPNMzEyl5yI/OtRTBBpCRGRE=; b=ojtILzkw5K7Gr87ykYJxfzNsRu47tfnOoT6T7rzC1Y5o2mm2jES3INsPswMc9d0bZA 0fYpJwsXLL2tiIW39XgHtai1hjjAQrSoUDabhzXquFKCp2N/0aM6Yuq5LpFC6PFU2OMb kp2CZ2tu6RA5nMwIGLpDcp7O1IBSQxGqE8c8XciseSYd32IrtBrdSSA+i7gae/b8Jrug M8UP3Dm4j/nm5JZUbb6Vi3XFv+/ZXFu0mwM5niuX7V6hIC8z67CeUgIJGBapkx2NH+rd 8RvbU+UsjzBrxRTmkI0kJohNLu1SYJpPfCeKaXd+6lzmQqF5eFzdpuGFaxEzYsBRONjp uYuQ== X-Gm-Message-State: AOJu0YxAuCgpZwMdMmL+yEBb4ANXpqMlgG9bwRJXxWvTyDDa9uO5vfM8 hzF1twTu6j/mkR9zPI763Cs3SWk8s45+yMQX X-Received: by 2002:ac2:4e0a:0:b0:50b:cafc:bd70 with SMTP id e10-20020ac24e0a000000b0050bcafcbd70mr4285598lfr.0.1702317065101; Mon, 11 Dec 2023 09:51:05 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id m21-20020a0565120a9500b0050d1d8674d2sm722733lfu.292.2023.12.11.09.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:04 -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 17/19] media: i2c: ov4689: Eliminate struct ov4689_mode Date: Mon, 11 Dec 2023 20:50:20 +0300 Message-ID: <20231211175023.1680247-18-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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:52:01 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008885069547084 X-GMAIL-MSGID: 1785008885069547084 With the output frame size now controlled by selection rather than cur_mode, this commit relocates pixel rate and default VTS to defines. Consequently, it removes struct ov4689_mode and the cur_mode field from struct ov4689. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 70 +++++++++----------------------------- 1 file changed, 17 insertions(+), 53 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index f3071e661f4a..e21527ae0b10 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -67,6 +67,8 @@ #define OV4689_REG_V_WIN_OFF CCI_REG16(0x3812) #define OV4689_REG_VTS CCI_REG16(0x380e) +/* Default VTS corresponds to 30 fps at default crop and minimal HTS */ +#define OV4689_VTS_DEF 4683 #define OV4689_VTS_MAX 0x7fff #define OV4689_REG_HTS CCI_REG16(0x380c) @@ -94,6 +96,7 @@ #define OV4689_LANES 4 #define OV4689_XVCLK_FREQ 24000000 +#define OV4689_PIXEL_RATE 480000000 #define OV4689_PIXEL_ARRAY_WIDTH 2720 #define OV4689_PIXEL_ARRAY_HEIGHT 1536 @@ -119,24 +122,6 @@ static const char *const ov4689_supply_names[] = { "dvdd", /* Digital core power */ }; -enum ov4689_mode_id { - OV4689_MODE_2688_1520 = 0, - OV4689_NUM_MODES, -}; - -struct ov4689_mode { - enum ov4689_mode_id id; - u32 width; - u32 height; - u32 hts_def; - u32 hts_min; - u32 vts_def; - u32 exp_def; - u32 pixel_rate; - const struct cci_reg_sequence *reg_list; - unsigned int num_regs; -}; - struct ov4689 { struct device *dev; struct regmap *regmap; @@ -152,8 +137,6 @@ struct ov4689 { struct v4l2_ctrl_handler ctrl_handler; struct v4l2_ctrl *exposure, *hblank, *vblank; - - const struct ov4689_mode *cur_mode; }; #define to_ov4689(sd) container_of(sd, struct ov4689, subdev) @@ -172,7 +155,7 @@ struct ov4689_gain_range { * max_framerate 90fps * mipi_datarate per lane 1008Mbps */ -static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { +static const struct cci_reg_sequence ov4689_common_regs[] = { /* System control*/ {CCI_REG8(0x0103), 0x01}, /* SC_CTRL0103 software_reset = 1 */ {CCI_REG8(0x3000), 0x20}, /* SC_CMMN_PAD_OEN0 FSIN_output_enable = 1 */ @@ -273,21 +256,6 @@ static const struct cci_reg_sequence ov4689_2688x1520_regs[] = { {CCI_REG8(0x5503), 0x0f}, /* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ }; -static const struct ov4689_mode supported_modes[] = { - { - .id = OV4689_MODE_2688_1520, - .width = 2688, - .height = 1520, - .exp_def = 1536, - .hts_def = 10296, - .hts_min = 3432, - .vts_def = 1554, - .pixel_rate = 480000000, - .reg_list = ov4689_2688x1520_regs, - .num_regs = ARRAY_SIZE(ov4689_2688x1520_regs), - }, -}; - static const u64 link_freq_menu_items[] = { 504000000 }; static const char *const ov4689_test_pattern_menu[] = { @@ -584,8 +552,8 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) goto unlock_and_return; ret = cci_multi_reg_write(ov4689->regmap, - ov4689->cur_mode->reg_list, - ov4689->cur_mode->num_regs, + ov4689_common_regs, + ARRAY_SIZE(ov4689_common_regs), NULL); if (ret) { pm_runtime_put(dev); @@ -858,14 +826,12 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) struct i2c_client *client = v4l2_get_subdevdata(&ov4689->subdev); struct v4l2_fwnode_device_properties props; struct v4l2_ctrl_handler *handler; - const struct ov4689_mode *mode; s64 exposure_max, vblank_def; - s64 hblank_def, hblank_min; struct v4l2_ctrl *ctrl; + s64 hblank_def; int ret; handler = &ov4689->ctrl_handler; - mode = ov4689->cur_mode; ret = v4l2_ctrl_handler_init(handler, 16); if (ret) return ret; @@ -876,26 +842,26 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE, 0, - mode->pixel_rate, 1, mode->pixel_rate); + OV4689_PIXEL_RATE, 1, OV4689_PIXEL_RATE); - hblank_def = mode->hts_def - mode->width; - hblank_min = mode->hts_min - mode->width; + hblank_def = ov4689_hts_min(OV4689_H_OUTPUT_SIZE_DEFAULT) - + OV4689_H_OUTPUT_SIZE_DEFAULT; ov4689->hblank = v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, - V4L2_CID_HBLANK, hblank_min, - OV4689_HTS_MAX - mode->width, + V4L2_CID_HBLANK, hblank_def, + OV4689_HTS_MAX - OV4689_H_OUTPUT_SIZE_DEFAULT, OV4689_HTS_DIVIDER, hblank_def); - vblank_def = mode->vts_def - mode->height; + vblank_def = OV4689_VTS_DEF - OV4689_V_OUTPUT_SIZE_DEFAULT; ov4689->vblank = v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_VBLANK, OV4689_VBLANK_MIN, - OV4689_VTS_MAX - mode->height, 1, - vblank_def); + OV4689_VTS_MAX - OV4689_V_OUTPUT_SIZE_DEFAULT, + 1, vblank_def); - exposure_max = mode->vts_def - 4; + exposure_max = OV4689_VTS_DEF - 4; ov4689->exposure = v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_EXPOSURE, OV4689_EXPOSURE_MIN, exposure_max, - OV4689_EXPOSURE_STEP, mode->exp_def); + OV4689_EXPOSURE_STEP, exposure_max); v4l2_ctrl_new_std(handler, &ov4689_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, ov4689_gain_ranges[0].logical_min, @@ -1050,8 +1016,6 @@ static int ov4689_probe(struct i2c_client *client) ov4689->dev = dev; - ov4689->cur_mode = &supported_modes[OV4689_MODE_2688_1520]; - ov4689->xvclk = devm_clk_get_optional(dev, NULL); if (IS_ERR(ov4689->xvclk)) return dev_err_probe(dev, PTR_ERR(ov4689->xvclk), From patchwork Mon Dec 11 17:50:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176854 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7230983vqy; Mon, 11 Dec 2023 09:52:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEj0kOmo9sPPJyG48pluXnv9MnzZzMlwCjRopuKLXlC4Dv4C2F/yCLmiGwVcDshwDx60Q/i X-Received: by 2002:a17:90a:ebc6:b0:286:9cc1:a24 with SMTP id cf6-20020a17090aebc600b002869cc10a24mr2088220pjb.12.1702317155653; Mon, 11 Dec 2023 09:52:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317155; cv=none; d=google.com; s=arc-20160816; b=ITGH5t346fVZo6AeewKKCIo04CXje9EEGmBoymLkNzlyeZ7h2lI3YXmRG1qRR+PzCU ca9kvlo2W73IOg+tNbpWbXUG8dWA0Olyaxwlc6PY9GiMgfUtFjlFYhEEktax4JS0m7Hh pkNdjexaZQdOBfFi7kmL9U9HI9a+hre3TV1+ZqlHRcpzr9gHonrYsi6O7kFd1ti7ACQZ v6kvN9ZqjGEEllwgiONxrhQFX9lnkrjBTssTo1zCzj6Lx006vrxtgvgzESOYwc/guWQx Qh3sruu/KwdCnzyNjOJmpuDVtKJwk8soNdzZb5dgHkwC6yg2v361R7ZYiBKFdSeoIhr9 nOIQ== 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=U1YDTnus4TPxjUF248/sdbNAm7YGCStl7FgqnfZm760=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=k/aOAdatNU4+pgdJzTjj/YvhmJS875YeaQJYPkKBP2OH9k0dtWTmJsNnJnwnXIMu8l joCN0jqlEbFkXA5ovpLnI7e8OzkBuS7bwoGjCkyj0d8UgaCT5CZcpHUo1j/Kk0/nGx68 Z4Y+RvwgzbzYVX0xozP5dekZS5rZIgRR6utc6JvQKWELIEHEHhJ5+dZtWRMsoLg2yZga 0gzUlujCkf7UU5SU619B3t/q28M4ozrBaisPv53Z0OXD9X8cbMJjqMpUrzR4flEQi5yL 4H9Cck9amB6MVXIW1Prq3oF8hOqlVP6CBJO/DPE1cB2bjJ7GZyEY5JFx52D0SM3eBQjd 2vjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HvQLV7n0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id y2-20020a17090a86c200b0028675cb4aeasi7594810pjv.47.2023.12.11.09.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:52:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HvQLV7n0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 8F59280413AA; Mon, 11 Dec 2023 09:52:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235044AbjLKRwF (ORCPT + 99 others); Mon, 11 Dec 2023 12:52:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235034AbjLKRvn (ORCPT ); Mon, 11 Dec 2023 12:51:43 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE60139; Mon, 11 Dec 2023 09:51:09 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-50bfd7be487so5404582e87.0; Mon, 11 Dec 2023 09:51:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317067; x=1702921867; 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=U1YDTnus4TPxjUF248/sdbNAm7YGCStl7FgqnfZm760=; b=HvQLV7n0+0kL/JkTnuruE2QH57SRtUBKq23ypn64xAT4uCP41PoWG6JE2M/pQKWg70 WUPQwJ+/R5dxsLkx3nScegHTWcGqDnNhTG37g59LXT+19QS13Y52f5jvZ6D/mT/XTXZR X5khxPJNsPpad5cIHWC2LOVuKbaytE6q09z8OE5K2k5FJdSbXbkd1z7M0wNaL8/uGgiL xNZZ3aep/hCyMAahsq1aWLGoSBQFQmdYX8KRZhh559sj2otiO9FHZGCq+2iuCjTT4xuO xlthv1YwJnybr/G+ZnlizzUz7GpLcuPVq1f1YBT+/ES6Sn/jMnCNx4pztpDj5rFXzq+U cUbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317067; x=1702921867; 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=U1YDTnus4TPxjUF248/sdbNAm7YGCStl7FgqnfZm760=; b=iywDbUfYCaFIoNmC23gbarIxewmP7HIXrP5JIv4+Bk3Tt+hOeDwK0/TX+UVnzR/jQK 5FY/3BCw//A2ZGDC6gcDQ3LHPDavRVNztFCWwEd7uKPVM89aGC/1K80zWWlsumJXI3tC neR2kfODxukqlEuVK8144f7UeNJcCq0/CR0JMdrFCtI7+5tsUFfYDTbmBdLFrLi105wQ cQPmsL3Y6KZcR6NHAu+tyrAoY5k1kcQgXkMR1o3X3uPtMq7EwINzbnplHKQRft7850EC CFTMznCLU3YSm+q1HuO80/AwC4TRXNDUIP7kPPJLVe2zmG/dJmf+L0vHBTsH9HaEVGRh UCOg== X-Gm-Message-State: AOJu0YxFYUsg5TB2BviCcac6ESfqDvt6ELIQLlzZM2XowUcYxrTcqPek VBYLbfE1+UVi+oyBHyDe017qgh9zrM668vFI X-Received: by 2002:a05:6512:3112:b0:50b:fda6:9135 with SMTP id n18-20020a056512311200b0050bfda69135mr1973338lfb.101.1702317066908; Mon, 11 Dec 2023 09:51:06 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id v25-20020ac25939000000b0050bef1c5b39sm1153777lfi.61.2023.12.11.09.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:06 -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 18/19] media: i2c: ov4689: Refactor ov4689_s_stream Date: Mon, 11 Dec 2023 20:50:21 +0300 Message-ID: <20231211175023.1680247-19-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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:52:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008913862284457 X-GMAIL-MSGID: 1785008913862284457 Remove repetitive pm_runtime_put calls in ov4689_s_stream function, and call pm_runtime_put once at the end of the "on" branch if any error occurred. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index e21527ae0b10..034bd9077a3a 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -555,35 +555,26 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689_common_regs, ARRAY_SIZE(ov4689_common_regs), NULL); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } + if (ret) + goto cleanup_pm; ret = ov4689_setup_timings(ov4689, sd_state); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } + if (ret) + goto cleanup_pm; ret = ov4689_setup_blc_anchors(ov4689, sd_state); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } + if (ret) + goto cleanup_pm; ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } + if (ret) + goto cleanup_pm; ret = cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, OV4689_MODE_STREAMING, NULL); - if (ret) { +cleanup_pm: + if (ret) pm_runtime_put(dev); - goto unlock_and_return; - } } else { cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, OV4689_MODE_SW_STANDBY, NULL); From patchwork Mon Dec 11 17:50:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 176855 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7231043vqy; Mon, 11 Dec 2023 09:52:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFp8V/r6DK71BO5xWclbZtYkM2FxQWWj0wwNV30TaB8e+lvoYJ+nFTTE6levj2yxQYFL2Mm X-Received: by 2002:a05:6a00:2d97:b0:6ce:7cba:3a6e with SMTP id fb23-20020a056a002d9700b006ce7cba3a6emr5287247pfb.10.1702317164634; Mon, 11 Dec 2023 09:52:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702317164; cv=none; d=google.com; s=arc-20160816; b=XwvrWGMUVvWRZxYdCdFvNh434Tn0AcxWIOF4oCOeSXw2DWnWuY7Xq4gr7sJUKu3tNL njvoAsVT5lCoVesX3Oe0QXklCHJnsl0khnh3zjQUjjPj7aN5HDnuEV3a7fMp7aKmvLWj 6FVOqtlqVd1dDhDxn3HouN4CmJbPkpFEuDZcmx8RTa1RmcPnmcXNghDTToF7o0rGE4UX 8oNJ2Nzm+SAlzVZZdxzZg4dFVx7QXqv5qyrOIb5CemLg9dAqbpfZo4ziqC4Rl19GJTiG c/gC+DCg58TKgryEkgH42O5C39U1sRldTK3u/ocnbfdU7KEC1+T5ZWwUpRWyARsRA/sg oZDQ== 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=xnEjGpYqb0K7tittd+dUy5/SHqg4UXSF+hRs5s4lNiU=; fh=fWwPNk1JCACPIViZY2QlWlGqVImCQC9sYxd2Gp7QPV0=; b=o42x5K1Ejen3OXHwCkTY5FJppkSMbtBL+2cOAIka0yd6ZnGZxHqjbRvcj5sWl9/skw Z8mjfpwPUmPrTEEmde9gsNKvFjJyqrc8ULaezD9lAoDdOKHzcGWekRsxKTMqQtZwl15v 3vUBk+ymupdGNsG4Wd7f/u/A1Vjth+HukwRhuVhZu68TfLejvyVJQHurSHE9wYkIo/eV U/eQeQ80a71YfXiCFQXCoEi5rjg3t8POMP/c1RYHkKVNU8dECzMruJlpMUgvXrqsztJZ 0K8OBvmOHxA+uiQJ1+0vWr5HBJrI6e0ZDHnCQ7z5f9fBp1F0H4UrRv/d1+2zGe39VWTg fWEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=V0NTn7Ae; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id m125-20020a632683000000b005c6183ccab1si6443223pgm.529.2023.12.11.09.52.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:52:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=V0NTn7Ae; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id D88C58098FDB; Mon, 11 Dec 2023 09:52:40 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345234AbjLKRwJ (ORCPT + 99 others); Mon, 11 Dec 2023 12:52:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235048AbjLKRvo (ORCPT ); Mon, 11 Dec 2023 12:51:44 -0500 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43CE3F4; Mon, 11 Dec 2023 09:51:11 -0800 (PST) Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2ca09601127so63403581fa.1; Mon, 11 Dec 2023 09:51:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702317068; x=1702921868; 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=xnEjGpYqb0K7tittd+dUy5/SHqg4UXSF+hRs5s4lNiU=; b=V0NTn7AegTR/N6P6knaLaKJSPKAMjGSD9R1rHHZjFwKA1xefdr1R4tUO/VY4Z9sBJ9 OTsIWgtHVmADErnl4e2CXLzjgKPf4fuGk7ZHYt5WBH3j3lWGL2/V2soCMOlyZhDZ0uY6 Dz/tU4Z03wSEinBBjKzMwu6+CLviB6KwNieKvBmYH/hyzXOPO1JaXlSKDNjZpC2ftUtD X3FJIbBT2t3OF0MwTQCOYxa56EZVES0ahPNKGqzeQFTBoOlJ5WIN209kkP4J1EDllUAW x2juxzbKIT4bcurTWov+v+9DTeNMiq6WgRJIBvOZO/+wByq2FFCoHzHbReKuc+M5Qc9N TgGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702317068; x=1702921868; 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=xnEjGpYqb0K7tittd+dUy5/SHqg4UXSF+hRs5s4lNiU=; b=Tg7Be8UQjCnKqbfy86tehPsi3XNAdCNCMLyk+Wck3lIe4T49IZx1KwiH067S8roa1j OVkgUF960cxWO/6T4hiyFuJwFdAV6VtI0QlQeWQLmx6WqTDjCmCf9fxJKtiGPRFouTve T3BGQOU8PA1D9AuIcx4bC+U3Fraew+tCzDYqg4LhxB0bYWx3pLuZVt8EobU3+p1cUiJs II7DdjExU07RF2JW0zuTASARh1nR7z/rVG3ZQSuu43IIWWbk1Q8U/Yug450kSm8/Pl+d t/Y9dWp/8JaA0wl7TgfQLk9Js6u59hGt6+MgNajavnp/KabnQmt/EsXb3tf3O23Rz+ML 7RyQ== X-Gm-Message-State: AOJu0Yw5FW5VNcLmM+9ZdiyvsVzVZc1vTDn/B3UEAAaH3Jg0wQyVR+8e tIk+ypQK2AlT9azCE8ovqFaDUUmfmpuqjK7D X-Received: by 2002:a2e:a585:0:b0:2cc:1d21:80a0 with SMTP id m5-20020a2ea585000000b002cc1d2180a0mr1257989ljp.107.1702317068111; Mon, 11 Dec 2023 09:51:08 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id p7-20020a2e9a87000000b002cc238645aesm303879lji.61.2023.12.11.09.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:51:07 -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 19/19] media: i2c: ov4689: Implement 2x2 binning Date: Mon, 11 Dec 2023 20:50:22 +0300 Message-ID: <20231211175023.1680247-20-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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:52:41 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785008923260811058 X-GMAIL-MSGID: 1785008923260811058 Implement 2x2 binning support. Compute best binning mode (none or 2x2) from pad crop and pad format in ov4689_set_fmt. Use output frame size instead of analogue crop to compute control ranges and BLC anchors. Also move ov4689_hts_min and ov4689_update_ctrl_ranges, since they are now also called from ov4689_set_fmt. Update frame timings to accommodate the requirements of binning mode and avoid visual artefacts. Additionally, report 2x2 binned mode in addition to non-binned one in ov4689_enum_frame_sizes. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 192 +++++++++++++++++++++++++------------ 1 file changed, 130 insertions(+), 62 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 034bd9077a3a..2967fbfb81e4 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -114,7 +114,7 @@ * Minimum working vertical blanking value. Found experimentally at * minimum HTS values. */ -#define OV4689_VBLANK_MIN 31 +#define OV4689_VBLANK_MIN 35 static const char *const ov4689_supply_names[] = { "avdd", /* Analog power */ @@ -256,6 +256,18 @@ static const struct cci_reg_sequence ov4689_common_regs[] = { {CCI_REG8(0x5503), 0x0f}, /* OTP_DPC_END_L otp_end_address[7:0] = 0x0f */ }; +static const struct cci_reg_sequence ov4689_2x2_binning_regs[] = { + {CCI_REG8(0x3632), 0x05}, /* ADC */ + {CCI_REG8(0x376b), 0x40}, /* Sensor control */ + {CCI_REG8(0x3814), 0x03}, /* H_INC_ODD */ + {CCI_REG8(0x3821), 0x07}, /* TIMING_FORMAT_2 hor_binning = 1*/ + {CCI_REG8(0x382a), 0x03}, /* V_INC_ODD */ + {CCI_REG8(0x3830), 0x08}, /* BLC_NUM_OPTION blc_use_num_2 = 1 */ + {CCI_REG8(0x3836), 0x02}, /* TIMING_REG_36 r_zline_use_num_2 = 1 */ + {CCI_REG8(0x4001), 0x50}, /* BLC DEBUG MODE */ + {CCI_REG8(0x4502), 0x44}, /* ADC synch control*/ +}; + static const u64 link_freq_menu_items[] = { 504000000 }; static const char *const ov4689_test_pattern_menu[] = { @@ -305,18 +317,96 @@ static const struct ov4689_gain_range ov4689_gain_ranges[] = { }, }; +/* + * For now, only 2x2 binning implemented in this driver. + */ +static int ov4689_best_binning(struct ov4689 *ov4689, + const struct v4l2_mbus_framefmt *format, + const struct v4l2_rect *crop, + unsigned int *binning) +{ + const struct v4l2_area candidates[] = { + { crop->width, crop->height }, + { crop->width / 2, crop->height / 2 }, + }; + + const struct v4l2_area *best; + int index; + + best = v4l2_find_nearest_size(candidates, ARRAY_SIZE(candidates), width, + height, format->width, format->height); + if (!best) { + dev_err(ov4689->dev, + "failed to find best binning for requested mode\n"); + return -EINVAL; + } + + index = best - candidates; + *binning = index + 1; + + dev_dbg(ov4689->dev, + "best_binning: crop=%dx%d format=%dx%d binning=%d\n", + crop->width, crop->height, format->width, format->height, + *binning); + + return 0; +} + +/* + * Minimum working HTS value for given output width (found + * experimentally). + */ +static unsigned int ov4689_hts_min(unsigned int width) +{ + return max_t(unsigned int, 3156, 224 + width * 19 / 16); +} + +static void ov4689_update_ctrl_ranges(struct ov4689 *ov4689, unsigned int width, + unsigned int height) +{ + struct v4l2_ctrl *exposure = ov4689->exposure; + struct v4l2_ctrl *vblank = ov4689->vblank; + struct v4l2_ctrl *hblank = ov4689->hblank; + s64 def_val, min_val, max_val; + + min_val = ov4689_hts_min(width) - width; + max_val = OV4689_HTS_MAX - width; + def_val = clamp_t(s64, hblank->default_value, min_val, max_val); + __v4l2_ctrl_modify_range(hblank, min_val, max_val, hblank->step, + def_val); + + min_val = OV4689_VBLANK_MIN; + max_val = OV4689_HTS_MAX - width; + def_val = clamp_t(s64, vblank->default_value, min_val, max_val); + __v4l2_ctrl_modify_range(vblank, min_val, max_val, vblank->step, + def_val); + + min_val = exposure->minimum; + max_val = height + vblank->val - 4; + def_val = clamp_t(s64, exposure->default_value, min_val, max_val); + __v4l2_ctrl_modify_range(exposure, min_val, max_val, exposure->step, + def_val); +} + static int ov4689_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *fmt) { + struct ov4689 *ov4689 = to_ov4689(sd); struct v4l2_mbus_framefmt *format; struct v4l2_rect *crop; + unsigned int binning; + int ret; crop = v4l2_subdev_state_get_crop(sd_state, fmt->pad); format = v4l2_subdev_state_get_format(sd_state, fmt->pad); - format->width = crop->width; - format->height = crop->height; + ret = ov4689_best_binning(ov4689, &fmt->format, crop, &binning); + if (ret) + return ret; + + format->width = crop->width / binning; + format->height = crop->height / binning; format->code = MEDIA_BUS_FMT_SBGGR10_1X10; format->field = V4L2_FIELD_NONE; @@ -327,6 +417,9 @@ static int ov4689_set_fmt(struct v4l2_subdev *sd, fmt->format = *format; + if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) + ov4689_update_ctrl_ranges(ov4689, format->width, format->height); + return 0; } @@ -346,8 +439,9 @@ static int ov4689_enum_frame_sizes(struct v4l2_subdev *sd, struct v4l2_subdev_frame_size_enum *fse) { const struct v4l2_rect *crop; + int binning; - if (fse->index >= 1) + if (fse->index >= 2) return -EINVAL; if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10) @@ -355,10 +449,11 @@ static int ov4689_enum_frame_sizes(struct v4l2_subdev *sd, crop = v4l2_subdev_state_get_crop(sd_state, 0); - fse->min_width = crop->width; - fse->max_width = crop->width; - fse->max_height = crop->height; - fse->min_height = crop->height; + binning = fse->index + 1; + fse->min_width = crop->width / binning; + fse->max_width = crop->width / binning; + fse->max_height = crop->height / binning; + fse->min_height = crop->height / binning; return 0; } @@ -398,42 +493,6 @@ static int ov4689_get_selection(struct v4l2_subdev *sd, return -EINVAL; } -/* - * Minimum working HTS value for given output width (found - * experimentally). - */ -static unsigned int ov4689_hts_min(unsigned int width) -{ - return max_t(unsigned int, 3156, 224 + width * 19 / 16); -} - -static void ov4689_update_ctrl_ranges(struct ov4689 *ov4689, - struct v4l2_rect *crop) -{ - struct v4l2_ctrl *exposure = ov4689->exposure; - struct v4l2_ctrl *vblank = ov4689->vblank; - struct v4l2_ctrl *hblank = ov4689->hblank; - s64 def_val, min_val, max_val; - - min_val = ov4689_hts_min(crop->width) - crop->width; - max_val = OV4689_HTS_MAX - crop->width; - def_val = clamp_t(s64, hblank->default_value, min_val, max_val); - __v4l2_ctrl_modify_range(hblank, min_val, max_val, hblank->step, - def_val); - - min_val = OV4689_VBLANK_MIN; - max_val = OV4689_HTS_MAX - crop->width; - def_val = clamp_t(s64, vblank->default_value, min_val, max_val); - __v4l2_ctrl_modify_range(vblank, min_val, max_val, vblank->step, - def_val); - - min_val = exposure->minimum; - max_val = crop->height + vblank->val - 4; - def_val = clamp_t(s64, exposure->default_value, min_val, max_val); - __v4l2_ctrl_modify_range(exposure, min_val, max_val, exposure->step, - def_val); -} - static int ov4689_set_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, struct v4l2_subdev_selection *sel) @@ -470,7 +529,8 @@ static int ov4689_set_selection(struct v4l2_subdev *sd, format->height = rect.height; if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) - ov4689_update_ctrl_ranges(ov4689, &rect); + ov4689_update_ctrl_ranges(ov4689, rect.width, + rect.height); } *crop = rect; @@ -485,21 +545,27 @@ static int ov4689_setup_timings(struct ov4689 *ov4689, const struct v4l2_mbus_framefmt *format; struct regmap *rm = ov4689->regmap; const struct v4l2_rect *crop; + const int v_offset = 2; + unsigned int binning; int ret = 0; format = v4l2_subdev_state_get_format(state, 0); crop = v4l2_subdev_state_get_crop(state, 0); + ret = ov4689_best_binning(ov4689, format, crop, &binning); + if (ret) + return ret; + cci_write(rm, OV4689_REG_H_CROP_START, crop->left, &ret); - cci_write(rm, OV4689_REG_V_CROP_START, crop->top, &ret); - cci_write(rm, OV4689_REG_H_CROP_END, crop->left + crop->width + 1, &ret); - cci_write(rm, OV4689_REG_V_CROP_END, crop->top + crop->height + 1, &ret); + cci_write(rm, OV4689_REG_V_CROP_START, crop->top - v_offset, &ret); + cci_write(rm, OV4689_REG_H_CROP_END, crop->left + crop->width + 3, &ret); + cci_write(rm, OV4689_REG_V_CROP_END, crop->top + crop->height + 7, &ret); cci_write(rm, OV4689_REG_H_OUTPUT_SIZE, format->width, &ret); cci_write(rm, OV4689_REG_V_OUTPUT_SIZE, format->height, &ret); cci_write(rm, OV4689_REG_H_WIN_OFF, 0, &ret); - cci_write(rm, OV4689_REG_V_WIN_OFF, 0, &ret); + cci_write(rm, OV4689_REG_V_WIN_OFF, v_offset, &ret); /* * Maximum working value of vfifo_read_start for given output @@ -507,6 +573,10 @@ static int ov4689_setup_timings(struct ov4689 *ov4689, */ cci_write(rm, OV4689_REG_VFIFO_CTRL_01, format->width / 16 - 1, &ret); + if (binning == 2) + cci_multi_reg_write(ov4689->regmap, ov4689_2x2_binning_regs, + ARRAY_SIZE(ov4689_2x2_binning_regs), + &ret); return ret; } @@ -519,20 +589,20 @@ static int ov4689_setup_blc_anchors(struct ov4689 *ov4689, struct v4l2_subdev_state *state) { unsigned int width_def = OV4689_H_OUTPUT_SIZE_DEFAULT; + const struct v4l2_mbus_framefmt *format; struct regmap *rm = ov4689->regmap; - const struct v4l2_rect *crop; int ret = 0; - crop = v4l2_subdev_state_get_crop(state, 0); + format = v4l2_subdev_state_get_format(state, 0); cci_write(rm, OV4689_REG_ANCHOR_LEFT_START, - OV4689_ANCHOR_LEFT_START_DEF * crop->width / width_def, &ret); + OV4689_ANCHOR_LEFT_START_DEF * format->width / width_def, &ret); cci_write(rm, OV4689_REG_ANCHOR_LEFT_END, - OV4689_ANCHOR_LEFT_END_DEF * crop->width / width_def, &ret); + OV4689_ANCHOR_LEFT_END_DEF * format->width / width_def, &ret); cci_write(rm, OV4689_REG_ANCHOR_RIGHT_START, - OV4689_ANCHOR_RIGHT_START_DEF * crop->width / width_def, &ret); + OV4689_ANCHOR_RIGHT_START_DEF * format->width / width_def, &ret); cci_write(rm, OV4689_REG_ANCHOR_RIGHT_END, - OV4689_ANCHOR_RIGHT_END_DEF * crop->width / width_def, &ret); + OV4689_ANCHOR_RIGHT_END_DEF * format->width / width_def, &ret); return ret; } @@ -730,20 +800,20 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) struct regmap *regmap = ov4689->regmap; struct v4l2_subdev_state *sd_state; struct device *dev = ov4689->dev; - struct v4l2_rect *crop; + struct v4l2_mbus_framefmt *fmt; s32 val = ctrl->val; int sensor_gain; s64 max_expo, def_expo; int ret; sd_state = v4l2_subdev_get_locked_active_state(&ov4689->subdev); - crop = v4l2_subdev_state_get_crop(sd_state, 0); + fmt = v4l2_subdev_state_get_format(sd_state, 0); /* Propagate change of current control to all related controls */ switch (ctrl->id) { case V4L2_CID_VBLANK: /* Update max exposure while meeting expected vblanking */ - max_expo = crop->height + val - 4; + max_expo = fmt->height + val - 4; def_expo = clamp_t(s64, ov4689->exposure->default_value, ov4689->exposure->minimum, max_expo); @@ -767,16 +837,14 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) cci_write(regmap, OV4689_REG_GAIN, sensor_gain, &ret); break; case V4L2_CID_VBLANK: - cci_write(regmap, OV4689_REG_VTS, - val + crop->height, &ret); + cci_write(regmap, OV4689_REG_VTS, val + fmt->height, &ret); break; case V4L2_CID_TEST_PATTERN: ret = ov4689_enable_test_pattern(ov4689, val); break; case V4L2_CID_HBLANK: cci_write(regmap, OV4689_REG_HTS, - (val + crop->width) / - OV4689_HTS_DIVIDER, &ret); + (val + fmt->width) / OV4689_HTS_DIVIDER, &ret); break; case V4L2_CID_VFLIP: cci_update_bits(regmap, OV4689_REG_TIMING_FORMAT1,