From patchwork Thu Feb 29 16:53:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577408 Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (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 935673771E; Thu, 29 Feb 2024 16:53:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225632; cv=none; b=FTpnUdMH6U760IBsszAM3XLZ19o/hhaHBZFfRTw8QzCnPp1XWnbUhn2gLXXmFEw2M6T2dp6VFNqVdkNNuzxq7KlNI25UeeANPIsaeN8qorRKXgxoyeYQqh8hjTGu5lEMQh4R9S0Ota5twPO7MxqFzXgmeePRlUo7XqJ/e1VvZ9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225632; c=relaxed/simple; bh=6LhnKLkyHoR2DQhrygMZnlhExO0jOETkNADL5rYjKBA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XGJvI2fOtyUXE+VChPbrQ4+2PLXoZaOA8bldI/jg/gvHyVdI80AQZL465NoqLfhKGOns931lq+XAqIr34bqaxDTmHtCKs+vx8Um2iKSdNu07EPSYfMk25Vxe4mjuNM700xIuf3ka29KS5XZUYZpZ2b6s/QxUYq7it4KD8enkKwQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fYctecZu; arc=none smtp.client-ip=209.85.167.41 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="fYctecZu" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-513235b5975so1542140e87.2; Thu, 29 Feb 2024 08:53:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225628; x=1709830428; 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=MDcEufGaeEidfkZcKTWsyxzNEaaKvnRrmWH2EUzo0uE=; b=fYctecZuKsXWxc8ny1v+Sxd7MP8N7pKVBS76esCbhXm59Znt2T0bvGGuyNCZtoNcYT v03nulk460IohSFsoBvogzoKjlFlvMT9AUIL/7LNdvkrrU/l8ZcJVsEdzEuZMu9YXdUf g+BKxRLfL8hNlR15BYrDftuuJDjOWaSU1EesEjKGyKkIckSNePI5U0t9jRyW6f0ukMNi b/Ahgf2mNWSFn0Gy5prBrYY4/htVsSmUGDHyM2wPtMGjXnPKnnH908XMK14GuQ//cOxB U2BdDQ6t68jQMHtsWQ+1o+fOMXa++xQPxOCblpaBHv2+/WPhU8S6q5TvZvexzjS1zPw/ GbOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225628; x=1709830428; 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=MDcEufGaeEidfkZcKTWsyxzNEaaKvnRrmWH2EUzo0uE=; b=viaabchR7OuZuJnXDRS3JoyN0C0oVMa6/uB0CPG7svicdU59IB1II3AyhIbkbicSnv wBZks4mgoYuGKLdP2+tUI2P3lVMcpcijyYjJ6PlUMxwKnWYmHWKms0FlQ8WiH9G3QcBY PBFpGiJhD8gOn7iCik8uO6s+OtHQwk/B/53t7I3auijIDnKI0dWwbog6O3t7o8Hbr1uS 8+KlOX1ETMLYcMZ7W8Jl+o3ahFEDVVJd+V2MJlk9+2O4quBHRsEUNgYcehTNbWnPErzw Rh3hewIWWLpnMpiw59FKU6qP9AyKoJ1HHKgKXf7yunZ0Q93gGv5WVW+trP+Vew3KMbNz 1Ogw== X-Forwarded-Encrypted: i=1; AJvYcCWIEEMiFrvIBRRqvZ52jao+MWH3hnqQdL74KvF7XN+1rkMR13ZdXWApbXw3pI4fvlu90dcGXV6GbwxBt3BrqAgGqs4b/PeJlrvIWPct X-Gm-Message-State: AOJu0YyKUjfWkemxu+by4RiOlGkKn4rIJHxvLqwDt2nr+7L3l7rIKSSM +yujXm98dEHCobpiQSpkJpDhL0dfhvBF2Ydx4TSmacxuHd63mVj5fbAPQ/KVwvk= X-Google-Smtp-Source: AGHT+IEtCrfAsH0/0aQdK3Zrv1ZJ9cSpKT2JDEkPiWDICd8OFMB10iFf5wo9ayhCzN01V+Qd/qcfeA== X-Received: by 2002:ac2:4d10:0:b0:513:2347:4b57 with SMTP id r16-20020ac24d10000000b0051323474b57mr1924844lfi.66.1709225627682; Thu, 29 Feb 2024 08:53:47 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id c41-20020a05651223a900b00513256fb6fasm293233lfv.187.2024.02.29.08.53.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:53: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 v3 01/20] media: i2c: ov4689: Clean up and annotate the register table Date: Thu, 29 Feb 2024 19:53:14 +0300 Message-ID: <20240229165333.227484-2-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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..5a509e908e3c 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, 2024 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 Thu Feb 29 16:53:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577409 Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 F2EAF3839D; Thu, 29 Feb 2024 16:53:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225633; cv=none; b=DWK5k+DN1ehjL4xv54Pzetk6qvx/DNQVfXjIGjNVxoy8koUTyVgEbLMoBtsDxXhoYZwTZx2LUEZrpHRg5DXeyp4s8+aacZ+vnslUCFnw/iwn4OSl0vJWutGKVjTvz5C4sUCq36bQOp5j9GSCGDeIv78MPoekDsS1PEuHDaETjF0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225633; c=relaxed/simple; bh=j+5NIEvfEP01ISHJtm0jL77SI9sa3eRsj8mG3FtpjjU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CYEh3FZ35MayCrTFSdSWs1Qvt35IppSU3v+PV8u7ITFSJ7naRIkC7TPzZlQpdTOBpaSxNXWAPkghc7JJo5lGHaYvy7DZYA+AfAXMBrAA24OAZJ8VvkxJA96xxY7aqNsuXCbrOka7qGcgYgjSJG4Un14vqiR458KSdufv5+SaW5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gcPaGFY8; arc=none smtp.client-ip=209.85.208.180 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="gcPaGFY8" Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2d240d8baf6so13223291fa.3; Thu, 29 Feb 2024 08:53:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225629; x=1709830429; 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=TnpFbPWiqT+OxvexmGOJHCE54uMlgYM+q9V2u9d1aOc=; b=gcPaGFY8I6jSSGlLZ9cTf8FWYiDUbwTllXSi5qBWemag/RJRIWDTfJ5TjCS84P9+Cf /I2/nRdIxNBQxtUo+CpOfBz1JxxsDcWkt9eBQ4Y1NdgrWVhvIOjeVEpdRz5AYOwrIa4/ Moxu6Vwk0ajcKZdIeCEOSLGgCwfEXRcX6Z7VPBlsTFAoxJfFVy6/ir3Mj9czayjJp2Al PoDzsrdR+R9G18bjdh/AvG1d5XSqIS0a4h4vKJNDXsTjZjKfDFXyeQjK6L1uSmCNynLd VVHxokSm8coPopWhaPKmWL8iW6FPkyr2dT2pqkqoCON7mdj3nT08SHrfEa8nljuOm0vz /OjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225629; x=1709830429; 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=TnpFbPWiqT+OxvexmGOJHCE54uMlgYM+q9V2u9d1aOc=; b=UM6fPYUxu2PbNEBpyUjnD8mUh09QHdvsqCrwVYGUX/yIzA+g6A5GSq36zyfqk5trGO gYZOQyIJdGVRQ6XslUa15p5VKt7zWhfyYonCSBby+GkFhKsh5gV5lqqgJp0Uacik4SZr 0kkDN5EifbB/KFNAdNj19XrWNP9sFt75+hcIsk5H3M77dWOYC4/ahgUgihFg5ziu7J6e SkIpcn9yqni7AEuVBdjyX5S5FVOk4FrqDYufXOFjkxL1kEwbw9fK+3pK9PibvVaCAS9J ySMEb5X4ltlIQLMgaXdiaa+8kuEPmFSjK7LiYuOx0lTEafxWk+b1Q0hfQ9MjSJXuPPEb WgcA== X-Forwarded-Encrypted: i=1; AJvYcCVvkIHfoxD9C8aTazpVV0XA8GWhFvCJkIW6ioCebFXD9Jy4fCl4/FalExbT8hmYGUQ769tv3in4pprR1rg1nRrUdFMtXBJPYwryoYWX X-Gm-Message-State: AOJu0Ywee1kF8cVmNBuenm6kU/wEjg6X5gckjrQvrqhfKg2HeL1vownv sabZKITeRJqQpII4f+Hnxc0wV3b5VpX/i3dAuNtraBqkUolHonvaDPLiAxSIbqQ= X-Google-Smtp-Source: AGHT+IEht79WtOAZjamDNriTIW5A1q8EutVCuO4inc1EIpvWDUFQOqiWIbZBnrlqvhQxwrgjY11N8w== X-Received: by 2002:a05:6512:3b10:b0:513:1b56:d46c with SMTP id f16-20020a0565123b1000b005131b56d46cmr2392229lfv.45.1709225629338; Thu, 29 Feb 2024 08:53:49 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id f14-20020a19380e000000b00513156a7601sm315668lfa.49.2024.02.29.08.53.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:53: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 v3 02/20] media: i2c: ov4689: Sort register definitions by address Date: Thu, 29 Feb 2024 19:53:15 +0300 Message-ID: <20240229165333.227484-3-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 Put register defininitions in the order of increasing register address. Signed-off-by: Mikhail Rudenko Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 5a509e908e3c..a6c101044eb3 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -19,15 +19,15 @@ #include #include -#define CHIP_ID 0x004688 -#define OV4689_REG_CHIP_ID 0x300a - #define OV4689_XVCLK_FREQ 24000000 #define OV4689_REG_CTRL_MODE 0x0100 #define OV4689_MODE_SW_STANDBY 0x0 #define OV4689_MODE_STREAMING BIT(0) +#define OV4689_REG_CHIP_ID 0x300a +#define CHIP_ID 0x004688 + #define OV4689_REG_EXPOSURE 0x3500 #define OV4689_EXPOSURE_MIN 4 #define OV4689_EXPOSURE_STEP 1 @@ -41,12 +41,12 @@ #define OV4689_GAIN_STEP 1 #define OV4689_GAIN_DEFAULT 0x80 +#define OV4689_REG_VTS 0x380e + #define OV4689_REG_TEST_PATTERN 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 From patchwork Thu Feb 29 16:53:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577410 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 03C6D6CBED; Thu, 29 Feb 2024 16:53:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225634; cv=none; b=Nho3mHW6v8x8rX7xuZ6JpySxyxUu0LgbGb1EfSpBdm1ShzQV1kWO9gb1No3zqaYmmjJXHRnsEhK8UQWXbS0Meo9TF/9399XUk5XMLrWHslpY7MdFkqKJlZcn8XKLxMqEtmZeMwyu3iHR6NbCVfVW7h9UdTyvyP47Y907hO4Yjoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225634; c=relaxed/simple; bh=j606ZlD8gl05cV2S9Sv71dKFd6GOqrmr3w9wbDSb3Lg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pn2uwRcnT+K4/vqCX/nuqnQnu9CPbwFEbYAx6IIAKtf3LzFP/O7BLaFVPGVGk5/mGvIrwwNdgTvM28R9Zvi06Xd8GKXlLMWS/RRCydi0DKydojhLIwoiz+tZ9CKeyGWvJhdjQxD2fK546XpJhNwwRpdZVP+/yzW/x1OHBJWFXAc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=StaxK95a; arc=none smtp.client-ip=209.85.167.45 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="StaxK95a" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5132181d54bso1252677e87.3; Thu, 29 Feb 2024 08:53:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225630; x=1709830430; 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=p5ZvgJwue3pMCGuTCyOPC8+J9NNnO47EiCt5EDIclk4=; b=StaxK95a9gy9AnUdHRO10ggwCGVEf2lWTF72SU2ZCYl9Bg0WjlXv5Wt3sE98j6gVTh 17C2COwTdcBpnIUaSdniAOx6oPgQj/mEVrI7s6GZeQk/++NdAgrkPNCKoCtCMiwbrzl8 bqEi9xy4VGFsQzV/IumY+gpzXzuHWf9i7yqw3cfLzZJ1hBtYhLSqKXWRL9kzvq2b4xm4 CINpaMT25i7bdLic/7PF7twzquv7NTFwXGbliiSB3y3qf3mChQhPGrywHT/d6iryWzwa lje9hmBbaoADkRw/Qk0BFT7SGrP2L2o4Kx0JC7wOzsI/UlIHJM/t7A5TY6xgmU8LzgT3 Rv7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225631; x=1709830431; 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=p5ZvgJwue3pMCGuTCyOPC8+J9NNnO47EiCt5EDIclk4=; b=C4IhcOFbJtff+Pj22ptoy7OOpYATo1REBPHs3N52PsLG/MTe9BRwT2NPFNON/eNV2n nIOUWTafwHwJoiPfWLxqNXBD28i4HaHKB0q7XgYlnRZvBxKlpl5tI62zShwWV11gJZsZ PJWKorcRIvOExrjdrbeVnElMLwrFwtFz4KIc/d/bd2Zb2Yo9ukG1A1lDKrWTMU2cETZj fS7Jk5L5TSEdrF2KlKQTWNvjT9xSMKMmath/Xg/KzUuudjuWPVVOcBu0rwTfyZr98QbU 4TsbFrukspmxTbgBntVzjW9zsNwjwb/2rhi5iCtwSkW9K9FR/wXQN7V1Ccf7uIT+jqRk M5OA== X-Forwarded-Encrypted: i=1; AJvYcCUMnBYQwnyBYN1eQqbnuZdqF/5eCiNJY4NyYWsWPUZlTy4KgXLFVIGVfd/6WiZIDXYADW43Qz1I/VkwpHFtj7vFnizXtk4XiNhMWS2j X-Gm-Message-State: AOJu0Ywjgh7ecim/q4nFu9KO6+/57Exfo/GxvlaQGYeVWiQixc4insx3 UJxALc5vZ7uGUMVmprSm9oJEfyLpvRh/YwkvFhm9fGB4+i2Cq0OOeci3pH1D8js= X-Google-Smtp-Source: AGHT+IFFopAHgABNiCnnmrTCDHTh1+/5AFtlUuuSwlj/1f+1Xupf4e2mMvy74apZVcCeHoLHYjf62w== X-Received: by 2002:a05:6512:3049:b0:512:fccc:f289 with SMTP id b9-20020a056512304900b00512fcccf289mr2202630lfb.6.1709225630635; Thu, 29 Feb 2024 08:53:50 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id m20-20020a195214000000b0051322d314e9sm305373lfb.137.2024.02.29.08.53.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:53: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 v3 03/20] media: i2c: ov4689: Fix typo in a comment Date: Thu, 29 Feb 2024 19:53:16 +0300 Message-ID: <20240229165333.227484-4-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 a6c101044eb3..f2614a0b1340 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 Thu Feb 29 16:53:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577411 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 DB4DA70ACF; Thu, 29 Feb 2024 16:53:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225637; cv=none; b=VBUKWUx+yqdW4zlUFO9JlDaBISHnp3aIpvB1ODh2m5PscZPBOMqZaYbqeh4JR672r+ZF29ANhLV7882oXYtTCBZXgJ5RLAzJgmdTBZxtAZPFjSNNo0g8h6URVm8Ia0BOMVD8MXZOsal4cGA8V7iNId3J8jukacSN8C+LIOmMTkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225637; c=relaxed/simple; bh=JuKsZlRxtFjAjW0SbmbSOEfLq2QmV8EUZuVrYd3Feu4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E7ndDlMo5dVxX7Krm1X8Jlzq1SSvuYsgOSxHRY2eAV6UuwVPRnsitiEKXk7Z3ihAVdxQGuqOmeUwCrNaazZk7KqDX85/VTIoZ20Y1lu2SfsXPoGevEE9Q+8LsofVC5HZrv55+TETV+M4LFAH7If3FM+EOCWrG4233pe5RVBvnzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=JwSMroYb; arc=none smtp.client-ip=209.85.167.49 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="JwSMroYb" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-512ed314881so1025534e87.2; Thu, 29 Feb 2024 08:53:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225632; x=1709830432; 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=8LUtmsLhutFNpOWJZ6bFEkYVjR9tYmtGTpqTnMKv+TE=; b=JwSMroYbKsoQJ9bfiL7FtxsHuNTi+1w9iJTu1h5jkZjR0w2lZHtV3AKI2ptJe5wZIH qjSg9Ka9V+Q/5PlP+EJpxOm02JLyLzJb0GhhDd2Yoft9TTJIsvhSsQJs8+tc3nE8MbpG kdX1ZAd+WP3dGf4qWEuHRHNlYeTfkOzv3ZTSFX9oVV400oOuXJ2NIuvNaRKUD72ONaLG J4X5A506H3cY3abzIi+4YcGvYWKaKZB4rVu8Lr0FZnDznXYI6guopZi15uj35frDBTcU 04vxtUIBxdYId5pYpQshbcv2mExKeByrqsrfgmYhzpWGnOfJczgU2QH6f+FsOU9cqhs9 0Axw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225632; x=1709830432; 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=8LUtmsLhutFNpOWJZ6bFEkYVjR9tYmtGTpqTnMKv+TE=; b=oQ7gZS6Soky7xz9cH/XqmidOjaQv+IeBPuL9p55v6IiN5tRPnP3Ron4aZztjIHIDS7 J2wgWDq+4R1bFTogonpqekv2Y8lPkmRQtVyzK5fzpf+9iPVRjdfbPlIDb2/99Opaj5V9 RTG6Od1vE6v+2xXgwZwNAIgK7j+OhmFTgKIaN5gXscCpvqrYTMoKU0OkZXTP71uMS2WM Os7iYE5t13ZXvgTIH00nvgT0aQPLSKnHQthKhqV5E+9GjEDsCGMMu76C4y/No2f0O1L2 KWLwgn6U74YoQesTS/rNnmIE4BHcNt2yHIJcYsGjTKDgOmuFFSlCF/Z1TIZIpnLWmrNC amMA== X-Forwarded-Encrypted: i=1; AJvYcCVnsviVsnV+rD5j4mAOGQ5Y1HxRWIxUuwmvELAQwWN13A+ZotamR1EDrnsxF2DeSCZHhI+e1f/iTgCJ4RWedOgGVmvtdai5ydVFq9e4 X-Gm-Message-State: AOJu0YzRcjCcss/tHtvjd7+AEW5I2rX0TDER6V8vyHgEQV3ZUiQynCcR zZOR3tvN3o3Qu/gem2GAV2W2lVlc4SOfj+jS/hqsSr036pGnLnIRXjMmlBcf+Mw= X-Google-Smtp-Source: AGHT+IEwfj10QghOhEOpFT2RWmyVKrjUp3bNpazxo7EYQyJ0MhfVG9DNkHv5AZ/uloAC3ko0eiHuSQ== X-Received: by 2002:a05:6512:1190:b0:513:263c:8acb with SMTP id g16-20020a056512119000b00513263c8acbmr1848958lfr.14.1709225631886; Thu, 29 Feb 2024 08:53:51 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id d1-20020a193841000000b005131eb404cfsm311200lfj.117.2024.02.29.08.53.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:53: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 v3 04/20] media: i2c: ov4689: CCI conversion Date: Thu, 29 Feb 2024 19:53:17 +0300 Message-ID: <20240229165333.227484-5-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 Convert the i2c register accesses to utilize the CCI helper library rather than relying on driver-specific functions. Also, set analogue gain in a single 16-bit write instead of two 8-bit writes. Signed-off-by: Mikhail Rudenko Reviewed-by: Laurent Pinchart --- drivers/media/i2c/Kconfig | 1 + drivers/media/i2c/ov4689.c | 358 ++++++++++++++----------------------- 2 files changed, 133 insertions(+), 226 deletions(-) diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 56f276b920ab..cef6cab14fd4 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -405,6 +405,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 f2614a0b1340..d31659139a6e 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -15,45 +15,35 @@ #include #include #include +#include #include #include #include -#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_CHIP_ID 0x300a +#define OV4689_REG_CHIP_ID CCI_REG16(0x300a) #define CHIP_ID 0x004688 -#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_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 -#define OV4689_REG_VTS 0x380e +#define OV4689_REG_VTS CCI_REG16(0x380e) -#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 REG_NULL 0xFFFF - -#define OV4689_REG_VALUE_08BIT 1 -#define OV4689_REG_VALUE_16BIT 2 -#define OV4689_REG_VALUE_24BIT 3 - #define OV4689_LANES 4 +#define OV4689_XVCLK_FREQ 24000000 static const char *const ov4689_supply_names[] = { "avdd", /* Analog power */ @@ -61,11 +51,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 +69,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 +109,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 +244,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 +297,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 +370,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 +415,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 +430,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 +603,16 @@ 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, sensor_gain, &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 +717,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 +837,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 Thu Feb 29 16:53:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577412 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 EECA770AF7; Thu, 29 Feb 2024 16:53:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225637; cv=none; b=k43Ync50szrFf6UVJLuug+4woqPwPK42JbfbrejiBOMbLG3ZwNGAbPHGA+iXZq6p2LD/CvPfzDzaow4Vp8zTJymHSnoSEsNzbRkmUcCT4oNl27Gs6iaRG1grORrBxB4QszOw72UAy5LYit2wOag99heT5A0SzrIyaHjTK8uMfwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225637; c=relaxed/simple; bh=etDRRTr/CNjroes7TicKi1vHkjrEQdFYU6BMYUsvrM4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vEpET/aN0E0ZEPUGofcROFrK2r+im9EXY3FXvlIxZJoSAkubBQZ5o5+hVbHc6wgJJZWtkpC+2S5yBDjMeksvw6/jBMz8Y1Ggrsa67+1sjyVQItkxQ8QqZi6T/pis50g+OvSSh3z5/yv20+itWud+LjhHjXmmeoUYaTDbnLLg3jk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dJ2rZAvd; arc=none smtp.client-ip=209.85.167.48 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="dJ2rZAvd" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5132b1e66ddso589497e87.3; Thu, 29 Feb 2024 08:53:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225633; x=1709830433; 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=lHSmb/9WbdODuXMrklIpysrM5LKlzco4ghJo7saWs/4=; b=dJ2rZAvdkXV5AJTkpAG8MVp63ZIFUUzaSASauyvA8ShqXCKmAUA0u6F7h7bxqRqfZt k5vOT8qyHvirEwR5dPsBVBuS0SwSgHRw7SC6ARNkrBY9TnmZ4nT6LHUh6faqbcHHIsmo 2B2XM95sxqKLAFcPDe9zYmR902ebshmC5BdYFNzOFxMFDSIrw4rPmB9HaSGf1i8189K5 7rM/x8mTu0WvPvt0r1BnUGJ+gd/zuVPexqN4gbwqHxksvWx0tl2+11XKGW9nztA6zYDs CTaqgdZMnov3FGdUratQ9Beo/BeqocAexgBGqB/PInf+O6f8L1pM0ukt8o+LizNW/WYB P1kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225633; x=1709830433; 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=lHSmb/9WbdODuXMrklIpysrM5LKlzco4ghJo7saWs/4=; b=ZgUNSXBZuZK/XWgOsacKuMixbKSKcDKB4LMtiHgt0cfX7eAo2Oehhmm+7KwnYWU4Z+ woLEfw+e13uxe6h4rhJYCMBG/yG0GgczTpAcr8Yi58RSVwSYfO/T7MzsTkw49u0GQ7Sh G7v/wLhpCkNtgOSMU6ds1pj5FpAG8/0x+0KAAANmHGs9jMqReOjy0mH+5SpfToPUMJcH H/HX9n7AY2JXoyUNQKwTQiWDhKA/1LZ6L3VqNqAbwLcbm4tIvldBMEO9dxkStXGFYdCC VGXcp3m/8kjx4KCgAuEJkizLQwZeYYAXTVg0z8S2J37o/lY+IGARSm5khIszf2FWoMdn hgeQ== X-Forwarded-Encrypted: i=1; AJvYcCU3QuW+afFPXlGHXWKanWGlNJHxICn6WE52UgagJPKyaxJcw3I53lAmni92Nspbsj9Hr5uSQMBnMejnivhBAO0GwlLZwcyrnAXIA44s X-Gm-Message-State: AOJu0YxDBQHOeZPW+FE977py86d4Vf3SynaMw7a2VoOHHEBBv7UhZFC0 rkj1XTf5JMzNS/NQ7EYOOwlr5kc1JpaGiANgO/mNSj37ku5U4/Z20k4nZCXCe98= X-Google-Smtp-Source: AGHT+IHBgeRsdeEHYzbFplFYTKMly9Z0UnsyIYhbPbbZIWwwuNV1D9WrGUq7sZYph7CycEMrf3aA4A== X-Received: by 2002:a19:8c4a:0:b0:512:e061:e35d with SMTP id i10-20020a198c4a000000b00512e061e35dmr1898793lfj.53.1709225633562; Thu, 29 Feb 2024 08:53:53 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id h18-20020ac24db2000000b00513142744d4sm304221lfe.191.2024.02.29.08.53.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:53: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 v3 05/20] media: i2c: ov4689: Remove i2c_client from ov4689 struct Date: Thu, 29 Feb 2024 19:53:18 +0300 Message-ID: <20240229165333.227484-6-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 '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 d31659139a6e..56bf1d964e43 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -74,7 +74,7 @@ struct ov4689_mode { }; struct ov4689 { - struct i2c_client *client; + struct device *dev; struct regmap *regmap; struct clk *xvclk; struct gpio_desc *reset_gpio; @@ -405,13 +405,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; @@ -420,26 +420,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: @@ -553,7 +553,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; @@ -564,7 +563,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; } @@ -580,7 +580,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; @@ -597,7 +597,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) { @@ -618,13 +618,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; } @@ -689,8 +689,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; } @@ -716,7 +715,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; @@ -744,7 +743,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); } @@ -813,7 +812,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 Thu Feb 29 16:53:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577413 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 DC838757F3; Thu, 29 Feb 2024 16:53:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225638; cv=none; b=K1skiH/d4Am8B8085KID8Tx8BNbTkPV0sfiM2WLwnrE/KkMNM3V5Z6RSPYudX8ewwej2VPS8eblgMz+uoXINmetIfjhEMn/31FvOGBWItPmwmIEx961P+Z2qZ/Iq1oMnJidVegbQU6SsPpcnn/t18VeWjljFO3EaCbrqL6Ski4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225638; c=relaxed/simple; bh=lmFS16DLEvweY84g6ZsRhA8j45XGSzBWi6FzU2Tk8QI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jEQQFpUrVwasF/tTsmZfJ4J5Fsxa0QWy6TJtBpDBJdRZb3ylwJv/nDyJkbtJJ880H7dmBKrxJkfoVM4X8wUAb1i/Kv2cmqMvDGqSO/biDe3sLjBsHdWz4x6Kr4qus/M9rCbgvvKol5Q24fjPTSK66LwRV/bnKXzIZDfZeuVd2ic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=L3EW2Yn1; arc=none smtp.client-ip=209.85.167.51 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="L3EW2Yn1" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-512bd533be0so1387519e87.0; Thu, 29 Feb 2024 08:53:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225635; x=1709830435; 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=BRgS0UXYHPj1RQ/rJTomS6xIK9CdxCZ6J6KiJf7SUus=; b=L3EW2Yn1juzhTLAUt4FPSf9bd5Aw6dvHDMABEuO9c8nuTHDdA6N5ykl9Hz1+Aul+/w 38Xho5TOpsR1r5VeNyE7RiDfRgjyKuU8r34gRjcAfm7UIs3DU3bMYD0L0b7WIUORYz/L +tDlAnU4De65+9fpPthilK8TIMUfe527c0kN4E5N4oQs6gy28Hif+xfi9Z+iDPHMnvxP gh/OBYWSu5Kg89QoAkejyIUq2wCAr2dusIsEiz1aq9vD+3RdFEWUV/c+T3cs2TZ7qDDL UV0be3P07LZMVpPJrMAx6tcl7KxtECwsZyOSRsoJPzuMhJzHpLXw24YOeYgltOkuyWp4 XVtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225635; x=1709830435; 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=BRgS0UXYHPj1RQ/rJTomS6xIK9CdxCZ6J6KiJf7SUus=; b=DbxcaUNes6RkjRpXj/4aOgXaiM9d5aWXl4fQC8/xlaH+VbWirZAQhd2eKl4Wy36B27 Ag8HYjnZPdo/WGmH1y9GTHugoq82iZAEQH3FG8FIJJ8CWiKaiCSKxzuNGGnwAJ+qFZi4 u61Czb6ZXPEKpQtzICXgrzA6nJwJ2rJRveaxigy5idAcJMiw5YwTUfSed4e7CxSqu5e9 hIsub9MQCmVgwwnB5qxVd23jYKl0niiyTpXT1KnDmZVp9XiSdLU2c0koWjiSY0CCTOBB OE2cDR6NroLOPMBz3mxGgvlTngfL/bbeAPMyxb7dLGFCSBhkklbKz9kq1ISsrLZRcWps IeoA== X-Forwarded-Encrypted: i=1; AJvYcCVX9+S8+B9yxZI8fbsjnHNSAhGWxLSqXxpO6sH/+ask0VJmVvefq1+UISQR7TJ/vX2A3S4SCg3I9XAldt1nGsPukgblfx+8yzlBgZdv X-Gm-Message-State: AOJu0YzxOy0BIV3JQISNbidunc4BG8Xye5yCedJnlC1/v50PivwquhjP GpuBAa3l2tBGMHU6+SVFzPmMl/iHKoRv2Hr0x4sPGZl3TeuDNe/Is8xrqWu6yaA= X-Google-Smtp-Source: AGHT+IEzBqLB+98tQIt10pO+oo/355mY4aAAk884okFArSwq1UAY60T9ZQ2keI5hzjUK3KGZhUjvUg== X-Received: by 2002:a05:6512:2248:b0:513:23be:e924 with SMTP id i8-20020a056512224800b0051323bee924mr2290513lfu.59.1709225634880; Thu, 29 Feb 2024 08:53:54 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id h30-20020a19ca5e000000b005132996de60sm200348lfj.28.2024.02.29.08.53.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:53:54 -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 v3 06/20] media: i2c: ov4689: Refactor ov4689_set_ctrl Date: Thu, 29 Feb 2024 19:53:19 +0300 Message-ID: <20240229165333.227484-7-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 Reviewed-by: Kieran Bingham --- drivers/media/i2c/ov4689.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 56bf1d964e43..1bc00404f3fb 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -580,10 +580,11 @@ 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; - int ret; + int ret = 0; /* Propagate change of current control to all related controls */ switch (ctrl->id) { @@ -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); From patchwork Thu Feb 29 16:53:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577414 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 072C27827F; Thu, 29 Feb 2024 16:53:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225641; cv=none; b=MoSYQJQz071Z4Ic09S2Z9EYAKR+b49qW5oJ6bkKq94GhCYNYqE02l6DhFsuGFvcn1PMg8PWNnimCyyGd2MkFFBdeLv/DlMk5C9ccfx2GGFZJD/PdZihZwlqGkjP2oAGtNTZrA/7iXz71OvUYymvL2BOOSZGIu5EwYQRrdWjTOhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225641; c=relaxed/simple; bh=ROQpCos746Zb3F1h9fLdI7HgIH3KQz5Xo0S4OnBLwVc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NMNHFIJ/BhNJZweZtINwTPcSPsxBCcWtB2Pjp9qeQAYd2tS/oMbKtOLjzrghcJlZ2uorBb6SXtLDx54iOkPIcW3MeQcjVT5O+8EilFIKmi871U/WNm464PEx4dt+OFGkvmk7Wu+C3E2+KeRWI+rUZFRVeSYqs4cGpVaCqsbMCzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d/LoaHrP; arc=none smtp.client-ip=209.85.167.52 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="d/LoaHrP" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-5131d0c3517so1075538e87.1; Thu, 29 Feb 2024 08:53:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225636; x=1709830436; 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=sw8k74BHt2o626Rf41Ehs+KdDJYpQNXuHT/61zn25bs=; b=d/LoaHrPL32RwGJ2MEa46UnLrwLO2fm585k8DibX8bEtrw3LtoVzDnp7aoq07TpEIc IdkGjsP5NzlyirPAZUUfSWliwFOfdzbWTH3t8h/skS/j69CG1mpZgnm4cuLKr3qI81dv dRRtZJroDm/kFGKnPv7sYjioyzZkj7lwNZMz7JhO5r7/qWLIUEF5qTJBF7mDetmPKmPJ /iw7/KHh8jK4GZk7ZmfyR+b2FRKiQxfB6xbBXvFkj9fj36bKqREbs/YPEp8/IajGAbB+ znPoZAQb3uT2d3ToraqivRp3tKLdbjp7bRz19a1R2dY/6Fj1FL46zDum0mUQb4vJQjuf pH5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225636; x=1709830436; 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=sw8k74BHt2o626Rf41Ehs+KdDJYpQNXuHT/61zn25bs=; b=ADn23GPgoZqlwQRxetxOmrFQj2/6RwfArejwlRIj5+79Iu34KLSnyXqR0dpdIcsQqg /5YWOjPkroPN0NteLUra3gvHe7ACnhe13tdQh9cLxTNfsclplfZ7knJiijepxJqVhFmX Iy4IVN0K8v2xEoOi9CgNMn9Ua2BgWXH0tsjB/gSSiyODI/JmXMoSvsp4KcIAJGvxSDVL BhwBrmf65Vd9rQeYjG9603mSItaobX9iwa87zkT0GVdPmL/bxsYvoWc8p9IyxfwQsKNh LutZYV6gDIMwLRQxy9o2KVTZoHbrQLdESItD9XGSO4d7ML4V8TgO2rgXPqubOT92xm9r hH/Q== X-Forwarded-Encrypted: i=1; AJvYcCVXyI1OM5HONSchvtqGY4MoqG5+5vynP3z3KKyx9SIlIeKiq5KQoqeZNFfNJW+SmixAsrrXA1huMpLg30aNeZ9HPbc13vqmnUtQco2f X-Gm-Message-State: AOJu0YzZmZkRrEfFeJjv0K2z8rbP4r++KdLCxwbPYkCJBbhSO3YO9+Yu 6EKnG2gtIcngyahgT2AQ0hR9LtpRN/10YypIs26Ttk92XJhsa3NdGx08kEnH2Mo= X-Google-Smtp-Source: AGHT+IHYGIK+btFwCkcrMJOBbWpQPUcD7ZY9P5QWL8rwYyFqwJr0SK38e8FszACQymiJ5JQdm3ZX7A== X-Received: by 2002:ac2:410c:0:b0:513:2d00:df3d with SMTP id b12-20020ac2410c000000b005132d00df3dmr73881lfi.1.1709225636040; Thu, 29 Feb 2024 08:53:56 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id c17-20020a197611000000b0051319cbe2e5sm311685lff.16.2024.02.29.08.53.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:53: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 v3 07/20] media: i2c: ov4689: Use sub-device active state Date: Thu, 29 Feb 2024 19:53:20 +0300 Message-ID: <20240229165333.227484-8-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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, 31 insertions(+), 44 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 1bc00404f3fb..47feb6b5ede8 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, @@ -649,7 +631,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 +843,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; + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; 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 +861,24 @@ 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; - ov4689->pad.flags = MEDIA_PAD_FL_SOURCE; sd->entity.function = MEDIA_ENT_F_CAM_SENSOR; + ov4689->pad.flags = MEDIA_PAD_FL_SOURCE; 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 +887,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 +906,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 Thu Feb 29 16:53:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577415 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 D5EA03771E; Thu, 29 Feb 2024 16:53:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225641; cv=none; b=Fl5tO5l/CmDtQLc5cJdD+T4v6QE31jwxgd4JFB4paxs5ImJx1aMKpD4eUP79JMFz4j5f9Oh6BuT+MgA/UwTn9gpqg3+R4ht20AA4A0qz6OsHudQR/eezhNnzm77RIdJjo9XaPjQVI98YMJf+HTQvezbxo76z8U1yGhh9hTSbIAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225641; c=relaxed/simple; bh=jODaE8bNQdgWYIBa/UL+z1/OzlLcc4wPCUOxYS1KWz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kO3p5t+Kiq/kvwYZLGhLFCbeLuJpLvIepjx9Jd9NkhfItN4KG4AxUDDVXJcuuG/NQ651r1LVyr1LwNhiFcjiTE07Aqzo5W9ZFxJmMnRRWg033snA75Ro6kXE9fODV7fmzRl5iM0nJkxoDy+I/IVvltj9PeuaMk2xINtg5+5VWGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Eap9U6Ww; arc=none smtp.client-ip=209.85.167.46 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="Eap9U6Ww" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-512bd533be0so1387572e87.0; Thu, 29 Feb 2024 08:53:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225638; x=1709830438; 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=PuxhRi+cO3aYPKrc+1v3iUal/8f5kBZLAU/GOUax1jA=; b=Eap9U6WwEtfTtrdZXqE1zzDVy2Ea8Y2Mjasv4IpvEWRrEdyX0e6TTDsqwY9SAqHi1w GMJP4zko6vmQEjjfR0yHFZw46UnVOJM+xow3kdyiASb+Vx1O7qbTdSIUujoaVqawuYX7 kgXfaI8Wm9JeGEitbZYNUOc5BTJqiB7BI3esxlMdkw/1O5lBFYZS0eH2ZR8J//Jbp2KN BlSfVVBQznq/N5CIMRjljVAEbaU7vgYP9hwpGtT/QuckgVCwTNsNwghihnTB+8VJIytA NJLcuIDxnC0s2l2fX6f/VJC0lOHz7Vh+fXcQYSW8V8rzJZ3AB53L02Q6WCcvnDHgUhqF 4ypA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225638; x=1709830438; 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=PuxhRi+cO3aYPKrc+1v3iUal/8f5kBZLAU/GOUax1jA=; b=XNdBz5yb1df6ry889b1so2tJa9LedkTaX0Cxy1bbdwhz9EaAEkFRH0DsoNaJfvHMEE 8xEse78qOpznwN3cTue3I7ThQl3g+qjryAom8HFPMlo2YRmjRJx9iXzYVmhcGTwDoDTe WiyTB3o9n5jmEo9m4bS/ynOjoi0JfYGq7JTrvmybEje18FUNXKZFjiNcw92Vdu8hxr1x Pd3lVMcUpM99flWE5TGaqGG7bDKk3yT9OJDFJv9v5t0v/L49ycCSxKViWGb2QawsfZls Yyfw5t72zfeCHe6kz/hKkDn8daX5DquUyJ3Un3XYOUz5hMlw7fUQDg6Ct7/QLs990kTi mWfA== X-Forwarded-Encrypted: i=1; AJvYcCUCcbEhxyX7J9eKrb1U/gHvw5dhgUiJDuOsuciWFiKuNbe++rHOBIezV0JPqCd5M3uFbeOh14BJ+Vs0zTmu7T1pqX6NqnryzCZzyM5f X-Gm-Message-State: AOJu0Yw7SDwhI8Hx2OLVgpiA4ZlbAQfaHi8+fC+dlX3ePWR1qpDQi6+C oCCXY/e0Ul7Lc13zZvVIt9pe62kSM18Pz9wJGhXifMSaaY940T7yN9RBsLhiPvo= X-Google-Smtp-Source: AGHT+IEajL316uZt/nReFBqnf9MjdphugjxgOK1hbnddLQgsVsJURWAfsXM8z17ZQ5TvMYp5E79ZlQ== X-Received: by 2002:ac2:446b:0:b0:513:1cde:a1a1 with SMTP id y11-20020ac2446b000000b005131cdea1a1mr1779619lfl.38.1709225637648; Thu, 29 Feb 2024 08:53:57 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id h18-20020ac24db2000000b00513142744d4sm304250lfe.191.2024.02.29.08.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:53: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 v3 08/20] media: i2c: ov4689: Enable runtime PM before registering sub-device Date: Thu, 29 Feb 2024 19:53:21 +0300 Message-ID: <20240229165333.227484-9-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 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 Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 47feb6b5ede8..0e0e694510aa 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -875,19 +875,21 @@ 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; + goto err_clean_subdev_pm; } - pm_runtime_set_active(dev); - pm_runtime_enable(dev); - pm_runtime_idle(dev); - return 0; -err_clean_subdev: +err_clean_subdev_pm: + pm_runtime_disable(dev); + pm_runtime_set_suspended(dev); v4l2_subdev_cleanup(sd); err_clean_entity: media_entity_cleanup(&sd->entity); From patchwork Thu Feb 29 16:53:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577416 Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (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 4CFB97828E; Thu, 29 Feb 2024 16:54:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225643; cv=none; b=Df/5l3klqziRcn/soJqmFs5sDTiJb6m6N1xkZbS9AhZcS6rjmRZ9+PMgeJ+qD3RUFFOiuXWXPObe/t6AbyPp9LncY5IdxIWyME0voe2wYKpQNEhJMaoaoyUfof7CRDQ90pXc1z4sAdsO+YozXQrDzVAOEPKrafJXTTnP8rN2Dps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225643; c=relaxed/simple; bh=RwZBkjBcy8SZvMSBuFZPyUzF0WRfRC8eJK3XqPT99Q4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=raQD6vV33uY2SYEE5Vl0QO/3TqV9a0w6PNwd3xGtP6RzeCZn2GceB0zNMw2Nt4EanfBqQvnLez/hYchcHjwbc8do/+UmS7hYC20lYUE55BYHIjm6CCFK7lb7gxxijn2K681ot7uLRmKt1hib1zV01h9T4qDh91+69hQzbDe1jy4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XyDY43fr; arc=none smtp.client-ip=209.85.167.48 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="XyDY43fr" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5131f3fc695so1241300e87.1; Thu, 29 Feb 2024 08:54:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225639; x=1709830439; 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=WePeaNPDWRbNBkHA7ri2XyOGnHUFGGKonSsyXRKZzm4=; b=XyDY43frMoh6LvnPFTHmvxOCMp7dtYtyL0x/naWmsE11kF3b8FvOzXZhdu10pLRfR8 iYZcFPMSoUByLBhaM8vlKdGR0dJ0ftbvNDmnDcCn7v75ACUFo1HLJWes2n0FazZD6I6R 11GfkeSgYPRSWZPCwzipJdoCM1K7clL1tetj8+n65AMmIu7KIh8OSaLAhAJZDYz7UlIM /RCvyMsqtI6MdyxbowwJj1wjPmzsjkRAzADItpY57Aoim+TYSo/nkJMlipK0nHkywU7J GbQIQ8BmtCi2+ZSEl+4WklINynC6wDAuqgXd9rNYL+K3RpB54ymfH/ZkO0Vt5ezoIoRb 3rfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225639; x=1709830439; 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=WePeaNPDWRbNBkHA7ri2XyOGnHUFGGKonSsyXRKZzm4=; b=bGmKXp5ETWCpcZci/7QZ3P2QwbUuiZDQp//TAD6vDzVxE/c3sUORMSqU5t3bFpQzXE HBfdS3b8h9RqSL2SrnZnve4Jmry4RM5BtCW3aD9XYyObNluXIwFyMxflTL8aJlo+vrFc OywOk0/5ILWE0XLeEQI9B/N4fjse1dD6O0PNcbwVJkas7PafHKfpKWjWCuYi/QRtzOyh DTijVjR+nn6Oj5fVgiMPFYt8LHl9pAZ6gIF2EWfVg3NsSCEgiPo2Mj2f889p9OOdEGKU TrvVELZ5YCDWAlU1LFRNIKVmOz3WTPtq7XMJzTaSGornazN8DSEu1CNnKCcxw5BD3bj/ uj7w== X-Forwarded-Encrypted: i=1; AJvYcCVYnty9/z2q9IZ3Otm9ccCezinByDLp2fnXvFKP9qJr5xNaquNrotLkyrnRyAxoY6lalECrJ0zz/S0jq01k9O/KYRGiY1iPtfEX+U/E X-Gm-Message-State: AOJu0Yy2thx3JWUpCxOsB25RDpnKHOZ3qPk0cKPBL2AOWTek9Oe6SQaM PpSu4MY/YwNBLh5XtqWJMHAFH2XORjowFACSD2kMysMbJ1BTMCnp6QVe5gCNaT4= X-Google-Smtp-Source: AGHT+IEXNx+UQ8+kfdXzFWGX7Hq5W+1lYNTkOanfNqdFOots3m+mWWwOMNThz5ANOdwkJqaZGE3zSQ== X-Received: by 2002:ac2:549c:0:b0:513:19df:4eb6 with SMTP id t28-20020ac2549c000000b0051319df4eb6mr1699606lfk.12.1709225638773; Thu, 29 Feb 2024 08:53:58 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id p1-20020a056512312100b005131c9b1c8csm301594lfd.273.2024.02.29.08.53.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:53: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 v3 09/20] media: i2c: ov4689: Use runtime PM autosuspend Date: Thu, 29 Feb 2024 19:53:22 +0300 Message-ID: <20240229165333.227484-10-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 0e0e694510aa..2354397ab34c 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -426,7 +426,8 @@ static int ov4689_s_stream(struct v4l2_subdev *sd, int on) } 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,8 @@ 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; } @@ -876,8 +878,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) { @@ -885,11 +889,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 Thu Feb 29 16:53:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577417 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 6694B7B3E9; Thu, 29 Feb 2024 16:54:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225644; cv=none; b=aBg9zTBonxZeXg63zeCmRABOJW2e2zP39G4upUd3zxRtoDXhfLi3LSi3l5clv0tlmFP42v0/WXAKBLIzsthO863VcURwhLq1n8zRLye/K6aMO43wxbonyf1GhkqxvqVHWOwkt8qL17AcWMYmkm7jgMj9+z34idgBaIbLWyDyUIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225644; c=relaxed/simple; bh=/6ZrMp4uzS6/sddTB8TYpGu6V+UXVOxVryZJevlr6tU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OyIaa8SGxhwR7CZ5NNW1DA4f30X268bFiPQkIY8clwQgf6XXtPEEhvFi7OXdBYQ/w+vrnBmqtnnY+3hfBkZFlDudjxQnArBc5YYU8X/nAgsKKxbjJJsfBJnCMH+R0sEEQ/YSLtcx+QhEGeJgE16Fcr9U61XYQhDBq94rZTg3nPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CMPu/+c3; arc=none smtp.client-ip=209.85.167.52 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="CMPu/+c3" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-5131c0691feso1406149e87.1; Thu, 29 Feb 2024 08:54:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225640; x=1709830440; 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=D0tbIWxrF3a7jfvPwD7Gc/OLDO0heS4wTMG6zodSI4U=; b=CMPu/+c3j0rhHryzkzcRfMfxurn2nWOOmdw5ntb0SDZ0ZkaQU0obRORGxAZMKM51Go wmrdOris1dRvDJeojqRSw4lfjDVKzocc8FGTsCPuM2hRI0diog1FpUgWbVkrD2IsH+7X 3JMq8bnBDLOEFOyDtRzM6MM31Ir1ZP40LlmXc3FXsjn2ZXXck3BxbcdbRrf7135LZ8oc o1eK1tKTvyxkB+pHAv2vn9CsjaCsKh/SFEsDFB6nQ0c2IWoFDLi91/RUXWaRhmywwWr5 dNnx+4l7b08GCM3mXSgfwk9L3IzTIS5wRO5gNOqXTLfyA5MpP6pOyvlFO2O9QzOQS4iX 87zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225640; x=1709830440; 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=D0tbIWxrF3a7jfvPwD7Gc/OLDO0heS4wTMG6zodSI4U=; b=pmqCcJhHqPewLuFYwl+GMJoyuui34e2KnOLZGovYV3B3ShCtvFmtvXBq++DDt7L/yD RZH6cm2OgEtbq6McDJRqGjve4JZaOTRmmEZVkQZyF4/OZ3MmJQT5ZF3GNr1Ebkznne4k 38H4WdF9uObJz21GBT19pv5AJ3Fff5WPmA3zTJG2/Euk5PnkCzsdTyrsHr4x55wuddXX J+AWm+XfozXaZO3LrWG9fQepxYNCPlaHbxMncBvqf5+SmfUDk5sK0oz0mFdFAUBuzLjN Z7hni880rhCBwgPQX47yKpafF1FM9ADLPX8ehu9Pf7Bon1IaZa5FqadWzpjHsGjRtY4S yuag== X-Forwarded-Encrypted: i=1; AJvYcCWHppq7LB0qoMEklBuhBJyInRDpRRM7Shcz6+n+hiuOFU+1OSCBLkK5OMHnaCtpaRnSZhOzzGcT5zmOORaNHTs2w2EUkkXheDQcgfpd X-Gm-Message-State: AOJu0YxLdZaj0vNK7PbEKiXgX0Jt1Wncei8+cs50txoQIh2Dby/6VBU0 c5qJSw6IYgeOo8JVfkJ2RsXPcQVjmPUG1iYRJj5H8HZ3L+zef5xqsmI4gP5YN40= X-Google-Smtp-Source: AGHT+IGVDx2+Lu4pZQV3CxmS3/SmgfUo6bBVsUFQCuTckBRAnKuf6FhpfcLNukpklCbptNEzxcgdsQ== X-Received: by 2002:a05:6512:7c:b0:513:2040:d5df with SMTP id i28-20020a056512007c00b005132040d5dfmr1675126lfo.1.1709225640196; Thu, 29 Feb 2024 08:54:00 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id h26-20020ac24dba000000b0051317eb0bcdsm306660lfe.245.2024.02.29.08.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:53: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 v3 10/20] media: i2c: ov4689: Remove max_fps field from struct ov4689_mode Date: Thu, 29 Feb 2024 19:53:23 +0300 Message-ID: <20240229165333.227484-11-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 2354397ab34c..45f055c57436 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 Thu Feb 29 16:53:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577418 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 AC87A134403; Thu, 29 Feb 2024 16:54:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225645; cv=none; b=onSoqPX538r2lZ/DxNMRBAGsMHPcSwZok85I38fykeTwCa/MsOykEcmvlNnK1/CcQxGsbsbwAO6JQlbU7fwzIkuwql3T6fb//Yfh0p2zhOfMnkWlkj54iLUXxEgHeuDc4/33w7nfiMcnNI+EisEZdPETgKY/uLv/BGglVeWJR4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225645; c=relaxed/simple; bh=ntVdPTcZpvBRjbwq47nv8+m3JpN9030guqT+pmZ++tU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nQBwWBIKaNy2bbBqm1hs7GPRNm2QXq8inPbD7L+MdA49fSjYB5cCjJuUk9oV/Xd13bNhs3qOrVF0QGeKatC1JTQD1VcSm8tP80JVv02um/oRNN7QjhjX0zTApswUbQwPSjGJlyBdOF0JZ+9GL3ya73HQB/kPvC8NWTG+vbHvhVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UdlnhR1z; arc=none smtp.client-ip=209.85.167.46 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="UdlnhR1z" Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-5132b1e66ddso589612e87.3; Thu, 29 Feb 2024 08:54:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225641; x=1709830441; 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=tYsTb5hvXEwkYOesWc/SeZgECL9fnzVJX2Zj7gHGLfY=; b=UdlnhR1zLPj+Q45DNaNgKr89Q2xwZ0tXVfflldIMFLfuM1gaMWUbm2mjVeZkvFsnuI WPzp5D+JDY0G7hNM6rnmCt7WUiNDgVtzqmktg9JZU9/ceLQOPxM0Wkdqd+1wDvS+UHPc h21Kyi42Jex1LzvVferXOzukTkiMHcUJSu35+i7Y5WefeKTiNL9lAthWex35w/95CPux HrXtRFC27y7vOrXFJgCq4vRrWOKKBEDAMeEMhSBtX5hWCQyjyG8HZC0HBzZUJ/km91Ge 8dhlLXCv8v2jc9yEp5zqzPwOOEzhiLFZkpyVcR9/kSHqKfPzv8phudBOO//sS4Q28rqP XyEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225641; x=1709830441; 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=tYsTb5hvXEwkYOesWc/SeZgECL9fnzVJX2Zj7gHGLfY=; b=QHdPeoi8OfiEWsR0Ie40h92ps+q2Mbhx36WqQAhl/AOrVv2shzO+97LmEiM2sTcXAH 3KTd6BWXV1Q9vFHSunGqjn+FCmtEQ+IVBWluL8Z0HC9LeSrkLNMn14TT7FDRuI1KgS3b e8CRVt1V2VCH9MNujBCJi7HU5tqRVe3evdTGiRvCSk8fRCWcrzfvO44+8QWYu/jRhfkL efGUjYXeRAaUVmKOM0wppxeBhC4HR5bkGaBzUwcP8ldZV9xp7VfiielbKg4w/pAzj6+A J8pc4fXsH267eOtIoyswo3WtmsUhfRXXov+IXO/3+dVnd+ZurVYa9KMOigUNLfGQAtyT 6LYw== X-Forwarded-Encrypted: i=1; AJvYcCXlpQW7wMs2xCOFVsR8S0LMae1vo8Y12qlP02mttLbJN4JJ9QDFAfZlRv/4Qr50o42cistQNzMcwF4mZ3uvPiV4so0Pl7/82qjEVrxg X-Gm-Message-State: AOJu0Yxtc1XR/SWkLklvwDbv7NvEUORbfvd6cKVJpDkW853UawZ9G5gp UngBFYcKlYQhQ4gle8/YvGjYkzg/2zw+HYODRvcnHjW2f/QhQKR6Rm233H7KA4o= X-Google-Smtp-Source: AGHT+IGnqpX6o4NWb8fh8u0w4A3uzbC6yYUrPgejJGRlnziqqW8tBUlj7mdSKZsmf2FWG2UWQ0duxA== X-Received: by 2002:a05:6512:1109:b0:513:1d10:decd with SMTP id l9-20020a056512110900b005131d10decdmr2379586lfg.34.1709225641435; Thu, 29 Feb 2024 08:54:01 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id y17-20020a197511000000b005131cefefd8sm306169lfe.240.2024.02.29.08.54.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:54: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 v3 11/20] media: i2c: ov4689: Make horizontal blanking configurable Date: Thu, 29 Feb 2024 19:53:24 +0300 Message-ID: <20240229165333.227484-12-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 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 | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 45f055c57436..8283a9ac86c9 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -30,13 +30,17 @@ #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 #define OV4689_GAIN_DEFAULT 0x80 +#define OV4689_REG_HTS CCI_REG16(0x380c) +#define OV4689_HTS_DIVIDER 4 +#define OV4689_HTS_MAX 0x7fff + #define OV4689_REG_VTS CCI_REG16(0x380e) +#define OV4689_VTS_MAX 0x7fff #define OV4689_REG_TEST_PATTERN CCI_REG8(0x5040) #define OV4689_TEST_PATTERN_ENABLE 0x80 @@ -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, @@ -598,6 +602,11 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) 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) / + OV4689_HTS_DIVIDER, &ret); + break; default: dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", __func__, ctrl->id, ctrl->val); @@ -622,8 +631,8 @@ 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; @@ -640,11 +649,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 Thu Feb 29 16:53:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577419 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 1A53A134436; Thu, 29 Feb 2024 16:54:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225646; cv=none; b=KeZ9vA/FVzXlLK2FGD5MXNUmrQwhsws6M2z4Brz48HPxpsj8U47GZOeLD1R2e0LMJA/LgpzCT/QuHdCImFVwlEvcmIBmcM7rAexA9JC8cR55iG1UzMl5CEK305lU3H42eMB6ty33cySmrQLP4bBPJywYYoDVMxqkS3McCZfMul8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225646; c=relaxed/simple; bh=SyZ9/l4hqqx6qeHjDJINR2+KFh3XcHfLWKiQUoRtv14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dB5xdqvgRMJO4p5ZmZuxPkqoAFDt9y2y0Yu7M/6vE4HD4JfNI0JEdm+jSybV11aceIXOdi3KG4qzdmtffKgenTvm0z4xY0VZnTuPta8wszk31uQQB4r5dMgJUiHw0iEmCgcHOtJ6DDL+ze4e8C+H8LXC2qWrX/5L0cw/pWLvvc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KxNZF7dx; arc=none smtp.client-ip=209.85.167.52 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="KxNZF7dx" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-513181719easo716740e87.3; Thu, 29 Feb 2024 08:54:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225642; x=1709830442; 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=4A+7fqGlgqB2e7gBYOUtUusaDBZS2HZQOBIfzoUKKJI=; b=KxNZF7dxNZePeZPvIxcRjGQ14GMznYSRUEbneeBS/Rph78l+IKfraacGxBPNFPWlvl Ecsh0fbaay+efdz5H/iRKCDOGF/e61M5PVHfy+f2Epp3DrXKDY2rWUPY4SQjS20H0aqZ 4UPs3wMA4nEyWukQK/IPP7oYygUTFHAFpWGG9J+AXnxz5ON3C7h6KqO+KJ92JUD7qP8e tDk/GPaW3Vao7G4xtyx6DmgMf/eBK2H0h8CfR7SYiKXkVDlIF8mo5PeHWTy6tMxIwe+j 3wBrMspG1q1kVal8DcyM3wRIKYh+Q2j3JqnDwwVM6TiE1Ni7kwChGIZtuGk6qlSgKNLd 2SkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225642; x=1709830442; 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=4A+7fqGlgqB2e7gBYOUtUusaDBZS2HZQOBIfzoUKKJI=; b=PFGMPDPs369VqpGvChTJuu7to3db0e7OSJj+ymWlxzXC94k6NF61WXmz6Yl7y8wb+X kj2Vr/5mhkvs5xntSBNahSSyTnOR+my74UXeX00tUKV5hgZzESGzlJD0RlFW/b7yd6bI lRMr525nnNG61A02BNvLIkCSBXb6BFcD7Ovxrgn4xC3I+Tvx7A3UgwnbkL+IpY173pbL ThPVnwOJZb7VOqaV1yqMmqNHlHPgIHldWFo1zggbzBwGGagt10UhZrz5/yysjhoYABsW nZtYH8Dg/BpYpfFVAgGqzR6rzoFzVy2/vxD0xZ7+D8TyjaOCCtHGCNwITTqVYMD4qsNv 3xBw== X-Forwarded-Encrypted: i=1; AJvYcCXtqgLfNUpgKaaG3T3jyH+n722SpD9detd9QvRTHh6m22Ub8Ze0z3QvhGS0WbDB40fai1LdhoG66yCruUTAtoug99JIeZbcIpoxMl25 X-Gm-Message-State: AOJu0YwcaJsO+52QPxlbkKsxbuvkbRE9NcfX5FtcQZpIGp4cTlFBbCOQ cvIFbSRyn4jyIuTamcoHBqL3fZ5CYF8EfsWc9gCGY9l9OhW1JXuCpYwemYOd24k= X-Google-Smtp-Source: AGHT+IHxHlgzXmfvpveI97xGc+iqGkr14wdZpTmusShiUw11YBd0OWd92+C3hP8mdXnqBz447bGIxg== X-Received: by 2002:a05:6512:2023:b0:513:1cf5:bcb0 with SMTP id s3-20020a056512202300b005131cf5bcb0mr1859303lfs.27.1709225642583; Thu, 29 Feb 2024 08:54:02 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id h6-20020a19ca46000000b00513273f4176sm250162lfj.143.2024.02.29.08.54.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:54: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 v3 12/20] media: i2c: ov4689: Implement vflip/hflip controls Date: Thu, 29 Feb 2024 19:53:25 +0300 Message-ID: <20240229165333.227484-13-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 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 Reviewed-by: Kieran Bingham --- 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 8283a9ac86c9..01ee8cadb7c9 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -42,6 +42,14 @@ #define OV4689_REG_VTS CCI_REG16(0x380e) #define OV4689_VTS_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_REG_TEST_PATTERN CCI_REG8(0x5040) #define OV4689_TEST_PATTERN_ENABLE 0x80 #define OV4689_TEST_PATTERN_DISABLE 0x0 @@ -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, @@ -607,6 +614,16 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *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, + ctrl->val ? OV4689_TIMING_FLIP_BOTH : 0, &ret); + break; + case V4L2_CID_HFLIP: + cci_update_bits(regmap, OV4689_REG_TIMING_FORMAT2, + OV4689_TIMING_FLIP_MASK, + ctrl->val ? 0 : OV4689_TIMING_FLIP_BOTH, &ret); + break; default: dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", __func__, ctrl->id, ctrl->val); @@ -637,7 +654,7 @@ static int ov4689_initialize_controls(struct ov4689 *ov4689) handler = &ov4689->ctrl_handler; mode = ov4689->cur_mode; - ret = v4l2_ctrl_handler_init(handler, 10); + ret = v4l2_ctrl_handler_init(handler, 12); if (ret) return ret; @@ -677,6 +694,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 Thu Feb 29 16:53:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577421 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 9C36D13C9C5; Thu, 29 Feb 2024 16:54:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225648; cv=none; b=h5hAy7z6ZKhYZefk/aCYh9dab3WavrUh8KlAKkq+U13bKb1HgPHsCS8UVlMCScEDvERo3JXXUc/gYaMKQ0CSK4r2AgmV9WgCTRwfnwezCUqOJRpDxJX0o3y5hqtrYMV3nzLLS93nIqEt3sbNbGbf+Gibe2bvt8ila2lJFMOM1F0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225648; c=relaxed/simple; bh=kIV+r0ACwujt8Ud8BN5PzX5ymKevE281zvWcgcIHk2E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e63PlXOU/KBVEDVyD1o8tFLiJST5rN3anO7+A8M0pdDiVMFK0pmQ6FX/2JXkPF0QB0l647ggNiXJgbj4lLye8MBkrrDyskYreBSXLYRdB9X4Z8mmLiwexV5Y/GOBmT0XdRJQDO6QnI5bBHdZrzc8cWWKw+WxhVmEJWiRd6RNesQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ub3H0jKp; arc=none smtp.client-ip=209.85.208.173 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="Ub3H0jKp" Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2d22b8801b9so14162051fa.0; Thu, 29 Feb 2024 08:54:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225644; x=1709830444; 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=BYKAzvzTJgBHvVjI4kCPgko7vz6zofMdlrXR1h42jjM=; b=Ub3H0jKpFbmvdeVsS4vItawiD6o9B/9Sr+B58PqKEc4JttXHK33ldEEiw/NM6opgiu F5ZWnSu4mfILRSgAEQ9DDU0h25e3ocIXrBENdStSnxne67zZG2r1EwdLZOsqscbA2JLf Af5BIuV1eRXxvoabKWizCkMrEtdw4CQwXY9UnXjPM/P+KZPekDt+dk7wP7b75WnKa4in 1FWQqDabKNEki522o78/3GsNknYXLmGYh6LVDAYHCBUa+c9dfYYvD8LldidScdEtyg9v d2kmtgLBODkhf9xw4g6cCMmzpsVYx7LbJC7NrEU1uR7LMoCV5L3PeIA/oE5L7nqzmTF6 c5oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225644; x=1709830444; 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=BYKAzvzTJgBHvVjI4kCPgko7vz6zofMdlrXR1h42jjM=; b=S0aOiNgmMfMYKxuvbuxbCYajba/cqf90nvFDdLapdSlgFOgjWHI5SRP3l8ME6NQsZO NWveQQr7ePyB5f76YCn258oRiPoL41FZvJdRzxddvxtEU+CBsBwm3TmTQTix4JZyAl/U uWEK1+5EyndlHnRRQ4uD1NEqBQo1bf2k+kcJ08Ejwbmb1NMRHiecf4mBpBZFx+fI5r4v QpOC/1EXqfQ8Fq5Cm4U1Q6kSZnp1CULlIi6nFI5uv90tqNKAi3tPoPkxaQKNzrYIhQnu dcMac6j9TstAXKyQedWCxGxBWfzRuep+xoQ4CQkFGMxvMm1s80J63+r11qygXY/Uvx0A uHag== X-Forwarded-Encrypted: i=1; AJvYcCW6hKcJx31T8wT+it6Y/4sro+nATBWMv5u74hA8XRK3YIyh6LgisED2GVdc5JKeAivMeic9ot8t2AOwr2n+ypZJpC0mWpCKozctjgxq X-Gm-Message-State: AOJu0YxRMty/SG6xfAZiZKjHCjFKiiUBNfWAeheP7JiOkTMGfiBRHiVO RIYnzXkfDGm2SnCbb6kFSltJx1CyqPc/4AhiS7fU76XeKLSVnwUFXgBCEJx/1Ps= X-Google-Smtp-Source: AGHT+IFsX4Pz5Ge5AAoI846ACK2R7Pf/hLFFMlTRl4+p0pVib8P9N5j87MWlmQA9jkUhcXEi2LBPSw== X-Received: by 2002:a2e:b6cc:0:b0:2d2:9b00:2289 with SMTP id m12-20020a2eb6cc000000b002d29b002289mr1936775ljo.29.1709225643834; Thu, 29 Feb 2024 08:54:03 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id v19-20020a2e9613000000b002cf55fddca7sm276255ljh.49.2024.02.29.08.54.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:54: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 v3 13/20] media: i2c: ov4689: Implement digital gain control Date: Thu, 29 Feb 2024 19:53:26 +0300 Message-ID: <20240229165333.227484-14-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 01ee8cadb7c9..1450db7302b7 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 Thu Feb 29 16:53:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577422 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (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 4E2CA13C9D6; Thu, 29 Feb 2024 16:54:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225649; cv=none; b=F9QnH+1Ndc040GiFmgKdG4C6Jj+PDqUtQxKlx7idl7DHBNHI+9U/oHCsPZYsr0EmLy5LeHR2hencXv8mWQfuiLKsKae8Pn+5U8tWqdPI4Pu1psTsuKfBdzU427089tUR+nD0RbLXmATZT2NtWi7ii+azPhmhudQpn1AsOn9lARY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225649; c=relaxed/simple; bh=z/lcJOGKZxYkIfwlG9//CrwgZ9h35lvAEPnEpxJLkdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gm3XwyTubAODfDpAjM2m1P0XuWHbMTAEVdo+rMfXn1mgeKtBVZZc7H3Voj/Zlq2tOBEiXqM/uCkXAKhe7SpQeAwsqEMUlGK7pP6VHBzaVFgVAs2957pSHnptmwGokEhLt13u2K47X7QKEjcZVB/Owj2tQiRXOgniKIneJJx56b4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ii0Fcwiq; arc=none smtp.client-ip=209.85.167.45 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="Ii0Fcwiq" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-5131f3fc695so1241404e87.1; Thu, 29 Feb 2024 08:54:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225645; x=1709830445; 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=vXRW1q4CHfYIIhyxDIUYDtnj8kIO+nPksr2cH8/pox8=; b=Ii0FcwiqZScOf5IF1Xst7M5NFnJze8agWGPGumlPp6nqZ1OVfSZY0/0H766M1lOM2d saMUqQ2u/P701/ecQZmYPoqQPZDSE50CEPPNMpv07K3W7vaM6Bku0c/2u82dDFZ8sDyb Sdy0zfk+/Ee1e45g9iMAzLr/wtoVWJ5aLroz6I7JFUprwUYB6LtFMV6Orm/CyDC9yrMk 9eD+NL0R4L0tdvsrKBVTMjp7+46bzwbX4+/laXlvSDVl36H7TT4PDu6K1PupQBlL6BVc rzw9yhgtuZByZ/FFGwOpaRJEieAlagdNDMHeBf2k0+HUI2x9AJPZSGljj5t6qbLE06M5 luuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225645; x=1709830445; 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=vXRW1q4CHfYIIhyxDIUYDtnj8kIO+nPksr2cH8/pox8=; b=C3hINPJt29rGRysSIVQvFDWGB3QpEOHd3SmrtD0YOjMznVRMPQYqQZ/o5LfFCve/5r V0etYyJ2YiiV1Xo1EVfpcRoLr0UB1TNQKwlD8buXHAI1fFsc0p9QPaMxvNuuIm/217BJ wxUheAEy4f25sT2xkE0+ORYqMS8S9iLBag2gB8Cph75LrA1hKW8C4JaCMjB1qXx0aXqq FBBw/kLkfS3G86eKm4gQtDwjEoIBJuiGiBp/siaLcoruQJHeGnQhyQVpfTl0dXc1IHvO oodLI3s93q3k953hKCTFrQ6ADC8UhNke8Y0bp3mMEX9batErXhE0yNuVqslxNtE62g9V Yzcg== X-Forwarded-Encrypted: i=1; AJvYcCWMkQINxYG5kjsBfY4LWg2d7EmQG+V1ktdeLyMaSxx8GTu7OiY6O5KtfzhJivbZa3XYhqNoCIL3fdTGHYDGRDlUkLOtrpatp1LKUXsT X-Gm-Message-State: AOJu0YyDhdsttXlWjn58NeWbdLf1yqEQNwCDrNjsBIZ8kN2WTW1GSwWY tFDimpUiYpggxvEL54rdd8kFb1vGw5Vk9qwk61lVRCbhPm74uaq5OPNJBsr1sD8= X-Google-Smtp-Source: AGHT+IEvsn4oYmH+ZHpMlUcrlrdmWavZQ3NAfN3rfUc8h0wwMj74Swwx9te38DBZBpT7NhOcAEUmhw== X-Received: by 2002:a05:6512:3b2a:b0:513:27a1:2fc7 with SMTP id f42-20020a0565123b2a00b0051327a12fc7mr1770408lfv.46.1709225645300; Thu, 29 Feb 2024 08:54:05 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id d12-20020ac25ecc000000b005131cf043f8sm308235lfq.155.2024.02.29.08.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:54: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 v3 14/20] media: i2c: ov4689: Implement manual color balance controls Date: Thu, 29 Feb 2024 19:53:27 +0300 Message-ID: <20240229165333.227484-15-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 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 Reviewed-by: Laurent Pinchart --- 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 1450db7302b7..6c36fe5f3b44 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -56,6 +56,13 @@ #define OV4689_TIMING_FLIP_BOTH (OV4689_TIMING_FLIP_ARRAY |\ OV4689_TIMING_FLIP_DIGITAL) +#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 @@ -632,6 +639,12 @@ static int ov4689_set_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_DIGITAL_GAIN: cci_write(regmap, OV4689_REG_DIG_GAIN, ctrl->val, &ret); break; + case V4L2_CID_RED_BALANCE: + cci_write(regmap, OV4689_REG_WB_GAIN_RED, ctrl->val, &ret); + break; + case V4L2_CID_BLUE_BALANCE: + cci_write(regmap, OV4689_REG_WB_GAIN_BLUE, ctrl->val, &ret); + break; default: dev_warn(dev, "%s Unhandled id:0x%x, val:0x%x\n", __func__, ctrl->id, ctrl->val); @@ -662,7 +675,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, 15); if (ret) return ret; @@ -709,6 +722,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 Thu Feb 29 16:53:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577423 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 D9A8313C9F8; Thu, 29 Feb 2024 16:54:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225650; cv=none; b=sdgnFZzGzRmqQ7CbuJCs2w+1I4XrK12X5yiAolDll5vcDDk+xWYJ/zP7H+cxaJUEyCNZaPVEPhTiQ9VcEFxUGDLxgWtc7rBmK3XHg7qiTA1jKZPVu77bSBX079kkAtAReIKCMgRI0cj3Ex6mLs4ZJIZm6WxxObY4KQNaVAK/F/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225650; c=relaxed/simple; bh=2qah5IkORwbyRN5g2N/9fCCwXEmTYgvXO/Gtw9Jlpe0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zg8CYIEBeL+kxHXNa1RndS4QgW99nvvCaXgn+0can1WJSPE7kjsv3ab8oTZyj4BE4gab8NzMNKsr8TF368Wg38+I6zRROZ2KqrVcMhAj+7eOR/YyltT5K3CFZ9gSiS1fhnkhlnwIKEM1pBADy8Dk/0NkX922iSnwtHdIYiTVnTg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=adl+gWQu; arc=none smtp.client-ip=209.85.167.43 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="adl+gWQu" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5131f3fc695so1241449e87.1; Thu, 29 Feb 2024 08:54:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225646; x=1709830446; 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=SJQkprQQfQSNaHlwTiO4ZnGarK6Ad6c4fE/9ick1hRU=; b=adl+gWQu/8gAEzvm1GjIrxeWp80wpuK/hu5mPAmTCIb2DfsCr0flt6q7Ikk3miKx6O mCM/HDGhj0A7lz7hH6hmNLJ3JeqZNF5Tb5FzGp6vSvVbw43FcpKhXKMzHeKrH2IquIIm jBCFYW5/mY5OQl5dz+uEmiEMNXmdFdOFZw2w8aF9Y/WwKtpcBTIsNu3F3P8wnx+oaH07 77oacxqq66r1vE72nUZEtccdf3cQ4IbFymg9NkJolnptxfptMB00MjfoXLPn3PuMh4cN 8JZujsky+NMqTDS3TTGbI8p4KOVb+Fdwqxt8FhI7+g1HN+6o8Hw1M2sEpsidmnqfYWWj DSjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225646; x=1709830446; 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=SJQkprQQfQSNaHlwTiO4ZnGarK6Ad6c4fE/9ick1hRU=; b=hMZztm6aD4Msem8h6Im657fdfTAkV/YiC6ITEvdC3b0J+psF19yiGc1UjsCEYM+A1x /670iP2s4si5rvhNawwvO39mTEqogcdblbTIgAVmaRKhB6cAldD04nZdwkMui1ztE/vB KrB9n/56G8p60GAowoWQIPTqcri15V8Q4X+UllYMyJh3e9WjPNIIeR3P0P0pM9BOMd7/ 1PbVwB00fKjHNP8jMUmAEEdwL3FgiE2AeVyIbcoQmnc1T0+m8SrFX7QgUHOUBW5KdkGZ BIhoJMaH+d47HS0pdNdvuhZuWRcfuJtgKKkFd7Iu6eEaSrXhEFDzjV/bxwYQsmuELhn7 kzaQ== X-Forwarded-Encrypted: i=1; AJvYcCX2O1xEWTND4w4Jr8zERghPh61M/yVoA/uTJqA8uhY2BWD1lv1CBZw9/hAopJ4uLoXkFqYZdT5Xeubf8jzM3GxTJx5nlfLQjMTfYgcA X-Gm-Message-State: AOJu0Yx9++CHW0MyT6MH4LNgXmdFHCbAVo2Aj2/px5I1W4Do7TxSKbsI Nk/Mn4GafWKGLA2tjmZWsTbenFLuzeW8CcCB5iuNb8BU1bzrFk1J8GTftzR3rC8= X-Google-Smtp-Source: AGHT+IGgV4XtE3FxovmT8emaKq3AzzO+2FM+TQqplSxR4HKjK1CewUfqoSVcJ2DNA2awPGfgaCnbCw== X-Received: by 2002:ac2:5599:0:b0:513:25c6:e98d with SMTP id v25-20020ac25599000000b0051325c6e98dmr1590452lfg.57.1709225646535; Thu, 29 Feb 2024 08:54:06 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id dx13-20020a0565122c0d00b0051255cbaf06sm310317lfb.14.2024.02.29.08.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:54: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 v3 15/20] media: i2c: ov4689: Move pixel array size out of struct ov4689_mode Date: Thu, 29 Feb 2024 19:53:28 +0300 Message-ID: <20240229165333.227484-16-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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: Kieran Bingham --- 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 6c36fe5f3b44..cc8d9fa369e7 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 /* 8 dummy rows on each side */ +#define OV4689_DUMMY_COLUMNS 16 /* 16 dummy columns on each side */ + 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_HEIGHT - 2 * OV4689_DUMMY_ROWS; return 0; } From patchwork Thu Feb 29 16:53:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577424 Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 7E96F13F447; Thu, 29 Feb 2024 16:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225652; cv=none; b=ufTa7hHCXzVghPg1AEgauIDhGRd6Gk1BvNnwY4WlIWKRK2OCJ9FSm/FVP4nmlKEGZUhpnPvhXhlDmLueM4Wka8GYmLZ1t1s4aBAmiZtJOpUX1qMEtY+F53h7FWlBamjY4HCOUfJ8kw2N5st0egdSz02sCEAu+kdP0Qc5vkD5dGg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225652; c=relaxed/simple; bh=HAjPxsQllXt2MklENcFQtTk5KhZZGpOecO/Grls893k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ebca3rOnIdjPdU1gKPndnEtkftcTVaTgJTY6x0wIDuDfUqwdi8Yc53ljxk5lqQAfdZ4Cn0aRDRS1GxHCnGdQaaZrc7G/p9vZCOnbXPBrHH/Lb1ZQilWBCj3RfJlkCodg2+NXAcX2Sq40j+0fu5oRRczgW7PG4zCC1OIZHQh7nrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jwiO5yyn; arc=none smtp.client-ip=209.85.208.180 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="jwiO5yyn" Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2d1094b5568so12035331fa.1; Thu, 29 Feb 2024 08:54:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225648; x=1709830448; 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=b9mcS8uBRt1ITRRT7Y6UHyXWxG9Pu0ZSy0V3XZb129M=; b=jwiO5yynWPrlDpA2JeorAb0ILqXaoCLV9K7GvK20BW1MAa+R587Rh8efxVIL3O4pwq v3B4M5KtbLMkyYZJ0EfJ6YBT+2sCOPSYN16cRtgICWo1hjKbfbOLTCtUjDeyR19VVjV9 fSwyK8TStr4RUJAjjuCXL15sQMS7M3m8fCR7ZoLsEtTv6vKWecASAXse6bBSrfIMKYCt OaYj2JZKDgokVWmJDpnFTrMc8wfZARnNp424MJGC59xT8gelrnkLjrALo3DVq4nCg88T lh9EQ9a7IsQJWaZXo7nqDhRQXAjh3xz2lH9hUsC/FN8hgRcqzi5aacgoxFskgHKgXWCh v8kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225648; x=1709830448; 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=b9mcS8uBRt1ITRRT7Y6UHyXWxG9Pu0ZSy0V3XZb129M=; b=TPhYJgxQtsQ+mlXDLb5bmTyW7ma4Y0mV5TstVqMTXenrgf1QNmPRYI0gzfRS2xffYu t2WOYMSVMfSBue1w4OjKkFijcnbll/f4lYT1bSQHKyslcfbzPMtHLEnyHCGsyPHvNR6t 9D7by5sujGXcLZ1YQY7XOoOVjw8v/Mw4RrUhC43XZgrjyCF0CLoS3nDIXd6bmxYhFpqs jmePnswMABYoaB64/7YdNZT3AGnGXSlLqqSGmYjWtKds63ShPV2wawrfPsL9nycYgFWV gdIm5EM6fNw8SJG6y39iKIyKstPBHF87+tX+ETRP6jeOrO/lazeRcGRDo9uEze1Mgcnf 6eqA== X-Forwarded-Encrypted: i=1; AJvYcCU6ivtFtDo7EO/QjUGociXWvyY/3+G4AQba1nq6NzBm9RMxhRC+zW96c/C7yTeQnZMyYEyVdcXCdfL0R1kyoNFeP85SmdLm0HFGHd0w X-Gm-Message-State: AOJu0YxW9pTVy+rGH+QiYph17eZMilTf2QQC8OkGWNU2WRLEfwtczyzz xizgog/DVdduXG1bqBN0O0MF/3J1NXpkyeCIsj1JMrdDb5Abrj7nZ8ZG58yvWhs= X-Google-Smtp-Source: AGHT+IG7mmSwSPHwCsovawh9rkEDXG4GDNSicttsi2KVCcA8Ya5smKfNaIlV2i1UEOqIVr4hAHDZbw== X-Received: by 2002:a2e:874c:0:b0:2d2:2cb4:f80d with SMTP id q12-20020a2e874c000000b002d22cb4f80dmr1769957ljj.10.1709225648113; Thu, 29 Feb 2024 08:54:08 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id x22-20020a2e7c16000000b002d2d439efa8sm260275ljc.105.2024.02.29.08.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:54: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 v3 16/20] media: i2c: ov4689: Set timing registers programmatically Date: Thu, 29 Feb 2024 19:53:29 +0300 Message-ID: <20240229165333.227484-17-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 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 Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 83 +++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 15 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index cc8d9fa369e7..d34699f35270 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_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_HTS CCI_REG16(0x380c) #define OV4689_HTS_DIVIDER 4 #define OV4689_HTS_MAX 0x7fff @@ -48,6 +55,9 @@ #define OV4689_REG_VTS CCI_REG16(0x380e) #define OV4689_VTS_MAX 0x7fff +#define OV4689_REG_H_WIN_OFF CCI_REG16(0x3810) +#define OV4689_REG_V_WIN_OFF CCI_REG16(0x3812) + #define OV4689_REG_TIMING_FORMAT1 CCI_REG8(0x3820) #define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821) #define OV4689_TIMING_FLIP_MASK GENMASK(2, 1) @@ -56,6 +66,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_REG_WB_GAIN_RED CCI_REG16(0x500c) #define OV4689_REG_WB_GAIN_BLUE CCI_REG16(0x5010) #define OV4689_WB_GAIN_MIN 1 @@ -199,10 +220,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 +235,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 +412,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 +470,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 Thu Feb 29 16:53:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577425 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 E34AC1428ED; Thu, 29 Feb 2024 16:54:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225654; cv=none; b=oj8WZVPs3VvRQ+FplFw0wRzd09MyfZB3KUS1FQsAeDXXH6rs+U5fc0DVggI+9RuOJh5DLP5+Kb4ssliAYGqVAgdQz38x4RsW9oAYhmY/i+G5+9Gjf3YuKOC4FgJjtsDNEIMt+HOSOsdVAEx4co+/xXjFZ4kQvt+BaSBgWdwJt9Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225654; c=relaxed/simple; bh=Bysl/cZmXzXHy+BoKKKEDLppPWX/1SiPhUxTOyRqg2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nFQrjI0sYqddZTBEbdXwiv7FIv09m2cj9beNDEp2F0g8dvUw4qN90xYnkkEDw8bU0UVQ5Glc0TKiuJbeeO9lkMXuht2aBpWGO5i2MMV+9y9ifseD6bL+qCGYtR2VVqqZefzfZQ1r44bnh6YDsRYq96YMK12q282zFAjTLsMMOO4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KgTEWkDO; arc=none smtp.client-ip=209.85.167.54 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="KgTEWkDO" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-512ed314881so1025828e87.2; Thu, 29 Feb 2024 08:54:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225650; x=1709830450; 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=8QWmNQa9+NZ4bXJ1gwaSxODEFKM/voH+fajV5EGFgeQ=; b=KgTEWkDO111ENkJMwKeHCj7g3nuaJYeHlVxN14bvoJnwY21v/FQ5VAKxrBppt1vZJ+ 9vVl7r9JUqeLD9ckZv51YwPWu3ACXJqNr1VxjHm12RRBudpENKF+qBxzNx/cWzNubrv6 E7JpSg2MO0q/QcHn3sV7wCOMaW7Pa8ceAcorP+PlzcWf121zSFnzdGJAg6RfLkjkOR5o GxdKcEAmxnwB+QVdqM/Ydw/K5vSHXUxb1c6RDbZpdZQMNSA3608owOYphGQPvEeC8xXp o8H16c9D0aRjZCWycWk9hjvDyF8TWAsSKE2xbOXIp/no1OHOM0hMQzGNiXT0HIvtIf2e pinw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225650; x=1709830450; 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=8QWmNQa9+NZ4bXJ1gwaSxODEFKM/voH+fajV5EGFgeQ=; b=TX0GIZUnb8JmftT6VkgT0KnED4Gw8q6huH6N9VeonFehdXnNAyTUAFlMdS8dECQ+OX K+eBwAmsUP/dB6ZQw/V6ttr5iH1/QLb/Y7Hh3YXOxFTW1dV+IEqxyjv5uKeMFkIpooLx wUt/JsQeryipBbxCvQeIs4dlfRmRABpFUFlSHGk+CK5RLy88B2Z+H9IVRxZQz/Grlm6L Sh2K4kP20zOzcw7sW1KII1fwtnzipyd0eamo07WCZTnSoKngy6zJgAzls76p7/VMOi9H Mb4qCpGIv33H6lyeS/Hi7dVRg940q2UJuxoZkCNqi78epXltXoXyAIeIPrFfwkBt0BVO EHIQ== X-Forwarded-Encrypted: i=1; AJvYcCVwCE1lyd5qsX8JUI821NxbDWQs+iMM0wbg726OBNrVDQuvNKmFORFCcEs9OEFX3wlIoqLk7QSWauzQxakq/WXe3kYtramdWdZKXlx2 X-Gm-Message-State: AOJu0Yw1KRsgS8dibvVhaeyqcq2XIzZceykCQBgzpoie51A0sbrIGUqx LA3iIVOyDNcM7m+UY+2lZdqqACnda74n4Kj0wZ6iAgo/rumXKJgLqj5h0niWc1I= X-Google-Smtp-Source: AGHT+IELmvreH2kgc9TfTg15H1Ch9yQvNpuDSdgJv5f2mz0ch3B+8MIzz9LhyRE0uXTHUJUUE4C+ow== X-Received: by 2002:a19:e00d:0:b0:512:f409:7a29 with SMTP id x13-20020a19e00d000000b00512f4097a29mr1781592lfg.48.1709225649466; Thu, 29 Feb 2024 08:54:09 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id dw12-20020a0565122c8c00b00512b28ca93csm310224lfb.45.2024.02.29.08.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:54:09 -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 v3 17/20] media: i2c: ov4689: Configurable analogue crop Date: Thu, 29 Feb 2024 19:53:30 +0300 Message-ID: <20240229165333.227484-18-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 Reviewed-by: Kieran Bingham --- 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 d34699f35270..06f202c12dff 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 /* 8 dummy rows on each side */ #define OV4689_DUMMY_COLUMNS 16 /* 16 dummy columns on each side */ +/* + * 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 = 0; + 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 Thu Feb 29 16:53:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577426 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 67D2914290A; Thu, 29 Feb 2024 16:54:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225655; cv=none; b=HToiarnFch+JCf64H2B+ftf7wujvB0Zu6OjLMzEBfuQ3i3uG8Hjs5Gz2HKE26LBf3oIm49rMxzoCSyWkq5EcCSzAAdWtiRYGhx/JKxeCJhNjgBiIdlNtEh1Z2NWvM1buPoVXZpooR3uyt5HgfxWkIv01dSP79fV1LqYsTeFITzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225655; c=relaxed/simple; bh=Ntw/d6iX+NglIRgzNiG4I8dsdDa+gl5uBzeOo8Vey4M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tvOf+hoQqIJ0iwnXA5k+3CRu7rBrmv1OwplNyFdfp7XJYUreWYrK02UGJ6I3mbRkNb8OilKBkUG1M1UhzOJ68xryFJBbyIrpIcSI4qEygqBWTJSafeszsBoRfUF04y5O4upK5WbfAO5DxpwzULLtTY0GG1t8rlFqogRvag7TyKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VIs4/YL5; arc=none smtp.client-ip=209.85.208.179 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="VIs4/YL5" Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2d311081954so7872741fa.2; Thu, 29 Feb 2024 08:54:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225651; x=1709830451; 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=6WzRoqjm9lKfEyEc1LCtY5plssFt/JZaQFi21g+dgzU=; b=VIs4/YL5psKrby/qlfNnD8YegcbWygDkLCQORzaAxhFs0rCjPhqFgXT82pI/zZnfio JX7+iaaRzskOtdbI4xMuO/RTOyFMZM+/I6RNXdmsBAcMpJdoH3fLOoIdHFJwTzknMohu meZMZGqjDlUldI7Bsa7h2+Y220+nrztSOJkhhHKtfscJvS3pT6Nz7iq2w4WVuzQxuOkL slvVc/O/ConqEsBdETIGlWZTNYxiLKXCz98Y9Dp96srwCP/pHoIP3woOx82JLuYdWN06 yC5ihBO+2L1yX9M7cuz7h4RX4VuMW0zTHq2N8ORJbs6IwWGME6MaIxh7ivJcTDYhQy2P hYMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225651; x=1709830451; 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=6WzRoqjm9lKfEyEc1LCtY5plssFt/JZaQFi21g+dgzU=; b=ZVlRCIUS3dXp8qB1Z8UBeL5k5arYsBGUZ8Yvp7tMccPMY93tk+/aA/E0PJ3Xw0rthp Dsd9uSGkXl35OvF9QP9VvQ0xLAfDlj0/K3sgpCIiLwa9FvaLmdDpa1y+mMjUptYXskBy B6wEf5AnYNn/Rb6DfpJpGh3Nm5NqdbroBs+HKFnae+i+RcYC4WJ461HhyheB74Lu/U/I aLShuWR6cPbYIldOzSrbGELhp2chpTbSZd1+CPfApELk5rZU5AQS43AG83QlZQpXx/xB QK5/daiB+mk3ebxEW4wEr0tnnbz1n3gqO3abls39IxTumTSu0zgjnr4VGQ7ukLN3AnD4 8FLA== X-Forwarded-Encrypted: i=1; AJvYcCVZWbhnPZzL2RazKQpItiSSXs1fCvnHZhNgn0OmG5A2oHOitEqBLZFAig9V+72aTONp6h97m8+r8XzrTY/vzyN71QHXkuRQ4GXujrkw X-Gm-Message-State: AOJu0YyNjeBrL+Y3ecCZtDjA3zl1FXFV+stMz4/yZeIklU23VU29xLB/ ZVeSw/tQ+CTIIzpAXYKB01C06yFj9bY1oUku1EBt03sP5wTbsE6P1ZrZWZ1G1jA= X-Google-Smtp-Source: AGHT+IHzJi4iFP98CYEteFi2onUdJx8hTUCGTfYl1a7vMObhRtERUZxI0Y8JJXc1w3E9VCCy6IQ0Rg== X-Received: by 2002:a05:6512:b9d:b0:512:e137:5f5c with SMTP id b29-20020a0565120b9d00b00512e1375f5cmr2280747lfv.34.1709225650745; Thu, 29 Feb 2024 08:54:10 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id v11-20020a056512048b00b0051320202080sm309261lfq.69.2024.02.29.08.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:54: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 v3 18/20] media: i2c: ov4689: Eliminate struct ov4689_mode Date: Thu, 29 Feb 2024 19:53:31 +0300 Message-ID: <20240229165333.227484-19-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 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 06f202c12dff..2496067b90a0 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -57,6 +57,8 @@ #define OV4689_HTS_MAX 0x7fff #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_H_WIN_OFF CCI_REG16(0x3810) @@ -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); @@ -863,14 +831,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, 15); if (ret) return ret; @@ -881,26 +847,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, @@ -1055,8 +1021,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 Thu Feb 29 16:53:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577427 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 3159B13C9F8; Thu, 29 Feb 2024 16:54:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225656; cv=none; b=TdHacpnCmwYCoUziHbu3NeC03gzHS8gl74op2N3BzbFUMnR6DWcO8mIxt6lp8BXx071Sq30aQ/anEkizGf9EBR9cU4DhlYAQFTQNxM6pQNXqxjnRk/ko6AtRJU0Lqp0kkXzSrxtfB8ttIcHGpsq92RB7n8wT7b/lIsyjehRX0Ec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225656; c=relaxed/simple; bh=DQgBBCe30PiuMHNAPhMabPDvQSowIGICsrFN+nn2ZhY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a3xHUpNvuGC1yPF4CCF+Qgj+ToErym6PLjiUQClEjHy+2HTWgPrfbQlOtwC4is9XeGgQmCYLQcyVJedUSneDjnFUVKqbHBJ7rTTydsBR3cuLS6CmGHxxlucf8lgheNAI9Jk5gUnPpD5V47yEfWlhmN4nnVMiCUamwRx2qblzvZs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Txigak+7; arc=none smtp.client-ip=209.85.208.169 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="Txigak+7" Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d28387db09so12600911fa.0; Thu, 29 Feb 2024 08:54:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225652; x=1709830452; 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=itbmjfXIRedOHxtrfBuhEmKTtpYmXBkZ0ygkNfj1H5o=; b=Txigak+7vqkYKc1MXfCYyTBzC7DZ9PFEPETMkRAq90XMM1hq102EcaMdazA+RhWED4 EtVJo53XRamKWZhjo2b10FuhAMCohVqbKIhxYvmiwCoveJi4s/RJJsMGFgbRO5A145Kc KJAbhUOJZWp4oxwGEXemPgEp9ZMVjGdsmvi1VCmBRTbq2f4moZefZebiVPcDyMTWR6wU gPWeauLYdtFSia0rEZcISMaMAMNZkSM6AFj9EGhLCY+iVTZphw2QY386jgMh0i+4ACGl 1XTTGFr8lSSoWx1fO+TqL6tSCxi57WpODB3WY71LcfTzQHQqfkMa/kKYmBb2Wl9Xgd3W uYGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225652; x=1709830452; 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=itbmjfXIRedOHxtrfBuhEmKTtpYmXBkZ0ygkNfj1H5o=; b=fkN0UA5pf/Ilc8/XdhusdvHkOynVNuotXT4mymP/YA0X8jp1/CxODE6/7fIw0q6oZN dgd6ZJmzgP3eXPRXfSUHthSbbeq4XifVTeNAzW4wzCot9xQWBH+lfIg4Il+DwD5tUPex OH5xG/zPVUpR1VcG1VBwSMvi6Ec9QCMV50FeD2IsmuAHpxs50qFTQ7CqYnSIPuMvNzxo ut2AkL7TEsu3sZCFI4Ivd7NrdllA84VVjb0iByhjcjiNmUnHaCu2A6c7d2J2T5NTGqc6 J/AZkuKPsyI38FduSIa8EuT24gy6HX+8It93+ttu08umRtQDmKCAn/HcxNMpKc3DEo7A t6Rw== X-Forwarded-Encrypted: i=1; AJvYcCVBnyKQmRRBNAKRbuTYrEctsJpWvFRcGmF6YuOhtaCtr0BLuDTUoUG6/ECSToTMCZ03a7WdBoBizaz3fm6jIIzpcfQXdOmIVJ7hVkOa X-Gm-Message-State: AOJu0YysOsxnVV0u70BiL9/pJQfZMuDZy2UNHr5ak+N2qlcklvKuycao AeNjdQwKvRtNxlPkZvRAPzSc5r8u2tZH8ijM6ynxPOs6z6avZXiuHef0u0dJ540= X-Google-Smtp-Source: AGHT+IE5bERwoR7nvXNmX5EEwXzLtN+OhCQtCadZJZH32mf06N02X70yuzSFhmVeS8p23iYNsSuuMQ== X-Received: by 2002:a2e:964c:0:b0:2d2:478a:83e with SMTP id z12-20020a2e964c000000b002d2478a083emr1793764ljh.24.1709225651922; Thu, 29 Feb 2024 08:54:11 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id h8-20020a2e9008000000b002d267e3bf5dsm275909ljg.81.2024.02.29.08.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:54:11 -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 v3 19/20] media: i2c: ov4689: Refactor ov4689_s_stream Date: Thu, 29 Feb 2024 19:53:32 +0300 Message-ID: <20240229165333.227484-20-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 Split ov4689_s_stream into __ov4689_stream_on and __ov4689_stream_off functions. Also remove repetitive pm_runtime_put calls and call pm_runtime_put once at the end of the __ov4689_stream_off function if any error occurred. Signed-off-by: Mikhail Rudenko Reviewed-by: Laurent Pinchart --- drivers/media/i2c/ov4689.c | 100 ++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 2496067b90a0..5cea9b5ba201 100644 --- a/drivers/media/i2c/ov4689.c +++ b/drivers/media/i2c/ov4689.c @@ -537,61 +537,67 @@ static int ov4689_setup_blc_anchors(struct ov4689 *ov4689, return ret; } +static int __ov4689_stream_on(struct ov4689 *ov4689, + struct v4l2_subdev_state *sd_state) +{ + int ret; + + ret = pm_runtime_resume_and_get(ov4689->dev); + if (ret < 0) + return ret; + + ret = cci_multi_reg_write(ov4689->regmap, ov4689_common_regs, + ARRAY_SIZE(ov4689_common_regs), NULL); + if (ret) + goto cleanup_pm; + + ret = ov4689_setup_timings(ov4689, sd_state); + if (ret) + goto cleanup_pm; + + ret = ov4689_setup_blc_anchors(ov4689, sd_state); + if (ret) + goto cleanup_pm; + + ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler); + if (ret) + goto cleanup_pm; + + ret = cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, + OV4689_MODE_STREAMING, NULL); + if (ret) + goto cleanup_pm; + + return 0; + + cleanup_pm: + pm_runtime_put(ov4689->dev); + return ret; +} + +static int __ov4689_stream_off(struct ov4689 *ov4689) +{ + cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, OV4689_MODE_SW_STANDBY, + NULL); + pm_runtime_mark_last_busy(ov4689->dev); + pm_runtime_put_autosuspend(ov4689->dev); + + return 0; +} + 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; + int ret; sd_state = v4l2_subdev_lock_and_get_active_state(&ov4689->subdev); - if (on) { - ret = pm_runtime_resume_and_get(dev); - if (ret < 0) - goto unlock_and_return; - - ret = cci_multi_reg_write(ov4689->regmap, - ov4689_common_regs, - ARRAY_SIZE(ov4689_common_regs), - NULL); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } - - ret = ov4689_setup_timings(ov4689, sd_state); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } - - ret = ov4689_setup_blc_anchors(ov4689, sd_state); - if (ret) { - pm_runtime_put(dev); - goto unlock_and_return; - } - - ret = __v4l2_ctrl_handler_setup(&ov4689->ctrl_handler); - if (ret) { - 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(dev); - goto unlock_and_return; - } - } else { - cci_write(ov4689->regmap, OV4689_REG_CTRL_MODE, - OV4689_MODE_SW_STANDBY, NULL); - pm_runtime_mark_last_busy(dev); - pm_runtime_put_autosuspend(dev); - } + if (on) + ret = __ov4689_stream_on(ov4689, sd_state); + else + ret = __ov4689_stream_off(ov4689); -unlock_and_return: v4l2_subdev_unlock_state(sd_state); return ret; From patchwork Thu Feb 29 16:53:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13577428 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 35997144025; Thu, 29 Feb 2024 16:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225657; cv=none; b=Egem3bvytuVWrzCO12jbjfQzdi+46EQWgCpp+11D1t5M2MRUECM5J9GNmSuawBbfknAOwLzUna7RZXspjDJwhnFUKIh/HyX64+gJnWi3JCwf4PtqwHwFA/G9cfdBUSXszbZvhNHvXceGn/FeZre40fUkNV4CxKB12hywsjc9Gy4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709225657; c=relaxed/simple; bh=DlrsfOVus2tjoAr55rWNJKBlusPLXRSf+fP+1tskGVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T5fCG+f5qlec2aJWIGwxC8vpoHfHaJjGGJrlUArc8fIYIht6ITRSYCwpPOYa0d+InDX4SZuM1AjC0LbpQNVvCZeLw1rm8lnqs6+M+vfpPKe46lIt0y0xoK7lH0L35utih5X7wBTN0q6vp4EzRxB5a6tuA01Uj3aDoPXRPK9U0NU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LQQ4unqV; arc=none smtp.client-ip=209.85.167.43 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="LQQ4unqV" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5131316693cso1452296e87.0; Thu, 29 Feb 2024 08:54:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709225653; x=1709830453; 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=rpGZZO+U9m0OGnl0kXpOxd0dX2SJu8im5jyVVvaWdIw=; b=LQQ4unqVeuN+AiTeOn2cFmQPT6KrttHD1m6DWzlq8co1Cky8Q9Y6nYwa1VsJbyhBAJ mZn1hEqkk3vvS3QMfxNOY++b3/qxb1FRwv9CUfGHR6ZQyD/9Y4jbO1U4O75kIjMG1XAP UDVTDgKnhopQcbl/RlBTzDoBzKxm9ZEEsEpKlldJNCYwdcXWTyML7p3iOEkqEzcO/Z7f +IPNLplnbG62VgCOpm83f9g+/MV3Ne0wkDN2e0uC37kFWkAuAYmN4Mx3U9Ca2YKXCBKw cpGAOGb/ILIW9fyx+ujGG8vPjkpP6bfT9egk00CvGwbu29CY8wkwIev9eXMwILDSd+0I 5EIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709225653; x=1709830453; 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=rpGZZO+U9m0OGnl0kXpOxd0dX2SJu8im5jyVVvaWdIw=; b=YIElytAmaxmNNoTQ3kyCMOc85jubVC9HjCfp7JFg4E/ineUMav7sYh+wfl2f1O8pv2 i+13w883nPZX31dHwSDLR337R31Q0u3KPeH3QSe/+9j6DbPJak+Q8A2MinemOOS0gfNh tfYFandWvClo63Y4wL1SxzmAmNp2gx7XuIe155x9/KRQVJnYhhPkiyB3GLttlvW5+chn CpnnxPTlcUbvpQ0cmeadLFtH9m7hnIHtlor+gPseJj0FV87kT9B4hULMWlXUo8iddSjd e+ZzEwanyp6J3PCxaWvC95GgtWgdItw6XSG0Bq20BDS9AIvb03lP83VTQk3bYSRHIxtB xYUg== X-Forwarded-Encrypted: i=1; AJvYcCVNRzeJt0e8MZWUGSpkVbOxe2bbSggwCezrJvUIQwW0L3yaTIt3azJQC3GGt1HYpsQBGuqahFkPVdCIZkOLesCAUciIZsfXO3ic6n5J X-Gm-Message-State: AOJu0Yy6A6zvLYxMapfyxAiHmH9X4oqvF4gM7wk6gw24PwB3gWujWrBj TP39216NnVNCXJxBeGZOKSqKBOO6FrleEK5L5WuwIAZGSEZV+nX2SfuX/jSIf0k= X-Google-Smtp-Source: AGHT+IH5jJB8CiJ+QegEG3E+/gGvML/SvDepVpVSlDp839OBX6tFyk3CWAPvQ0RCZnv6WrJKKhayhA== X-Received: by 2002:ac2:593a:0:b0:512:a980:719f with SMTP id v26-20020ac2593a000000b00512a980719fmr1951477lfi.69.1709225653141; Thu, 29 Feb 2024 08:54:13 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id n13-20020a05651203ed00b0051301777b44sm309174lfq.253.2024.02.29.08.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:54:12 -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 v3 20/20] media: i2c: ov4689: Implement 2x2 binning Date: Thu, 29 Feb 2024 19:53:33 +0300 Message-ID: <20240229165333.227484-21-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240229165333.227484-1-mike.rudenko@gmail.com> References: <20240229165333.227484-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 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 5cea9b5ba201..2b789b9ffd9b 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; } @@ -749,19 +819,19 @@ 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; s64 max_expo, def_expo; int sensor_gain; int ret = 0; 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 + ctrl->val - 4; + max_expo = fmt->height + ctrl->val - 4; def_expo = clamp_t(s64, ov4689->exposure->default_value, ov4689->exposure->minimum, max_expo); @@ -785,16 +855,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, - ctrl->val + crop->height, &ret); + cci_write(regmap, OV4689_REG_VTS, ctrl->val + fmt->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 + crop->width) / - OV4689_HTS_DIVIDER, &ret); + (ctrl->val + fmt->width) / OV4689_HTS_DIVIDER, &ret); break; case V4L2_CID_VFLIP: cci_update_bits(regmap, OV4689_REG_TIMING_FORMAT1,