Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp45132rdb; Thu, 25 Jan 2024 07:50:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+5l1H5ji+WYfrNOXKA7KADoBWniy2uszrXOH9hBVlbGqP3Wd7MfPEp9SzKGieVYfbMjOj X-Received: by 2002:a17:907:8743:b0:a31:2e35:2a5b with SMTP id qo3-20020a170907874300b00a312e352a5bmr563251ejc.120.1706197857318; Thu, 25 Jan 2024 07:50:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706197857; cv=pass; d=google.com; s=arc-20160816; b=PCdf3S8pPGD5Y40NR6jxp1sYDgTxaXwqiFCmmQtSzP99sJD3or8saSU+9FguZZm6/G Z3oArXwpkE7Kb3xfrAK+oR3iqmhzFNhC94DTtq6mpk/uGpz5cswwodRii5PI1mIw0ppj RBvJ0GkbOZ+rhqaaDNUlHxTF/E3HUULeYwMBI6c+XnfnhNg7YzptdKFup6VQxcTl47Mw VLZTD6Uro4luwBJZfzAePdmSNe6j4wq7cbe8xIyWjLP540NLQvMRNjtdWgieHrImOtGd T1OleqLQaWFzsZM21NGHQGHkoPZDcFkgiHd69y8YbtoRR6EM5hqxVbGJQgAutI8cgesZ V3BA== ARC-Message-Signature: i=2; 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=hOCUTUFWAycEpBXwmLXswqjh6f3cwYE4nuRtFQQPRAg=; fh=sm2MKrLKbZDLCL1DnC1zGAWx+IXS/LhgeDG/k75WZVg=; b=RWrAeQUVr+QU1L1ARDuEekxZO9gRtAPqUqfWcJa4yTK0hGKim7FInVDQJ2NOJjaSyJ dCwUaR7adZOyZx+fbHzljQ07qSvjIaftjujX/WpLNJRRadHASNAj5yL+tXTz2KXQmjGR PUB5eDZqnNLq41JovpHwRufeeE7Ol2/L4VddPwGVQFdr5GWCMLYnhQTUzEtWnOSfyo9F FgAYZDRcP00+PfWl/cCG198zLQ5jwe7ku+vFY5PCJgXhnOUVauPwOtrALbFFbUOeQQ3L M5FwEc6bRNHGkqEXHMXANZd5v0o1MbE/9Pu+XgJIR+8JZwb9u61s0iIPXnOyup83y+rv MjYw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=OZiRQtwq; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-38853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38853-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h26-20020a170906585a00b00a3074dbb4a1si1073859ejs.148.2024.01.25.07.50.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 07:50:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=OZiRQtwq; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-38853-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38853-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1871A1F26226 for ; Thu, 25 Jan 2024 15:50:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55D0B7CF37; Thu, 25 Jan 2024 15:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OZiRQtwq" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA6797A707; Thu, 25 Jan 2024 15:49:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706197776; cv=none; b=a658ZMYhoV4UP8AnCs/fKQ+HqmNcKCppKE9irFdizelDIP+s4+lO2jZLaBnm9ih84F+CSrMyxvaMUuONFNpkS4ox/Ihu6ySrl8xTc48h8sTE5NsFzygLv0QTzrkQvZEvXfVMm6KIAEkl9arwv75gACykiuukflz4KxB8dD2QRrA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706197776; c=relaxed/simple; bh=W1Z5z7CyCm6OJIhlRbgJ7qn8gVztgK3gJEzxblTd6J0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i/R976hNReNV8NH/tN61XCIgHIj/63aDxjx8P2GIp92Jy6Tt0pJkymfG+11FiLiR/acS/+AQFkfBaOOPZEPhysg+JWabCuhc02fVRgndCBY44KD6dbjn5mEjsnY9wV30sSsEg9ER1qb+C/7u93oE3aEIgCVQ4kPMrg5rG8/le34= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=OZiRQtwq; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from umang.jain (unknown [103.86.18.175]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B760951A6; Thu, 25 Jan 2024 16:48:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1706197695; bh=W1Z5z7CyCm6OJIhlRbgJ7qn8gVztgK3gJEzxblTd6J0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OZiRQtwqP73QFH7tCmGmTedDWV1o1yIGO/87wKQ3AgVVk2nCEmP8YoZURugOc0zTa b1+Y+pItMc1UrCvsmQd5mcp1AcyfT/FW6Z12Mf5LKzCjVeI9VNvhOkInPCZ1xJzXeD PZTdq7DD3jacYG180ySdXqbm9iSs1ZgHB/WqhXjs= From: Umang Jain To: linux-media@vger.kernel.org Cc: Kieran Bingham , Mauro Carvalho Chehab , open list , Sakari Ailus , Matthias Fend , Umang Jain Subject: [PATCH 4/4] media: i2c: imx335: Add support for test pattern generator Date: Thu, 25 Jan 2024 21:19:08 +0530 Message-ID: <20240125154908.465191-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240125154908.465191-1-umang.jain@ideasonboard.com> References: <20240125154908.465191-1-umang.jain@ideasonboard.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 From: Matthias Fend Add support for the sensor's test pattern generator. Signed-off-by: Matthias Fend Signed-off-by: Kieran Bingham Signed-off-by: Umang Jain --- drivers/media/i2c/imx335.c | 99 +++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index e64ee99cbae4..f9a2337a80c0 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -45,6 +45,21 @@ /* Group hold register */ #define IMX335_REG_HOLD 0x3001 +/* Test pattern generator */ +#define IMX335_REG_TPG 0x329e +#define IMX335_TPG_ALL_000 0 +#define IMX335_TPG_ALL_FFF 1 +#define IMX335_TPG_ALL_555 2 +#define IMX335_TPG_ALL_AAA 3 +#define IMX335_TPG_TOG_555_AAA 4 +#define IMX335_TPG_TOG_AAA_555 5 +#define IMX335_TPG_TOG_000_555 6 +#define IMX335_TPG_TOG_555_000 7 +#define IMX335_TPG_TOG_000_FFF 8 +#define IMX335_TPG_TOG_FFF_000 9 +#define IMX335_TPG_H_COLOR_BARS 10 +#define IMX335_TPG_V_COLOR_BARS 11 + /* Input clock rate */ #define IMX335_INCLK_RATE 24000000 @@ -162,6 +177,38 @@ struct imx335 { }; +static const char * const imx335_tpg_menu[] = { + "Disabled", + "All 000h", + "All FFFh", + "All 555h", + "All AAAh", + "Toggle 555/AAAh", + "Toggle AAA/555h", + "Toggle 000/555h", + "Toggle 555/000h", + "Toggle 000/FFFh", + "Toggle FFF/000h", + "Horizontal color bars", + "Vertical color bars", +}; + +static const int imx335_tpg_val[] = { + IMX335_TPG_ALL_000, + IMX335_TPG_ALL_000, + IMX335_TPG_ALL_FFF, + IMX335_TPG_ALL_555, + IMX335_TPG_ALL_AAA, + IMX335_TPG_TOG_555_AAA, + IMX335_TPG_TOG_AAA_555, + IMX335_TPG_TOG_000_555, + IMX335_TPG_TOG_555_000, + IMX335_TPG_TOG_000_FFF, + IMX335_TPG_TOG_FFF_000, + IMX335_TPG_H_COLOR_BARS, + IMX335_TPG_V_COLOR_BARS, +}; + /* Sensor mode registers */ static const struct imx335_reg mode_2592x1940_regs[] = { {0x3000, 0x01}, @@ -505,6 +552,46 @@ static int imx335_update_exp_gain(struct imx335 *imx335, u32 exposure, u32 gain) return ret; } +static int imx335_update_test_pattern(struct imx335 *imx335, u32 pattern_index) +{ + int ret; + + if (pattern_index >= ARRAY_SIZE(imx335_tpg_val)) + return -EINVAL; + + if (pattern_index) { + const struct imx335_reg tpg_enable_regs[] = { + { 0x3148, 0x10 }, + { 0x3280, 0x00 }, + { 0x329c, 0x01 }, + { 0x32a0, 0x11 }, + { 0x3302, 0x00 }, + { 0x3303, 0x00 }, + { 0x336c, 0x00 }, + }; + + ret = imx335_write_reg(imx335, IMX335_REG_TPG, 1, imx335_tpg_val[pattern_index]); + if (ret) + return ret; + + ret = imx335_write_regs(imx335, tpg_enable_regs, ARRAY_SIZE(tpg_enable_regs)); + } else { + const struct imx335_reg tpg_disable_regs[] = { + { 0x3148, 0x00 }, + { 0x3280, 0x01 }, + { 0x329c, 0x00 }, + { 0x32a0, 0x10 }, + { 0x3302, 0x32 }, + { 0x3303, 0x00 }, + { 0x336c, 0x01 }, + }; + + ret = imx335_write_regs(imx335, tpg_disable_regs, ARRAY_SIZE(tpg_disable_regs)); + } + + return ret; +} + /** * imx335_set_ctrl() - Set subdevice control * @ctrl: pointer to v4l2_ctrl structure @@ -558,6 +645,10 @@ static int imx335_set_ctrl(struct v4l2_ctrl *ctrl) ret = imx335_update_exp_gain(imx335, exposure, analog_gain); + break; + case V4L2_CID_TEST_PATTERN: + ret = imx335_update_test_pattern(imx335, ctrl->val); + break; default: dev_err(imx335->dev, "Invalid control %d\n", ctrl->id); @@ -1122,7 +1213,7 @@ static int imx335_init_controls(struct imx335 *imx335) u32 lpfr; int ret; - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 6); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 7); if (ret) return ret; @@ -1156,6 +1247,12 @@ static int imx335_init_controls(struct imx335 *imx335) mode->vblank_max, 1, mode->vblank); + v4l2_ctrl_new_std_menu_items(ctrl_hdlr, + &imx335_ctrl_ops, + V4L2_CID_TEST_PATTERN, + ARRAY_SIZE(imx335_tpg_menu) - 1, + 0, 0, imx335_tpg_menu); + /* Read only controls */ imx335->pclk_ctrl = v4l2_ctrl_new_std(ctrl_hdlr, &imx335_ctrl_ops, -- 2.41.0