From patchwork Fri Feb 3 19:17:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89581 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1Zr-00EtlH-Cc; Fri, 03 Feb 2023 19:18:30 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233571AbjBCTSZ (ORCPT + 1 other); Fri, 3 Feb 2023 14:18:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231614AbjBCTSY (ORCPT ); Fri, 3 Feb 2023 14:18:24 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B728B70D58 for ; Fri, 3 Feb 2023 11:18:23 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id ba1so1478963wrb.5 for ; Fri, 03 Feb 2023 11:18:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=iV7cEjOEkCBAw9kSdJEJORaQ2AZ3g69IwUjmjoQIzkE=; b=ih2jRgx4T5ZOiFGruZGGdqMrG/RloIEykbs6wirs5zMOHbkVjtKIuFonnxACKvxVaB F0wAVreP7B6T0sOERQapHwHtvbomsw81FPdCg1PJe1CW9hy2IxUJrqVfy4Hw7d+84zx7 CD49i892o40lp2RVIutK6+rx7CZtRTCwZkoq6de2bJflAn5XlaCsXvE08PD61jj/hoyy pIAVwzRukSGetvwaRad65DWFmMVQH+1jWUTn6QBjK4QHT5q2l0/OO1yIiWWGT5UZdc9a A56LjmrxC+6nxG4o0VtC+NJVkOBQgFERrW21n/kP5ZwXJVPCnNgtZw5VQYgHbm33JpE5 Vbcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=iV7cEjOEkCBAw9kSdJEJORaQ2AZ3g69IwUjmjoQIzkE=; b=qRHfuMxjaCFIwi3rFc2rzQilmTlD4i/mip4xN3mr0r2lVIcm2KqmzPZs1h2fbc7s/k sxlFxQoMZhEoFESC4damllY2ZgLszYJsuky3YKmvck+cz6oRJCIs/MWj5IJR+H+9ITzZ fT2eCZSIsbpg9SALKwx0UxgGEV/1jBkEGRhgSqhUFE+1ELiJWVq4ciJxCUdlQ2b9fQph LhK4RcvRzY/qetNYJ/lmBmOeZhY79N2MuPgrIoqISFnUnoboqJMfgeDexQSanesCR4F8 yfZ6hPQ9e2lBB/9kuf4tZUAuXiidmc1C4+0VMGuuiDNWYwfOn1MG+9CWZ8OhnIy4wU1m Liwg== X-Gm-Message-State: AO0yUKW9VC9R5jIS1VmZYHJ8qrAefgZqjpo6+AcEvVke1ysOL7ZMrW7h sQJI1AvY2mhy2hFgrdqIIfk+IQ== X-Google-Smtp-Source: AK7set96YFTahWD7IwvFH8xVBIuupaOE1l6FzODMjI+oDGLa+ZwGrXs7+pvexv0lH2GK4TnrjRzIIg== X-Received: by 2002:adf:c60b:0:b0:2bd:c1de:a33f with SMTP id n11-20020adfc60b000000b002bdc1dea33fmr9700335wrg.19.1675451902287; Fri, 03 Feb 2023 11:18:22 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:20 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 01/13] media: i2c: imx290: Match kernel coding style on whitespace Date: Fri, 3 Feb 2023 19:17:59 +0000 Message-Id: <20230203191811.947697-2-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no Fix up a couple of coding style issues regarding missing blank lines after declarations, double blank lines, and incorrect indentation. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx290.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 9ce839541926..22d6194678bc 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -106,7 +106,6 @@ #define IMX290_VMAX_DEFAULT 1125 - /* * The IMX290 pixel array is organized as follows: * @@ -350,6 +349,7 @@ static const s64 imx290_link_freq_2lanes[] = { [FREQ_INDEX_1080P] = 445500000, [FREQ_INDEX_720P] = 297000000, }; + static const s64 imx290_link_freq_4lanes[] = { [FREQ_INDEX_1080P] = 222750000, [FREQ_INDEX_720P] = 148500000, @@ -485,7 +485,7 @@ static int __always_unused imx290_read(struct imx290 *imx290, u32 addr, u32 *val data, (addr >> IMX290_REG_SIZE_SHIFT) & 3); if (ret < 0) { dev_err(imx290->dev, "%u-bit read from 0x%04x failed: %d\n", - ((addr >> IMX290_REG_SIZE_SHIFT) & 3) * 8, + ((addr >> IMX290_REG_SIZE_SHIFT) & 3) * 8, addr & IMX290_REG_ADDR_MASK, ret); return ret; } @@ -506,7 +506,7 @@ static int imx290_write(struct imx290 *imx290, u32 addr, u32 value, int *err) data, (addr >> IMX290_REG_SIZE_SHIFT) & 3); if (ret < 0) { dev_err(imx290->dev, "%u-bit write to 0x%04x failed: %d\n", - ((addr >> IMX290_REG_SIZE_SHIFT) & 3) * 8, + ((addr >> IMX290_REG_SIZE_SHIFT) & 3) * 8, addr & IMX290_REG_ADDR_MASK, ret); if (err) *err = ret; @@ -772,8 +772,7 @@ static int imx290_start_streaming(struct imx290 *imx290, /* Set init register settings */ ret = imx290_set_register_array(imx290, imx290_global_init_settings, - ARRAY_SIZE( - imx290_global_init_settings)); + ARRAY_SIZE(imx290_global_init_settings)); if (ret < 0) { dev_err(imx290->dev, "Could not set init registers\n"); return ret; From patchwork Fri Feb 3 19:18:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89582 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1Zu-00EtlH-Kl; Fri, 03 Feb 2023 19:18:30 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233572AbjBCTS0 (ORCPT + 1 other); Fri, 3 Feb 2023 14:18:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232893AbjBCTSZ (ORCPT ); Fri, 3 Feb 2023 14:18:25 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FF1A761C5 for ; Fri, 3 Feb 2023 11:18:24 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id q5so5591097wrv.0 for ; Fri, 03 Feb 2023 11:18:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=pq7cAaa5YCWtfkDJToG1qTV8iLIyoimpB23UZGTLuXc=; b=IZnF0SrODwfywIkfuchzl16TIDllOtZoa9GLftOph85xBBK05oJylmGt2LrgZrWttB golBnoHAQN6EmgTnf8om810o3CoaZd6ZVlUb5PV8f9idE61Zw48HACCCId/hbyMeU9N7 TIImWqTXUXcFl7hVeCxyRJyslRXIHM/o5vnswpCK0Falssz5NVV9HZU5YrGC1PQF7uQ1 m4HdjOYvw08ojOS1IZKsTyAvoIgr58S7TD/2xF6WdKHLVc7RjZuKZROTMK5Fweq8rhBv CkNBwbIWi6X2bf8RFwF3Mn7HdbC9VD0xIXS09j1eTIaSO2v3pBVnqxIzkDZ94YRUD6K8 p6Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=pq7cAaa5YCWtfkDJToG1qTV8iLIyoimpB23UZGTLuXc=; b=Ohad3bKbT876xhlvZYyWAMOJNcIpWejzMQZ5P3ITnAlCtqEnv7eS9pXcdVuX8vtQgb ZmWGgXzS2AXWq3v9095XBmBfJgp575tzXoEzmNHYtB4eC2T80yYylKtJSEHPUoGKO8GD Gt3oy9xv2dFh8AENv0Re97aSM42bRxFOHjtYIsROLAZeLfLkv+qToZHULPX2eIbM5OIf mXF1hZ+0qClfe6qXwZQHLdVLEItH2QGA+jag4Vr1utb7SEIS+hWgzUkXSrdd40yEgW2/ p+e21nCQCKQnS0tWY5FGNPcEyT+zklUuFVlNBTt9tDe4H+bq24eTo5o6lCfFdtGZ3XLc j31w== X-Gm-Message-State: AO0yUKV4U0lJY8Ot8NTwnUu4JBMZQxLui5SuEtg1SuAHHzwSyHYxI71i smdAsQBclgj51TJR9wNm/9N7vg== X-Google-Smtp-Source: AK7set9+VOaNG4NK6/2AFJVfKjk81f07uoxurQKj+uczrCOVKqwyQTRdAtJ3evshMlQiyGG9bOgeCw== X-Received: by 2002:adf:fb92:0:b0:2c2:de2b:e7cc with SMTP id a18-20020adffb92000000b002c2de2be7ccmr9155108wrr.40.1675451903090; Fri, 03 Feb 2023 11:18:23 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:22 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 02/13] media: i2c: imx290: Set the colorspace fields in the format Date: Fri, 3 Feb 2023 19:18:00 +0000 Message-Id: <20230203191811.947697-3-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no The colorspace fields were left untouched in imx290_set_fmt which lead to a v4l2-compliance failure. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx290.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 22d6194678bc..827c0804792f 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -917,6 +917,10 @@ static int imx290_set_fmt(struct v4l2_subdev *sd, fmt->format.code = imx290_formats[0].code[imx290->model->colour_variant]; fmt->format.field = V4L2_FIELD_NONE; + fmt->format.colorspace = V4L2_COLORSPACE_RAW; + fmt->format.ycbcr_enc = V4L2_YCBCR_ENC_601; + fmt->format.quantization = V4L2_QUANTIZATION_FULL_RANGE; + fmt->format.xfer_func = V4L2_XFER_FUNC_NONE; format = v4l2_subdev_get_pad_format(sd, sd_state, 0); From patchwork Fri Feb 3 19:18:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89583 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1Zz-00EtlH-Kx; Fri, 03 Feb 2023 19:18:35 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233576AbjBCTSe (ORCPT + 1 other); Fri, 3 Feb 2023 14:18:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232448AbjBCTSd (ORCPT ); Fri, 3 Feb 2023 14:18:33 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0898371985 for ; Fri, 3 Feb 2023 11:18:32 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id a2so5267156wrd.6 for ; Fri, 03 Feb 2023 11:18:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=U6/i585QuyYiT5AbB1cETNkPYf1BhpBh6CXnJ02051s=; b=QJB/VvJYX7e7y7n3xvXNg7zRrnK3hv5FoecfWSMKXdg3G+qGHxtvzmuDObYhWRiFpg 8JDiToRJOACGJuecJMAICFYBFxx3Y5FqS3FSXLAln/oHrjim8AnEnF6XkoBFhbCKm9bp bFp8eNYaBrc4RNaEGvSsbEbLuMJghRHsnXYbqMlC/kyqOCyj1OVUW7fuM3lesL5LgYBr dnYv6Gg92qTu5nvNYcunMo4B6isI+GbdnB15NKlC++m5fmbMMov2/dbVSn6DcSv/wymL JSsGlHQS1TDN7LD7vdNfJZxuvN6uMlZFMgjR+PWJXSlFcOz0IBtQm/nctmdcn2xY0b8Y xlmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=U6/i585QuyYiT5AbB1cETNkPYf1BhpBh6CXnJ02051s=; b=Qop5zfuOR5MvKvDdiaJlGaokLe5Gm3B8/ImTHTFDbY0NyyObVgSK9aB5RAgOw2zEr4 +Csms+P4KHWYs7E8B5ZQ17P4CoPmbkwOU5vpBh7KpSuyCk4yFcS95gD7OYpo0tG+vnKp kDNoKshgBmW3ZT9lLWOSJrG0QVJuHYmNqeHy8nAC4P7D+awi+THaUFzgQlV0KwTrdHrY n7f1A2HTWHl9GD+hs3SMJGogck4Qll8JJKeZ6HCmWaRc5ld0r8hXQk+4lw4vIuRnvFgh JTzpa7P7GMFzLxwN5x00zcEd5zcQzd/A683JvDPOfpJ7xtZNqUiDrgHH+nQvN8CWM1Hs FPKg== X-Gm-Message-State: AO0yUKUXm6IS2O/eSAJ+hiNYnF+RLLgA4vvbKcWuymeSb8Y26Rb45ezR dw/LMY5RIg1XvN7IsgO/um1gXQ== X-Google-Smtp-Source: AK7set+w7YVquF3njKgZ2Djh0iZxcCw437cyZ9nyNz69iIALE4jRMNw5f0p68EemiqeVnQfNlqSwUw== X-Received: by 2002:adf:e0c3:0:b0:2c3:d808:e82f with SMTP id m3-20020adfe0c3000000b002c3d808e82fmr2837948wri.17.1675451910539; Fri, 03 Feb 2023 11:18:30 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:23 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 03/13] media: i2c: imx290: Add V4L2_SUBDEV_FL_HAS_EVENTS and subscribe hooks Date: Fri, 3 Feb 2023 19:18:01 +0000 Message-Id: <20230203191811.947697-4-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no Any V4L2 subdevice that implements controls and declares V4L2_SUBDEV_FL_HAS_DEVNODE should also declare V4L2_SUBDEV_FL_HAS_EVENTS and implement subscribe_event and unsubscribe_event hooks. This driver didn't and would therefore fail v4l2-compliance testing. Add the relevant hooks. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart Reviewed-by: Alexander Stein --- drivers/media/i2c/imx290.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 827c0804792f..22faa9b54810 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -993,6 +994,11 @@ static int imx290_entity_init_cfg(struct v4l2_subdev *subdev, return 0; } +static const struct v4l2_subdev_core_ops imx290_core_ops = { + .subscribe_event = v4l2_ctrl_subdev_subscribe_event, + .unsubscribe_event = v4l2_event_subdev_unsubscribe, +}; + static const struct v4l2_subdev_video_ops imx290_video_ops = { .s_stream = imx290_set_stream, }; @@ -1007,6 +1013,7 @@ static const struct v4l2_subdev_pad_ops imx290_pad_ops = { }; static const struct v4l2_subdev_ops imx290_subdev_ops = { + .core = &imx290_core_ops, .video = &imx290_video_ops, .pad = &imx290_pad_ops, }; @@ -1025,7 +1032,8 @@ static int imx290_subdev_init(struct imx290 *imx290) imx290->current_mode = &imx290_modes_ptr(imx290)[0]; v4l2_i2c_subdev_init(&imx290->sd, client, &imx290_subdev_ops); - imx290->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + imx290->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE | + V4L2_SUBDEV_FL_HAS_EVENTS; imx290->sd.dev = imx290->dev; imx290->sd.entity.ops = &imx290_subdev_entity_ops; imx290->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; From patchwork Fri Feb 3 19:18:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89584 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1a0-00EtlH-SP; Fri, 03 Feb 2023 19:18:37 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231511AbjBCTSf (ORCPT + 1 other); Fri, 3 Feb 2023 14:18:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233573AbjBCTSe (ORCPT ); Fri, 3 Feb 2023 14:18:34 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB7D470D58 for ; Fri, 3 Feb 2023 11:18:32 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id c4-20020a1c3504000000b003d9e2f72093so6723651wma.1 for ; Fri, 03 Feb 2023 11:18:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=Z+tArQniRx14r7yZucrdT8fDuMw1hl5b1bA0Bop/kfs=; b=rXQ+HqLSAHgdTyoTyzAIRGN3QBiXasGVNpim/TTzwIjaCxV1oJU0HEoVM2h+mVkUAD LZG935MprevD0xaexjLE2lM+owZGKE8soUNbnBP2dVYYQI76Q7PnUZBnablSWSxDTgZQ /i7lq0FmeBAKGlFq37baa5zrYULYJD83NGqVXTtemxnaixUt+YjfCXHSBecEw0wE5T0n 6QbhuMnILmYYLXqY8quR2m8KnTIuH5SoebBjXdxR3WuwtFx1RcoIbynk4Efj6XTjNKKx 8W/dfFBCgOCHz+/BS8O2dJJN+I0w6x/wHZwGjn2mj/bdUIuq64fOGiDFwYhwcoh5rjir sPRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Z+tArQniRx14r7yZucrdT8fDuMw1hl5b1bA0Bop/kfs=; b=TY7VHnwiW2LX7KhfnLf4cFmWKPpkOts955fs7ah8xHdoXiZWQKRfFk6WpQtTEWnLZT 7tc7qXtdKwKVeIAQukFAzFMmku92Wyo6sziT1wCtPWtGRaJ5MslKIMRTlglTUsG8CyUz QVPHd4xXEIPyusiEintcYdXpICXzixTSDj4e8I2Yo6Ia3gWdd6M4gYvjKOGFxWMMtI2x xNYOWHA8CcyUeidDUsUzJRqRrh8gYym/l3IXwTTIpjipHhJpptBj584zIB5sWKB9DUUI NfmqRSzt7TqfNyT5RKd4FKIiE3nX/VsVprk+sO8VgVT2+JdCK57oKXIkIOu7y32ALeRa kB+g== X-Gm-Message-State: AO0yUKW4bgGTTboH8ouDbVCwTnpD/5ibgfTEOpw7YmmGgbvmMQzFGVx6 y+ctRrjkmtHfT/l+JcxlpSgwr9TSrlxJuciY X-Google-Smtp-Source: AK7set8Scy9tPpUQmTl+YbaK9jOxDr/wXlDvwN4X2wiCM/MWfGzNNuOqfmBQN7bPUaSP1kkSQDYJ1A== X-Received: by 2002:a05:600c:3b1c:b0:3dc:443e:420e with SMTP id m28-20020a05600c3b1c00b003dc443e420emr10304799wms.2.1675451911482; Fri, 03 Feb 2023 11:18:31 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:31 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 04/13] media: i2c: imx290: Fix the pixel rate at 148.5Mpix/s Date: Fri, 3 Feb 2023 19:18:02 +0000 Message-Id: <20230203191811.947697-5-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no The datasheet lists the link frequency changes between 1080p and 720p modes. This is correct that the link frequency changes as measured on an oscilloscope. Link frequency is not necessarily the same as pixel rate. The datasheet gives standard configurations for 1080p and 720p modes at a number of frame rates. Looking at the 1080p mode it gives: HMAX = 0x898 = 2200 VMAX = 0x465 = 1125 2200 * 1125 * 60fps = 148.5MPix/s Looking at the 720p mode it gives: HMAX = 0xce4 = 3300 VMAX = 0x2ee = 750 3300 * 750 * 60fps = 148.5Mpix/s This driver currently scales the pixel rate proportionally to the link frequency, however the above shows that this is not the correct thing to do, and currently all frame rate and exposure calculations give incorrect results. Correctly report the pixel rate as being 148.5MPix/s under any mode. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx290.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 22faa9b54810..e83c458c7cf8 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -107,6 +107,8 @@ #define IMX290_VMAX_DEFAULT 1125 +#define IMX290_PIXEL_RATE 148500000 + /* * The IMX290 pixel array is organized as follows: * @@ -205,7 +207,6 @@ struct imx290 { struct v4l2_ctrl_handler ctrls; struct v4l2_ctrl *link_freq; - struct v4l2_ctrl *pixel_rate; struct v4l2_ctrl *hblank; struct v4l2_ctrl *vblank; }; @@ -669,15 +670,8 @@ static void imx290_ctrl_update(struct imx290 *imx290, { unsigned int hblank = mode->hmax - mode->width; unsigned int vblank = IMX290_VMAX_DEFAULT - mode->height; - s64 link_freq = imx290_link_freqs_ptr(imx290)[mode->link_freq_index]; - u64 pixel_rate; - - /* pixel rate = link_freq * 2 * nr_of_lanes / bits_per_sample */ - pixel_rate = link_freq * 2 * imx290->nlanes; - do_div(pixel_rate, imx290_format_info(format->code)->bpp); __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index); - __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate, pixel_rate); __v4l2_ctrl_modify_range(imx290->hblank, hblank, hblank, 1, hblank); __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank, 1, vblank); @@ -727,9 +721,9 @@ static int imx290_ctrl_init(struct imx290 *imx290) if (imx290->link_freq) imx290->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; - imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, - V4L2_CID_PIXEL_RATE, - 1, INT_MAX, 1, 1); + v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_PIXEL_RATE, + IMX290_PIXEL_RATE, IMX290_PIXEL_RATE, 1, + IMX290_PIXEL_RATE); v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_TEST_PATTERN, From patchwork Fri Feb 3 19:18:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89585 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1a8-00EtoR-4I; Fri, 03 Feb 2023 19:18:45 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233657AbjBCTSj (ORCPT + 1 other); Fri, 3 Feb 2023 14:18:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233583AbjBCTSh (ORCPT ); Fri, 3 Feb 2023 14:18:37 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DD2D80171 for ; Fri, 3 Feb 2023 11:18:36 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id bk16so5524688wrb.11 for ; Fri, 03 Feb 2023 11:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=Js11dA2ey08Ky6H5UqdPTtHT+g2+2gxctpS4sG1t1Pw=; b=E74GmhOa9bKNaN1EQdlLjl8UvbkcYeLI7L6Pp77OfWh8Ik5AeFqbtwR7vyzXM6YLZx KqJa6CYW9GPn3Wf39L7bxv8joPg19w+cfl8ShrN6ExVR5/lh3I0rb5mIV19obcUyeoFi ZWf85L9l3aRHfj4cNN1Iyd8gMWhHSlkd+syzgNxDaNHQXKxOjYp7Nm05FynDK8WY1wZt OYwoYBpNTyFFgMy57F26DqplvQN5QGd7IRzaahxZQNceTFL+AW/3ubkkwBMQ+U/4Sb+Z MBLE99WaBmV9R3NMOkR4BkrXrezhcowAyJlCTzccC93SowtgIa6E73mySexPpXVVqX1c gXYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Js11dA2ey08Ky6H5UqdPTtHT+g2+2gxctpS4sG1t1Pw=; b=Q2AufXLKnA83H69FgV/ZtoFN6Ez7RFLLiLasgn4xuPY0up1HfPRkcDCu3wV8vSi5aM 9vlfmL0fzIBQ7lm2yqzV9gN+oLxFKT/MyPMshYNLrawIg4905JABVn+qPrB3+eAhmivT l9OZKBWkC9XcXMNt1v8E4+ex7cNXqS5vQW/fhDpXBuOFjJ846kMs2wRRh5d29garj937 exG8Dy58U9Jkn7jnJKcyoHDCHhTnwO6Km+VGLdQ6zaCleAntcUjzKQMMiUj4uQ52ChUq kI5zN8JFzkAM8Cmio8f9Umw4PQqC5ULByaNzJ2VNJ3yztHLbBZhjv2gWjn6ZyhKwiny2 +b1Q== X-Gm-Message-State: AO0yUKXAybSl/ML+YOVlxrCNe372FbRCJH7eiRh9RTICvPbJ6MA99q+Z UccM7DFjGSEuj3FhrR/hupT4Zw== X-Google-Smtp-Source: AK7set9uqzEabXtLcIEz9GFFNKkQukI5PvbSphuI+yXcAH93WY7MFW1itr9wmThiBo9Y7GP4Q6OFhw== X-Received: by 2002:a5d:4b06:0:b0:2bf:bfc6:4358 with SMTP id v6-20020a5d4b06000000b002bfbfc64358mr8965468wrq.57.1675451914912; Fri, 03 Feb 2023 11:18:34 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:32 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 05/13] media: i2c: imx290: Support 60fps in 2 lane operation Date: Fri, 3 Feb 2023 19:18:03 +0000 Message-Id: <20230203191811.947697-6-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no Commit "97589ad61c73 media: i2c: imx290: Add support for 2 data lanes" added support for running in two lane mode (instead of 4), but without changing the link frequency that resulted in a max of 30fps. Commit "98e0500eadb7 media: i2c: imx290: Add configurable link frequency and pixel rate" then doubled the link frequency when in 2 lane mode, but didn't undo the correction for running at only 30fps, just extending horizontal blanking instead. Remove the 30fps limit on 2 lane by correcting the register config in accordance with the datasheet for 60fps operation over 2 lanes. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart Reviewed-by: Alexander Stein --- drivers/media/i2c/imx290.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index e83c458c7cf8..a5ea59353a4d 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -382,7 +382,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { { .width = 1920, .height = 1080, - .hmax = 4400, + .hmax = 2200, .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), @@ -390,7 +390,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { { .width = 1280, .height = 720, - .hmax = 6600, + .hmax = 3300, .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), @@ -539,21 +539,10 @@ static int imx290_set_register_array(struct imx290 *imx290, static int imx290_set_data_lanes(struct imx290 *imx290) { int ret = 0; - u32 frsel; - - switch (imx290->nlanes) { - case 2: - default: - frsel = 0x02; - break; - case 4: - frsel = 0x01; - break; - } imx290_write(imx290, IMX290_PHY_LANE_NUM, imx290->nlanes - 1, &ret); imx290_write(imx290, IMX290_CSI_LANE_MODE, imx290->nlanes - 1, &ret); - imx290_write(imx290, IMX290_FR_FDG_SEL, frsel, &ret); + imx290_write(imx290, IMX290_FR_FDG_SEL, 0x01, &ret); return ret; } From patchwork Fri Feb 3 19:18:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89587 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1aB-00EtoR-92; Fri, 03 Feb 2023 19:18:48 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233065AbjBCTSo (ORCPT + 1 other); Fri, 3 Feb 2023 14:18:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233647AbjBCTSi (ORCPT ); Fri, 3 Feb 2023 14:18:38 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 674D111F for ; Fri, 3 Feb 2023 11:18:37 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id j25so2007571wrc.4 for ; Fri, 03 Feb 2023 11:18:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=ED04Jjib0S5Ccnml5lJKy3n+5EcEHVxL34La+9RfJEo=; b=QGTmLXsiPq/GGtJQwvNb5v+C23EpWU8yHJXaXO2e5pm2RYqKiM7z+IUV59Yl8TI16c HMtVk68+Dios/iz3YcQBpLeT49XyJ0cPGYN2cWGNIKOqoibRgFXWq+YebBZrRXOG641a xyXuHUheJ798VRnDq4ZXVL55N/4VwBqv58OVl6jg1qKT1tCyE8XKjPnbXaSybzyvS5Md GsTspbI+WgsHS7EvYucaxyni5I1X/q8OjNcp/oJHhvDYqsqRQ46rdptsdQrJa8wGe6Kf KEB4QYYab+lFJaTH7ZV2NgGvTmtQw+/hGmdToso3CaehV4Cbcl4ifF0AoAgFSmIfJI50 DUJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ED04Jjib0S5Ccnml5lJKy3n+5EcEHVxL34La+9RfJEo=; b=V0Ibl1llC9j/wBj9EOY8dVK3TMUKQsL90UfQDEE0KGxUz2/Xwvi3CCY7sBzdv3R/Nm HvQTKXIV6BYH9drMuzb+4MrHNntuRIHcqtr6vl/i9gOJG4fjpWAe8dZoA8D25Psb9G1K C/LZqlxWJD+syO259m4Bso+DZLTVksSc9+Etq/KPHqFlK+Ash+761YAIc2YP2HUCtWRZ PU34aVupvchtVaEf3bv4PFglNrHYucLYBszTwmaJqG0P63Nv0lLg3IvlydQOv0ueHwnI 7q+j5/hMofKLboCRLLfgUq4BKkHOwzYA852yJQ5Kg4uHThyP3COw4jrCIaSV+XYNGc5y dKkg== X-Gm-Message-State: AO0yUKVYq2AB2NwIPR2gfdrPKUo0A2Qf6R3QOT78a9yU9H4hTIgVREth e8LM8cmcCynFiYtN/LpNS7VSyA== X-Google-Smtp-Source: AK7set8vNoag6Ohzb/qiDqbtfdCysN48f8xIqNDhefgtPo2IA+RtuCLEQQyXu4+UbEqn8d5bz3Ibig== X-Received: by 2002:a05:6000:1376:b0:2bf:d937:3589 with SMTP id q22-20020a056000137600b002bfd9373589mr3933327wrz.14.1675451915996; Fri, 03 Feb 2023 11:18:35 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:35 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 06/13] media: i2c: imx290: Use CSI timings as per datasheet Date: Fri, 3 Feb 2023 19:18:04 +0000 Message-Id: <20230203191811.947697-7-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no Commit "98e0500eadb7 media: i2c: imx290: Add configurable link frequency and pixel rate" added support for the increased link frequencies on 2 data lanes, but didn't update the CSI timing registers in accordance with the datasheet. Use the specified settings. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart Reviewed-by: Alexander Stein --- drivers/media/i2c/imx290.c | 126 +++++++++++++++++++++++++++++++------ 1 file changed, 106 insertions(+), 20 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index a5ea59353a4d..2abe4cdab819 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -190,6 +190,18 @@ struct imx290_mode { u32 data_size; }; +struct imx290_csi_cfg { + u16 repetition; + u16 tclkpost; + u16 thszero; + u16 thsprepare; + u16 tclktrail; + u16 thstrail; + u16 tclkzero; + u16 tclkprepare; + u16 tlpx; +}; + struct imx290 { struct device *dev; struct clk *xclk; @@ -289,16 +301,6 @@ static const struct imx290_regval imx290_1080p_settings[] = { { IMX290_INCKSEL4, 0x01 }, { IMX290_INCKSEL5, 0x1a }, { IMX290_INCKSEL6, 0x1a }, - /* data rate settings */ - { IMX290_REPETITION, 0x10 }, - { IMX290_TCLKPOST, 87 }, - { IMX290_THSZERO, 55 }, - { IMX290_THSPREPARE, 31 }, - { IMX290_TCLKTRAIL, 31 }, - { IMX290_THSTRAIL, 31 }, - { IMX290_TCLKZERO, 119 }, - { IMX290_TCLKPREPARE, 31 }, - { IMX290_TLPX, 23 }, }; static const struct imx290_regval imx290_720p_settings[] = { @@ -314,16 +316,6 @@ static const struct imx290_regval imx290_720p_settings[] = { { IMX290_INCKSEL4, 0x01 }, { IMX290_INCKSEL5, 0x1a }, { IMX290_INCKSEL6, 0x1a }, - /* data rate settings */ - { IMX290_REPETITION, 0x10 }, - { IMX290_TCLKPOST, 79 }, - { IMX290_THSZERO, 47 }, - { IMX290_THSPREPARE, 23 }, - { IMX290_TCLKTRAIL, 23 }, - { IMX290_THSTRAIL, 23 }, - { IMX290_TCLKZERO, 87 }, - { IMX290_TCLKPREPARE, 23 }, - { IMX290_TLPX, 23 }, }; static const struct imx290_regval imx290_10bit_settings[] = { @@ -344,6 +336,58 @@ static const struct imx290_regval imx290_12bit_settings[] = { { IMX290_CSI_DT_FMT, IMX290_CSI_DT_FMT_RAW12 }, }; +static const struct imx290_csi_cfg imx290_csi_222_75mhz = { + /* 222.25MHz or 445.5Mbit/s per lane */ + .repetition = 0x10, + .tclkpost = 87, + .thszero = 55, + .thsprepare = 31, + .tclktrail = 31, + .thstrail = 31, + .tclkzero = 119, + .tclkprepare = 31, + .tlpx = 23, +}; + +static const struct imx290_csi_cfg imx290_csi_445_5mhz = { + /* 445.5MHz or 891Mbit/s per lane */ + .repetition = 0x00, + .tclkpost = 119, + .thszero = 103, + .thsprepare = 71, + .tclktrail = 55, + .thstrail = 63, + .tclkzero = 255, + .tclkprepare = 63, + .tlpx = 55, +}; + +static const struct imx290_csi_cfg imx290_csi_148_5mhz = { + /* 148.5MHz or 297Mbit/s per lane */ + .repetition = 0x10, + .tclkpost = 79, + .thszero = 47, + .thsprepare = 23, + .tclktrail = 23, + .thstrail = 23, + .tclkzero = 87, + .tclkprepare = 23, + .tlpx = 23, +}; + +static const struct imx290_csi_cfg imx290_csi_297mhz = { + /* 297MHz or 594Mbit/s per lane */ + .repetition = 0x00, + .tclkpost = 103, + .thszero = 87, + .thsprepare = 47, + .tclktrail = 39, + .thstrail = 47, + .tclkzero = 191, + .tclkprepare = 47, + .tlpx = 39, +}; + /* supported link frequencies */ #define FREQ_INDEX_1080P 0 #define FREQ_INDEX_720P 1 @@ -557,6 +601,42 @@ static int imx290_set_black_level(struct imx290 *imx290, black_level >> (16 - bpp), err); } +static int imx290_set_csi_config(struct imx290 *imx290) +{ + const s64 *link_freqs = imx290_link_freqs_ptr(imx290); + const struct imx290_csi_cfg *csi_cfg; + int ret = 0; + + switch (link_freqs[imx290->current_mode->link_freq_index]) { + case 445500000: + csi_cfg = &imx290_csi_445_5mhz; + break; + case 297000000: + csi_cfg = &imx290_csi_297mhz; + break; + case 222750000: + csi_cfg = &imx290_csi_222_75mhz; + break; + case 148500000: + csi_cfg = &imx290_csi_148_5mhz; + break; + default: + return -EINVAL; + } + + imx290_write(imx290, IMX290_REPETITION, csi_cfg->repetition, &ret); + imx290_write(imx290, IMX290_TCLKPOST, csi_cfg->tclkpost, &ret); + imx290_write(imx290, IMX290_THSZERO, csi_cfg->thszero, &ret); + imx290_write(imx290, IMX290_THSPREPARE, csi_cfg->thsprepare, &ret); + imx290_write(imx290, IMX290_TCLKTRAIL, csi_cfg->tclktrail, &ret); + imx290_write(imx290, IMX290_THSTRAIL, csi_cfg->thstrail, &ret); + imx290_write(imx290, IMX290_TCLKZERO, csi_cfg->tclkzero, &ret); + imx290_write(imx290, IMX290_TCLKPREPARE, csi_cfg->tclkprepare, &ret); + imx290_write(imx290, IMX290_TLPX, csi_cfg->tlpx, &ret); + + return ret; +} + static int imx290_setup_format(struct imx290 *imx290, const struct v4l2_mbus_framefmt *format) { @@ -769,6 +849,12 @@ static int imx290_start_streaming(struct imx290 *imx290, return ret; } + ret = imx290_set_csi_config(imx290); + if (ret < 0) { + dev_err(imx290->dev, "Could not set csi cfg\n"); + return ret; + } + /* Apply the register values related to current frame format */ format = v4l2_subdev_get_pad_format(&imx290->sd, state, 0); ret = imx290_setup_format(imx290, format); From patchwork Fri Feb 3 19:18:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89586 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1a9-00EtoR-PV; Fri, 03 Feb 2023 19:18:46 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233170AbjBCTSn (ORCPT + 1 other); Fri, 3 Feb 2023 14:18:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233642AbjBCTSi (ORCPT ); Fri, 3 Feb 2023 14:18:38 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F051073770 for ; Fri, 3 Feb 2023 11:18:36 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id a2so5267396wrd.6 for ; Fri, 03 Feb 2023 11:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=9whmx4oFFCwkxifzifzTesBa+oZIQxjzUQmNRhiSrrA=; b=kar8MaZELzLEwhvnhglu5dY4cY0rzpIHyKRXqx9+Sc1KVO0oT0fMpWQVyQEZ9nfa8N Mea91ExDa+HzvEOTMwwG1xFXDWC94evdF8Scdia86dCcaeR4f8ALo4Wc1Y6G5FQFMsdR pztInqumrSMZR2+NR8uc6tLLHrbEP/K6doWwivIGieEPaiS0VRsYGMKtDqn0oz6rwapQ U8jRjxJ+iQCUtDgTScaT1Kwps7PV8cGg84Br8eK/NYkyGHgSQdLMrFnXU1y6wcz8kjfq I/RPTnQh3KrRDPSjNY5lh4rPOfZj8rKDfXgKCa/R1qR4r8iCcMY2bTukgWeFhpgpQm1X AzIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=9whmx4oFFCwkxifzifzTesBa+oZIQxjzUQmNRhiSrrA=; b=rBG+d8ZdPMPtgKsyMGTmxW0RoZA2itbdfs2sAExVRW4Fbx6yWaOdmfXBz1zmSFioGu 0+NqNF8or66qPOd91Q5oimcCUWuppepNK1zlUiS8h+opn5/KZAnSkqXJqXD6VfDZKJNf M2BCufnVxIqnMSU2O8FjGeNMUcNxgFsevgCwScPNBQoZwYGM9D2jt8bImpZCdy1MI8UU 8G5k2faw6JcElq0rUahYF7tXaZa6x3pp22lKWi8OelG2z09CedF6hN7o0l+1bwDpHJGZ DlbLNaxHSjS2I2EWTJetxNU4XsLkZMBOVSIRwu4HIju2L6digMpnYmSZTQSq/64jcdP5 7sBA== X-Gm-Message-State: AO0yUKW1bWWqRz30Eg/MbD3YvRlEl3ey53EMDFXOl3+CWKWMAy1RlTAD 5d60tMxKQf7T2FbXPqeKkRd57Q== X-Google-Smtp-Source: AK7set8BNKA8DMcUFA9QM03kQyuy0wb4DehNCuBB1WTtNYbFeiWDjUKMK0wJSvjEVCyATLW5Y6/4Dg== X-Received: by 2002:a05:6000:38e:b0:2bc:7fdd:9245 with SMTP id u14-20020a056000038e00b002bc7fdd9245mr10765620wrf.5.1675451916601; Fri, 03 Feb 2023 11:18:36 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:36 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 07/13] media: i2c: imx290: Convert V4L2_CID_HBLANK to read/write Date: Fri, 3 Feb 2023 19:18:05 +0000 Message-Id: <20230203191811.947697-8-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no The driver exposed V4L2_CID_HBLANK as a read only control to allow for exposure calculations and determination of the frame rate. Convert to a read/write control so that the frame rate can be controlled. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart Reviewed-by: Alexander Stein --- drivers/media/i2c/imx290.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 2abe4cdab819..74eafed15613 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -47,6 +47,7 @@ #define IMX290_GAIN IMX290_REG_8BIT(0x3014) #define IMX290_VMAX IMX290_REG_24BIT(0x3018) #define IMX290_HMAX IMX290_REG_16BIT(0x301c) +#define IMX290_HMAX_MAX 0xffff #define IMX290_SHS1 IMX290_REG_24BIT(0x3020) #define IMX290_WINWV_OB IMX290_REG_8BIT(0x303a) #define IMX290_WINPV IMX290_REG_16BIT(0x303c) @@ -183,7 +184,7 @@ struct imx290_regval { struct imx290_mode { u32 width; u32 height; - u32 hmax; + u32 hmax_min; u8 link_freq_index; const struct imx290_regval *data; @@ -426,7 +427,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { { .width = 1920, .height = 1080, - .hmax = 2200, + .hmax_min = 2200, .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), @@ -434,7 +435,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { { .width = 1280, .height = 720, - .hmax = 3300, + .hmax_min = 3300, .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), @@ -445,7 +446,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { { .width = 1920, .height = 1080, - .hmax = 2200, + .hmax_min = 2200, .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), @@ -453,7 +454,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { { .width = 1280, .height = 720, - .hmax = 3300, + .hmax_min = 3300, .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), @@ -707,6 +708,12 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) } break; + case V4L2_CID_HBLANK: + ret = imx290_write(imx290, IMX290_HMAX, + ctrl->val + imx290->current_mode->width, + NULL); + break; + default: ret = -EINVAL; break; @@ -737,12 +744,14 @@ static void imx290_ctrl_update(struct imx290 *imx290, const struct v4l2_mbus_framefmt *format, const struct imx290_mode *mode) { - unsigned int hblank = mode->hmax - mode->width; + unsigned int hblank_min = mode->hmax_min - mode->width; + unsigned int hblank_max = IMX290_HMAX_MAX - mode->width; unsigned int vblank = IMX290_VMAX_DEFAULT - mode->height; __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index); - __v4l2_ctrl_modify_range(imx290->hblank, hblank, hblank, 1, hblank); + __v4l2_ctrl_modify_range(imx290->hblank, hblank_min, hblank_max, 1, + hblank_min); __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank, 1, vblank); } @@ -799,10 +808,11 @@ static int imx290_ctrl_init(struct imx290 *imx290) ARRAY_SIZE(imx290_test_pattern_menu) - 1, 0, 0, imx290_test_pattern_menu); + /* + * Actual range will be set from imx290_ctrl_update later in the probe. + */ imx290->hblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_HBLANK, 1, 1, 1, 1); - if (imx290->hblank) - imx290->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; imx290->vblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_VBLANK, 1, 1, 1, 1); @@ -871,11 +881,6 @@ static int imx290_start_streaming(struct imx290 *imx290, return ret; } - ret = imx290_write(imx290, IMX290_HMAX, imx290->current_mode->hmax, - NULL); - if (ret) - return ret; - /* Apply customized values from user */ ret = __v4l2_ctrl_handler_setup(imx290->sd.ctrl_handler); if (ret) { From patchwork Fri Feb 3 19:18:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89588 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1aM-00EtoR-58; Fri, 03 Feb 2023 19:18:58 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233664AbjBCTSz (ORCPT + 1 other); Fri, 3 Feb 2023 14:18:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233650AbjBCTSk (ORCPT ); Fri, 3 Feb 2023 14:18:40 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7B2311F for ; Fri, 3 Feb 2023 11:18:38 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id h12so5528934wrv.10 for ; Fri, 03 Feb 2023 11:18:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=n0FDKkzy1dQbNBgFR6ybwu/xD+gyy+MskA28TAJg1Pw=; b=nBm5eeY+jhsxdvNMVe+p1BEUZ2TWTB3s5usixA5b2E+WH5BqtncNfIzhBwd9FJhNM6 dc8WTNTbnGue1oB/G6SDuG6tRGWZ8uheA8SinnLtnZTQLGq3+2fioN0bX1aEDXYCmOq0 4HDqNj5snUSKA9GzPT+91u6z1XhKj7hwJbxCXc7Nh2FI2zsLAUNeMskT9Wtoa+iCxPG+ hIMkZCMYB/EXqv/cvAwJ4hx26qzxA7j+PctaCHvwtjJhILdUZM2TqQuWBXkLBid/PMvy HqWGZrq8ShkfFItYCzbqEXRAQv9SDzZbt5URfeh+u2xqQlXgkPzSgaD/xDDh5L5lcyiW VT0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=n0FDKkzy1dQbNBgFR6ybwu/xD+gyy+MskA28TAJg1Pw=; b=Sq8xArxsa2qC9I9kqwczao8NyikLUJ5hzA+RFDj2y/LfM4D90L2H9eanDHAkYN2Wsp zpPTcYedHeajde4Ake4mYVkQgI4hbuCh/jPQhf/WX/+HcYNtrl+NDaYOMr5iO3Fo0xsx CRd0Y7DzESVdhoNyXumqOZcbFuVi9yC98BEliZKGSlxH+MVaxWjSD3CCdpG93VC+lbxJ 8qdW7ZeMw7hrWaK8fnOFsn6bmkFPSj86mPVdwKopr7PDFopVLbK7ECZ6R0NNpJoh106U QXouq2bpiXZFlqN5dVBDbL5gyF2W1LiroiWpvgMVsdJ8TXqGrrXB1TMVu+d3xmUasSPu DEUg== X-Gm-Message-State: AO0yUKWrneooH5hAFgGMbxQYr/kDWHz1PAQB7eXRnvvORNGiW1c0f+Zh xYab6ELvJdb98NJpIdaxk41Ngg== X-Google-Smtp-Source: AK7set9EhzKi1LCPAvxQModCPD1z/kWdy54+P7O2eqbMKChilN2YGvTPSgFP+Z+jRBcUKrRbaWtm3w== X-Received: by 2002:adf:fe86:0:b0:2bf:f6b7:7a63 with SMTP id l6-20020adffe86000000b002bff6b77a63mr12285212wrr.0.1675451917494; Fri, 03 Feb 2023 11:18:37 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:37 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 08/13] media: i2c: imx290: Convert V4L2_CID_VBLANK to read/write Date: Fri, 3 Feb 2023 19:18:06 +0000 Message-Id: <20230203191811.947697-9-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no The driver exposed V4L2_CID_VBLANK as a read only control to allow for exposure calculations and determination of the frame rate. Convert to a read/write control so that the frame rate can be controlled. V4L2_CID_VBLANK also sets the limits for the exposure control, therefore exposure ranges have to be updated when vblank changes (either via s_ctrl, or via changing mode). Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx290.c | 58 +++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 74eafed15613..403bd7de875e 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -46,6 +46,7 @@ #define IMX290_BLKLEVEL IMX290_REG_16BIT(0x300a) #define IMX290_GAIN IMX290_REG_8BIT(0x3014) #define IMX290_VMAX IMX290_REG_24BIT(0x3018) +#define IMX290_VMAX_MAX 0x3ffff #define IMX290_HMAX IMX290_REG_16BIT(0x301c) #define IMX290_HMAX_MAX 0xffff #define IMX290_SHS1 IMX290_REG_24BIT(0x3020) @@ -106,6 +107,9 @@ #define IMX290_PGCTRL_THRU BIT(1) #define IMX290_PGCTRL_MODE(n) ((n) << 4) +/* Number of lines by which exposure must be less than VMAX) */ +#define IMX290_EXPOSURE_OFFSET 2 + #define IMX290_VMAX_DEFAULT 1125 #define IMX290_PIXEL_RATE 148500000 @@ -222,6 +226,7 @@ struct imx290 { struct v4l2_ctrl *link_freq; struct v4l2_ctrl *hblank; struct v4l2_ctrl *vblank; + struct v4l2_ctrl *exposure; }; static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd) @@ -235,7 +240,6 @@ static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd) static const struct imx290_regval imx290_global_init_settings[] = { { IMX290_CTRL_07, IMX290_WINMODE_1080P }, - { IMX290_VMAX, IMX290_VMAX_DEFAULT }, { IMX290_EXTCK_FREQ, 0x2520 }, { IMX290_WINWV_OB, 12 }, { IMX290_WINPH, 0 }, @@ -659,6 +663,16 @@ static int imx290_setup_format(struct imx290 *imx290, /* ---------------------------------------------------------------------------- * Controls */ +static void imx290_exposure_update(struct imx290 *imx290, + const struct imx290_mode *mode) +{ + unsigned int exposure_max; + + exposure_max = imx290->vblank->val + mode->height - + IMX290_EXPOSURE_OFFSET; + __v4l2_ctrl_modify_range(imx290->exposure, 1, exposure_max, 1, + exposure_max); +} static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) { @@ -666,7 +680,7 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) struct imx290, ctrls); const struct v4l2_mbus_framefmt *format; struct v4l2_subdev_state *state; - int ret = 0; + int ret = 0, vmax; /* * Return immediately for controls that don't need to be applied to the @@ -675,6 +689,11 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) return 0; + if (ctrl->id == V4L2_CID_VBLANK) { + /* Changing vblank changes the allowed range for exposure. */ + imx290_exposure_update(imx290, imx290->current_mode); + } + /* V4L2 controls values will be applied only when power is already up */ if (!pm_runtime_get_if_in_use(imx290->dev)) return 0; @@ -687,9 +706,23 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) ret = imx290_write(imx290, IMX290_GAIN, ctrl->val, NULL); break; + case V4L2_CID_VBLANK: + ret = imx290_write(imx290, IMX290_VMAX, + ctrl->val + imx290->current_mode->height, + NULL); + /* + * Due to the way that exposure is programmed in this sensor in + * relation to VMAX, we have to reprogramme it whenever VMAX is + * changed. + * Update ctrl so that the V4L2_CID_EXPOSURE case can refer to + * it. + */ + ctrl = imx290->exposure; + fallthrough; case V4L2_CID_EXPOSURE: + vmax = imx290->vblank->val + imx290->current_mode->height; ret = imx290_write(imx290, IMX290_SHS1, - IMX290_VMAX_DEFAULT - ctrl->val - 1, NULL); + vmax - ctrl->val - 1, NULL); break; case V4L2_CID_TEST_PATTERN: @@ -746,13 +779,15 @@ static void imx290_ctrl_update(struct imx290 *imx290, { unsigned int hblank_min = mode->hmax_min - mode->width; unsigned int hblank_max = IMX290_HMAX_MAX - mode->width; - unsigned int vblank = IMX290_VMAX_DEFAULT - mode->height; + unsigned int vblank_min = IMX290_VMAX_DEFAULT - mode->height; + unsigned int vblank_max = IMX290_VMAX_MAX - mode->height; __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index); __v4l2_ctrl_modify_range(imx290->hblank, hblank_min, hblank_max, 1, hblank_min); - __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank, 1, vblank); + __v4l2_ctrl_modify_range(imx290->vblank, vblank_min, vblank_max, 1, + vblank_min); } static int imx290_ctrl_init(struct imx290 *imx290) @@ -782,9 +817,13 @@ static int imx290_ctrl_init(struct imx290 *imx290) v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, 0, 100, 1, 0); - v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, - V4L2_CID_EXPOSURE, 1, IMX290_VMAX_DEFAULT - 2, 1, - IMX290_VMAX_DEFAULT - 2); + /* + * Correct range will be determined through imx290_ctrl_update setting + * V4L2_CID_VBLANK. + */ + imx290->exposure = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, + V4L2_CID_EXPOSURE, 1, 65535, 1, + 65535); /* * Set the link frequency, pixel rate, horizontal blanking and vertical @@ -816,8 +855,6 @@ static int imx290_ctrl_init(struct imx290 *imx290) imx290->vblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_VBLANK, 1, 1, 1, 1); - if (imx290->vblank) - imx290->vblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; v4l2_ctrl_new_fwnode_properties(&imx290->ctrls, &imx290_ctrl_ops, &props); @@ -1003,6 +1040,7 @@ static int imx290_set_fmt(struct v4l2_subdev *sd, imx290->current_mode = mode; imx290_ctrl_update(imx290, &fmt->format, mode); + imx290_exposure_update(imx290, mode); } *format = fmt->format; From patchwork Fri Feb 3 19:18:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89589 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1aN-00EtoR-Mv; Fri, 03 Feb 2023 19:19:00 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233690AbjBCTS6 (ORCPT + 1 other); Fri, 3 Feb 2023 14:18:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232127AbjBCTSm (ORCPT ); Fri, 3 Feb 2023 14:18:42 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 100649A808 for ; Fri, 3 Feb 2023 11:18:41 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id d14so5529092wrr.9 for ; Fri, 03 Feb 2023 11:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=U3qRwCguQfc6S4o7EqZyYm6Ixd/OxnoTvqE74zmYYZ0=; b=kaQCiatdPr4C+3nKtWmsRummtMdgWddpe6+33xNixYCmrhnQsOfjPSEHNdp52xcP8v 5Af0GoPUp+LsVyd2uXZsNEQ3rQsQ9Q3XQXSarVA57QdMX37EpYme+tjUz3c2LNv/SVpy Nzyn/JUKP1yK5ZWamrxFbRSsq+uO29BzCCYhVj0ZLwUWli7/ZQuIlNScQ2P8eScYjEQq 1maA8tghho9kcs4A49vzHkWDDQHXKqqwiC7DZJv7DMXhOfSU+RxTSlGrtcoAR4Z1+SaC pW19/guJC21h8spiZXMa+BFN/mssgfcNDLtbzp/+WaWp2CkecZudiZGjTUbZ03yKj7V9 L/uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=U3qRwCguQfc6S4o7EqZyYm6Ixd/OxnoTvqE74zmYYZ0=; b=QnM4x3jLHSmDgzC2SCLeEsEmC7CSvm1N9J1ppgscb+MWu3I2iZTne//DUxgCA6Mcct qFGxrHZGt4u/zA32gLSOsyX/5nTs/zXVjC6SguzTHnqAFMR9TfDmejt+s+WYleOTjpjW +q2uXwMQ9f6Erh4MMEh3bxeOHmDqvwy+dl8fO53KO3tY7oBNwCrlcP0wnsxwb64wHbB+ 8z2h+E143hr+NEBzTTq7FOrvfS7JlTgch2StOLscZBsMSJ8FBrgrBQsdugYonfL6c+3J uJd9NQyfmfvbSw8tvqacWrh4KGVpWKiR/uNjb9zigHhaZxtTdp7Azu2QHhMSS0fvIHJL Fw9g== X-Gm-Message-State: AO0yUKWsnxXqqLxUtKTJcv+7udATBJmHat4u319E0l1y1jusbO7a2uDE qw8X/oZVGo0Snj6R4N2NEH+Cpw== X-Google-Smtp-Source: AK7set/rT/MuTZvCPbpty8GIlP6B1rrjOXSuS1oquvwiBG7ovseXrTYx1zYiHyk4Er9d99f4Bw1f/w== X-Received: by 2002:a05:6000:1448:b0:2bf:d428:a768 with SMTP id v8-20020a056000144800b002bfd428a768mr12485141wrx.49.1675451919435; Fri, 03 Feb 2023 11:18:39 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:38 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 09/13] media: i2c: imx290: VMAX is mode dependent Date: Fri, 3 Feb 2023 19:18:07 +0000 Message-Id: <20230203191811.947697-10-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no The default VMAX for 60fps in 720p mode is 750 according to the datasheet, however the driver always left it at 1125 thereby stopping 60fps being achieved. Make VMAX (and therefore V4L2_CID_VBLANK) mode dependent so that 720p60 can be achieved. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx290.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 403bd7de875e..6235021a8d24 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -110,8 +110,6 @@ /* Number of lines by which exposure must be less than VMAX) */ #define IMX290_EXPOSURE_OFFSET 2 -#define IMX290_VMAX_DEFAULT 1125 - #define IMX290_PIXEL_RATE 148500000 /* @@ -189,6 +187,7 @@ struct imx290_mode { u32 width; u32 height; u32 hmax_min; + u32 vmax_min; u8 link_freq_index; const struct imx290_regval *data; @@ -432,6 +431,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { .width = 1920, .height = 1080, .hmax_min = 2200, + .vmax_min = 1125, .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), @@ -440,6 +440,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { .width = 1280, .height = 720, .hmax_min = 3300, + .vmax_min = 750, .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), @@ -451,6 +452,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { .width = 1920, .height = 1080, .hmax_min = 2200, + .vmax_min = 1125, .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), @@ -459,6 +461,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { .width = 1280, .height = 720, .hmax_min = 3300, + .vmax_min = 750, .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), @@ -779,7 +782,7 @@ static void imx290_ctrl_update(struct imx290 *imx290, { unsigned int hblank_min = mode->hmax_min - mode->width; unsigned int hblank_max = IMX290_HMAX_MAX - mode->width; - unsigned int vblank_min = IMX290_VMAX_DEFAULT - mode->height; + unsigned int vblank_min = mode->vmax_min - mode->height; unsigned int vblank_max = IMX290_VMAX_MAX - mode->height; __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index); From patchwork Fri Feb 3 19:18:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89590 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1aO-00EtoR-UY; Fri, 03 Feb 2023 19:19:01 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233712AbjBCTS7 (ORCPT + 1 other); Fri, 3 Feb 2023 14:18:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233473AbjBCTSx (ORCPT ); Fri, 3 Feb 2023 14:18:53 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7DB580171 for ; Fri, 3 Feb 2023 11:18:41 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id r27so1726947wrr.1 for ; Fri, 03 Feb 2023 11:18:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=5BY1kwD8rg2QYC3ufnAOmog3UEo3pjbjiA4aP6onfDM=; b=fpSYIo+TEsYHNjq9KJcvz13F123yLaIWlGmF4zKgnTga2NQVnLgiAXDfAbNy+8S2p8 bGWFeBGU105e1HSX8FjuWJVi4tfepx/d3wyxUxOlwMY/iiYPHsEB3tcZp9vOqNo68RNu +WySZ/MkNgaYzJEOZNsgjIqsmqLmt5yZ/EMhrEm25Knoalh/zuAsgVy78es8n5GCObr3 2q/TuSJ+gr2Ymrmh8qgsUGjQ+Kwu7MPuExE380G0Xk7+B3brucZ3I5UZb5JYO4KpwWZq kQMXEYVSjdMjyCQmtbAON6IMA+1HHxVzCjEyGWJ99dvEWR6RCrVgmtv4rRQ3ZRxVfKa9 jkJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=5BY1kwD8rg2QYC3ufnAOmog3UEo3pjbjiA4aP6onfDM=; b=v/92jkhaiCQsH6JWHnGG1IU6uewjP6kbYR8Q83KoIgjIoUQA0pZpXZ+h3UeNHk6xOY ZDARNbPhSuuXq9hqiHZ8JLDc8fK6Hm5GxykwtsCLLkgJ0XVxU+y4km+RjfbiWvCBaL8l qejx26Xv4fLuLXkcrokh5hI2mqaDGaLA6YDdOxm9r3ylZLXvshFXu2P3O4dS/mcEHZWM xL4XytjlkQseZYJ/2oUECmcLaw6w2jtPo1I5LIuReKB0ogomhUDisH4ZP0jgFj4EhMNi WXSnS1Qqu/C6GMZVJJJ7yiOiOynwGAoNMuODB91sZsBhPIhxTjb6NM+ffvafFPHxAaWp sHZw== X-Gm-Message-State: AO0yUKWOykbLcJ3t8vCop5o7MxZqEf0IdDGH8lI7xxK+QNVEr5aQV28H BkphFmkoor5c664yOvNVMSypeg== X-Google-Smtp-Source: AK7set9UAMy6kY4sTBto8t1HcsGSgOmjVlK4qAMQMtvputCWRDts4oyjO2t/d4TkDAp+phiQOd7nUw== X-Received: by 2002:a5d:4352:0:b0:2be:12a8:9f75 with SMTP id u18-20020a5d4352000000b002be12a89f75mr8585214wrr.55.1675451920554; Fri, 03 Feb 2023 11:18:40 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:39 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 10/13] media: i2c: imx290: Remove duplicated write to IMX290_CTRL_07 Date: Fri, 3 Feb 2023 19:18:08 +0000 Message-Id: <20230203191811.947697-11-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no IMX290_CTRL_07 was written from both imx290_global_init_settings and imx290_1080p_settings and imx290_720p_settings. Remove it from imx290_global_init_settings as the setting varies based on the mode. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart Reviewed-by: Alexander Stein --- drivers/media/i2c/imx290.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 6235021a8d24..a74930e86a6c 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -238,7 +238,6 @@ static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd) */ static const struct imx290_regval imx290_global_init_settings[] = { - { IMX290_CTRL_07, IMX290_WINMODE_1080P }, { IMX290_EXTCK_FREQ, 0x2520 }, { IMX290_WINWV_OB, 12 }, { IMX290_WINPH, 0 }, From patchwork Fri Feb 3 19:18:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89591 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1aQ-00EtoR-27; Fri, 03 Feb 2023 19:19:03 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233720AbjBCTTA (ORCPT + 1 other); Fri, 3 Feb 2023 14:19:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233656AbjBCTS5 (ORCPT ); Fri, 3 Feb 2023 14:18:57 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8F2188F1C for ; Fri, 3 Feb 2023 11:18:42 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id h16so5515299wrz.12 for ; Fri, 03 Feb 2023 11:18:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=JDkgCSaLwZZOHl7EllYkYm7lwz1dU/U56dHAvdDPza0=; b=qf9V3svOhCsvbu9gEubKZegtj7EHxB9vaFn4aVGa5YvCQZErg7WFiPbBzerjcA3jza xPYdPxB21N6uE6uYH8bcVSFmfHb7Ck9wAlFX+OrTK/hZ3OjOzo+Lkc5bBfwqoqFaL3x8 X3xKnrqDjQhBsoFmTgY6xH9guSLSd5LnPmcrxZiiofnoqDfu3edq6+QiSNpAID8AKRta GFK8GsUbjXjyEgpJLCOYltKRS7DhSYVRB5TJA6ujedKXZE2uNxhrjSthvcwetTXs5xPw xDJNC8GtyEcXHBxigVL9Rh7kx4nzXyIHvPxdPcvFE5ueMscUJkLI5rv9mHX/9J+jDI0P tDXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=JDkgCSaLwZZOHl7EllYkYm7lwz1dU/U56dHAvdDPza0=; b=JgbHDYAg7wJBE+dNNPZ/SGH9+jOrziiqAqmv7putiFLVr7b/O4KfbhKT6Lho+kmUG6 1wzitDx9aKqg+d/8mt8rF08z0uT+iItQH8zhgjiE6OIFJk7IwVmLJ7+wPhVmzNmOeAas Al26RUGev6Qua9MlrXd7g7d4HxwYfRTfDp8g+4dZjHHiRAhTqW+thb8QuJK+o5oIE0g9 3PjO4Vksd66iLHZPIdU6BdxvBkpT7zBusxd8PUSDz9O+vlKv75fmsavcsUzAQNjBjZK1 6U0VX4J2CYF3yVpGTi7K9tNIH3vXUroD9hoiU3KjfvKwttqV3wfgQNK5m1Hgja63zoLh 3fMg== X-Gm-Message-State: AO0yUKWI7aTXYEUL6JcnIDT835v+N/WuIjGzIIgbmWTa54Km04N4Aki8 4vjywM4QOtDSf8mLkR+UkCi5Ng== X-Google-Smtp-Source: AK7set+BHzxUIC62x6653MZLwkpzibDQPmbb21iho/s2vO/gnCLcbVcowv6cSko1WWNptioDFJWntQ== X-Received: by 2002:a5d:6984:0:b0:2bf:bcab:8e20 with SMTP id g4-20020a5d6984000000b002bfbcab8e20mr9285746wru.32.1675451921335; Fri, 03 Feb 2023 11:18:41 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:41 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 11/13] media: i2c: imx290: Add support for 74.25MHz external clock Date: Fri, 3 Feb 2023 19:18:09 +0000 Message-Id: <20230203191811.947697-12-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no The sensor supports either a 37.125 or 74.25MHz external, but the driver only supported 37.125MHz. Add the relevant register configuration for either clock frequency option. Signed-off-by: Dave Stevenson Reviewed-by: Alexander Stein Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx290.c | 132 ++++++++++++++++++++++++++++++++----- 1 file changed, 116 insertions(+), 16 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index a74930e86a6c..045d27b4d31b 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -102,6 +102,7 @@ #define IMX290_TCLKPREPARE IMX290_REG_16BIT(0x3452) #define IMX290_TLPX IMX290_REG_16BIT(0x3454) #define IMX290_X_OUT_SIZE IMX290_REG_16BIT(0x3472) +#define IMX290_INCKSEL7 IMX290_REG_8BIT(0x3480) #define IMX290_PGCTRL_REGEN BIT(0) #define IMX290_PGCTRL_THRU BIT(1) @@ -178,11 +179,29 @@ struct imx290_model_info { enum imx290_colour_variant colour_variant; }; +enum imx290_clk_freq { + IMX290_CLK_37_125, + IMX290_CLK_74_25, + IMX290_NUM_CLK +}; + struct imx290_regval { u32 reg; u32 val; }; +/* + * Clock configuration for registers INCKSEL1 to INCKSEL6. + */ +struct imx290_clk_cfg { + u8 incksel1; + u8 incksel2; + u8 incksel3; + u8 incksel4; + u8 incksel5; + u8 incksel6; +}; + struct imx290_mode { u32 width; u32 height; @@ -192,6 +211,8 @@ struct imx290_mode { const struct imx290_regval *data; u32 data_size; + + const struct imx290_clk_cfg *clk_cfg; }; struct imx290_csi_cfg { @@ -210,6 +231,7 @@ struct imx290 { struct device *dev; struct clk *xclk; struct regmap *regmap; + enum imx290_clk_freq xclk_idx; u8 nlanes; const struct imx290_model_info *model; @@ -238,7 +260,6 @@ static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd) */ static const struct imx290_regval imx290_global_init_settings[] = { - { IMX290_EXTCK_FREQ, 0x2520 }, { IMX290_WINWV_OB, 12 }, { IMX290_WINPH, 0 }, { IMX290_WINPV, 0 }, @@ -288,7 +309,18 @@ static const struct imx290_regval imx290_global_init_settings[] = { { IMX290_REG_8BIT(0x33b0), 0x50 }, { IMX290_REG_8BIT(0x33b2), 0x1a }, { IMX290_REG_8BIT(0x33b3), 0x04 }, - { IMX290_REG_8BIT(0x3480), 0x49 }, +}; + +#define IMX290_NUM_CLK_REGS 2 +static const struct imx290_regval xclk_regs[][IMX290_NUM_CLK_REGS] = { + [IMX290_CLK_37_125] = { + { IMX290_EXTCK_FREQ, (37125 * 256) / 1000 }, + { IMX290_INCKSEL7, 0x49 }, + }, + [IMX290_CLK_74_25] = { + { IMX290_EXTCK_FREQ, (74250 * 256) / 1000 }, + { IMX290_INCKSEL7, 0x92 }, + }, }; static const struct imx290_regval imx290_1080p_settings[] = { @@ -298,12 +330,6 @@ static const struct imx290_regval imx290_1080p_settings[] = { { IMX290_OPB_SIZE_V, 10 }, { IMX290_X_OUT_SIZE, 1920 }, { IMX290_Y_OUT_SIZE, 1080 }, - { IMX290_INCKSEL1, 0x18 }, - { IMX290_INCKSEL2, 0x03 }, - { IMX290_INCKSEL3, 0x20 }, - { IMX290_INCKSEL4, 0x01 }, - { IMX290_INCKSEL5, 0x1a }, - { IMX290_INCKSEL6, 0x1a }, }; static const struct imx290_regval imx290_720p_settings[] = { @@ -313,12 +339,6 @@ static const struct imx290_regval imx290_720p_settings[] = { { IMX290_OPB_SIZE_V, 4 }, { IMX290_X_OUT_SIZE, 1280 }, { IMX290_Y_OUT_SIZE, 720 }, - { IMX290_INCKSEL1, 0x20 }, - { IMX290_INCKSEL2, 0x00 }, - { IMX290_INCKSEL3, 0x20 }, - { IMX290_INCKSEL4, 0x01 }, - { IMX290_INCKSEL5, 0x1a }, - { IMX290_INCKSEL6, 0x1a }, }; static const struct imx290_regval imx290_10bit_settings[] = { @@ -424,6 +444,48 @@ static inline int imx290_link_freqs_num(const struct imx290 *imx290) return ARRAY_SIZE(imx290_link_freq_4lanes); } +static const struct imx290_clk_cfg imx290_1080p_clock_config[] = { + [IMX290_CLK_37_125] = { + /* 37.125MHz clock config */ + .incksel1 = 0x18, + .incksel2 = 0x03, + .incksel3 = 0x20, + .incksel4 = 0x01, + .incksel5 = 0x1a, + .incksel6 = 0x1a, + }, + [IMX290_CLK_74_25] = { + /* 74.25MHz clock config */ + .incksel1 = 0x0c, + .incksel2 = 0x03, + .incksel3 = 0x10, + .incksel4 = 0x01, + .incksel5 = 0x1b, + .incksel6 = 0x1b, + }, +}; + +static const struct imx290_clk_cfg imx290_720p_clock_config[] = { + [IMX290_CLK_37_125] = { + /* 37.125MHz clock config */ + .incksel1 = 0x20, + .incksel2 = 0x00, + .incksel3 = 0x20, + .incksel4 = 0x01, + .incksel5 = 0x1a, + .incksel6 = 0x1a, + }, + [IMX290_CLK_74_25] = { + /* 74.25MHz clock config */ + .incksel1 = 0x10, + .incksel2 = 0x00, + .incksel3 = 0x10, + .incksel4 = 0x01, + .incksel5 = 0x1b, + .incksel6 = 0x1b, + }, +}; + /* Mode configs */ static const struct imx290_mode imx290_modes_2lanes[] = { { @@ -434,6 +496,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), + .clk_cfg = imx290_1080p_clock_config, }, { .width = 1280, @@ -443,6 +506,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), + .clk_cfg = imx290_720p_clock_config, }, }; @@ -455,6 +519,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { .link_freq_index = FREQ_INDEX_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), + .clk_cfg = imx290_1080p_clock_config, }, { .width = 1280, @@ -464,6 +529,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { .link_freq_index = FREQ_INDEX_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), + .clk_cfg = imx290_720p_clock_config, }, }; @@ -587,6 +653,26 @@ static int imx290_set_register_array(struct imx290 *imx290, return 0; } +static int imx290_set_clock(struct imx290 *imx290) +{ + const struct imx290_mode *mode = imx290->current_mode; + enum imx290_clk_freq clk_idx = imx290->xclk_idx; + const struct imx290_clk_cfg *clk_cfg = &mode->clk_cfg[clk_idx]; + int ret; + + ret = imx290_set_register_array(imx290, xclk_regs[clk_idx], + IMX290_NUM_CLK_REGS); + + imx290_write(imx290, IMX290_INCKSEL1, clk_cfg->incksel1, &ret); + imx290_write(imx290, IMX290_INCKSEL2, clk_cfg->incksel2, &ret); + imx290_write(imx290, IMX290_INCKSEL3, clk_cfg->incksel3, &ret); + imx290_write(imx290, IMX290_INCKSEL4, clk_cfg->incksel4, &ret); + imx290_write(imx290, IMX290_INCKSEL5, clk_cfg->incksel5, &ret); + imx290_write(imx290, IMX290_INCKSEL6, clk_cfg->incksel6, &ret); + + return ret; +} + static int imx290_set_data_lanes(struct imx290 *imx290) { int ret = 0; @@ -891,6 +977,13 @@ static int imx290_start_streaming(struct imx290 *imx290, return ret; } + /* Set clock parameters based on mode and xclk */ + ret = imx290_set_clock(imx290); + if (ret < 0) { + dev_err(imx290->dev, "Could not set clocks\n"); + return ret; + } + /* Set data lane count */ ret = imx290_set_data_lanes(imx290); if (ret < 0) { @@ -1290,8 +1383,15 @@ static int imx290_init_clk(struct imx290 *imx290) return ret; } - /* external clock must be 37.125 MHz */ - if (xclk_freq != 37125000) { + /* external clock must be 37.125 MHz or 74.25MHz */ + switch (xclk_freq) { + case 37125000: + imx290->xclk_idx = IMX290_CLK_37_125; + break; + case 74250000: + imx290->xclk_idx = IMX290_CLK_74_25; + break; + default: dev_err(imx290->dev, "External clock frequency %u is not supported\n", xclk_freq); return -EINVAL; From patchwork Fri Feb 3 19:18:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89593 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1ax-00EtoR-NC; Fri, 03 Feb 2023 19:19:36 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233223AbjBCTTE (ORCPT + 1 other); Fri, 3 Feb 2023 14:19:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233652AbjBCTS7 (ORCPT ); Fri, 3 Feb 2023 14:18:59 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7134F783C3 for ; Fri, 3 Feb 2023 11:18:45 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id ba1so1479817wrb.5 for ; Fri, 03 Feb 2023 11:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=eVb2HFMgTJ3usCiBzIHZIOSS+2N4i8CB0Qx5yT0IF7Q=; b=XYnWn2+rxvrgIV6AA45Hybehe2D5jRXuJrmMQUeUdD25xIc56unlCAgwRj59i1VQoa JkSdThl7OSh6V9Vda8KiV1w7Ua3iKDn8A7Kp0QT6PrUu7RSJlC8OZrGxKWGWFKGIZtf8 9x/5zMNH+7A+1B9jtfvrCYDTIURwzqLQ2vB+RFPvNbL08tOiIeaEAfJ4dhSzyAR0duoj VW61QFm0mdGzoCPNu1acXGni8lH0+qZ9ORMiTRH4BQ7l+bwGhZEMnqlYOnvMXlJGpR/q 8ievbZzfAO9I0z/y8wP72tQ/Ea0u8MiyaxnX73kHQAxlk6oaazpkkCqNWMHl3r4C4CqN zvuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=eVb2HFMgTJ3usCiBzIHZIOSS+2N4i8CB0Qx5yT0IF7Q=; b=0rj34GaXD1ZrZu/HrrRg9IBA/CjviU2My1+k509YwyYClf9rRMKZikFL7MRhUXr862 2pyfzeQzHr51Cx5Ij0ue0UvRV6plSla0oNAir22TolnGcnZsB+quh4kvpnoBEoWDxzVe NqAAoQryH7VXxjC0qtqgQxljOk/Oh4M9wlqz7UYJ08eEZAOe6IsdjZDLlWRUKZl6jfqq sjKZNn/EF+np6Nz5tCZNN3QexvCJQVd3QWwM78/To43bpreCgHK36PhftprU8x5UwsKs 52jOoQ538Soq3vO9t1iQfBTH7i5J6PFx5RhpCU1X1gQkdsBsqwJ0aPUJ16cU6Tnh7O0T 1dEQ== X-Gm-Message-State: AO0yUKXOaUM2tsD3Q3cYvr6IPd2pYieAODnh5Ajq4RIiQyuW2KUHMUby 0Sv4danXSlH2XRNnLjXpiAnj2A== X-Google-Smtp-Source: AK7set9gYktPXgDg42quCWFbwX3rcNsG+xnUXKnREt6mujYiJnbBqgf0RUZuc2FqELIndHNz5kdc8Q== X-Received: by 2002:a05:6000:1843:b0:2bf:d776:1c9a with SMTP id c3-20020a056000184300b002bfd7761c9amr13171096wri.4.1675451925408; Fri, 03 Feb 2023 11:18:45 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:41 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 12/13] media: i2c: imx290: Add support for H & V Flips Date: Fri, 3 Feb 2023 19:18:10 +0000 Message-Id: <20230203191811.947697-13-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_PDS_OTHER_BAD_TLD autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no The sensor supports H & V flips, so add the relevant hooks for V4L2_CID_HFLIP and V4L2_CID_VFLIP to configure them. Note that the Bayer order is maintained as the readout area shifts by 1 pixel in the appropriate direction (note the comment about the top margin being 8 pixels whilst the bottom margin is 9). The V4L2_SEL_TGT_CROP region is therefore adjusted appropriately. Signed-off-by: Dave Stevenson Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx290.c | 51 ++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 045d27b4d31b..7167eb1edb9b 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -208,6 +208,7 @@ struct imx290_mode { u32 hmax_min; u32 vmax_min; u8 link_freq_index; + u8 ctrl_07; const struct imx290_regval *data; u32 data_size; @@ -248,6 +249,10 @@ struct imx290 { struct v4l2_ctrl *hblank; struct v4l2_ctrl *vblank; struct v4l2_ctrl *exposure; + struct { + struct v4l2_ctrl *hflip; + struct v4l2_ctrl *vflip; + }; }; static inline struct imx290 *to_imx290(struct v4l2_subdev *_sd) @@ -325,7 +330,6 @@ static const struct imx290_regval xclk_regs[][IMX290_NUM_CLK_REGS] = { static const struct imx290_regval imx290_1080p_settings[] = { /* mode settings */ - { IMX290_CTRL_07, IMX290_WINMODE_1080P }, { IMX290_WINWV_OB, 12 }, { IMX290_OPB_SIZE_V, 10 }, { IMX290_X_OUT_SIZE, 1920 }, @@ -334,7 +338,6 @@ static const struct imx290_regval imx290_1080p_settings[] = { static const struct imx290_regval imx290_720p_settings[] = { /* mode settings */ - { IMX290_CTRL_07, IMX290_WINMODE_720P }, { IMX290_WINWV_OB, 6 }, { IMX290_OPB_SIZE_V, 4 }, { IMX290_X_OUT_SIZE, 1280 }, @@ -494,6 +497,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { .hmax_min = 2200, .vmax_min = 1125, .link_freq_index = FREQ_INDEX_1080P, + .ctrl_07 = IMX290_WINMODE_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), .clk_cfg = imx290_1080p_clock_config, @@ -504,6 +508,7 @@ static const struct imx290_mode imx290_modes_2lanes[] = { .hmax_min = 3300, .vmax_min = 750, .link_freq_index = FREQ_INDEX_720P, + .ctrl_07 = IMX290_WINMODE_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), .clk_cfg = imx290_720p_clock_config, @@ -517,6 +522,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { .hmax_min = 2200, .vmax_min = 1125, .link_freq_index = FREQ_INDEX_1080P, + .ctrl_07 = IMX290_WINMODE_1080P, .data = imx290_1080p_settings, .data_size = ARRAY_SIZE(imx290_1080p_settings), .clk_cfg = imx290_1080p_clock_config, @@ -527,6 +533,7 @@ static const struct imx290_mode imx290_modes_4lanes[] = { .hmax_min = 3300, .vmax_min = 750, .link_freq_index = FREQ_INDEX_720P, + .ctrl_07 = IMX290_WINMODE_720P, .data = imx290_720p_settings, .data_size = ARRAY_SIZE(imx290_720p_settings), .clk_cfg = imx290_720p_clock_config, @@ -835,6 +842,20 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl) NULL); break; + case V4L2_CID_HFLIP: + case V4L2_CID_VFLIP: + { + u32 reg; + + reg = imx290->current_mode->ctrl_07; + if (imx290->hflip->val) + reg |= IMX290_HREVERSE; + if (imx290->vflip->val) + reg |= IMX290_VREVERSE; + ret = imx290_write(imx290, IMX290_CTRL_07, reg, NULL); + break; + } + default: ret = -EINVAL; break; @@ -887,7 +908,7 @@ static int imx290_ctrl_init(struct imx290 *imx290) if (ret < 0) return ret; - v4l2_ctrl_handler_init(&imx290->ctrls, 9); + v4l2_ctrl_handler_init(&imx290->ctrls, 11); /* * The sensor has an analog gain and a digital gain, both controlled @@ -944,6 +965,12 @@ static int imx290_ctrl_init(struct imx290 *imx290) imx290->vblank = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_VBLANK, 1, 1, 1, 1); + imx290->hflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, + V4L2_CID_HFLIP, 0, 1, 1, 0); + imx290->vflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, + V4L2_CID_VFLIP, 0, 1, 1, 0); + v4l2_ctrl_cluster(2, &imx290->hflip); + v4l2_ctrl_new_fwnode_properties(&imx290->ctrls, &imx290_ctrl_ops, &props); @@ -1065,6 +1092,13 @@ static int imx290_set_stream(struct v4l2_subdev *sd, int enable) pm_runtime_put_autosuspend(imx290->dev); } + /* + * vflip and hflip should not be changed during streaming as the sensor + * will produce an invalid frame. + */ + __v4l2_ctrl_grab(imx290->vflip, enable); + __v4l2_ctrl_grab(imx290->hflip, enable); + unlock: v4l2_subdev_unlock_state(state); return ret; @@ -1147,16 +1181,23 @@ static int imx290_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_selection *sel) { + struct imx290 *imx290 = to_imx290(sd); struct v4l2_mbus_framefmt *format; switch (sel->target) { case V4L2_SEL_TGT_CROP: { format = v4l2_subdev_get_pad_format(sd, sd_state, 0); + /* + * The sensor moves the readout by 1 pixel based on flips to + * keep the Bayer order the same. + */ sel->r.top = IMX920_PIXEL_ARRAY_MARGIN_TOP - + (IMX290_PIXEL_ARRAY_RECORDING_HEIGHT - format->height) / 2; + + (IMX290_PIXEL_ARRAY_RECORDING_HEIGHT - format->height) / 2 + + imx290->vflip->val; sel->r.left = IMX920_PIXEL_ARRAY_MARGIN_LEFT - + (IMX290_PIXEL_ARRAY_RECORDING_WIDTH - format->width) / 2; + + (IMX290_PIXEL_ARRAY_RECORDING_WIDTH - format->width) / 2 + + imx290->hflip->val; sel->r.width = format->width; sel->r.height = format->height; From patchwork Fri Feb 3 19:18:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Stevenson X-Patchwork-Id: 89592 Received: from vger.kernel.org ([23.128.96.18]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1pO1aw-00EtoR-Ni; Fri, 03 Feb 2023 19:19:35 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233705AbjBCTTC (ORCPT + 1 other); Fri, 3 Feb 2023 14:19:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233594AbjBCTS7 (ORCPT ); Fri, 3 Feb 2023 14:18:59 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 714EA8627F for ; Fri, 3 Feb 2023 11:18:46 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id j25so2007925wrc.4 for ; Fri, 03 Feb 2023 11:18:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; 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=UB+6XYV9fp+4PqV3sEDVlKkbKE212lgndbUm+hP8wtk=; b=di6+D8vU2YGlCCyliMZFbp8G3/d5g44p0rHVKOlfR1/a9ayq8823r/nYKhwXJ7qsKG ucuZavI0wizZSKBpRaJzWJW+ZpoJgP4DfEGhn7roJU6jX+tBCaoofePhE6P1tD8KG9EI /tt+CBNlq196yMqLu5VeC2MXxdtIH6TZAHoQ+4g81eimqn4U1CppiFoyUfJ8BoV3841t USTT3EWJm4Plje+donFZxjcBFUXmLS5SMojL0bgDw5e1tY89DvgpOllT/9+BEXsE8Mfn 3bJvDwku9W7sXwq8Ze+28Udq7uqy/0w7op0n5t+9joDlpPPSCfS7XUnAt2jjjhxTghUG iYvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=UB+6XYV9fp+4PqV3sEDVlKkbKE212lgndbUm+hP8wtk=; b=hlUd4FaQhD0g8KDESzSyU/mOb20iOjkXxVjzMxHG5nxfEDRjxew6Rmba7bCBjLxk2z +zbs9oJOPzVZQUrVCnLzKYPmP3uJYQFp0QjZu+R40b6eOJC2lIycp1TmX/QHRvOWu0kb rahOH35cfBonBr7+f64tCeqXDoL9Ve34lWlVI5Stnmx62H1XHfWEKRO+8vPxzi0f50mX 6vKpuDai5XfzotGNcnbpeRXfgGvZz83//Gy5PBmAmdFoB6m55QmDKxkfFIvkryY5H2VO Hp7yJT3s/2qFLaq22fbP6KZ7pTW1bc4704h+fRsNX7knCQBAU9A3YBqZMAH44GY+gGRh uqtQ== X-Gm-Message-State: AO0yUKV0Q/SBczZawrD8pUb/Gkf0wkIHGtutHCX8wMzLgjPcE8XKzd4E E9jeN736csFEcq3MZjzgSDk+fg== X-Google-Smtp-Source: AK7set8PfEw0S0lNQe3en6IQp9kAfydEQhnOFM5CpV539jZShANDtiufQ35X8EtWtHaLNj8if678rw== X-Received: by 2002:a5d:5147:0:b0:2bf:bd9f:23cb with SMTP id u7-20020a5d5147000000b002bfbd9f23cbmr8893526wrt.52.1675451926248; Fri, 03 Feb 2023 11:18:46 -0800 (PST) Received: from dave-Ubuntu2204.pitowers.org ([93.93.133.154]) by smtp.googlemail.com with ESMTPSA id f6-20020a5d5686000000b002c3daaef051sm1348637wrv.82.2023.02.03.11.18.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:18:45 -0800 (PST) From: Dave Stevenson To: Manivannan Sadhasivam , Mauro Carvalho Chehab , Laurent Pinchart , linux-media@vger.kernel.org, Alexander Stein Cc: Dave Stevenson Subject: [PATCH v2 13/13] media: i2c: imx290: Add the error code to logs in start_streaming Date: Fri, 3 Feb 2023 19:18:11 +0000 Message-Id: <20230203191811.947697-14-dave.stevenson@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> References: <20230203191811.947697-1-dave.stevenson@raspberrypi.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-LSpam-Score: -2.5 (--) X-LSpam-Report: No, score=-2.5 required=5.0 tests=BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1 autolearn=ham autolearn_force=no imx290_start_streaming logs what failed, but not the error code from that function. Add it into the log message. Signed-off-by: Dave Stevenson Reviewed-by: Alexander Stein Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx290.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/imx290.c b/drivers/media/i2c/imx290.c index 7167eb1edb9b..f635f1213477 100644 --- a/drivers/media/i2c/imx290.c +++ b/drivers/media/i2c/imx290.c @@ -1007,20 +1007,20 @@ static int imx290_start_streaming(struct imx290 *imx290, /* Set clock parameters based on mode and xclk */ ret = imx290_set_clock(imx290); if (ret < 0) { - dev_err(imx290->dev, "Could not set clocks\n"); + dev_err(imx290->dev, "Could not set clocks - %d\n", ret); return ret; } /* Set data lane count */ ret = imx290_set_data_lanes(imx290); if (ret < 0) { - dev_err(imx290->dev, "Could not set data lanes\n"); + dev_err(imx290->dev, "Could not set data lanes - %d\n", ret); return ret; } ret = imx290_set_csi_config(imx290); if (ret < 0) { - dev_err(imx290->dev, "Could not set csi cfg\n"); + dev_err(imx290->dev, "Could not set csi cfg - %d\n", ret); return ret; } @@ -1028,7 +1028,7 @@ static int imx290_start_streaming(struct imx290 *imx290, format = v4l2_subdev_get_pad_format(&imx290->sd, state, 0); ret = imx290_setup_format(imx290, format); if (ret < 0) { - dev_err(imx290->dev, "Could not set frame format\n"); + dev_err(imx290->dev, "Could not set frame format - %d\n", ret); return ret; } @@ -1036,14 +1036,14 @@ static int imx290_start_streaming(struct imx290 *imx290, ret = imx290_set_register_array(imx290, imx290->current_mode->data, imx290->current_mode->data_size); if (ret < 0) { - dev_err(imx290->dev, "Could not set current mode\n"); + dev_err(imx290->dev, "Could not set current mode - %d\n", ret); return ret; } /* Apply customized values from user */ ret = __v4l2_ctrl_handler_setup(imx290->sd.ctrl_handler); if (ret) { - dev_err(imx290->dev, "Could not sync v4l2 controls\n"); + dev_err(imx290->dev, "Could not sync v4l2 controls - %d\n", ret); return ret; }