From patchwork Mon Dec 18 17:40: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: 755782 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5789371468; Mon, 18 Dec 2023 17:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j0LS66qB" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-50e389473fcso1732643e87.2; Mon, 18 Dec 2023 09:40:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921257; x=1703526057; 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=j0LS66qBoldQQ8DRkaluVySVsyyE8lqf8AxBwyCfzg1fEa0rkZNPPs6FBrCsndp1DN h2AvryR7+8tj6kna1M6TwJr71g0h/4woIMR/GGZ23Zwn41czRJSxOpN0CdFSR+VVsXAK +TyCcuYNETrefASly96hrpvJQQm26kRdr+GyQysbskllWUzQvPm6pwf0r+jM0joHiKho AwNIO7I8cKSw8GSQCIoKkgkjAhpThV3bhsi9YQaLTT35blC9sU5GOhRIXqtCc+8QSANa qo955JMLaKaOEVPeFQGK+L7j3hckNw6Dm2Rkdb1/9JwxjxrjWG+DVwgZAaOYEPeFNHGv AbGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921257; x=1703526057; 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=UvA/FLMmQefvKvolub9P35LwhKNALOQi9LLOMQBT/MOlz6STlK7V11D7yQj3ieHvWg VdBMOWRIwJJZPIlUCZf1IN9GrfXJ5D2EZg8Fewi0nEUPQTB3fpXrk46+aShmF+C933Rl l/7EaN60Dkhnd9H1Y9Px81N5R7CW14b02X6RiDou7t3aC7Tgh94x9MNTq3SbmYYJad7N vH3aJRdg8FcUnc1/zW8RGSplNzD//A86nIGlbOR7EJ9PuCO73FHCtQxNyKlWr1G6+oSo jV5m4u+5MlQ8EjDoA/UcN63kfoyb9mrke5kIJzW8aG4Jrv4cxDTBsm1HdYgHDh9yVLA4 raBQ== X-Gm-Message-State: AOJu0Yxt8cVXK7sDqRN/cNzp9DpqGHZf6QKPgdExjGlvXoDDIgxUQ8Cl VXjLHfAEGxqCa4cZLnRXU1chnzma3XpEzQ== X-Google-Smtp-Source: AGHT+IFRZlYiV1RrtKLd/tt7YdaB8WYCS3mHUoi9HVIFDw+Sw/cPdJXGmipZyR1nbzVsPGbdrv/86w== X-Received: by 2002:a05:6512:6e:b0:50e:20fe:2c66 with SMTP id i14-20020a056512006e00b0050e20fe2c66mr1950035lfo.46.1702921257312; Mon, 18 Dec 2023 09:40:57 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id eq24-20020a056512489800b0050e233d2533sm803945lfb.159.2023.12.18.09.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:40:57 -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 v2 01/20] media: i2c: ov4689: Clean up and annotate the register table Date: Mon, 18 Dec 2023 20:40:22 +0300 Message-ID: <20231218174042.794012-2-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Acked-by: Laurent Pinchart --- 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 18 17:40:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 755781 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28ADF5D75A; Mon, 18 Dec 2023 17:41:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SiBl11nX" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-50e389473fcso1732707e87.2; Mon, 18 Dec 2023 09:41:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921260; x=1703526060; 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=lTDInBpm9IOKZKwVJjEBdmix1UD/v8KGld+1PsGVp6w=; b=SiBl11nXBEMHTM5Oe5DpIjlyoSvW9JFsoiLyu4PRkumz9HCk71neQmlVGjuqgr+oCl TdQeuEy4cCmkR8zOgT1HbVPnAR0h4MjgEudfjWCzP53Y26qfDWxCGDWp7YgF4KQVDDVU qNQ4qYayOlC1WcfXvs9zAzgvobdjZnAmRBcKBm7Pkk76mJh+3kCC/RlNPHYKDHIoR+Yb XdpnKHdAtLGyOJcYZ2fKv6jhjzZwQKJlsVEJSGFgAGJPgskTPeSvW8Jkb9HwjynOQbGf Cz2kQxyiWUb/nBpsiSzfS3Va/UGy45SsJ4zzpNnmexOta5j+VNzOtlWrQ0kf9SFDpF5e jiEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921260; x=1703526060; 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=lTDInBpm9IOKZKwVJjEBdmix1UD/v8KGld+1PsGVp6w=; b=nFmvA/rMl1UKeopbR6X8zBhaaSSNiBTQVu+ssWBDyvb4SKDz6rqsNcqXVV3DtnuSLj zxT++KHIGz6ASK2LOOCUMyhDu4dSqmTAAr41RxCMJ/PEj/FjDK3CG2rHHxboV6M4JI6v uRkHl8CJ2ONWNvsD/JuWQBHu76aIabJc5mfGy/8gRD6yQ/7ALMKUnNjTlC47yL7heCSy 3hnp6nykzVecpHB6+s9juIhVesofn7kU4wahW1wuw0lAPh3F79EbVtjMys01RON7ZV67 oCruYoDON3+GSjEEd+D6mXQ3G0yjhT6UIDfSJl7LBAx23mh9H6nVvimcUZ4AapVcB3/m SzTQ== X-Gm-Message-State: AOJu0Yy+8INZZ3z/J8E2DGxdOq9z8/E2SZKMxgK/keFpy01q0gz+7MSN VOUSJaEdTz4xdNhkZd8bstSJbQQn3LPv4w== X-Google-Smtp-Source: AGHT+IF8m8vP0MsejeJK8yQbMHuQD09w2Ti/wP3cYuz/5CHJeklc0I5BDObhq9cKffHNyB42jbQiIQ== X-Received: by 2002:ac2:46f3:0:b0:50e:24c4:6080 with SMTP id q19-20020ac246f3000000b0050e24c46080mr1815577lfo.7.1702921260303; Mon, 18 Dec 2023 09:41:00 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id k5-20020ac24f05000000b005094486b705sm3016372lfr.16.2023.12.18.09.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:41:00 -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 v2 03/20] media: i2c: ov4689: Fix typo in a comment Date: Mon, 18 Dec 2023 20:40:24 +0300 Message-ID: <20231218174042.794012-4-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 1ae6d9b9c9b3..7c33961fbb89 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 18 17:40:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 755780 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6ACB73462; Mon, 18 Dec 2023 17:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eNeuCI9/" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-50bf2d9b3fdso4627494e87.3; Mon, 18 Dec 2023 09:41:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921265; x=1703526065; 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=zRAVS4vC9ni6nFv/TOVO0tDXxMYBMHf0gL/d3MqoeLg=; b=eNeuCI9/n8IPTWNx30Fk1ROiHUtsmOZcgYTGHFJaoRZeqYcl9rCewx58shHDR1REXr yO2PHSUgJMVEkLVD5yeFNdZgyUlTPCUp5/V30l8q9zTcdIC/355B+50lDCScOsTNLCPz oWWvRLkUklIJe9BfjU3Y24Ulhp+xwlss7+uofV/rSGtw3rMXqXqOEmMbzKjBWXbc3Ktg ZInWIk0iumOtGAtN5zKXNwNDDZ5ZN55cnhhtdpEgDRLoTCbZL4gtSJdRLFLFrrGOqXmW 0aa3EGUW8VUyXoOXmy3wnCDShI1zn4sbIwVzjHJYeoZGK9P3OB06f8dFRoNLbL/ZT7N0 f0LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921265; x=1703526065; 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=zRAVS4vC9ni6nFv/TOVO0tDXxMYBMHf0gL/d3MqoeLg=; b=iYt7o04uzR1mKjf9VeuLd8yDcHfwdlukYQ03SjK4V4GUZFx+Yviln3+gbFkaeMDzVr m6J7f8+3NgY+GLb9N48IQa56GitkaY6JNotUzkO+nzGD1Rguk3Ymh9n3+EonL9dnDyfR AOpS8+qXLnyqO5oxO1NoVpJWvHUt4b9EJ/q/PUixFDLGQRWzadcH7BzhoFm3NHLFy/EW 0hNQyAgukry9m8y4jjG9fsu2ypaZfkIU26asApRtRQGEuZQ9Ay/aEqFb3Og+h2cxeBgC gSLEtyBcLhuvEfnsarhMLC187wTArb8AvZUwVSLBbdT1SOOXl+9VXZmllXkpJ//GyWG9 pDlQ== X-Gm-Message-State: AOJu0YwYuuFCw0ifx3GmIBZpEZrrd7Zn/5T8iwUR1qjkBN7xlbApsFgQ yq+s1oL1M+2TvH8Q/pM7Jou4+f1LHC9xMw== X-Google-Smtp-Source: AGHT+IFuVh3NnbRkHJJQpPto8uz+sG7n1PpAvbfvBBjPePQSJZd4LNqyRfmPpOoi4pv+MbeYIiK9ZA== X-Received: by 2002:a19:6d0b:0:b0:50e:2e79:eb2 with SMTP id i11-20020a196d0b000000b0050e2e790eb2mr1602734lfc.14.1702921265055; Mon, 18 Dec 2023 09:41:05 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id bi6-20020a0565120e8600b0050bf44d0d23sm2947923lfb.20.2023.12.18.09.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:41: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 v2 06/20] media: i2c: ov4689: Refactor ov4689_set_ctrl Date: Mon, 18 Dec 2023 20:40:27 +0300 Message-ID: <20231218174042.794012-7-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce local variable for regmap within the ov4689_set_ctrl function. This adjustment eliminates repetition within the function. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 3b20eba59c9c..d42f5d1a1ba8 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -580,6 +580,7 @@ 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; int sensor_gain; s64 max_expo; @@ -603,16 +604,15 @@ 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, ctrl->val << 4, &ret); break; case V4L2_CID_ANALOGUE_GAIN: ret = ov4689_map_gain(ov4689, ctrl->val, &sensor_gain); - cci_write(ov4689->regmap, OV4689_REG_GAIN, sensor_gain, &ret); + cci_write(regmap, OV4689_REG_GAIN, sensor_gain, &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, + ctrl->val + ov4689->cur_mode->height, &ret); break; case V4L2_CID_TEST_PATTERN: ret = ov4689_enable_test_pattern(ov4689, ctrl->val); @@ -625,7 +625,6 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) } pm_runtime_put(dev); - return ret; } From patchwork Mon Dec 18 17:40:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 755779 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B6F2971477; Mon, 18 Dec 2023 17:41:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PqvXmH1u" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-50bf3efe2cbso3901608e87.2; Mon, 18 Dec 2023 09:41:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921266; x=1703526066; 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=M0/5NCPPEP08dxHiHIezXLBrilHL+5rztH1UO29obAo=; b=PqvXmH1uUnkEz93haJsEFNRHyvGppMKE/C31snNWw6Mp2zk47O8wZP1wcH4bHbjkIX 0qA81yYknYGq5sQJ9HWHX/qI82mBOhPSnjVWnv5UTIajDY7Q/V0060zW2U96H8MiNbYW 3iOMbj75ja5rQr6QOtEU3gzGZ5uLGSL5kzgWIUOPuH1VuFAf0+9ukeegFq7laIxcUQss HNBLAHu4HL5ETFSkKgsgAKkPU9oT4qvlsSarJ+mIf4MmrHJ2y5qWHAh1lCCh18n3d2dB n2VTlI/cK8gXT/fqituofYxwGA+XBkAzof1zj5CgbXdFNrrVkBo7RNlclIQZryh63Obk 5W5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921266; x=1703526066; 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=M0/5NCPPEP08dxHiHIezXLBrilHL+5rztH1UO29obAo=; b=o1pnAVNq/7bbzufwbMKt8P7MO03r85nJfqJLn7vqogwSvCF7rGYKkOf7ijt72KmJwV vpPl0EkYnKUf5J1fPcRZ4rQ6G7mGZNdhKX1RhPTNhc/EOBHjFXnRg9mwDPu+mUPiECfF I2Phe6mBthvxckYOhMzIyCOpetfqE+8sytZJ3PHgZBCm+kMAVZOT5WY55SZ4wffDk8yi EA07YoRCqdt6/6wdomtOUnYJcGh/WF98R7FvE9ujJ8uYLULT+zmx1l4Lpw8Q5NioTXlh OoL0VZbIjOxQEj3Vddm+wBvjRMc0dbE6B1B58nrtOHtIvf2mohWAO+8vAlG4ROD/8K6L aYlw== X-Gm-Message-State: AOJu0Yw+8cETf0IrCn5BYJsllb8t6e8JVKUIIPCWvYyDxKCiO8IN0VlO bFDtdjneZQuRi+DXWTwiuDR3OGQcbYpFdw== X-Google-Smtp-Source: AGHT+IF9ey4UQ6SUMpAGvUqYRTmdaHtMtctv+O6YHO1u0m2u4Rue0WRtBrlpVqU33PMFNKB4V2vFxg== X-Received: by 2002:a05:6512:1586:b0:50e:719:6feb with SMTP id bp6-20020a056512158600b0050e07196febmr4040180lfb.213.1702921266432; Mon, 18 Dec 2023 09:41:06 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id f8-20020a193808000000b0050d12fe487bsm1077566lfa.277.2023.12.18.09.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:41: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 v2 07/20] media: i2c: ov4689: Use sub-device active state Date: Mon, 18 Dec 2023 20:40:28 +0300 Message-ID: <20231218174042.794012-8-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 75 ++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 43 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index d42f5d1a1ba8..501901aad4ae 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,18 +493,13 @@ 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_state(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); - - try_fmt = v4l2_subdev_state_get_format(fh->state, 0); - /* Initialize try_fmt */ - ov4689_fill_fmt(&supported_modes[OV4689_MODE_2688_1520], try_fmt); + struct v4l2_mbus_framefmt *fmt = + v4l2_subdev_state_get_format(sd_state, 0); - mutex_unlock(&ov4689->mutex); + ov4689_fill_fmt(&supported_modes[OV4689_MODE_2688_1520], fmt); return 0; } @@ -526,10 +508,6 @@ 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, }; @@ -537,11 +515,15 @@ static const struct v4l2_subdev_video_ops ov4689_video_ops = { static const struct v4l2_subdev_pad_ops ov4689_pad_ops = { .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, }; +static const struct v4l2_subdev_internal_ops ov4689_internal_ops = { + .init_state = ov4689_init_state, +}; + static const struct v4l2_subdev_ops ov4689_subdev_ops = { .video = &ov4689_video_ops, .pad = &ov4689_pad_ops, @@ -648,7 +630,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); @@ -861,13 +842,15 @@ 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); + sd->internal_ops = &ov4689_internal_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) @@ -877,19 +860,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); @@ -898,14 +888,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; } @@ -917,9 +907,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 18 17:40:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 755777 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9F497408A; Mon, 18 Dec 2023 17:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hsmO4MPg" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2cc4029dc6eso41241111fa.1; Mon, 18 Dec 2023 09:41:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921269; x=1703526069; 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=Q+AOlN1QWf7zHgr+1BqJOwJHJOoAiKQ8ZouD3wx/nb4=; b=hsmO4MPgEEvT84rvsWcOuG8HLxtbSnqmbwbKWYoBaFgp9Wgx3EgdAls70FT5zxg54+ v+iNXcIRZtHNYcqtDL75wAu5xpwNm6umzKHFbesJQHVRyNehu2Te+DQOuDBEfMxcTQ2C ojqDmfgaezA0sbuiDy7qa5iRJ0ouW6wMoQUR85srW7F9xOUF1nJQnhlSQ4LQIBwgaUJ3 cwbMTiz1CwREdfCfjfF/7VasvwMb+WedEHkhAK3Dxy8BVEQQBBE8Iq3w1VjyTCQQokL/ bZSAczwKtbkMLMKqNLrYsSWrh7WfwQUxWUtUsvJn7s5+3+AOk5wD0GP7jqIOvgN8cJB7 Ia6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921269; x=1703526069; 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=Q+AOlN1QWf7zHgr+1BqJOwJHJOoAiKQ8ZouD3wx/nb4=; b=i5/vlKX7aJP3PwG4zhEF0fu8LUi62SIkD1P7mE17tJqOrJTU2AULEH0yotYWwBbkIX lSr0VSoPGZBR7rvXC5As9Rgexw5syq8meyJbKOIL0iXALaPL+B89iVXfKx5/VxQmd4+5 98RfjUZthCvhKwtW/fk7+9C6JxLexqsK4xJbVhvIvD9Di7mxwREjX1ocpWThfyhqtLqp RcE1SmAU5FhHAEqNwtEjGHwl2enJV/GZ7TO3UEzWkDPjXC1PHwYOZf97W3iGYK7fchlv JGaHTFkUaec2FX427nJaP5aOsUXSY1jJ8Rc8bAwUQIs5pC4WSt6vzOQ53CK6cF/0oKV0 YlGA== X-Gm-Message-State: AOJu0YzHkB3R7Kzd85CFCm6d2vAS22unW/a5EBo85h1KoKmr8hOv5h3S QS8MHJiuq1wqcgnBk8LptXvE5MQlzXcBGw== X-Google-Smtp-Source: AGHT+IHwpj/ptq03du2UQFOKrRI41kSsBCF0FBxBKU/3tNcFaqP9tLQwjSDhNd/ueoYRbFegnVyQTA== X-Received: by 2002:a2e:bc08:0:b0:2cc:41c9:9c71 with SMTP id b8-20020a2ebc08000000b002cc41c99c71mr5214230ljf.25.1702921269208; Mon, 18 Dec 2023 09:41:09 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id w22-20020a2e9bd6000000b002cc710614besm455091ljj.0.2023.12.18.09.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:41:08 -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 v2 09/20] media: i2c: ov4689: Use runtime PM autosuspend Date: Mon, 18 Dec 2023 20:40:30 +0300 Message-ID: <20231218174042.794012-10-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use runtime PM autosuspend to avoid powering off the sensor during fast stop-reconfigure-restart cycles. Signed-off-by: Mikhail Rudenko --- drivers/media/i2c/ov4689.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 5300e621ff90..64cc6d9e48cc 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -407,26 +407,27 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) ov4689->cur_mode->num_regs, NULL); if (ret) { - pm_runtime_put(dev); + pm_runtime_put_sync(dev); goto unlock_and_return; } ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler); if (ret) { - pm_runtime_put(dev); + pm_runtime_put_sync(dev); goto unlock_and_return; } ret = cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, OV4689_MODE_STREAMING, NULL); if (ret) { - pm_runtime_put(dev); + pm_runtime_put_sync(dev); goto unlock_and_return; } } else { cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, OV4689_MODE_SW_STANDBY, NULL); - pm_runtime_put(dev); + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); } unlock_and_return: @@ -606,7 +607,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) break; } - pm_runtime_put(dev); + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + return ret; } @@ -877,8 +880,10 @@ static int ov4689_probe(struct i2c_client *client) } pm_runtime_set_active(dev); + pm_runtime_get_noresume(dev); pm_runtime_enable(dev); - pm_runtime_idle(dev); + pm_runtime_set_autosuspend_delay(dev, 1000); + pm_runtime_use_autosuspend(dev); ret = v4l2_async_register_subdev_sensor(sd); if (ret) { @@ -886,11 +891,14 @@ static int ov4689_probe(struct i2c_client *client) goto err_clean_subdev_pm; } + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + return 0; err_clean_subdev_pm: pm_runtime_disable(dev); - pm_runtime_set_suspended(dev); + pm_runtime_put_noidle(dev); v4l2_subdev_cleanup(sd); err_clean_entity: media_entity_cleanup(&sd->entity); From patchwork Mon Dec 18 17:40:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 755778 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20987740B2; Mon, 18 Dec 2023 17:41:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XdadFdtp" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-50e1112b95cso3689125e87.0; Mon, 18 Dec 2023 09:41:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921270; x=1703526070; 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=78C4018Wj6QQ6G/TMfHrY+9uEZBmbcTZYvwwuREmiaI=; b=XdadFdtp/8+DeNh9A5xmVYAA3wh/UFHiyaXZTK+jVPAcXB1B+hpytXV/Q8lXTzoz9t D/eOD+Tx4pCW5vpUE+PxEFewrLuhIUnYGYYNlVAPALgHm+q+mD+QwnctpfcpREcTRAwE W36w0ESPMEk00qGn87u07KyHZFyAWa581BKd9c8LOlfWZbGiqReaAH3y5KwYfuQ/Qn6U kc9Mx/vch3tAMSCq0mo/5tjEEiamA4id8BGeue2ywvUhAQtAxguqWxswm9GaV70DAp31 2lRrk8M53qmvoRPMTkN1iE4fRDUDqLvmKuGe+LHVGtikw0gUouDWJNWELtWnxWxnPK+h xN3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921270; x=1703526070; 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=78C4018Wj6QQ6G/TMfHrY+9uEZBmbcTZYvwwuREmiaI=; b=QxbC9w7o7zg99GzTi3ftpZb/AnQDEpA2dFaNzF2acGl9Ruq53hTOuZTskGUDqsva5x cJjfI0cEHhTVhNUOry1QJBrmhg8rb7OFIQOJv+PBUJjE2q4ovbtB0l9pG6R1Y8fNr5BG pVk6k2ZhW5SmK7ZbS9hW9ub/dCJEcAMKXhkxOdvBtVhh2mBr1IxhsGxyD+dDYbY7fihk NMqviJ6SqTDVQBegTYUlWnskPUYwUasLSgDu9YKAM+Oi//g/S3a+Az8rAmLaFZW5Y78p VCv0/wn34brVP9J9Pz+ytcWpx2PMqUY47YChOSo9+TB85C5PQm5G03Zoz4DsmAWmWgFk buYg== X-Gm-Message-State: AOJu0YzvJ6T5eJGLy2L1Nh/s+GvW38FaDyP4GSXfgp4qs/kgina+6kqf mdOxoNPRfOlFSju3vbbVOnTani9GGqMHcg== X-Google-Smtp-Source: AGHT+IHoW+UvwA10FafX4ZKJJjhDgqd1FlaW5EV33a76GpIWRud9d485W+bLdB7KmpgrDAKBtd49oQ== X-Received: by 2002:ac2:4e11:0:b0:50b:eadf:f175 with SMTP id e17-20020ac24e11000000b0050beadff175mr5774966lfr.91.1702921270413; Mon, 18 Dec 2023 09:41:10 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id g42-20020a0565123baa00b0050bfe7a602csm2978189lfv.74.2023.12.18.09.41.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:41:10 -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 v2 10/20] media: i2c: ov4689: Remove max_fps field from struct ov4689_mode Date: Mon, 18 Dec 2023 20:40:31 +0300 Message-ID: <20231218174042.794012-11-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 64cc6d9e48cc..cf1303744e7c 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 18 17:40:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 755776 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 066A574086; Mon, 18 Dec 2023 17:41:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kZypryEv" Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2c9f8faf57bso42616961fa.3; Mon, 18 Dec 2023 09:41:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921274; x=1703526074; 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=JIwzcax46A46ItNbQ7ZCrC54+Ug7OcXYl/iMtTi3jXI=; b=kZypryEvoFfLSzH0Ni241v+8l/vZnN7WareyrSaFiVe22FZ3W3y+05eNBJyOW5rP7+ INtWG37unttZEfblN7UriXKa44CSke4rtNFSSxmYypLMOo7tHXkOY9WhBcTFsQuEI8bs 46vkDkwFq5hAG4NhEk5m2urE+NvFkahiY7c1joWDIhWw21D5ve6VVt6LjQMpD0VjOURM qrKy0BnDb8fHZJrhCTRHvFFW+9gM8pXGD1ABInH5fngdRm6LmDuqedPeViohkna+bfkP HazZe5TRU804aZGlsVJCD9VLj/Z/zYZQrG4Pw+KIL218vpEQ859N3Q2TAkLS3XMtXQc0 Y16g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921274; x=1703526074; 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=JIwzcax46A46ItNbQ7ZCrC54+Ug7OcXYl/iMtTi3jXI=; b=GpXzkzSMwBillItMc27IRlLC8uZB1+FT7Yf5H55R3cUsma+oYl6exkFy/GinyosAeX qQGefQRzYz7mkEzltW1vG1Hmy8hFrL822C2qzNvr8tj1oNDEDygkUwr5XG1BwKg/pOW7 AXfyzKRyen/SZSOdGpvMR1MVwY2wd+t2mPuVcQdLCkj15Tg/A/5GG0IWL2FTxAfWfCa0 IP6HnuZYIQV9FzWtxgW7gi9/c2AGERfzCeuLLoxGHvX+30u7NJd7Pp32FNnp3R7wW2Q6 T29gWrB3hyBr8/etHSAj3pk4yrs8kMtrFgVCM0iz6QbYEhDXD9yLGS1TAtu4JM4qg5H+ NBjw== X-Gm-Message-State: AOJu0YzIRpBZYed0S/IIs9FYylWL7jowAuAfS1S9T9MeA+VUFmAab+QS rBCjgPLk1JQn2rqvSLeJsdC8Vq+3bDG9Mg== X-Google-Smtp-Source: AGHT+IEBNWfcbcWCGaGFrxIgQ1i2BeJaXMZ+icuzr+MbhXAPm4xz81Q4UnfrAQqpzBb8Q/PWRET/9Q== X-Received: by 2002:a05:651c:149:b0:2cc:671c:a449 with SMTP id c9-20020a05651c014900b002cc671ca449mr1515868ljd.2.1702921274379; Mon, 18 Dec 2023 09:41:14 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id d18-20020a05651c089200b002cc782cf190sm210269ljq.72.2023.12.18.09.41.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:41:14 -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 v2 13/20] media: i2c: ov4689: Implement digital gain control Date: Mon, 18 Dec 2023 20:40:34 +0300 Message-ID: <20231218174042.794012-14-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Laurent Pinchart --- 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 6cf986bf305d..579362570ba4 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_HTS CCI_REG16(0x380c) #define OV4689_HTS_DIVIDER 4 #define OV4689_HTS_MAX 0x7fff @@ -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}, @@ -624,6 +629,9 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) OV4689_TIMING_FLIP_MASK, ctrl->val ? 0 : OV4689_TIMING_FLIP_BOTH, &ret); break; + case V4L2_CID_DIGITAL_GAIN: + cci_write(regmap, OV4689_REG_DIG_GAIN, ctrl->val, &ret); + break; default: dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", __func__, ctrl->id, ctrl->val); @@ -654,7 +662,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret = v4l2_ctrl_handler_init(handler, 12); + ret = v4l2_ctrl_handler_init(handler, 13); if (ret) return ret; @@ -697,6 +705,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 18 17:40:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 755775 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7826B79955; Mon, 18 Dec 2023 17:41:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NzD3u9KZ" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-50bf2d9b3fdso4627940e87.3; Mon, 18 Dec 2023 09:41:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921277; x=1703526077; 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=4SjlvAuV+ITVZU87l8JftGavoBHWbV2WagI03hZeup4=; b=NzD3u9KZ6UbCKI8H7DB1Z3O7fH8g3PkrclL6XA/Wn8Gp4jCt4ozpGz1fQRdG7ykA9c /s4gAaTORzIqOiduM403whLdWgr0dXbK8YHoyVm7oSPjoNU3k5WBkpWkB9/gH7v7OloP mGtM2kc6SEWZSDslkfncHQhnx8vHtZr2ks+nYAc/pbK2h9wLWWuW77bNiRc5HT3TRPRM g2UdkNFe4XP0o6cfaDHakr38O783eQhJQeAtpXn4vU7rcoHR3H5A/f2ufevoO0Nq5SUx nPZPOQ2ct03xuK5BzRd4Bi04xljL4hITeVSwTvGKr/SZlj5oCZ+gvYf/WLrFTL7wAq9t ksdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921277; x=1703526077; 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=4SjlvAuV+ITVZU87l8JftGavoBHWbV2WagI03hZeup4=; b=Ca3YdSxwHNcqjksxti0zSct4SFbCJAS3unlCIKXOr6YrRCt0kDCfTJCqoVbXqTQb2x mDBdPf+N6iz8nQuWSx6hSHiFo9PF5TuaR7/unq5Kzg/d/GmCcMhJpKBtW1SJ2HYPHJw7 ZwnS9h8m2F4q4b/CgQYg83TlQwLeR32qifHIq6W6DBP9n2X6FSUDOceF00w5jCwJoY/X XDK+Bymk+F619qDkT+62okgs22iHtVoXh9eBberecydnPz0MhlezZWWx7tXRNiK+xax6 tlWt5TtX8uFfm2txN7zF7cX5vSeegreLpq8eY5YUcgu9HQIUfJF3MU/nZneIBivoUcwr uwjg== X-Gm-Message-State: AOJu0YxkLZnLCF4I/s8Web6HdWrwWoGxKkOAVjGiOi8T71lYGZCzsqur 25GHnU0XxIqFkrTTDKojTTMGh05MvGd5xg== X-Google-Smtp-Source: AGHT+IEpHBMcQFNgHrRtF7STxyBad7yeoLMk3qAFvX+/l/O6so3UTpn9p3QJpE9w7exXQyhfLJ9k9w== X-Received: by 2002:ac2:419a:0:b0:50c:222b:2489 with SMTP id z26-20020ac2419a000000b0050c222b2489mr6965947lfh.135.1702921276912; Mon, 18 Dec 2023 09:41:16 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id f9-20020a0565123b0900b0050e3b2646a0sm265645lfv.152.2023.12.18.09.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:41:16 -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 v2 15/20] media: i2c: ov4689: Move pixel array size out of struct ov4689_mode Date: Mon, 18 Dec 2023 20:40:36 +0300 Message-ID: <20231218174042.794012-16-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Laurent Pinchart --- 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 b43fb1d7b15f..475508559e3e 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 18 17:40:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 755774 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04CBD74E11; Mon, 18 Dec 2023 17:41:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cEh5l6Eh" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-50e2bd8c396so2411514e87.0; Mon, 18 Dec 2023 09:41:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921283; x=1703526083; 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=KTzwxcQOtEUgdARmaClunNggauUXTYf3+l9k/4G0WNY=; b=cEh5l6EhPDNzOS9ufLgylh0QR3O65Hrq3Q8513vqg2WhQ3Y36xndHvjciIBSMiX8YZ 3uGGd4qzLI9G1jgPFYcDWoPd6NjQWOYUgW4hcl4fDu/+x6lLDJ1p7ycSzEGhJysKyaF4 Y4r/leZ36rN8kSZAa8QGPBG8gYnfSHJFNSYyiaBd35yHBgIL0K75Vbo2IMm4oZNspi19 z0P/zKhh53sq167zpY6YDyDfDEMe+CUUGBEfqis/SwUFKHEpigbVyUxosG9e+cggT3ec lykRuDcygR6zdCAQO4oKmSKg2FAhMQLo7N66HjJKAuRB7Lrc1aa8Aux6bNBR2SM1/WEq vfcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921283; x=1703526083; 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=KTzwxcQOtEUgdARmaClunNggauUXTYf3+l9k/4G0WNY=; b=Ho4TzWTgjbDPg7Iyagoj0MapJqwiOW9Ewl+g8edEwwDpeKI1HHMDPxjcgsNQQ68SGN xVaxCOx7da86rpQLERplDr5qrdrqGdvNj/ZZbtG0Ydc25BMkuldb/bBLL/vf79Qvv1dI p1bgxjUIRrEL+HXq4SrsA0mgmcLD1YEW3KpyMnVgHaie0Dl0mqwl5c4BPRsNpsnrIFoK guCXWubNCRXCbWKGSNKx/cA3gNsx5sSd+Pw0RPhw8bhY4kc4Qf8zre6XnKIVXfD5sN3v C1S4RDyOF7qIqbmd++JnKkSTvK2ZnT2UuxqiR5fl9SGj6kO9nKn9PCVF4kJPzAhdAbAU juXw== X-Gm-Message-State: AOJu0Yw0BefNjCMzW6pPyn+afT4wCRilflclpZ1Chbo1O+QGr/d439wm abTy/T0y2TeBK79MPm8OT22BfEQPaMCMUg== X-Google-Smtp-Source: AGHT+IFDvucPOD3vVTUe7QGw2qRtwiLqwDJh3p+oGlTMd9PTfm9uN3xmQC7Kc6JCsLFK4DdpB07hOA== X-Received: by 2002:ac2:428b:0:b0:50d:ae2:2a9f with SMTP id m11-20020ac2428b000000b0050d0ae22a9fmr6827246lfh.24.1702921282838; Mon, 18 Dec 2023 09:41:22 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id i18-20020a056512225200b0050bfbb6a388sm2967537lfu.22.2023.12.18.09.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:41:22 -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 v2 17/20] media: i2c: ov4689: Configurable analogue crop Date: Mon, 18 Dec 2023 20:40:38 +0300 Message-ID: <20231218174042.794012-18-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 | 276 ++++++++++++++++++++++++++++--------- 1 file changed, 212 insertions(+), 64 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 3b73ee282761..d2d3e5517576 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -45,8 +45,12 @@ #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_HTS CCI_REG16(0x380c) #define OV4689_HTS_DIVIDER 4 @@ -96,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 */ @@ -134,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; }; @@ -320,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); + + format->width = crop->width; + format->height = crop->height; - /* only one mode supported for now */ - ov4689_fill_fmt(ov4689->cur_mode, mbus_fmt); + 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; } @@ -357,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; } @@ -388,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 = @@ -412,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) +{ + 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) { - const struct ov4689_mode *mode = ov4689->cur_mode; + 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; } @@ -470,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; @@ -568,10 +690,25 @@ static int __maybe_unused ov4689_power_off(struct device *dev) static int ov4689_init_state(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state) { - struct v4l2_mbus_framefmt *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, + }, + }; - ov4689_fill_fmt(&supported_modes[OV4689_MODE_2688_1520], 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_internal_ops ov4689_internal_ops = { @@ -635,20 +773,28 @@ 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; + s64 max_expo, def_expo; int sensor_gain; - s64 max_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 + ctrl->val - 4; - __v4l2_ctrl_modify_range(ov4689->exposure, - ov4689->exposure->minimum, max_expo, - ov4689->exposure->step, - ov4689->exposure->default_value); + max_expo = crop->height + ctrl->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; } @@ -666,14 +812,14 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) break; case V4L2_CID_VBLANK: cci_write(regmap, OV4689_REG_VTS, - ctrl->val + ov4689->cur_mode->height, &ret); + ctrl->val + crop->height, &ret); break; case V4L2_CID_TEST_PATTERN: ret = ov4689_enable_test_pattern(ov4689, ctrl->val); break; case V4L2_CID_HBLANK: cci_write(regmap, OV4689_REG_HTS, - (ctrl->val + ov4689->cur_mode->width) / + (ctrl->val + crop->width) / OV4689_HTS_DIVIDER, &ret); break; case V4L2_CID_VFLIP: @@ -739,14 +885,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 18 17:40:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 755773 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B23F77BF09; Mon, 18 Dec 2023 17:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PTG8rUde" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2cc259392a6so40380091fa.2; Mon, 18 Dec 2023 09:41:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921285; x=1703526085; 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=0Db9zQ/cEzdabx9SHSYCUhC/ZN+6oeRqIuZFUX0OxwU=; b=PTG8rUdeNkGfdmowl5R1KJTy3z+neKeSws7v5yD1wstCvJwJcF4spM55YveLjCSf3D mH1b207EF+Caj+ublnDu8Ap9wfmwnn09pIs85YhdpSjwtHS9Vptv9VgkkQ3fAdsvnXgV 8ZZmZq4WB+C0m+zOFpLoUnoQSDLhl9eTaYOYVNG6Am9j5/PPv4hmNOjOjLHVm8SEh7LW Y60d9OZHnOPMKwWvHdvucp9beBoNXiiKiI7JIzJJmpiViLSu16KJKvvRbdbkk3KSHgvZ 2NU83GoZlwx8G3ZkaUxFUoMj4Dh2J1cKXsEVvm+u6+S1uANnjcPNuTg6/ea0kYuW2V5x bbbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921285; x=1703526085; 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=0Db9zQ/cEzdabx9SHSYCUhC/ZN+6oeRqIuZFUX0OxwU=; b=r1+xxZonbHKcPBZJYgXt7o5oMJfkaVL3EhCLau8E2XSp8TV7Lx+9chD7kZbSO9Xj6G oMg+T4gQU4KZwb5lGxHerRRgCXbLhIiE/CSRBRJZ+BEz3KXC4Gj0sDQd1U8BkM9tioqy CTgxDxxHbB18dmsBEx2GxoDvoj0VaPjiFIjmExxcXd17MK1qhxsoqr+vRVfVJRqlhpD4 QEKZa7j90LK6w69wbKVpgauPJmlFgmIWanuT2413aMH+ko7z1UaTbYeXx3aMgVmVoZeF TcwpWh347jK65+tCGvi3dTVIHTPjJ07Yk67oqShWg7vpv3ytZhc45MumP02ZfR1sA0ZL H4Dg== X-Gm-Message-State: AOJu0YxetExudEY1aFXulm/cWD+YnyqqbXOwCpyVMT8SUidT/+E6eldx kCxcID1VcP7dIBuDUIzGOZyMObA9EAwseA== X-Google-Smtp-Source: AGHT+IF9vx4KlzpdrYsIUTYLFL8RO+IiPNxkVU/6Y5Pspf+P2xp+K3abQf+H/+3amsy4xccrqY4b+Q== X-Received: by 2002:a2e:8783:0:b0:2cc:5a63:3903 with SMTP id n3-20020a2e8783000000b002cc5a633903mr1994561lji.79.1702921285505; Mon, 18 Dec 2023 09:41:25 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id k11-20020a2e888b000000b002cc5f5fc8cesm866940lji.63.2023.12.18.09.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:41:25 -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 v2 19/20] media: i2c: ov4689: Refactor ov4689_s_stream Date: Mon, 18 Dec 2023 20:40:40 +0300 Message-ID: <20231218174042.794012-20-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 e997c3231e85..884761d02119 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_sync(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_sync(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_sync(dev); - goto unlock_and_return; - } } else { cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, OV4689_MODE_SW_STANDBY, NULL);