From patchwork Tue Apr 16 22:45:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13632698 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 E1C8B84E0D; Tue, 16 Apr 2024 22:45:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307535; cv=none; b=dTgJ23Xgk/2njxd4VkXec0/WMdFOylbl4CHOIvi70oN+Xr8TD+GsUvkzWyCDpjb7rXAZiC4mn9ofmkpFE3UlESMcrLKZ6sihO2RvJzjma7XP52ZR5Wxcbqy5DlC0ALpJlGEypD5z4YUbDQpp3NehBE1G1tyz8djNlcfXtEN4uCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307535; c=relaxed/simple; bh=OvWapGcT6t4PFAv9+2O2wLSpw37LChZYxPCfgsgzZ3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bhy9uON1grTt4bRRvznrGijuz4XOlpRgIgxT+Bx9J4trBFzDf2/UW0HDCM41FBKut50Sarn38O3KuCQru1EJ1aJAZrv7R4AXcOd9BiP2pl3uHljsA6canWHTzXHSSluEScOgM6EIM9sZEF7Akrd6HsKlIzGuq06rEBVHMP14FvU= 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=fdO+3V2i; arc=none smtp.client-ip=209.85.167.44 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="fdO+3V2i" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-516ef30b16eso5908711e87.3; Tue, 16 Apr 2024 15:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307531; x=1713912331; 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=Fl+09NveEZ7JrOZQLpZJo0GxD4IEZYvfFa4c5KwVM9I=; b=fdO+3V2iYJzSovvGc0QtskuKatBGrz2VwUfa+zSEa9OxtgO2L87zJV1ETun21Jb6uX fb1oMhcZR2RJtvcTaxrkRIWCyloj/GfEwU+yEjFqJ9vAosv5EP1M9zjy5V08v0vjC2wJ TnpsJMGJf/DBVvg+R1AG2k+wmUsL5l3hl0kU2Az4n77/HMCcIqi+Vr7Fsb5+gFzCRwd/ wA9QCMw5QYzfxAxGgZ4iUKlZBOerzQfI1D8YCw3uxvLGOFHcNa+Zjob/8igoqpjImN0h nQUwMn1xI1vnyiGyXHi8rem4GvJYLrv6zvdQk5xrS5XxixaA1Tbnk80HtlLyB5wsQMYW 2IHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307531; x=1713912331; 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=Fl+09NveEZ7JrOZQLpZJo0GxD4IEZYvfFa4c5KwVM9I=; b=WMDySlzaF4SurcZGDicvfDESvlLSeIXSwthfXCN3WlPTkN6i3rqOTLg1dyQQDWVkpp ZS3Fa8flkQ19tWlE+9Hh1l6UByKRGEr/f3wnH+9lJPMlB0JNjnkAV5BszkEpuUvXMouj vadSb5nvz0ZG4qGuWrR+3xGWR5ylMiD7clUCOZ73Pm9yMPAriDy6kmHQ/xFIhRJxk545 yR5SWKs6+ZQe/MRVVN8DZkRRI9pPWgDviNByLc7lOmvr9fBitPqmLWwGJPcw9q49bk5G jlL/OXpufOT8ZeSDFgAOphWcnFxR2/nZ6c51tT6w0f3Y2cfTA4+Qf1S28mXsbZdB7JrZ VE/A== X-Forwarded-Encrypted: i=1; AJvYcCXnXMyi7Lg9dqu8xlU4/ux6z9fnIAouchLs0BwV16YRsjiPWay83Er/UZBcRnHQ0v9GSu2NKPyoJdpHZ62+6q+Ln1Bruaxo5FoHVPTZ X-Gm-Message-State: AOJu0YxTwGqc3fEje0MBEdQ1N3roKbLSZ/N7iJULT4H+MrNlJ3PIpuzt 6oJcqkWW5e+oBDOcl2kvFBvbuuLJ9FKufUbmibabyuMj3PIjh57ZFSTcJDjyYeM= X-Google-Smtp-Source: AGHT+IE6ZdHzRi1VVjigAZ2YOFt2mlRMbLsSa1Cd+g7FYHmjByvPZ34EzYuhRXAY1tM+iR1u/Tg9mA== X-Received: by 2002:ac2:5a03:0:b0:515:a733:2e21 with SMTP id q3-20020ac25a03000000b00515a7332e21mr7995112lfn.44.1713307530848; Tue, 16 Apr 2024 15:45:30 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id t11-20020a192d4b000000b00515acfbe448sm1770829lft.163.2024.04.16.15.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:30 -0700 (PDT) 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 v5 01/16] media: i2c: ov4689: Clean up and annotate the register table Date: Wed, 17 Apr 2024 01:45:09 +0300 Message-ID: <20240416224524.1511357-2-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 | 205 +++++++++++++++++++++---------------- 1 file changed, 119 insertions(+), 86 deletions(-) diff --git a/drivers/media/i2c/ov4689.c b/drivers/media/i2c/ov4689.c index 403091651885..9890189bcbd5 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,91 +123,124 @@ 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}, - {REG_NULL, 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 }, }; static const struct ov4689_mode supported_modes[] = { From patchwork Tue Apr 16 22:45:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13632699 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 182191386BF; Tue, 16 Apr 2024 22:45:33 +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=1713307536; cv=none; b=aKjqxz7qOr0A+IF4F+l1HL2x4qDv8sEoMlJDwpGcAURcJekg8d7UK4zsInzDdrwbBXHsHlwFwUfOTiCteLjcDJqANT8wwFzga+evPsOTKyjnzmkbOD8srf+xbp+WoTZwOTW0tIza5EdIYml6MFnLJenh9FkT25XDUpfIrW5Lr7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307536; c=relaxed/simple; bh=FJrlk6QnL//BUemzFKki2Dq54faR6yE8vBjGpDaJcxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=in/wN63XGxSgC97dj7uiBGwewVUXVhEesAS2qohJb2UgBuwVtkWQcCIcQ+82fYsUST62L6iaWNWQ4ReK+0UJWWak7rSBWYNajtWtrZJLhCu2GhenQL8rWdyvuORXRXLwfEf3A56RgCcjZfhNHefU+6BiiRAJJ/u2ryig/kRbFfE= 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=nXMju8nv; 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="nXMju8nv" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-516d6e23253so5512551e87.1; Tue, 16 Apr 2024 15:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307532; x=1713912332; 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=1DAM7ahXd7SQRtOs2FSyPEW9HzmQhg/l7bpOIUxyW00=; b=nXMju8nvP9J64lhP8buQVxW6qqr8zZK0pPZsjET2tWHy75Ap4tnRlgPJZAeQv/POXn vzLbJGPbMcQTBMd/bU0qDbVk+mu6DezLS0vXIWEUfOhrTnuFlRCx2dHfC9LPCGiz0saE uDRLPeeEbQFPqklzmPRNf9e6Mo02JAWPeu1MZ5JxqWyK++R8HATHO5OifRFVN4KMMbmo vJoQsiQlU7e/d8a9pCjIFZCd/z9jsq60h/RpHbxgmlrSTfq3d26aVXMYlKxglb5ZE4Ri Cllw4bMTjdO8RQgMrqikyqcSNHSHasuz681AvxZSaqV4tyPVjiirvptpoZpKuNkeD/4B zRUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307532; x=1713912332; 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=1DAM7ahXd7SQRtOs2FSyPEW9HzmQhg/l7bpOIUxyW00=; b=aLJCYVT+iHRTmtj9xcn87gH+QfNF6s6BW7XgYWmFkjP2dMzq22+IlVU86Pr0EmLvQ7 05Wil7BeNl956E6k8yfw3GRKASK/VfLkv6qvNB9cY0xBzi1662oxOEVgHVWIYL6OPqKh aSWKXF/cYdl1JdmRXIRIO/ID3AvgiXrmln9A8Q3gOamx5yurESqQ90XjHE1Y/J/WulPX YxVXxy+2X1Qlj3IxlYZcLQx0OhUHhUVsI95a2gWnNsKj1teKh99wDRzmtgzjTDXsZMTu NSLYosesU4PT8UfVnmmoTBTbPn+570IHaANcwPDgWR9v0Gx2ZQ6YHmocPiKxbFOi6hlO Gn0A== X-Forwarded-Encrypted: i=1; AJvYcCXKbnotw+G7hI2l/JPzJfze1c1mrCUHE0XFwRRAcThUwwKIsTgDN08tYWnnkDU/Rqre3Y/Q2W1rxpUmpw7zOgXfvhFINUhDFvjLwEAn X-Gm-Message-State: AOJu0YxMBgXWmtH4jr37TBgiK6Ab37j8vQJaty86x1g/b7u28m53OZLu 1+KepEhFBIY+KLZPzyefb+QHvkGg3bfZ+Yjsd9NacPISmYFcw1bI0FaBkbplaSo= X-Google-Smtp-Source: AGHT+IFX2Dt4ozv+xwfHUx898pIdk0gN72rg8VtZDXpTZLK+ddEd2acJQT/ZVoYsjvsoQXGlMlyeUA== X-Received: by 2002:ac2:48b7:0:b0:518:6d35:e4cc with SMTP id u23-20020ac248b7000000b005186d35e4ccmr10336742lfg.25.1713307531804; Tue, 16 Apr 2024 15:45:31 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id n12-20020a19550c000000b00515d32e33a8sm1733241lfe.99.2024.04.16.15.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:31 -0700 (PDT) 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 v5 02/16] media: i2c: ov4689: Sort register definitions by address Date: Wed, 17 Apr 2024 01:45:10 +0300 Message-ID: <20240416224524.1511357-3-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 9890189bcbd5..c4d4afd38906 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 Tue Apr 16 22:45:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13632700 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 A69FA13A24E; Tue, 16 Apr 2024 22:45:35 +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=1713307537; cv=none; b=QfCECktOz02+hUmGkUbyENjVUPmDppQKIHIbivRV3Y5TgmK+LPkFYXqD8YaN9S9pnYKACNVN2jBv6fPEk5kjbVFOWCrnWfng4jIZax9IzVJvBr4/3DGgHPEIdlRswBIwV9D5euNBig/63kxHZhlcHiWURT0X3DsG+RVWW9c0YhQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307537; c=relaxed/simple; bh=E3frt4ehQ5KQRbJiZ5A7MbCj4GSdU8t7aOnund7MNMw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V236aXtRBBjnAs7SWjDBxkhrknjt080LoPvjseT1Q0LYkD6MhepMIsP37XR/u25GlclAAudW+Sq6tw0ZpfPSZXe1cZoXfMG/8RATbE40Oj410QSUIhuZIXod9N0hnZegypPRPwFavPrfPpqBZtsSUxV5h08+inOD0KsW4csdXyk= 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=nGMy032n; 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="nGMy032n" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-516d0162fa1so6358506e87.3; Tue, 16 Apr 2024 15:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307533; x=1713912333; 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=0s3AWew5rQcLgKkmRXC5fEXauJBaZDm/I3x8ACFaWdM=; b=nGMy032nmkWgkVunkiiBcNxZ3ingi9CGtO4tZKIMYPEJXZ/+JfjY/LHaUkxhjQm7iQ 3IndpfoGztZLbuvNqmeHmU1He4SzKG5l/LZs73jefQdJ5rfnBxvw+IA9NL3oM3eYF6XV hsUNqrxPRuKZ04kQc2Es7Xmaj6/Lh4RAeLxs521ZaI3ouLJ6bhwO3b1gshrecjl4u9Lc ujORDVVq3Y2Gt8gZ/UILuKLDnYEwB9D44Lf6NWuP8ecHGIDLxHqx7k4WUECTYpWAED73 sIejze2G9cMjfCClCT8ne2nYk4Qvs4bZ+SevIgfAs6PPJGj5KJK8SsvG2nzDq5qz709G 7BpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307533; x=1713912333; 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=0s3AWew5rQcLgKkmRXC5fEXauJBaZDm/I3x8ACFaWdM=; b=VF8cAXECfB4vXX6EU0nqSEdg0E5NPDQaHJvg+HOmFtaLq+mmuCTXi2aeOUxN6gjLF7 MqfBvp2VS6RKzFg34GyjJqm1y+ksrDAI6NK2/RR8fpwdeXwWGsOvWEveTk/dbBxMY3c3 RQMsZ9NZczwnIL/b2l4rE44/pdKONmnJfaigOTzooW8o7lrFDD+3vUENluG1Nezc9PK1 gex62hlKLlFv9s4LUA/rXu5LAfFrC6EpEsj9B3ZQkcs9RzLab6XqpOuLWy83NKq63wED mp/uf9pmsBNLns1M1Lu374ZbNXQSMziwuDF7xu3U0ON+PM3ZHIQZFePDrhaHI7rBg3NX tn0A== X-Forwarded-Encrypted: i=1; AJvYcCVYgIaCsqbIlgBA7pZ0RdbuK7H2XMu5wUxG+powoC7Yy2blZjB2Yua4UFqIhy/gWzyihX4Zan5QMTcP6u+nyuUBjeZOvkVho9oW9cgu X-Gm-Message-State: AOJu0YwbkVrySl9EMWVDEhmPGgQOOvn9mTwQn1j7PfFlPuETn10pPD7s CPoFHPF9cy5vPek3ssAjQ08FDFgOC8adCfx7Zd3881gJGPvHYS/wVHsywf8TOzY= X-Google-Smtp-Source: AGHT+IHtCPcr2C0oNh8Rad4+2X6NliKqAzJ2cchHzlJPahx+njH+sRsYV8iH+hGSXYeQZ4T0T69Fpw== X-Received: by 2002:a05:6512:52f:b0:516:d4c2:5410 with SMTP id o15-20020a056512052f00b00516d4c25410mr10838708lfc.64.1713307532879; Tue, 16 Apr 2024 15:45:32 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id f16-20020a05651201d000b00518be970fb3sm1010384lfp.221.2024.04.16.15.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:32 -0700 (PDT) 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 v5 03/16] media: i2c: ov4689: Fix typo in a comment Date: Wed, 17 Apr 2024 01:45:11 +0300 Message-ID: <20240416224524.1511357-4-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 c4d4afd38906..f826571f8f68 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 Tue Apr 16 22:45:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13632701 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 413C013A894; Tue, 16 Apr 2024 22:45:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307539; cv=none; b=FAozL+0dfMyVfg6B0yzLsPvYg/TaxIPiAJQWJ+dkD/wQ7UO9IrTtDwIq7BHmo9OKd4nd2xW44ebEKgaYVfshSsX25h53Q521iObY3ELz71D0nQuJGuN7Xon3K8UCxxWhcPYeff9CANn0TwzGotiIMXo0kDOorcjlHPThMUtvE9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307539; c=relaxed/simple; bh=a59o8BdM4+NENNy4/9lvDfZpD8DiPXnQ34d3KNjXO1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u0QzyKod+iI4wRxnmL69oxok0CFCmpcG23e7HlgV0Fg5gDY3YdgBstoUkmz95rCax0zgurKO04QE3vd95yhgwj8k2CCIuaM0tveNghgV6CgmRJaroICEMvpWJKV3YZ7FfTYt/V7D29Ul9iScml22npT3wVmWeX3Adh1EdxTFOoY= 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=A0MMvCdH; arc=none smtp.client-ip=209.85.208.171 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="A0MMvCdH" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2dae975d0dcso2192611fa.1; Tue, 16 Apr 2024 15:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307535; x=1713912335; 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=NjHdzKiu/BLpKoeThpfFp+cVAeTn49iR66hzE4gnsbc=; b=A0MMvCdHG0irfMube6UCFM0kgK7nGLQBRbb8MMHBqQfETUsqOq7o5Ys6IUnuKppwYV CXJLw87WkBM8/rMaBC1NI69TjcOPjFozaCLJ0kKBfg0XHHSuSHY4n929nO5CMkZ+l2LQ UQMPX852n9WII3wvDcXiOM9HO9wWy8uBikNVgtbAISjfrt5WAiWjqCx7DinRGWLzxXt+ +9TLSnamQUkYMcwEHwk0oxfxcGqvq4pmJaPEX+qdF4Dy26OdLBFiEeErxrrw2OZUPiyj xX2fKUdi2Z2AfHAcFoXQKonh2QydfeZlPcbKGStp6YDGP/oVImWQNPg6O3fv8mV1KTDD wuJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307535; x=1713912335; 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=NjHdzKiu/BLpKoeThpfFp+cVAeTn49iR66hzE4gnsbc=; b=B3oJwFQbBs3j+FmoHZ1h1ai0qD/ysyf6m8vlQqeg/6Z1s8003k/luF7nS/o4/Tq5po eZgmdOiDSw80cuO1q0DOfalMaaEUxKh6RZC/0UMcH7kSix7iivI+bn73eXFtF5k5Owre ZWhw4NxCM+5wQnRWUceAv2UPYbD+KJMgv2zmbgjEjMBRMnhsOkdFwdZ/2FNr6daeLL8N tLke45ljTz7ldQIMJDejFPp7/KWWpEYpXY4SLgQWd15ugRtL9a0INg0RMcNBN7PZ6tlD KzbVBViAgM1/nR+aAn/ppEC1gGZfbsnZM62yjlC2Jj/yKjjS39sxpuX6LPPeh42/8qeH YMiA== X-Forwarded-Encrypted: i=1; AJvYcCU1jjijNEKzw8Nefk6lWL+tFid2csUBo3DbS22GpHXkx+XUoyo1hcSENux+R1wIzG6QwArAXbrnyXhCLAJEX8loj5Vl9oV89nGIzQ2e X-Gm-Message-State: AOJu0Yz7LaqSJc+aOgkVYr+sNCgvUIv7fzmqSdl1svTCudtgpk5Y40c/ nDIcle3D/P6lT6whcjzaP6ZRts5a0tVQQXC/MTsLL/CRGNkWm0p/LkEXsu+uddg= X-Google-Smtp-Source: AGHT+IHehrH3QaLP4nYqJoUqN0sflmu8+ChJ58BUUBH79TBGh1nDDRhp+lk/QXSilyt4y5y4matPbw== X-Received: by 2002:a2e:848f:0:b0:2d8:4271:8c45 with SMTP id b15-20020a2e848f000000b002d842718c45mr1184701ljh.17.1713307534411; Tue, 16 Apr 2024 15:45:34 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id g25-20020a2e9e59000000b002d6d4192ce8sm1715102ljk.6.2024.04.16.15.45.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:33 -0700 (PDT) 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 v5 04/16] media: i2c: ov4689: CCI conversion Date: Wed, 17 Apr 2024 01:45:12 +0300 Message-ID: <20240416224524.1511357-5-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 f826571f8f68..06a3e02b5c80 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 Tue Apr 16 22:45:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Rudenko X-Patchwork-Id: 13632702 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 A4B8D13AD2A; Tue, 16 Apr 2024 22:45:38 +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=1713307540; cv=none; b=nLNwyAgMzr/nJtBPD/CWlcV2LLvViVxIx/mYwi0mOi99FFkBNMioPZHFwpvacSjgfxlD+j/R6gZKoo8vZDOBr9UGu6CK+wY6K8qgd1MpQQBH1O/p+zDzF4JJJplnfptgyAwbt7s3H6uIUhC0YIhRz/7Lm9V78uNWAoaFkf2uqdE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307540; c=relaxed/simple; bh=Az1qPONXhvU7zLA+l9wbEw7Pq7A1FrFAxWKB/xjwA4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R7rRkM7UAFRctpv9Rrulfa0GdzH9+iLPdEVnvY7fG0Kwtps5VA79SePyc1RFboq6/XqTwwHgv92S9frOiW4RHSM/X7xB33tXUBNOwwNr807I+fuoynh1QrDcR6PgHTuKA6NyRe+HZZqljHvI5UZyKikELWtXXKtJyEgFgmUj990= 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=FA5ivX/7; 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="FA5ivX/7" Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-516d2600569so6339396e87.0; Tue, 16 Apr 2024 15:45:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307536; x=1713912336; 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=tjf5sKRPFKmqZtF9xerWNP7YPIPFDcYHmMoKl8ei6RA=; b=FA5ivX/7jagiPlAlz4pA6dueDknXHsfw8SAxWfchESY5RbO3hR381G7feVYMPUwHed Gazc/5fRk/6CFD3YQRTo5fmNkKvyqF+2KnXKBKquVuuS0fwfCMpLArRN1wSfGLzs5nVW s2dWZggzN7C7Km2AhetyCKa7nT8ikq9L091+YXcol5khG0FMmRplaVEdMwdNImYW2ego 4v/2UnAHzFJ/ReOBzb1+jF10s6/gizJHNJ1XykCs73IAIjVv/Mlp4gBNzi+sols7jCUc Hy+AGgOuU3F1WWx3Y7OLN1ptErXJLs/NpuSmqas6srTLiiShukOZ5WFVDTbYx0KXC/im 0IzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307536; x=1713912336; 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=tjf5sKRPFKmqZtF9xerWNP7YPIPFDcYHmMoKl8ei6RA=; b=ieXcIGe1XAwXWyqfKorHFuHUbdqsEKLOz7393MWgpnVCn3z0st+oWSEgTmY+X+J6os xl0ZV1kNcE0pMUnkIZnlKp+BwCnB0f//Pf7Kp04H4CRKXfYyiLAm1eRV+/XwNENzt3Gc V5a6F3Hslg7xfvo9c+nirD8tcYENim/Q6VOxoG03MHnH56+cbKtIq3bv6tRGPRXIamWZ Abr4ludBcAl8qC7Mxjf00TxF8LBEchPoctH3Qy/CzPlj/CGYZdVfaum+OFCVe2g7xT6A twsarTzbIXaB9IQ7KQ9paIUN9xs9xEaUAssV5DvutTQypJC1OaGW7x5wU1urQgiWgn8I ozZA== X-Forwarded-Encrypted: i=1; AJvYcCXvUeQ0ioBa6MSa8+ynIxGsw3k/1U/LHZMF823qLSbwayYhxinh5OaLYTyn2Ob5KYT9ks1pzwB9ti6xg2zQ+B9hmaBpvSE9Kmlu+e8J X-Gm-Message-State: AOJu0Yz1g2KIG0q2XHcdqcZYYzWwQhOMLwMZFev7p2fyICap21+iKLXZ XiDbjmu+dKCBaKJK2O7JYzQo635yZYbER5VCviGQxQM12p+5si+4+KplPvtpyAI= X-Google-Smtp-Source: AGHT+IGdCCbPYmi32d5FO1fSAsqP6VWKrzXnj0yw6bAy07Ja4NdpC0ERwjRUVuH/7HWulrLwj+lRrg== X-Received: by 2002:a19:6441:0:b0:516:582:2348 with SMTP id b1-20020a196441000000b0051605822348mr9532300lfj.54.1713307535911; Tue, 16 Apr 2024 15:45:35 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id g22-20020a19ee16000000b00518e9495a30sm748394lfb.97.2024.04.16.15.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:35 -0700 (PDT) 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 v5 05/16] media: i2c: ov4689: Remove i2c_client from ov4689 struct Date: Wed, 17 Apr 2024 01:45:13 +0300 Message-ID: <20240416224524.1511357-6-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 06a3e02b5c80..a3fb6498753f 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 Tue Apr 16 22:45: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: 13632703 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 1265713BAD6; Tue, 16 Apr 2024 22:45:39 +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=1713307541; cv=none; b=N/A3JKHa4LvS91ggXzxMiE/sai1QlLlqYcokbI+vSM4H/J4PeJvlGAZkV6RqlRNiK4pnc52OItdUi8q4lKerLSrjafh5TdfCj+Lb9EjEPn2PlJLnbiC8jY3F929SfrGrWtCJMNwyHmBSbNTcJNgF9ev8Y61cDSgYeR6woyIJoRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307541; c=relaxed/simple; bh=VTXE4UhrTmceY1NPmrJgDEtmUJXENr5T4SfLMtc2i2U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tkMqAxS2AdCfN60SnvNATAlKCO4oG6b0yiqH1lhV5ASd4kF8R6v0AiGo/JwQPaV3nNUtvHQgeu8FHOCsK6gHdLgzMnYjfWpVYWZDxH0xTEfMtFXRqbjYF1N4YvYqCD1bcpVInG1WNpr3TFuiT5lNdvpq85mobF2xYG2ueF8uyNs= 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=QdRVdV8M; 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="QdRVdV8M" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-516d4d80d00so6143081e87.0; Tue, 16 Apr 2024 15:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307537; x=1713912337; 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=/vdGgiBkIc5YnTlEo2gOEmdH658ja8P/q71eV02YwcA=; b=QdRVdV8Mv4ta1pMRM4ACeCtNfkgOr2CqGPHaUduwSyJvRhRO8FybrS0KRGRGL93Y2Y CpYeoNjj6k20IVv5kflgLdHkEmAFEzGE/gcZIM6Dnb2HJwjQn36Du3qbMX7aafmevdk8 O1ZtoGAnM0gVbT/+7JFmb6GJVQStNmetJ6ZxO4SA7nYvZWsAfdbDqR24R+x1qrM5HZUe lD2qAdYlLv+jXnyNeLAuxwQu3atAMwofxyrZ9Am+uzfSMx30wtMuimRApXyd5SgZQbVJ fLKzBY/lkTMNuBWp4xqhfuZvFRvYBzBaGc5ruD29mv57e5KASzJ2Tbpkd6yJgvrhTSKm U8tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307537; x=1713912337; 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=/vdGgiBkIc5YnTlEo2gOEmdH658ja8P/q71eV02YwcA=; b=uqtAo6nQpEgDWyXS0FIfzsS+2bW+9TL+3Jg5TOB5roEG/FKpJTNtqmzpUa/U7WAvhf ngRmVbfDy7uKYcqH/GFLUmlVKzKv+TDv3dmwR3ZPtnkhlhccUnNYzVC9IZjX6Nf/YNqk aQUT3/Ja+q4xWOpWwLtmWYnhP0p5t6ZHP/vtLHtNrDYALp9+KjxJhgHyxJGZU5h517RF vq/JUzH6erm06iULf/b1y7Vk22UW5Ds1oZ5o+wKPwHXMZkjOW6ojKs9h1ryJRpSuOuzl m0NI6tTdECbTsZyacb6fWZeRnqrYM/GHBiX/CpxKG2YMz8DOWPTn1B3i2Fj7ULJYDWTJ Zz4Q== X-Forwarded-Encrypted: i=1; AJvYcCU+OZqLMdt44nMrUVHvYa55rGFoNyZuiD1iYTY+yAOI8isMrgBIerfzawnF9wK5qlUElcFHeyKYDv2du6MUvRWvEVunWZdb7H8BaiOh X-Gm-Message-State: AOJu0Yw8sJmCSlzm2PkQLAvvNlhBLdXCfCfKPyNQdm5QMb8NAjmjgCWp JGyYmsEwRTxYJ/2n9vWiN38PSbe8p8rRKzvvnShNS7qbKkvfOYSodm/aD2HT8YM= X-Google-Smtp-Source: AGHT+IHV3Rl5Kj5X5gq4S1dZsdPwKit3xs05UygSRKauN4NgZtn2MPpbTr1HGc0kC5Cx5tSJEb5wlQ== X-Received: by 2002:ac2:5f1c:0:b0:518:9f1f:8f33 with SMTP id 28-20020ac25f1c000000b005189f1f8f33mr7379150lfq.15.1713307537395; Tue, 16 Apr 2024 15:45:37 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id s12-20020ac2464c000000b00516cea36d5bsm1752857lfo.21.2024.04.16.15.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:36 -0700 (PDT) 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 , Kieran Bingham Subject: [PATCH v5 06/16] media: i2c: ov4689: Refactor ov4689_set_ctrl Date: Wed, 17 Apr 2024 01:45:14 +0300 Message-ID: <20240416224524.1511357-7-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 a3fb6498753f..883dcee52d5f 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 Tue Apr 16 22:45: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: 13632704 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 0AE6113BC28; Tue, 16 Apr 2024 22:45:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307542; cv=none; b=ITzphaSnIJXLFiT/K3A65dfnnqwPFu7yNKE1foZqwoQLCkN93xPD3KrQSVbAW2vQ7c0LcK30hRD0KPHHA7XAolsByoaqPVI0bywtTnYeeW5xMypOwtpnCnI4LkZYnovdW+m8qslV/LcEM9FZhdU4Wm7HTZTVt/O6iPlfJvsGCnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307542; c=relaxed/simple; bh=Saxqx3lmLcgbb+ICTRw6YQqKVUl/lRV9LTGS0HUzVKY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a6lEfhmhj5vkTKbwAj58gydJUviO2i3WLp6GLm3lzjgJKvwiT7oOOChTA0ES3zy+N7l3yvF5uOdIsqN3MbOpg/4EqWiULQ1YNXAmYDsPZsb1NUVVdMwxrDujT142rJgR6SYD3jUniBOcsb557SLbtuXG47gQvGTE1ij57eMRLUc= 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=AdFWIPWa; arc=none smtp.client-ip=209.85.167.44 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="AdFWIPWa" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-518c9ff3e29so3592457e87.0; Tue, 16 Apr 2024 15:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307539; x=1713912339; 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=066Z/3wdqy7ovWFhIxkpo5iLtCJYYC6gpX4VoF2eBy0=; b=AdFWIPWasWdW3O2bc9rb/g/l7qdCgB1j3oTQZ1PfxMYBPm0Fi99UtsUN3bxN/wZLoT iSYTNB529GTdRl4ucnUuo/knBsbld/jTiS09DJs2mwm8SpvecjoQh4HtvuIY5PHLn/+M KPft5SGarUBDeuwMjSeN4043ncjvqCiZGDkLwcwVM7+qsS+VR0y3NOnY+9u6ca75kHTz BQO603ihJjdUY6CXUKtPclYu+OU6qAy+63b5e1+lnuW2/PSU5Qq7qZ4ng4YS1C5EspqL nrcKUbm9BdxElVnu4cdiP2Kf0Q1nylgfCMC4mQnszvY1NGZsrP85gLlEsa9Hvz3n7wP8 d4FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307539; x=1713912339; 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=066Z/3wdqy7ovWFhIxkpo5iLtCJYYC6gpX4VoF2eBy0=; b=bml/2dsqxeP/6LPDnxWZBbqxW/tnPWjWDzSt0AyKywq1iP/uMBttO0z4H1zJvFFI2P BcYZsgHmHketKpMib0N4kjUihW9lPsG07brpGXy5hqCvxNrlvk4tXFNcLyQWpfiIkHNH Us7BkJj4WWHnWjr00fMz7g3+HTMLio2+Virys0rgRqVKNHtXTjX4/3FuqZezm48da+DC OnYLLmpsUDQNBMhpOWzLxGjAm0xGN+b4qoQQ6dKF5FBY+6P/6nd1JawpQb6Icwe+iyGH QWYOpvURsrLisvTDFB1iHefWm3zDBPf+isHGprxyrz0yYaGFC/L/5a3junTTuiIUH4vL Y/Fw== X-Forwarded-Encrypted: i=1; AJvYcCVpUV+JJqu83oJdX3+tXmmIM9EZCMWzRsSbAnVtxVrqL0d30mP7QQ70KS94bktIQU8/alZEpDxWnvEAjf0zIhq7Z1D0lUS8YZa8+Gtw X-Gm-Message-State: AOJu0Yx7prj0HH8OFfEPTz8Tquv4t+OP6G9FXVXnYqilJ+/lgQRM4mMn 2GzprDpyfrxfVLNEpSoMGByXEgWncBZie+7DHLahENCDqlxgbu/RGJQSY8wiVaM= X-Google-Smtp-Source: AGHT+IG53fru3EkQoz0semfrfBl28aPa7HoSvUV3fWtysuP9EKpl7Be/WQyBCwhNrvy4upm8mrUNJg== X-Received: by 2002:a05:6512:224e:b0:518:87ba:c846 with SMTP id i14-20020a056512224e00b0051887bac846mr11314855lfu.31.1713307538770; Tue, 16 Apr 2024 15:45:38 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id bp32-20020a05651215a000b00518f6b9a5d7sm652201lfb.137.2024.04.16.15.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:38 -0700 (PDT) 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 v5 07/16] media: i2c: ov4689: Use sub-device active state Date: Wed, 17 Apr 2024 01:45:15 +0300 Message-ID: <20240416224524.1511357-8-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 883dcee52d5f..f0505942000a 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 Tue Apr 16 22:45: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: 13632705 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 3710413C3D8; Tue, 16 Apr 2024 22:45:42 +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=1713307543; cv=none; b=qDorFraeFahny9gC5Emtq9wDs6RJQ99EziLBhDon8hmZCO2sv8u07CLlgNOqb83n+K7Ty3uSUPzW9otmU+YpMhPgIYpDPWVL/2OJpqcOrmrtyl2oh+Vpmb9/OhrGHDWyPwmudhManTnbpbFWpxdOcPOnc2kuBGIgi1L4PHywBPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307543; c=relaxed/simple; bh=z+qmmXpzq6nTSNsqOsbvOlSNaLFSzRdLB33VDRY6Skc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=epBgSAv9flyfrdcDz8XK/6u0bnGyxiWmsTr+CNI7R9LqxsiL6AI8Le2VOiCIEbUUx6FWleJYQKbzc9tnLsoOl83YTfm0Uy99/s6Hmd570Btsn7py14nfuLs0ljdgg2lJVyLGHFXnLl3MwXFmXJAkn7czWEYLbhKulp4EQ3Zf9cM= 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=GbQVd3vN; 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="GbQVd3vN" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-518931f8d23so4009748e87.3; Tue, 16 Apr 2024 15:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307540; x=1713912340; 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=v2oCVnQurf2j1hwUUqHHtzxHqRucm9czT99yOLVFDWg=; b=GbQVd3vNIg1GIRr+GokkBsiP2Pr2mjuE7nMfrGtl/WFvDa//o+KDqMtz6EE0KTtVQ3 Dz4+DLcNABEtIps7YPWVXdsmKsH2Fgdx6YZX9L1EyIRRwhLEg8w0KTlj7fnqXar6HigC 94uumbDTETnXbttGbWXo5yR6Nk8GfiY2OldK8zldN5LUDhdx7FeBBUx5a8Yq6SSfFGIK dtuQAkLpPleuczhfAv6g9P22KqFvdiPg8oGmhs85GdwoUHkrYfa13Jxry0XV+FwC/8D7 OnNeJGZKyiX1AsFgTKJfV1W/xFKg5Y4KOWALNx7trekd/6pHs1WgKDmiODCg2Lt90Qge f2NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307540; x=1713912340; 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=v2oCVnQurf2j1hwUUqHHtzxHqRucm9czT99yOLVFDWg=; b=VRnNucS9aa7dYXY7p+k9guixYlrNXy8m00uex+6ClZUaAgggtclLg/iIqaih4DhYbf orcbd7dsuMmtbzk4szoLu3reOE3mCQ6jg7MM8fXyKQ6zSDs3/3P2b3uireczflKpAcpd /k8GSAcTA0PQpok1U4vrN+8mdks0kZlQxOT4Dfuk2OE/dXSm52ZXhId1e/QF0m1wl8+u DttS275P1fAHIh179YFBvhLGBA2LIgHZv/CttPKO/+kzL02EAm+XSRVUPE91ndN9lGCJ O3X0nx9MFhwcRSyKm5lsuwy4wdv9P7HUqmc1VGgDw/KHYqpUhXf3j5dBpGMI9ybXlncT ujUQ== X-Forwarded-Encrypted: i=1; AJvYcCWDrF8vnMrZnXNmFBs4cxb83bH6aceAKiweYt+aDw+MdsiB+JElpBPxeu1r9NkwvjkvhzY9t7NI1wWRPoYL+Kk4XyqC/md3SCgaVAUP X-Gm-Message-State: AOJu0Yx9uz3ZGqxb6NfpHTzPgZ/WEX8AatYgaJLgPWaFZ0GH2hTkl2my MZnH0zSJGIbxWPoO77Fg2vJhx6qhlnGhSG7OHXyctdeG4mBJtawRmjTzx79NH3U= X-Google-Smtp-Source: AGHT+IH9kwj7ikjWf34pW3xaEE45/rQHUi17Cm6yPDrloMLFRuIgWvRzdixVmwKSOnEcbu0ZV5LD0w== X-Received: by 2002:ac2:4e15:0:b0:519:27c3:1b67 with SMTP id e21-20020ac24e15000000b0051927c31b67mr1951572lfr.37.1713307539718; Tue, 16 Apr 2024 15:45:39 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id r7-20020ac25f87000000b00516d0029383sm1751908lfe.28.2024.04.16.15.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:39 -0700 (PDT) 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 v5 08/16] media: i2c: ov4689: Enable runtime PM before registering sub-device Date: Wed, 17 Apr 2024 01:45:16 +0300 Message-ID: <20240416224524.1511357-9-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 f0505942000a..ab30d7de5a52 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 Tue Apr 16 22:45: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: 13632706 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 7D7F513C668; Tue, 16 Apr 2024 22:45:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307545; cv=none; b=Z26qKKcHbjDCXRfsKBxd4aFIWFlAu7FO9fe0BYHNquV7ahra+GJ4k7sV2b0gYkI1mK3I1ope+jqIV3HGBQDZN99yTsQPM7M+9o6igI9u7278wgxIb2vrwACF27v/Y+59LzDD3jxu+JxAkcCeWYauF8vS9S7I/SN67rzLHtA2ysg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307545; c=relaxed/simple; bh=dV8K4F0A9pXNtzsdUUObhQc03J0IRYcsli8GUU2LmRU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AJxfutJg+FHxuh3fBiGx/RJcyG1JdHuo8Bb2Dw5PIKNqMLTOLh3zqHJIWz3OU2VVRCkNuBU+++EuBwTUdvUsJ+7YuNh1Th3fEVdzJg80BWtyycqAA8Ltsnz5jhkmLx5mecCm41H8EP8KjgPdnl1kH5E+2mkgyxrLRXEzHoV9GwE= 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=H/cKjnt/; arc=none smtp.client-ip=209.85.167.44 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="H/cKjnt/" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-516d6e23253so5512666e87.1; Tue, 16 Apr 2024 15:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307541; x=1713912341; 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=/wi/0pJh/E7nGNzByWLAqj9/04e2L/P2ERnTt5QTMBc=; b=H/cKjnt/zPYr5Ahe4jm4hCJe1YtVRXrlaqY080OSEYTqFbfb7uGaFUnfRgrJy/uwD0 1ISJfpLeYRXgZgDe3t4ThtA52wnqeCwdN6PWJ9yvzZHIdUp24yOHt4P4YXeVfg+UaNWA hVJkdKlaODX8Br8IY9tAz0/9sdaBkfAUmHTl9rsFmyKX6Mg/j9zoPiJqx+DSMUSft4O1 yQTq8+NCSMAiKtMT9Nhc7faAQYm2dz4BnL5by3jYZ8fD89Iq4NSc7ZE1kWCMFw0mxA8c DlcrxYU5/dVZLmhoRCjh1YNvNIxul7rgTvusyBJUrZ7YFTHLeNdLRzYS/KVOBbM5d3Lq rbBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307541; x=1713912341; 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=/wi/0pJh/E7nGNzByWLAqj9/04e2L/P2ERnTt5QTMBc=; b=L1X0N+JDrOepbd+dHxClCLHgUNdSbWeblKSyNWHjWJlmlBj4crCuY7PLlThJyajPqY 15mIKnM9FliPcSxbmNScKuGZpAGsBlz7Jk2gco90rJGIzz1uQYcrugA4rFpM44ECu60G FqOHVxxYVGE6dCLL3BpxvqwRahT5dzWxxLshZuNXGGqLRXeSBKArfS4nk8eKEczatXze ClLqsRtfWepBqK1ENZGAlcaOMdmzDgARzXcdMC3mKgMOsYs+Eakzv3jFYw9QXAZkGl5+ eEfOoKb+rXx6LBMDrLHj0TCNDKG0eMxARKvIMbnPV+EuUiRBe82xCShIllEh1iWXaFDq LJlQ== X-Forwarded-Encrypted: i=1; AJvYcCVViDDzwHqhynLl+sNL8r+Uip1528R8sP1Rdr3FwudfNIgTUwz5odjtf6GCauFBKGUpo0fumjlQyj6ktyqwJ16CfJcHyjt6KAaMkgCk X-Gm-Message-State: AOJu0YzTlCQ7Gqfs8sGJdNuhS98fklOWUJTtJZKmpVa2IrNpDkURnisN /kzc4WDadXkcvkH9plV7G7g440jwmYGQqiSD4Jg+gQrJGVzU6KbnMUXfibP2tRM= X-Google-Smtp-Source: AGHT+IETqAohtet3hQMMVhNOQpBkqkPJ+OOj+5eX8IifNJsIPT1d7nADsiBnRukOB1bGYxlZzaTYsQ== X-Received: by 2002:a05:6512:281b:b0:518:d956:5c5e with SMTP id cf27-20020a056512281b00b00518d9565c5emr7813250lfb.67.1713307541016; Tue, 16 Apr 2024 15:45:41 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id y5-20020a196405000000b00515d407aaa0sm1756247lfb.252.2024.04.16.15.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:40 -0700 (PDT) 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 v5 09/16] media: i2c: ov4689: Use runtime PM autosuspend Date: Wed, 17 Apr 2024 01:45:17 +0300 Message-ID: <20240416224524.1511357-10-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 ab30d7de5a52..12bd4b010c05 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 Tue Apr 16 22:45: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: 13632707 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 0025813C830; Tue, 16 Apr 2024 22:45:44 +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=1713307546; cv=none; b=PsF1ZzsnM3MXjY+JjEH54a0pmAA7Uf0pA6drdVPFcwKAaoX5pBEuT+BFAS1qxfB26PwaNL+DEtpb3uaxdqUi2o1ikrMiY9fEHBj6XopqlDjtRrbYro9U97VLP8f5sbMBQiv0w+q6fZ2MASoaY7+ECWpT15hatrND4Fr4K7rQ8Xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307546; c=relaxed/simple; bh=K4PLJDc96oGdajL43d4DQTDBd3c8uU2qyB3w9d2ZmVA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oMJNc8esXsyPTtLZXb7bJLayefJcKazQ1qd0xUH7vPL7ijOWoYntXlNazx9xRt+MTCeArJkUbqQEIYOJ0Qy4X7T7Q5r3T8nsb8TNaH2YGi0KOJpWjBO2kJ1nVaApsbNk9b7hMTC5E5O4UDkwKC8jmM+BLasX+YECnYwNQv48BeU= 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=AVUKQ4Xo; 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="AVUKQ4Xo" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-516d6c1e238so5889572e87.2; Tue, 16 Apr 2024 15:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307543; x=1713912343; 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=I+BIOfq3ynaR01vX89L5lVtxWYrZ7VGc3tkryXiEmCM=; b=AVUKQ4XoNStUrFzDfk/Ikl65+5qV/XppwpTHSCIfx65/GclknAI2WYJdCmqjZzy+/9 7/PhOyerRuPxHmwI2vO3Ikxudc8qGUuf0SBQOwBXiNnKu7v1eyv2fC4i6qZ57NkzOwMv LaEPaPtMxFTSCOSxNsSfeuhKMcWn2Fp+VL6YGEJ8+iRU04MdTfmBR4UHjA29ap3oIOmQ AFqMqrNHjOp5TTud1f0+02qRi6havTC5Hre0sVEkdDQauDmWJSSGoJYILx5Cxnovqerp hWQBMhjwKvFHMU39jUqP20mT5yoEcTmi1TA/XWah7PmhEF2xzoJLVKyMHnExa8fXE1ab mVKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307543; x=1713912343; 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=I+BIOfq3ynaR01vX89L5lVtxWYrZ7VGc3tkryXiEmCM=; b=boR5U7LTpCL7pXMLaHO0SI8481Ns5IT0oV8fQ2VGZvWdBiYlmIrl+OBTX+9XULxAV3 0IO24Tdajk2e7lNeucTJCRWUQZ4CKReNh0Kk8d+HF5uOCNCMCfMzw80Afajk3BNEIfn/ 2JsRiyX+jI/4u5FRsS2k8hIbJ9OKL/KJQQeik9MqfyICE8V44eLMHnatJdHhHjzaTAJ5 R8mGcEG/uwX8SnAL+rWwJlQyqB1ABbwHO85Nsmq/tpV8IbLA+Rci4bwlnqIzs3bAw6ol bYYMi+Cxb5LtXjPW3J0MYwpVP11JOiR8QVnMtCcrGBvfdPCFOBC30Lz0qU+F4XpY0bU4 86fQ== X-Forwarded-Encrypted: i=1; AJvYcCWvWUvOld23xe6sK0zSZ1hx2XvjJ91uilsCPPH3sqUFFeWxQSAQv7AgSTQK4PHrWclcQStfs4gbq6CTLFGySGZkl2yeV3kEnLXzaq4k X-Gm-Message-State: AOJu0Yx2EckJDvPhmaFcwQgsX6rJ8QTjx/m1T1vstWH1H48ihpEqRtxl cP2Ww4XImdlPrmlTQU/wNX5+ZMLATuolRkU3lihnMeK/M3FFx0zvSXvGxbaa3r4= X-Google-Smtp-Source: AGHT+IFrdonpuA3ezRfw0gWz+Hl/anAr616WSLB6KxDR86CbrAF7GyGoXp6ryMS2huLpt84nWzPCYQ== X-Received: by 2002:a05:6512:4023:b0:515:cb94:af57 with SMTP id br35-20020a056512402300b00515cb94af57mr11740814lfb.57.1713307542314; Tue, 16 Apr 2024 15:45:42 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id q13-20020ac2514d000000b00515d1dfab34sm1734382lfd.81.2024.04.16.15.45.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:41 -0700 (PDT) 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 v5 10/16] media: i2c: ov4689: Remove max_fps field from struct ov4689_mode Date: Wed, 17 Apr 2024 01:45:18 +0300 Message-ID: <20240416224524.1511357-11-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 12bd4b010c05..31352838c3ff 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 Tue Apr 16 22:45: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: 13632708 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 7925613C915; Tue, 16 Apr 2024 22:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307548; cv=none; b=G1yAwQQZ2WmhdIS8Lw6u/bTwpwds4xrv2Z7+CU+/JHOKL3jGc9DfClUeXQTKkx7yuUCIrLC4mNr+X6YA7lDhsQijJJd38kUwdy8IYV5ce/eXVY8tDgPEt5Kqd8b8/yrlqu9IfezTpOCB6sZmrFFlU9Wk0kOix/t34HcEz6/F8BU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307548; c=relaxed/simple; bh=m9CFC3S9xdi685DiojYl567zsahvLdjx6bORHbJsrUg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H5f8uYjWzk4wvi5WiTjIX9vz/6tSptTB5eF5aZx4y1SYQLnBeKIAmvt4muX+eK2tqagWTtNRQptDszE2gCTdc7PZvHJ79LLop4HXNBG7um3B+xFNbhov7+23ZuCrRINN6psNEeMm5ul4lNmGO+5Xc6SIQQaTBWUmGxEtUPJrPqE= 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=bz88lBYm; arc=none smtp.client-ip=209.85.208.182 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="bz88lBYm" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-2d29aad15a5so48865931fa.3; Tue, 16 Apr 2024 15:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307544; x=1713912344; 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=IIGVqgD2Rn8KY+nqi4UbhbJ6rG2DCyQeOTXHZE77sPQ=; b=bz88lBYmjZMrnfra1HzKLQL8Gp8t+wlYyByoIDCq9r0c8m4DUFXeERpO1AxI/GdVGi YR59EPu8dJYEow+kUfUHkjJ7r3xoX1Q9UynpeYrLfSpbp6iUyrcmGW5z55dSH5N8JMJp vGd32x3FU31KsrxQCzAszim+Ow4atvpmcKkHMWgiJu+dQ6LA72ueDkLwVm5/xFBeL9J4 gqCEcXCv6Rn7euTIng0ZWJYaXGMBcD5j+lkkTWh47TRgq7PVV78dxEYeMqmpRG34l8d+ Q6Pfh06fo5dViP9oMMnIUimaLOU0hGgk+XRTlCJDhOCrRmD1TmHo2tZtSIk3cMxL803g fJ/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307544; x=1713912344; 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=IIGVqgD2Rn8KY+nqi4UbhbJ6rG2DCyQeOTXHZE77sPQ=; b=qCw+XqmlKz1B5JV/A61HuCeBPXRomRVad3wXqI/Ut4PwQ5jEENyzbhclyfpI5JlY+s 6DwDydhYlXfI5HKoevZDlylxQbRJ3dDBa06xzhk/bcuERAtABfBI8MLRT1EIuxP9w2hc D8CsFQwYgMsVfmGJQqE5am5046Q6e6m3zPYZR15gGcRi8VVLP6OyCIfkhVePpTpGJYcA 3Kr88FlMTpdk2NPCPQWpVAxihJ2ugf3WZL+4W6S3YgzUft+CCVH/LhWnBNxTgGQWEpiW np9ZWOnZXLy9aub+goiSn5y82Ipp+6jTXV7G9BOUNjSTrex0MXi4gz3BizpRn/ZARgT1 UZ7w== X-Forwarded-Encrypted: i=1; AJvYcCWZ1+A3zijpUYpTrVFWjduedByy0xZPaGBrC3HmlHCZBbHA4Ewhm3VoEprQqut5OmXLwBJR0DWp/5be7rmHtYJYkGbFWhoGy2Yor3iA X-Gm-Message-State: AOJu0YxSzyYJBKThkhXvHvdFMST52viqWGka0KWFRd1n3xgRjNad0qCU PQSzjhKeIU1oT13ZpYiXU3MdW3wFCTWfM8oqJASsIoGmScDdF1ZPlLAaTAJuieU= X-Google-Smtp-Source: AGHT+IHs2NGWFAPmERxTGL+gsDdRK02P16sQp5TY0po/RJfR+9tB9Ko+hbbIAdKVq3tT7vKzZEPVTg== X-Received: by 2002:a2e:965a:0:b0:2d6:c29c:a4e9 with SMTP id z26-20020a2e965a000000b002d6c29ca4e9mr8630177ljh.22.1713307543929; Tue, 16 Apr 2024 15:45:43 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id u22-20020a2e8456000000b002da25e60918sm1214638ljh.18.2024.04.16.15.45.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:43 -0700 (PDT) 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 v5 11/16] media: i2c: ov4689: Make horizontal blanking configurable Date: Wed, 17 Apr 2024 01:45:19 +0300 Message-ID: <20240416224524.1511357-12-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 31352838c3ff..e478c1f7a8c2 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 Tue Apr 16 22:45: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: 13632709 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 6B86D13CA9E; Tue, 16 Apr 2024 22:45:47 +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=1713307549; cv=none; b=XFHgjRsQDhbT/x/eh4WAPZh9xfaEXaCuzWJ84624OZnQgxm6lEYblD0a3UuKyCguTCPMumyX3m7fe4HiWzLyeBR4CJNgAgRVtPWw6gjNGSD42p3PYFP/o9l+8W8iVQFuP4kvFnE0FMNG7KmIgh26KOqdGqMHHLJAHgZpfY/mFIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307549; c=relaxed/simple; bh=nQLaOOi1m3INUw8IYeGsWUSR1Y5F/FcGFOzChmGZ6gQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qn8amzr+g1+189PlDh9xGwT68gKdSIlaR+g1u9LGY2TvcKmk/JDSnzlIe85y8y/iFzrnHSMMnqb254B8nsGdeGWyN2jZpyHIGjG2VAj7I0J4Lx4wDfB0LGJqRr/m618DjwvLnAL7H4F9tO78kG2CHS+vESrpL3lWpzRmlaE3UWQ= 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=hoLxRmHZ; 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="hoLxRmHZ" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-518f8a69f82so2907013e87.2; Tue, 16 Apr 2024 15:45:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307545; x=1713912345; 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=lfYWLG20tWLCctmjoEIlSfMzY43ed7+aAxJ9RfPojYc=; b=hoLxRmHZqBRIgxPvpIdrN7Ba5ct5GH5g+/JS0Vqn2KiT+J/gsTH9LFx5JzHAEdAH1h QM/lc/muiQxfJBZ+lvW/qYIh1mAPGFSAy5ymwscXnDk7Eyx/fU+NjwpNtF3ttWIsuy99 VAwS5rLw3Bm/tDZR7uLH/U6oKyyldN29qu5ohHyUIGiLz+wfz0yIeRM3PjuMjzWGbSkA v9dPN9lO/pg6HPs6ZrBeZrage3vhROlghDoZP7WRikCzb89B3lxilnyjjthmvuBiHZyL qALOyF9L4Y2lzBoSpbCRc+mavJ8A6vcDOgfmOkjJxGRHEx4d3ONg516LF/T/Rp0PteUb EGFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307545; x=1713912345; 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=lfYWLG20tWLCctmjoEIlSfMzY43ed7+aAxJ9RfPojYc=; b=DggCiFziFVQup3d63kKsynbQTUnLg6j0tFAi7emCfKp4ZJ+r1JXvakGzzgjrwcJeqE 1/OXqK8AhUK8GryTGQsKLlSC3ZzsmeoQ1q+sdagTsJMZhDnHwyfnmoUArXJnJe1P/epR ZlQC08V2epkOVuwY4PRDugYaH8i2g0+cq8bTehwDlrXJbqtGHuimft+p/ZSAI+iwHQ61 YAtl7pzWvVRuFmQyYMzeBk0As2ss1A70T8uKCzwuTtOFxbKngp8EHm/s7WZRvhAYmF0O 3X5HDuIwjdK1EKrKKS48IyrK3s3Be1qCRKplBs9S8e/4EiAInkQtXYk9W5VcBYNZXUpt XZqg== X-Forwarded-Encrypted: i=1; AJvYcCWfU8nfmkE7lor0HPF+4c/nh/gMjfekhQ0gJgSAaSE0Q+oH8Ul4GPbLsXPt0WL9feo1SvyUZnpTL+ZPgIsT0Iy8v3aVi6Npw2DVkNQN X-Gm-Message-State: AOJu0YxBFSx4swRn+WO6sClxuTaMi1AKfKVLj3F1a/h3Xaeo5OgRj7W/ kD8Y5ZOtTzrtZdgyF+OSmaEbjHwamrAUv7Bhx5VmS7bmPTwg1bXmQhdjtmWyPKs= X-Google-Smtp-Source: AGHT+IEk405u1zD+q0VmGL18rrASDlrBdHE//jacygoJwwtu7sDabFy7W31Z/oko/GplGnhEvniKRw== X-Received: by 2002:a19:7510:0:b0:518:c7e5:d1ba with SMTP id y16-20020a197510000000b00518c7e5d1bamr5931604lfe.63.1713307545291; Tue, 16 Apr 2024 15:45:45 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id y5-20020a196405000000b00515d407aaa0sm1756270lfb.252.2024.04.16.15.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:44 -0700 (PDT) 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 , Kieran Bingham Subject: [PATCH v5 12/16] media: i2c: ov4689: Implement vflip/hflip controls Date: Wed, 17 Apr 2024 01:45:20 +0300 Message-ID: <20240416224524.1511357-13-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 e478c1f7a8c2..aed87a1b6141 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) /* Vertical */ +#define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821) /* Horizontal */ +#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 Tue Apr 16 22:45: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: 13632710 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 4A31313CF9D; Tue, 16 Apr 2024 22:45:48 +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=1713307549; cv=none; b=h5/ENHVh2mDhO9X3zcL5WoT+J24CDQAjlDyKsWGwUHbiggHopwoF/DsCJJn4GJGnq5y1utxnFrzpEJAPI9WeZAVGbJVAbealFr20EAdnb6fnkkzVLfzdWDSs9pQTaxgLQj7f53gJ8bhAqXbtJv6soEcCTmj2MMNBVrpxGOFuK8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307549; c=relaxed/simple; bh=hbl71ErSBzkD6kHWrHMCOjLZqMs6UNDDekpRwwC8K4M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iBcOj7epM7e2JBduf/mldHAR/FlWFSs/sfVGtpFvby22HDIZFC0HxUav9UHofNtpXgCzMa+CD4ze4SvOhPwYNJh66N4YP183eY4F+mf2LjDGyFiarklzrpYY5E7Ls6XHtJMOjAnNTb/JCBB936cgJ7XWs2T2qplveoQn/PAiW8c= 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=kdnQXgii; 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="kdnQXgii" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-516d6c1e238so5889601e87.2; Tue, 16 Apr 2024 15:45:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307546; x=1713912346; 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=DTiIt4/6Hl6mPaW2hMZHjAcnbQ3TgX0d3sLt6FdNZb8=; b=kdnQXgiiVUook+3XC0MneU3LdzykQs3swkt3veM2JEVw3vazGVrOVtopsE6uigRRUU IzLTjsNyOCk6Y6MdV2LHOCwzUB/3SGe3WRC/Iavsxbg/l3Q7N+dihoepA/JmQghjhbjy yZRaQ0NgXd2bBM5V0tvkREFf9b9rYyQ8PLy2Tu9Bd5l+WPwkYUCdwx1QVk0vT3jAUGBY S/3RzWC16oKe4QhIdpH4Wq6tGd7sZHK8JgZtmA5Va4GhTWB7MDnC6c5acYbD/5Dv/iop b8q00rInMxI615E5Z0vFzPZaFQ+JtOA0SkemisL/KdomUHQww75aKCNT6WVURpUwLKiJ LhWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307546; x=1713912346; 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=DTiIt4/6Hl6mPaW2hMZHjAcnbQ3TgX0d3sLt6FdNZb8=; b=HhUlekZkULP+TzBbY32HPnm/ALQUFyKCHSdLnNTnloeyOWJ1dFO18JXbRUVkbAo2Ty HRFziuqYAt8Nz7rFYdXjA3cY2+ze1ZnweudIu2p2dyYRj2R89d0YXpp7mioRauPJD1L+ dLlEXplwKh1xfOVAafbNnhueuXxvFc19Qaq7YyKhYlFh5HIL8fbuYmLush3odHxVJQi7 DB2jfSI24VzbTiXsZoib096cE9Dv+jKthhQa5tXF0fxI+tz+6Oioanue3xbZod5eJ4/H 3upqcX3JnEcCJP4ZosCPHGNLik+yZuwGyRAt61oXdZ6cxaHid3SPvlyIwICNump0kpNq LVjw== X-Forwarded-Encrypted: i=1; AJvYcCWoiCH9wUk/6zDLkpxkoi/lOFWGFjLHhlU1lR0OFDuz1Hy7ni+MD09Cp44ZkkiGnGFfxv1S28iFRbF/gMScXt5t0Muq3dq6W1YnFvZD X-Gm-Message-State: AOJu0Yxe1R/fX6tkj0nGei0eO4DlmuGz+O2+qOHwOTaEH13Fcjocb4dm HlNPzRXwfhVvn6qECwLMijZaJVJFJ8p2xMJCogvM8+DMeO7zHZfuTEh8yXseoUY= X-Google-Smtp-Source: AGHT+IH04duWoR4wt54iYga0fEwnBfZLMpiAF8tynWpSdLcBdx4NDToAIYtkcaMcyZgCWUEYzP72oQ== X-Received: by 2002:a19:f015:0:b0:518:c564:1089 with SMTP id p21-20020a19f015000000b00518c5641089mr5328953lfc.52.1713307546207; Tue, 16 Apr 2024 15:45:46 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id w14-20020a05651204ce00b0051949824d57sm4013lfq.27.2024.04.16.15.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:45 -0700 (PDT) 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 v5 13/16] media: i2c: ov4689: Implement digital gain control Date: Wed, 17 Apr 2024 01:45:21 +0300 Message-ID: <20240416224524.1511357-14-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 aed87a1b6141..9419fc4de33e 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 Tue Apr 16 22:45: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: 13632711 Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFEF313D291; Tue, 16 Apr 2024 22:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307551; cv=none; b=GaFYhBbavKeG1EGmqAocm4ikQxSiIZgE5s+OM/4xY7mCdmwTJ76AqI7+pLtbZqMVf9yRMvWlfC1EWccG6HCcqce4eEd6u5qDaQaPun/3k6ipnZhetNQcdqkBXRC9FTH0oKwALGtrSiKnOLd3cQxZhJ6kL72+JBMOD+TK0edPEo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307551; c=relaxed/simple; bh=DtVUHIfAgevKu4djLbP7nqbfz3fagvRXoPG1r681QNI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VmUqNlfatmNl84Fm6+4zrmG4F45GDUXVyZs1N65hiTWwkeFykxgc6HEDxjzOZc+r45QdBSC7EZKEBOSGulElSkjCU3Z8bZQHPxMnWEniI3ZrZKgXlfC9wH5yhc8RyniUHXfdazIeObiSaCFQfZ9jbx9tDxDT1i0pTpjREFcTcio= 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=mLBSAdZe; arc=none smtp.client-ip=209.85.208.175 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="mLBSAdZe" Received: by mail-lj1-f175.google.com with SMTP id 38308e7fff4ca-2d715638540so59384901fa.3; Tue, 16 Apr 2024 15:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307547; x=1713912347; 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=XnB6EJezC8uEYf8UpSPwf0QVKtD7oJuVnHfWXzU0FRs=; b=mLBSAdZeaEEWs13K8yqif38Rvhqg1EWfLABzZAN/6zE60oXNYTuse6R1Dsmzgse6BE rLiTTBfSO8V40/TUCXnnvXVt/fcmUwyLe7v0NKRYR7jIBQlRjf5uc+Obb6PudznF/j+D vYiCEsOoeaBWKtZ4ny3rncn7aiAsgoLDt6Xui52KktorRfY6NuUp1oqhU4n8e61i2i5c B05eyrJnnnzFVDkClkHTqIHFii4BsMWnvqjI66+XN6jMfi22RlR7TITqTiZ0obruY8sI nDy6Qlmz6dF52ze8BliW3/ktId6coe1ZKOsS2aQ1w/Is07q8Oq7YFir/FL6X0lE1pEcK X8/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307547; x=1713912347; 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=XnB6EJezC8uEYf8UpSPwf0QVKtD7oJuVnHfWXzU0FRs=; b=Su1nAY1+/gfbWFTLl1/nMppPxNC3BFMbU+uhwFkRNqBOp/et9VcuoDDM1A1Sb7ofVH udKg991BKx6wbpWe5Hc9U+h4n9JNDmy6SU50xTJmZ5Kv4LNQTbjmfiNjSDrjAcnKvmE+ L3YWNcMzUI60bci/4HoUCHsmti1MfFndN/WGxS4iRsUG+Di0j2yUnPCIHj40uvLhDJ57 XxOr+J96Cxu79Yms4ciOdZHpnADrobeTVbmLc6MjXYeFrv7pUhpiXLprOQPW6+BVH8nV CyUPgMK9wrz4jlTTAaMmayzMfYIxn472JSN4lh+ldcNtRxZtC5zC47cLLt6MW/laUF9J HJKA== X-Forwarded-Encrypted: i=1; AJvYcCV8KXNOoNs8GA31FpTaN+TLkqrDaSqSYslKLw414+ufJMDSfyu+1UZO9bVn4tPwA/tT1dREe5Un1L72FQrM3pynjdIbjt1zEQvIltTa X-Gm-Message-State: AOJu0Yz8OL5WByIDXY3jf0Ewd3pJ4DgHey2vNck2ck5QS+IIxxSHHyG+ wa7/dnapQS1rPkNcQQ1rDKY2FG2YM5FBKgf6lfUWTc0c6+MDjiV040bP5eVnayk= X-Google-Smtp-Source: AGHT+IEvriP6sQBlcmr+Hy9a6IM5os+FLPMPiuFDW+kvAJIgTO/WULr1+E+BcVf2XnlMz5gB5u56TA== X-Received: by 2002:a05:651c:1254:b0:2d4:77c0:d61c with SMTP id h20-20020a05651c125400b002d477c0d61cmr8709506ljh.35.1713307547087; Tue, 16 Apr 2024 15:45:47 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id y1-20020a2e95c1000000b002d2d1c11703sm1704617ljh.76.2024.04.16.15.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:46 -0700 (PDT) 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 v5 14/16] media: i2c: ov4689: Implement manual color balance controls Date: Wed, 17 Apr 2024 01:45:22 +0300 Message-ID: <20240416224524.1511357-15-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 9419fc4de33e..81153b1a49a5 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 Tue Apr 16 22:45: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: 13632712 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 2DF1713D60A; Tue, 16 Apr 2024 22:45:50 +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=1713307552; cv=none; b=nESaffBT2PgOIBeRO5stXA3HbQPGG8Ppyjd4GYo5GmduXxlxZEbnwku/pi6LJ7L2aiJTRkyVbrWT7Ecib9e4s2+4Fa6T4ut99cbbAVJT3bfq69zqRgUdEmLcwZuGdo9MQe2GGE3Tx5/PMxJqMlODx+LXy3x3L0Jvdg+6hPcemZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307552; c=relaxed/simple; bh=sLICh8uWL/pFkYZmub7k1MwFmB7JItN36Hx/5frbUuU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=taX8UXIvXspKUShBOBivWNprbiZbN5xCN35VrUk8lRehqijdCMKqb/12hzB6FxdzueSrISoLRPtCCGvaAhA1YsxAktPqpGHupPJlOis3eaiRp+moSwaHXy0yvi1mCPYVJCX6WHmKq113mJtsy83sJkzQ6oacawVCI37WZNX0hgc= 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=amCj3tS8; 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="amCj3tS8" Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-516d6c1e238so5889630e87.2; Tue, 16 Apr 2024 15:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307549; x=1713912349; 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=QNrZ+v7tBZ68Mo8D5/6+veCro3vnKNVEByeT1M+GGEA=; b=amCj3tS87BvLGuDZC0e/eJQBGYFUraUT39hgbXAgRvNXCBLUrqcVIlhdeJHINXX/Gf kPk0NS6hBZ0NoDPT0sMyfPK3cMJp8TnhoWVXGhutiEFLsI6OjvhHskxQOXlhilYT96A1 GAPExUzKLW0p/7qN9ElAgATrQM93ocb/qlTNydbq/xm+4ZAFAFYVX9azShbZEWS6gWLT kHGBAW2WNR2eQA6UpcEjCtnVkVieOjpG95boRk0IPL4wt0B1fr3dlRovlZRl/fOT2P5e TOY4H3qCeFpeeibpmp8V79mxMX503KM3OSHMSWUXkevyPiQfUxDoMRwGZ8rqIOZsCR0M 3MEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307549; x=1713912349; 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=QNrZ+v7tBZ68Mo8D5/6+veCro3vnKNVEByeT1M+GGEA=; b=PNZDG/VQLEHTG0edjuaeSyfSjV/N535DD/9LJwnqtTwlxcWBmdkK2X9RSOGwQEcaxO uKRwlIQQ7TDPSS128xeqs4b3WjjyYHIqjvLVTWBfqkaM0K35gOnfiwqBztovQjP80k1E ettw+vFcRDyCX5ON7t5BCZucQKmvWzWHpHYpjSzP0EKOg1MjTF6J+sTlXjP3ap82N7at rvsZdhpDH9e1KJ0znqEAR2Dpjh8GIzb3BttuubPpX2U/z/Nhom4AO0mlBQ8mdpB0L6vU YiUXjsOKYFj0TrBIbB0MbRTbPmcUYl/xXI3LqbL39OgS+AuZc6zTycyQuUxdaTeL70bw ggOg== X-Forwarded-Encrypted: i=1; AJvYcCUwj8m06auq5OvfKQsQKZg38422+O/vJt+cSEZV8QhkvNjpi8OHsQmGrYk3TKE2w74BrmfjY4rr+mvr/vH67yipNhEJw4I7RFwERqQW X-Gm-Message-State: AOJu0Ywbw8uR6FX7vVEAOIPZOCa/ypofGMITcbXzEKiTFMY3/fxkc6SE 2ViTPwIOAnzyUuABG/FeZ6xEQ9+A7F/WeEzp3xXMPpUP6zGaMKFnXCcZe0YWxr8= X-Google-Smtp-Source: AGHT+IGymgJktXLd90G06oaSwmUX2LOPBgoVgIwP8g2xxsJea7dBlERLI7/P3Qk/sa0qrtFKfqjozw== X-Received: by 2002:ac2:410a:0:b0:515:bacd:adbf with SMTP id b10-20020ac2410a000000b00515bacdadbfmr8584259lfi.34.1713307548463; Tue, 16 Apr 2024 15:45:48 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id z18-20020a19f712000000b00518e3a194e9sm800817lfe.304.2024.04.16.15.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:47 -0700 (PDT) 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 , Kieran Bingham Subject: [PATCH v5 15/16] media: i2c: ov4689: Move pixel array size out of struct ov4689_mode Date: Wed, 17 Apr 2024 01:45:23 +0300 Message-ID: <20240416224524.1511357-16-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 81153b1a49a5..9da4f84e63b1 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 Tue Apr 16 22:45: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: 13632713 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 8E80A13E052; Tue, 16 Apr 2024 22:45:52 +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=1713307554; cv=none; b=qA4QdQGppCJgm4qKa53gCWbwQgnbCIJ6ATXI1GbfFNhPFNRY433bG/vPy6ENKzmnGg6ABpGMAHtzqDha/SoXjSaxY04T/EddL7xb1Thrbbn85oOJadC9Piou4vTXWCW/++pRMEhBlLPTR4oeWrqpN+aqQngF5SJSX9wPwSnoO5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713307554; c=relaxed/simple; bh=fpjcBYWKI7/oU2A5MYkdaQS7my7qviwEtb9hhcIwAKc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kxFeOUK0LI2KyhoKG3QJ3v57TWYnt7baleisRQUk2BIBnEO+8YdiTfU5wa2VX1vMnL5/nWmfFcXCMHUzwIZF7fDqBQt8AphX5HoCrQLAsb3KoyZz+kg130CrcUjCGxttzfj8U2aahlpaqRyesXs+DsgbvvNuEPnWCeWee4NReGc= 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=CJvw7l9U; 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="CJvw7l9U" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-518c9ff3e29so3592674e87.0; Tue, 16 Apr 2024 15:45:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713307550; x=1713912350; 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=6WTz6RxNbzEeUZHtBYgSuV5IA4nML2YqNqY1OSaSBE4=; b=CJvw7l9U/paOx4tnDJPccXphixbSR6aEJBRAVyGk/1xvedQ8uy3IX5ki1Btr++YISR NR+NeVWdxXxRGlRjAEn99Dwp1kYuR1QDIvzTE7Bq9EI277hn04bmx+gr85LsTB43+BdX LfsuK7ZFnt6UlQ3MO3wTl34CRWzFxISY9tZEojJaGs5oQBK9OTRoR91EsLRBYFIQ9EZ2 UqJ82uJr4jQxCeZwcDTaiKKu4G5qo4c8sjJwNq49SkBUhOd2g9ZR5KSPJe5G9Q+B2iuV CWd3qRpXP8xq72Xy6QOVkSD0afvr4I2QVirBadowiCj7gGv9KtmJ0zlw2ypFF8Ct/ZUV eo7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713307550; x=1713912350; 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=6WTz6RxNbzEeUZHtBYgSuV5IA4nML2YqNqY1OSaSBE4=; b=dfCZGpOzl6aZGQs0eLix1aqyFTuVllRvMJky037WxDZaCU7EUkm8zwsb6M7zyVL3fO XtM9VIsNuf4bOxjJSC4Vyc0GoD4qtvPgk4mDm002bZWB9mbIKTo3W6r544OJOuiYNllu p49L6G36AW0lecfGa1+WMJFLb7HO97S3BDXOOqR7dnP3cxq6Nmoa3Bg3uElL1GU81gNz sX/4FHf1d4bUebuszd9B3jNOIOoTb2Lhn7KdDpAiEL9+cuZSmf07W1QxzftOWxBysOyz jpIxjSTi46/HwOAjR3kH7qWTIKjASkKwjh+aFzA/lSXDl5q2Zu6mbfdSgV5Q1PxtcR+6 YX5Q== X-Forwarded-Encrypted: i=1; AJvYcCVm88chDLDbx4+/mCZbu8Us3l6VA6UkVccWJ8WMqa0mnFQrewDtdMxFdTcXQEWMq80vgmNH8LfJcfwMXCfOH81DpDnH5z2/eWSVa8hl X-Gm-Message-State: AOJu0YwANfmJkdjXuUn2+q8eNygeDlQzPyW7ahID2ZppRtgfMsItiGk4 1SUh+R8mBohpRgsLcrohvOwvOd13let4qB1NcD54xiShx2i03XE6DQm16BIhK1A= X-Google-Smtp-Source: AGHT+IFRQeiSrlNFBGze9bikBICwT+4Be4weNOJX+RPDCnHjz0mCwy8ltjNBBbW+oNSi07Q9ph7pYQ== X-Received: by 2002:a05:6512:3b98:b0:518:fb01:448e with SMTP id g24-20020a0565123b9800b00518fb01448emr4984114lfv.57.1713307549892; Tue, 16 Apr 2024 15:45:49 -0700 (PDT) Received: from localhost (95-24-153-47.broadband.corbina.ru. [95.24.153.47]) by smtp.gmail.com with ESMTPSA id eq9-20020a056512488900b00518c3eb3a9csm981831lfb.309.2024.04.16.15.45.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 15:45:49 -0700 (PDT) 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 v5 16/16] media: i2c: ov4689: Set timing registers programmatically Date: Wed, 17 Apr 2024 01:45:24 +0300 Message-ID: <20240416224524.1511357-17-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240416224524.1511357-1-mike.rudenko@gmail.com> References: <20240416224524.1511357-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 9da4f84e63b1..0c623d43c0ad 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) /* Vertical */ #define OV4689_REG_TIMING_FORMAT2 CCI_REG8(0x3821) /* Horizontal */ #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);