Received: by 2002:ac8:6d01:0:b0:423:7e07:f8e4 with SMTP id o1csp6899503qtt; Mon, 18 Dec 2023 09:42:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IHgx6u9lMyXOlKlisahHl7d0gO2/sTZmawX4Tv3+gZcbQ3BQS94r2A6LqjAPyRi+4V3tmBT X-Received: by 2002:a05:6a20:2590:b0:190:7d54:f0c4 with SMTP id k16-20020a056a20259000b001907d54f0c4mr21784794pzd.87.1702921378226; Mon, 18 Dec 2023 09:42:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702921378; cv=none; d=google.com; s=arc-20160816; b=0x7JL8TKJfY3QvdrocSir5Ga+M+2Qz8YbPuEKri3zQ3fuqvXMrFYJ/CI6Bg+KVtGvO AFJ1D0k9dScEXbE5vpAoUAvijTxqbXP4GA9H9k5CZU1Lrm0aB0kHXz4JkSkhBceOmgic l0tRVNlgcgUXQwffwoPxYSJIwMDo9+VVcav3XsetHRWMNAXuu56SGFMzX2obG7mX6oTA oVWqAEWCr76j467GNBguk7o8aquKPSaLl/zRzpysEXTsEqvicyxqMnlemJFYYHet81Yk uWdrQvQbZ2SFNUmtkOOLOh1pJG79rcEONeR30GD4F3EsZ04HipWVZjQej8GQt7HtrBu0 rRiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=b+z53GlwzR6CHam2mzBPbYh2yRBDEISJoZAlKq8qtpo=; fh=Ft8dYvEuFIKwnehVwpL0WG7QMIrRLMi0wgN4ll940k8=; b=s1iXK/0tTfiqeIfY3+mmpBFlI6vc+Yu2HvwhesTClbGmQ3egqMS7KdIrrV+wvY2RbI 3oNyLLN/WP2iF48J+eEd7jS6QiEclmLo/GvhOKumWy+rXtmV7T4b2+gHt6z8IywDk5QZ J/Inla+H1HAGWFOuOD2VxzIoxv6IL26NADl/BAtgXzi7mNRdrEQ6TjZbBecdftDk3MqG 5Zf5uOQGeH+qMiNVKeuIjyGVnzBgsWqRM8dLyKxv90ulYByScpFNDsG5JdNM5yZzp9WY QTUdemEEB7StEo61ihgo2c1uf4i7hGSbWnpCXJxVLCYgqlWHkAeDljzddOZwU5FGFrJ5 szXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gvU7vlFc; spf=pass (google.com: domain of linux-kernel+bounces-4188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m7-20020a635807000000b005c665c81b7bsi17767802pgb.36.2023.12.18.09.42.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:42:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gvU7vlFc; spf=pass (google.com: domain of linux-kernel+bounces-4188-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4188-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E7A82285358 for ; Mon, 18 Dec 2023 17:42:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 388C6740B4; Mon, 18 Dec 2023 17:41:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gvU7vlFc" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCBBC7146C; Mon, 18 Dec 2023 17:41:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-50e389473fcso1732812e87.2; Mon, 18 Dec 2023 09:41:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702921262; x=1703526062; 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=b+z53GlwzR6CHam2mzBPbYh2yRBDEISJoZAlKq8qtpo=; b=gvU7vlFc6ex3gCfccLU139DJI9hqOvbeUPCJqzm8DXgvzXYKA8S/DACjd10042LQiT ZEs6BZxZv27fLVmLBosaLaK5Ny13UDssrk3vnQzM97FLGpqfKqeGlT+01RqrIqO/JQs2 TuJU6bP20zibwJlEloPnkvfRIT4opiYXBpSJAqwzWHVVpwyckSe4O0TcnjqqcI+NixdU GXIxLXhvZgOShUCL7Al9o0TISnjXmWs/kT+xFEaPjsGqUysZznM4ku1IcpFCw9J5Ffkc ibU/8clfX7Xasdm0Dto3WlghzmKz9JkhWcfyzp+NPNNXvjoSo4hAKcHFV+CY4YCsJwLG ybJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702921262; x=1703526062; 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=b+z53GlwzR6CHam2mzBPbYh2yRBDEISJoZAlKq8qtpo=; b=Wcqgmn/kw4S3K5FTNQBIApAhp5sODdSPNciGV9m0GX1n64s5JKVx6n9VzdLYeTyAR4 XjShjNBEIngTeMrC/JpwqDIa1OC9zc0nZb4Bm+3NuechGjnGIYZqU1s16cs4xTuBge9o c40ZuKic2IcdfoIvCV1vvzCs+EvATKG9JDo4U0cfJntjkL1Kv54cHxyVrcMTwU+sxhLc nkEWfTSIXeWNodqIMvj5U7THHdFNsTJ/WMJTfxgOSHaeG4X5vhmTXIqtbJDX53Ptv3QZ eN5rdZXUy9iW/b7a4JGsoJiiIEgpXVxxtHzSbcGbayLSKmLlSdH2cay2nCQ1fVqM3Nzr bo8Q== X-Gm-Message-State: AOJu0YwKPHWP6rwCwx/YJJiKahJ+gnH2yKux29TgQBJwg7u3BKZIz5XP ywTA0jfuGgvIlp6dGldX3jUcGUbR9Bp7Fg== X-Received: by 2002:a05:6512:6c1:b0:50e:1f22:3110 with SMTP id u1-20020a05651206c100b0050e1f223110mr2838827lff.65.1702921261733; Mon, 18 Dec 2023 09:41:01 -0800 (PST) Received: from localhost ([83.149.246.185]) by smtp.gmail.com with ESMTPSA id c13-20020a056512104d00b0050e2036327esm907828lfb.252.2023.12.18.09.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:41:01 -0800 (PST) From: Mikhail Rudenko To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sakari Ailus , Laurent Pinchart , Jacopo Mondi , Tommaso Merciai , Christophe JAILLET , Dave Stevenson , Mauro Carvalho Chehab , Mikhail Rudenko Subject: [PATCH v2 04/20] media: i2c: ov4689: CCI conversion Date: Mon, 18 Dec 2023 20:40:25 +0300 Message-ID: <20231218174042.794012-5-mike.rudenko@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231218174042.794012-1-mike.rudenko@gmail.com> References: <20231218174042.794012-1-mike.rudenko@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 78a87331686e..b3153bb769b7 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -404,6 +404,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 7c33961fbb89..6ea1c37323d1 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)) { -- 2.43.0