From nobody Fri Oct 10 23:10:33 2025 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 181CD380 for ; Wed, 11 Jun 2025 18:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749667046; cv=none; b=KtvTkjT6pqY0vRCEKic1mY0ko1rN5M1IdlP738Qb5/QEQLuxrfLfKXm5yZ2w89wu83W6St2McaZBnxhIdKHXnmJKwnVYN4id9f2aOAvbMfK2qpnLjdabeOzzeZU7pIuCp9HxTcWrZjmPKy9BxjhgDYFPJZVTpFeZDBx1zur6rN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749667046; c=relaxed/simple; bh=i7gGdufPkSGRwB6IPZKAt6alZaKpalTRVeGTcHa0rDg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=O4GgwRQw19cK3IyCDIvFN85pJmpQChvpWv0C4ecVPZ2Hyc+S+4JZLq0EFevah1H9oS6GaXFYsZ7bTCMnynp1IsJa9rcQ+vSqGWhmSgM3e8NWk4At9tVFMpWZiezG1FnEQoiVl77gz7D+BxIw9kBU9VeVGAA0JPltFURly2rdjsE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=hEp2WiPD; arc=none smtp.client-ip=209.85.221.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="hEp2WiPD" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3a50956e5d3so188531f8f.1 for ; Wed, 11 Jun 2025 11:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1749667041; x=1750271841; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=qgYBfY2UR29MQlCGcRFEVcrLVgS61xcAj8mfuW0laMQ=; b=hEp2WiPDuXfZ9f3XhKZ/PJSBZrBA1nspeqUhsyJmy5UxhK3JvwnxnorzGAUDiGtpqW BczdVAmQ0CQti+OxQiheFfcVUD01xKkFOpEnJ+10plYZYlBiqudX3EJ5iTXp+0ee9Bi7 u/ofqYX8t1SQLb6PswiU769wsxlvbsFAnUL4Y6T/9HHVAK7fHHlikFNK/2MpAovD9ZTZ /cd3fNfVOPBabMdCOOQlYc2AyNXpeVaL+DNUZ5oUDfa8QODx401dpNRuYOTJnoTCqBmF KqPESMzyIcDJm2+VmOvaH4XzlAerUj6xF+Zg6TlS+QScHM7S1/zpUSeDWr6pL1e0YSlp 4I+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749667041; x=1750271841; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qgYBfY2UR29MQlCGcRFEVcrLVgS61xcAj8mfuW0laMQ=; b=URJ7jxLFT8soRnaed+rt9bSc94LxBkFXBdwE5oq3n/27nURxc5jOaPCdEFUb1SEtqx GBb84E91YhAjBifQJflCxC+p84V79Q2vHmYCi42pL4biMDqQtFP1py/c6DWevKoAsfZw 02m0aLPCVb1Re/0TcVOoU93S+r8bqytMKEkXnJ1BrSqNBWj8xt8QZ0OuthlJ05baqTx0 lLGszrXikDbICCVaUfT31BzQIU7nvj8BSx4v95IqNttstOAOkE22yrjRfpFEyjBzGLhS cD0fa7c0EWiBFssYBY5nF/QyBKQN+FDBTxQ1TYACHCIqmPBTrAoFbMUNifQEy7AVFF9s 9UpA== X-Forwarded-Encrypted: i=1; AJvYcCXGwF0D92wMSWcASroJcHPTtHs+nD4yM/KJV+glvXhEBGRf+js5TGiPVHjzB8o6o9YpfqB+Or1pGYbkhRQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzpPBzxDt33UHCvVl1cJjL4ZsMzglmWPkG+O50FKIcZT1TByOCn o3b5eKhQHJpTtnzJ3CY4/kcHcgjIQhXrMAqHVKK9kM2cqVngVaCFYMvtgjTSAOX0pcylrwiKVdF Ir5gM X-Gm-Gg: ASbGncvS88EYiTHC1Rc01owxRRgZwGpErRtxNiVhGXi7azqr4zbuKIzhxh4gD308qFN FWz39eWTZu+d2xL3n3B5mj3KvmR780tjHg0BVKiDvVhgDn5hH/iLwO2IoDqWobUPlT3OXX914wl o2fayXlpI1t1K14d2NhldoioOezmEn6ACjJUZVoc0mcnaCI51ergtd6EMb65Obi1038dtGtQl6Q yX1wVKfTxilbzpT4ObtdiPWJ7nok4JIVg27Glb9Tk68h+fDeuBza24WU1wd1E0Edz8N5rRlbSta lR8mJF4gvuiMzd7akpoltsRNgMiK28I0w5QNe34kPyP4TEu4jkWVTA== X-Google-Smtp-Source: AGHT+IHHT50NdMoz+n9TfRr2G7Tew6o4zd1nSosAD5QXIFC2jG2M1x+AHqx1qfPmXTcOGk2hed8jOw== X-Received: by 2002:a05:6000:26c5:b0:3a4:d0fe:428a with SMTP id ffacd0b85a97d-3a558a27540mr3799331f8f.28.1749667041208; Wed, 11 Jun 2025 11:37:21 -0700 (PDT) Received: from [127.0.1.1] ([2a00:1098:3142:e::8]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a5324364d4sm16119390f8f.55.2025.06.11.11.37.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 11:37:20 -0700 (PDT) From: Dave Stevenson Date: Wed, 11 Jun 2025 19:37:13 +0100 Subject: [PATCH 1/4] media: tc358743: Add support for 972Mbit/s link freq Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-media-tc358743-v1-1-708556026f9d@raspberrypi.com> References: <20250611-media-tc358743-v1-0-708556026f9d@raspberrypi.com> In-Reply-To: <20250611-media-tc358743-v1-0-708556026f9d@raspberrypi.com> To: Hans Verkuil , Mauro Carvalho Chehab Cc: Maxime Ripard , Philipp Zabel , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Stevenson X-Mailer: b4 0.14.1 Adds register setups for running the CSI lanes at 972Mbit/s, which allows 1080P50 UYVY down 2 lanes. Signed-off-by: Dave Stevenson Tested-by: Maxime Ripard --- drivers/media/i2c/tc358743.c | 48 +++++++++++++++++++++++++++++++---------= ---- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c index 3d6703b75bfa..b87db3de20db 100644 --- a/drivers/media/i2c/tc358743.c +++ b/drivers/media/i2c/tc358743.c @@ -1993,6 +1993,7 @@ static int tc358743_probe_of(struct tc358743_state *s= tate) /* * The CSI bps per lane must be between 62.5 Mbps and 1 Gbps. * The default is 594 Mbps for 4-lane 1080p60 or 2-lane 720p60. + * 972 Mbps allows 1080P50 UYVY over 2-lane. */ bps_pr_lane =3D 2 * endpoint.link_frequencies[0]; if (bps_pr_lane < 62500000U || bps_pr_lane > 1000000000U) { @@ -2006,23 +2007,42 @@ static int tc358743_probe_of(struct tc358743_state = *state) state->pdata.refclk_hz * state->pdata.pll_prd; =20 /* - * FIXME: These timings are from REF_02 for 594 Mbps per lane (297 MHz - * link frequency). In principle it should be possible to calculate + * FIXME: These timings are from REF_02 for 594 or 972 Mbps per lane + * (297 MHz or 486 MHz link frequency). + * In principle it should be possible to calculate * them based on link frequency and resolution. */ - if (bps_pr_lane !=3D 594000000U) + switch (bps_pr_lane) { + default: dev_warn(dev, "untested bps per lane: %u bps\n", bps_pr_lane); - state->pdata.lineinitcnt =3D 0xe80; - state->pdata.lptxtimecnt =3D 0x003; - /* tclk-preparecnt: 3, tclk-zerocnt: 20 */ - state->pdata.tclk_headercnt =3D 0x1403; - state->pdata.tclk_trailcnt =3D 0x00; - /* ths-preparecnt: 3, ths-zerocnt: 1 */ - state->pdata.ths_headercnt =3D 0x0103; - state->pdata.twakeup =3D 0x4882; - state->pdata.tclk_postcnt =3D 0x008; - state->pdata.ths_trailcnt =3D 0x2; - state->pdata.hstxvregcnt =3D 0; + fallthrough; + case 594000000U: + state->pdata.lineinitcnt =3D 0xe80; + state->pdata.lptxtimecnt =3D 0x003; + /* tclk-preparecnt: 3, tclk-zerocnt: 20 */ + state->pdata.tclk_headercnt =3D 0x1403; + state->pdata.tclk_trailcnt =3D 0x00; + /* ths-preparecnt: 3, ths-zerocnt: 1 */ + state->pdata.ths_headercnt =3D 0x0103; + state->pdata.twakeup =3D 0x4882; + state->pdata.tclk_postcnt =3D 0x008; + state->pdata.ths_trailcnt =3D 0x2; + state->pdata.hstxvregcnt =3D 0; + break; + case 972000000U: + state->pdata.lineinitcnt =3D 0x1b58; + state->pdata.lptxtimecnt =3D 0x007; + /* tclk-preparecnt: 6, tclk-zerocnt: 40 */ + state->pdata.tclk_headercnt =3D 0x2806; + state->pdata.tclk_trailcnt =3D 0x00; + /* ths-preparecnt: 6, ths-zerocnt: 8 */ + state->pdata.ths_headercnt =3D 0x0806; + state->pdata.twakeup =3D 0x4268; + state->pdata.tclk_postcnt =3D 0x008; + state->pdata.ths_trailcnt =3D 0x5; + state->pdata.hstxvregcnt =3D 0; + break; + } =20 state->reset_gpio =3D devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); --=20 2.34.1 From nobody Fri Oct 10 23:10:33 2025 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC6562153E7 for ; Wed, 11 Jun 2025 18:37:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749667045; cv=none; b=grZGIsFqe6S+TGc3urqMzqxogYuBzIy/KK6b5mQUI71//0WTCkVynKddrqYiEiV7TxiFJDKzrF2IiYw5iVC4ps/JjZGfkxF7lC151x6j74VETWkGilue/I4gf+UZUKXZddH1knuVCavnL6iEUYTk26PeyErPh9aVoLWsaL1K1iw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749667045; c=relaxed/simple; bh=RyLIKNeJDHGcRQHXIaBVFM/PFmHB/hcFvEYioa32LRQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Y+SlnE5a7hj/1BFgtqRMcgjWypqNmabyA2LqSJ51whxzPkVzr2YfWqBNww6+hWy5WsY5o/h+da8HxZFMejaLt9vHwGgI/AWo32ZG58eg+FYAoA1Y13t2Kx0QyTwDDFkmHvc8nqhFyUYAVcUOVwDFel15e0nzo5COxI7fzwX8jP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=VB2T1mWi; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="VB2T1mWi" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-3a54700a46eso198531f8f.1 for ; Wed, 11 Jun 2025 11:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1749667042; x=1750271842; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6/DWf3eFTS1FAKsBMmWgLu1g2vHF8byXbBX1nrqf/VM=; b=VB2T1mWifQGJcLguGEC73P3aw+Ok5QvPAwB0qwbo4C7m1ahWrx+yILFuMXTkwqK9Vr Ps1IQui43AjQB/n1Z9f+7HGWq6honuJ7HJDWjA45aKQBERpVVkVJS/PS6rlV3C1P5sl7 HxOnVWCxCGVJ8iePCamBxtWi6E/lkMIb/MuVNYLhohYXpeFJVsvpYWrQyAlgZwHVRxZU K5CCcIAvTNPc8alozPrRdZMIZbEZ1DqYJBPnHYUYYVYC9KWxXVkQ7zskO/yYXGRLGKQx 7+pdtQKKovkbjpjoDc+EcfhYOZ6kN1m5j7IGsmG9mfXI44h8RqsIN2c0ZUSuGP18mJ9n wVeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749667042; x=1750271842; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6/DWf3eFTS1FAKsBMmWgLu1g2vHF8byXbBX1nrqf/VM=; b=NwUlXE9YwB7zgbtl//pPRmX3ilLgUppcs0n3Yz4/w9tl+s4U7TYG7KHLe/lpt2uPuS rxHTekPemcdMe3H3a7cHp0iw22NK55eASU0xPS4mrfE35Q4dGcKkOR3/FHZsJzdnxN18 ESfT53h2//Ge3uscTb+G152B4wJWX9NabUN7Nf1oPqu1Snj4VDxjveZw2c1FRbIxPu16 1upOP6KhbpB/qnFoftQEbA0ZK7zDHjR5Du+3ObAL63NVvMjvYRapv5Uo89rTU1XUpYG0 6cO2w386OcMg7FgSZXAS2FNiAzlVRMC4IKvd6ZQ0wG+mXre8nAUncLd0IptncV8LskKn OfAQ== X-Forwarded-Encrypted: i=1; AJvYcCU9VC37e11bWEMhLRlx0KlAfTy1YaclvOiFm4mJfZ4vXcBxUUBwlleKUxalXQi774eFeNIR8IzBT8lV9R4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx1YOohgjNYCk1EKioz9HDjtYYd0UJgtiGot0EqBCsG8wtm+YyW 5/GCEDPrd1rIAomnimcJ1w9MhYxuwOyRO5J4rPVC+NcS2Hf3KZyCo7rKQWlYf74t3kQ= X-Gm-Gg: ASbGncu23PoLMaTF2H1Tuq6mgbihu38CSr9Yy5e9wfKqhWktXLM9JpK20wco8i5ku7b YYsMaYBTcJd1/FP1SPQoKELo5BMwwoWeJV6jGVS0MZJ2aLpnaU3uECjtieyh01iNTmLF1TFdJvs 2Z0XJIIqF9s8YlMHCJv+cD8nLxyY3nSVV9OXbW1NIaS43/6AX2oiHV1sx7j3UeTyMmbIukZlEMJ IXAVWtwHOe+j5njbbNJgF9+FwFhJGj+ONDNjpRcldUNb9UYmvKG42FzJqmMU9YNmm/LN0nccgzO LgAF4YNKxS47jvti3Y8MO6VlRvIPAI5d4nHBytT+dSOBvWVsUMAAQA== X-Google-Smtp-Source: AGHT+IEkF/dFZASIDjRh7yC2bAPt/if4YBRK41hg0H9/5YtD56ovdLDxPjw06Yoz2hJ3UEcOFPSVyQ== X-Received: by 2002:a05:6000:2204:b0:3a3:7593:818b with SMTP id ffacd0b85a97d-3a558695e91mr3797607f8f.21.1749667041968; Wed, 11 Jun 2025 11:37:21 -0700 (PDT) Received: from [127.0.1.1] ([2a00:1098:3142:e::8]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a5324364d4sm16119390f8f.55.2025.06.11.11.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 11:37:21 -0700 (PDT) From: Dave Stevenson Date: Wed, 11 Jun 2025 19:37:14 +0100 Subject: [PATCH 2/4] media: tc358743: Increase FIFO trigger level to 374 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-media-tc358743-v1-2-708556026f9d@raspberrypi.com> References: <20250611-media-tc358743-v1-0-708556026f9d@raspberrypi.com> In-Reply-To: <20250611-media-tc358743-v1-0-708556026f9d@raspberrypi.com> To: Hans Verkuil , Mauro Carvalho Chehab Cc: Maxime Ripard , Philipp Zabel , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Stevenson X-Mailer: b4 0.14.1 The existing fixed value of 16 worked for UYVY 720P60 over 2 lanes at 594MHz, or UYVY 1080P60 over 4 lanes. (RGB888 1080P60 needs 6 lanes at 594MHz). It doesn't allow for lower resolutions to work as the FIFO underflows. 374 is required for 1080P24 or 1080P30 UYVY over 2 lanes @ 972Mbit/s, but >374 means that the FIFO underflows on 1080P50 UYVY over 2 lanes @ 972Mbit/s. Whilst it would be nice to compute it, the required information isn't published by Toshiba. Signed-off-by: Dave Stevenson Tested-by: Maxime Ripard --- drivers/media/i2c/tc358743.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c index b87db3de20db..ddba8c392ead 100644 --- a/drivers/media/i2c/tc358743.c +++ b/drivers/media/i2c/tc358743.c @@ -1972,8 +1972,19 @@ static int tc358743_probe_of(struct tc358743_state *= state) state->pdata.refclk_hz =3D clk_get_rate(refclk); state->pdata.ddc5v_delay =3D DDC5V_DELAY_100_MS; state->pdata.enable_hdcp =3D false; - /* A FIFO level of 16 should be enough for 2-lane 720p60 at 594 MHz. */ - state->pdata.fifo_level =3D 16; + /* + * Ideally the FIFO trigger level should be set based on the input and + * output data rates, but the calculations required are buried in + * Toshiba's register settings spreadsheet. + * A value of 16 works with a 594Mbps data rate for 720p60 (using 2 + * lanes) and 1080p60 (using 4 lanes), but fails when the data rate + * is increased, or a lower pixel clock is used that result in CSI + * reading out faster than the data is arriving. + * + * A value of 374 works with both those modes at 594Mbps, and with most + * modes on 972Mbps. + */ + state->pdata.fifo_level =3D 374; /* * The PLL input clock is obtained by dividing refclk by pll_prd. * It must be between 6 MHz and 40 MHz, lower frequency is better. --=20 2.34.1 From nobody Fri Oct 10 23:10:33 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97312225388 for ; Wed, 11 Jun 2025 18:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749667046; cv=none; b=XsfkicPxL1BukkCHGyab2RqrhCzvSKu8h5uwRgZi7cJ9lRbcdslRsV5IZpIpRWXVDwO4xWBQTfzLGgFwzZybGtdI0nZ76hNqcTHC9XhHQmvECuagIbO2cHugGVcVtM+Ov7tW4uAkD4mLUYEH7uI8KqFji/VWBUDoRGY5zGPudXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749667046; c=relaxed/simple; bh=VRd2k/Q/i3FDTIxyZfK84tJ4lV+Mf4e5ymoaKFQZRCs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WxPKWsmhFXS3IhbuJnk6Z1dt2LJVsPo8wNny2NB0w44POXHZ87zUUpXfF1OSbAGsDv+qn5Tmf2gG+hyVUjPOzbOOOaPhWfAyuY4z8Ytl1KKokAGdP5/lcmCUHuUw1T1A0PoLIJnC/N+MPqMYsLMkCZn841kJqcoQe9sRpY08JdI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=IaFJ8l/q; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="IaFJ8l/q" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3a51d552de4so147303f8f.0 for ; Wed, 11 Jun 2025 11:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1749667043; x=1750271843; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=f/axqm8k3/xlEItyAFlEMdzmmFWn3XyIBiwkuVUA9GE=; b=IaFJ8l/qw3xgAcnyPN3GjYU+xik77kVDNYqfPwv+dyQYE8DKPsxb1iT6bMvDto98S3 KvscFzeqX7p5eVZvjBkkEoKZqDPHhgwjINU0o/Zirz2PldJ7kstaN3KbV6lrL5YkLWzB qgMJWuUU159D1JSbDNXwkiY89evPhSmH7Xa5YExZak1Twi1tst7+SmC+0BL/X2LKSsFd hRyVt2iaLDnrlOFcadMacurpLx2zdn/IPvpBDxx0iljUWHlix0LfKbbjkcpoR4rB2qMN +Q42t0QORIkokBEe8CRazFl2AwT5AwcTTfqcE+jQRnQZm3eNSFynSg5WR3Ur04iXFeaQ 8Tdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749667043; x=1750271843; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f/axqm8k3/xlEItyAFlEMdzmmFWn3XyIBiwkuVUA9GE=; b=v2diryhXgCm6Ui+AyxHl2IaXtTm1LtdQeA6HeMoHRYY8iBlZjSOgFVerP9mIZ+uOyQ ILshM1TclftYo4r8FfcWTq0R0oVdN2PsF50Hc7qUrSkd5wL8OWsHpahanuVqkJE5zr3j Rsg0Yd6Qp5gy5YPKNLgb8bwBNPVbbSZGaPhrb9TAeyIWfz8gD46B9sdP1UChjh6QzgW5 SLjPkTFYTF24OykVHr2U81Vxpo8vtwOxs3cNQbi+vHUGuiprQyB/5dyhOIbalusoLjqp E/30AN1kh0sT8BP3ph0Hg/YyQLLwHVOvdMnOIJOuBJeFDLdcKlqORhILvvzRrAjjnZ93 DQyA== X-Forwarded-Encrypted: i=1; AJvYcCWcONN2SBninyyFjZms10Vk7OaMV5T0kkHzL3dHYy+XewjLriuh21AdsaZWkQXmT+ZUna42ucHSUitFANY=@vger.kernel.org X-Gm-Message-State: AOJu0YynH+B0/2k4fcCedHhPxsbwWRqouRTwwwzOtP7lbfDYLHs11Aok h/MJU8G8r5NCtM7KuS1ENk441CQzVveKMZmhnP3LAixR2odGhqsZY1xcgl5YtQftIA0= X-Gm-Gg: ASbGncub03tIDAY1df6E1c+yen0rI1x034ThMPOhHyFWtrFJOouJBFnt31KZmozG86v OpHhLLlljnYyB7UdTy89+MaK+ANMPrGatuVjjLhtVpNkBFRRDTA8Cv3VMTdXABGwxnE23mT5rCJ wB853peMIwkeVIKvbzMOPVCmuB91b4Jf8aGCGiU3Pe/yUAaHLZz4iURpVd+OKjo+60KpsWtpTD/ ohRQ3NHZXRXQKj5j+3VRa46yPTyE+FdEv8TyKMKBLdXqo4jhb3CNHWDX2WDCE07x2CZqJn6X9gx 30wlaB0dHM/nVmQyFB4XyQF42srsPfFPnra9EHhHcp8FzYL6VvaI8g== X-Google-Smtp-Source: AGHT+IHy4y7hCn0YytWiolkQuGznWohvLW0swvm6O3+u87Ddu4wgBl0yE5V8jmp1ZcCdpnMkxt7mIA== X-Received: by 2002:a5d:584a:0:b0:3a5:2f23:376f with SMTP id ffacd0b85a97d-3a5606c83b4mr431761f8f.13.1749667042774; Wed, 11 Jun 2025 11:37:22 -0700 (PDT) Received: from [127.0.1.1] ([2a00:1098:3142:e::8]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a5324364d4sm16119390f8f.55.2025.06.11.11.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 11:37:22 -0700 (PDT) From: Dave Stevenson Date: Wed, 11 Jun 2025 19:37:15 +0100 Subject: [PATCH 3/4] media: tc358743: Check I2C succeeded during probe Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-media-tc358743-v1-3-708556026f9d@raspberrypi.com> References: <20250611-media-tc358743-v1-0-708556026f9d@raspberrypi.com> In-Reply-To: <20250611-media-tc358743-v1-0-708556026f9d@raspberrypi.com> To: Hans Verkuil , Mauro Carvalho Chehab Cc: Maxime Ripard , Philipp Zabel , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Stevenson X-Mailer: b4 0.14.1 The probe for the TC358743 reads the CHIPID register from the device and compares it to the expected value of 0. If the I2C request fails then that also returns 0, so the driver loads thinking that the device is there. Generally I2C communications are reliable so there is limited need to check the return value on every transfer, therefore only amend the one read during probe to check for I2C errors. Signed-off-by: Dave Stevenson Tested-by: Maxime Ripard --- drivers/media/i2c/tc358743.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c index ddba8c392ead..4d3dc61a9b8b 100644 --- a/drivers/media/i2c/tc358743.c +++ b/drivers/media/i2c/tc358743.c @@ -114,7 +114,7 @@ static inline struct tc358743_state *to_state(struct v4= l2_subdev *sd) =20 /* --------------- I2C --------------- */ =20 -static void i2c_rd(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n) +static int i2c_rd(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n) { struct tc358743_state *state =3D to_state(sd); struct i2c_client *client =3D state->i2c_client; @@ -140,6 +140,7 @@ static void i2c_rd(struct v4l2_subdev *sd, u16 reg, u8 = *values, u32 n) v4l2_err(sd, "%s: reading register 0x%x from 0x%x failed: %d\n", __func__, reg, client->addr, err); } + return err !=3D ARRAY_SIZE(msgs); } =20 static void i2c_wr(struct v4l2_subdev *sd, u16 reg, u8 *values, u32 n) @@ -196,15 +197,24 @@ static void i2c_wr(struct v4l2_subdev *sd, u16 reg, u= 8 *values, u32 n) } } =20 -static noinline u32 i2c_rdreg(struct v4l2_subdev *sd, u16 reg, u32 n) +static noinline u32 i2c_rdreg_err(struct v4l2_subdev *sd, u16 reg, u32 n, + int *err) { + int error; __le32 val =3D 0; =20 - i2c_rd(sd, reg, (u8 __force *)&val, n); + error =3D i2c_rd(sd, reg, (u8 __force *)&val, n); + if (err) + *err =3D error; =20 return le32_to_cpu(val); } =20 +static inline u32 i2c_rdreg(struct v4l2_subdev *sd, u16 reg, u32 n) +{ + return i2c_rdreg_err(sd, reg, n, NULL); +} + static noinline void i2c_wrreg(struct v4l2_subdev *sd, u16 reg, u32 val, u= 32 n) { __le32 raw =3D cpu_to_le32(val); @@ -233,6 +243,13 @@ static u16 i2c_rd16(struct v4l2_subdev *sd, u16 reg) return i2c_rdreg(sd, reg, 2); } =20 +static int i2c_rd16_err(struct v4l2_subdev *sd, u16 reg, u16 *value) +{ + int err; + *value =3D i2c_rdreg_err(sd, reg, 2, &err); + return err; +} + static void i2c_wr16(struct v4l2_subdev *sd, u16 reg, u16 val) { i2c_wrreg(sd, reg, val, 2); @@ -2092,6 +2109,7 @@ static int tc358743_probe(struct i2c_client *client) struct tc358743_platform_data *pdata =3D client->dev.platform_data; struct v4l2_subdev *sd; u16 irq_mask =3D MASK_HDMI_MSK | MASK_CSI_MSK; + u16 chipid; int err; =20 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) @@ -2123,7 +2141,8 @@ static int tc358743_probe(struct i2c_client *client) sd->flags |=3D V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; =20 /* i2c access */ - if ((i2c_rd16(sd, CHIPID) & MASK_CHIPID) !=3D 0) { + if (i2c_rd16_err(sd, CHIPID, &chipid) || + (chipid & MASK_CHIPID) !=3D 0) { v4l2_info(sd, "not a TC358743 on address 0x%x\n", client->addr << 1); return -ENODEV; --=20 2.34.1 From nobody Fri Oct 10 23:10:33 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA0BB27467F for ; Wed, 11 Jun 2025 18:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749667047; cv=none; b=T888wyROw6kBuH4huRkTVCDkJCC5wdnUDCnGDODZtU1/VWes3foh/CAjzkx90EXDPUQQkmv57RHffZQQGv3J/aGGhotO/NpBIfRA/8qy2E/KGLljDEIsgOL0BH48VFKN+RiQkBtAR5jLtX2jdjKyLEfQgvnGovKkAmwizzmZQow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749667047; c=relaxed/simple; bh=As5A0OqeYX31BcT5f8MqqEWBy/dKh075/j28h5b08z0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dquRfXt/16HqPQSBMSOMi5cgZMU+L3wUk8TLfjKy6tTNzzVkdETYQYLEZkqZFgTmSRhmVf7u80gtTgysdxWurILjdMbLtyx8OnFmbK4RlLN+NmJx4C861DQ6OSUqrc0kWZkEyzATDf0qWna6jXVCA8DEZATu4HpRDbvaDm644qU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com; spf=pass smtp.mailfrom=raspberrypi.com; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b=BTrCvNfK; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raspberrypi.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="BTrCvNfK" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-450cfb79177so555555e9.0 for ; Wed, 11 Jun 2025 11:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1749667044; x=1750271844; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=+P+Xcul569I8IEtQZA+nCLqa8EijcGyUC3HbPjalOas=; b=BTrCvNfKl8vNM9rWO9YOjOUn3mOL1wOccHTE5guaZBDMrL/7FNe1ydH2fjASKkzWoO PnXWoly0Ek6nNsnz7cc96FYYwP/l72245jr2HuWvreuV7yjdy8cfCkRQpzBvuOnXwOPt vWS75pyffHucmbjqRqVlNtX36rgNydXzvL3oR11Pdjq/eLsUzYDFZefpRiDgvHAjP4Ar 0XutGc3pMh5ERCeiMS64vPXXbfGSHqPLAurPbWQe7KdnldeCPn0R4Num7TkOb14WDPgS jnM27OwDL/8viC+ai75vyAwePy35of3en6NLObyEn7/7buM025XlA84RcdicOJRtANZP NQXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749667044; x=1750271844; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+P+Xcul569I8IEtQZA+nCLqa8EijcGyUC3HbPjalOas=; b=V/FsBfyrbKAxlLOihKYxu308oGfuhnesai7OmL+ZywRFFC1t5+umbHFeLyFHY0QoX8 MF7w++abN8m7ynGhVu2PF4uTI7VN3Qh8VHTcMeL3jMkPVc/TGS4clC2tlhSvAZSwhfIR 1/DBDcWRw/qBBe72KgbpJzlUrU6kfhOLrmOIWu/cWEieRG/G+PTbG4baaySUKnqxm9b7 Vv069FjLYtaNgOt1j0nOE21wHNooY1ztl6ijqiPgMmfj2S3tNG0htSvL+duM7VYakc1k jquYwUbwk5HWC55mDc7Q1M1AlBkk6Mb8LaCpedJZc7YakTQU8qwN3fl1u4W7H70ZEhuD A0zw== X-Forwarded-Encrypted: i=1; AJvYcCVZIcYNPa8JT35LCIqSmoF/1YgA1sA70xbBHsG0IYAVYIyvVVLTr0xfjg+GWijZKoHUpOEvOZAUQ5HJUSM=@vger.kernel.org X-Gm-Message-State: AOJu0YzEJcqLXQbCxa1N3aZB/DbtnWJUKXhsHjcQADN3Sk/P2DmQqkYI +4au1wx9OMP1hlX1+kS1zlnmTj7xo0LaLAsQWV3Osa05I7tnTlnX3jIgEePpBZp/ArE= X-Gm-Gg: ASbGncs0Zm4ML/TXfMnpo5m6Z0tvwn1tssCPlVBfevMeaKk6vyl0tf1U0cg8pAWPh03 P8UwM+BiMroVolcGA5npn2RCbGqHwvFGiQtAhUeZUWSsqNZpW97T8C/aDNiPeFyXpsHPpE+QJE6 Kc6+Go8/0kTNM3TecRoVuOhttW0HPYkG5hsbWVIMBHEtbKWYadmJTHeDG50U/TWIRjV8LEuDR9p ddIQEctlry/zvFnoeZ4I0DD+O72OwnfCvg04+L9oxuhekuPriONEHXXvyOIDYfhsUMi5DfslTJx EvVCRxfMUDhKq+gSu4Sv2ceWpEW8/Go4ADpOHCbCeCn/LKL6DAQ4O96RjX69Eq8m X-Google-Smtp-Source: AGHT+IFoP50tmhgFnoHamwtAePqFHuyZl0kIlu1pe1rTBJjxaOHhQLNNJiWGEyddK2iuPOKOY76sBw== X-Received: by 2002:a05:6000:26c7:b0:3a4:f70d:dec3 with SMTP id ffacd0b85a97d-3a5606c7a11mr367720f8f.16.1749667044189; Wed, 11 Jun 2025 11:37:24 -0700 (PDT) Received: from [127.0.1.1] ([2a00:1098:3142:e::8]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-3a5324364d4sm16119390f8f.55.2025.06.11.11.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jun 2025 11:37:23 -0700 (PDT) From: Dave Stevenson Date: Wed, 11 Jun 2025 19:37:16 +0100 Subject: [PATCH 4/4] media: tc358743: Return an appropriate colorspace from tc358743_set_fmt Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250611-media-tc358743-v1-4-708556026f9d@raspberrypi.com> References: <20250611-media-tc358743-v1-0-708556026f9d@raspberrypi.com> In-Reply-To: <20250611-media-tc358743-v1-0-708556026f9d@raspberrypi.com> To: Hans Verkuil , Mauro Carvalho Chehab Cc: Maxime Ripard , Philipp Zabel , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Dave Stevenson X-Mailer: b4 0.14.1 When calling tc358743_set_fmt, the code was calling tc358743_get_fmt to choose a valid format. However that sets the colorspace based on information read back from the chip, not the colour format requested. The result was that if you called try or set format for UYVY when the current format was RGB3 then you would get told SRGB, and try RGB3 when current was UYVY and you would get told SMPTE170M. The value programmed in the VI_REP register for the colorspace is always set by this driver, therefore there is no need to read back the value, and never set to REC709. Return the colorspace based on the format set/tried instead. Signed-off-by: Dave Stevenson Tested-by: Maxime Ripard --- drivers/media/i2c/tc358743.c | 44 +++++++++++++++++-----------------------= ---- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/drivers/media/i2c/tc358743.c b/drivers/media/i2c/tc358743.c index 4d3dc61a9b8b..37ebc760f73b 100644 --- a/drivers/media/i2c/tc358743.c +++ b/drivers/media/i2c/tc358743.c @@ -1708,12 +1708,23 @@ static int tc358743_enum_mbus_code(struct v4l2_subd= ev *sd, return 0; } =20 +static u32 tc358743_g_colorspace(u32 code) +{ + switch (code) { + case MEDIA_BUS_FMT_RGB888_1X24: + return V4L2_COLORSPACE_SRGB; + case MEDIA_BUS_FMT_UYVY8_1X16: + return V4L2_COLORSPACE_SMPTE170M; + default: + return 0; + } +} + static int tc358743_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *sd_state, struct v4l2_subdev_format *format) { struct tc358743_state *state =3D to_state(sd); - u8 vi_rep =3D i2c_rd8(sd, VI_REP); =20 if (format->pad !=3D 0) return -EINVAL; @@ -1723,23 +1734,7 @@ static int tc358743_get_fmt(struct v4l2_subdev *sd, format->format.height =3D state->timings.bt.height; format->format.field =3D V4L2_FIELD_NONE; =20 - switch (vi_rep & MASK_VOUT_COLOR_SEL) { - case MASK_VOUT_COLOR_RGB_FULL: - case MASK_VOUT_COLOR_RGB_LIMITED: - format->format.colorspace =3D V4L2_COLORSPACE_SRGB; - break; - case MASK_VOUT_COLOR_601_YCBCR_LIMITED: - case MASK_VOUT_COLOR_601_YCBCR_FULL: - format->format.colorspace =3D V4L2_COLORSPACE_SMPTE170M; - break; - case MASK_VOUT_COLOR_709_YCBCR_FULL: - case MASK_VOUT_COLOR_709_YCBCR_LIMITED: - format->format.colorspace =3D V4L2_COLORSPACE_REC709; - break; - default: - format->format.colorspace =3D 0; - break; - } + format->format.colorspace =3D tc358743_g_colorspace(format->format.code); =20 return 0; } @@ -1753,19 +1748,14 @@ static int tc358743_set_fmt(struct v4l2_subdev *sd, u32 code =3D format->format.code; /* is overwritten by get_fmt */ int ret =3D tc358743_get_fmt(sd, sd_state, format); =20 - format->format.code =3D code; + if (code =3D=3D MEDIA_BUS_FMT_RGB888_1X24 || + code =3D=3D MEDIA_BUS_FMT_UYVY8_1X16) + format->format.code =3D code; + format->format.colorspace =3D tc358743_g_colorspace(format->format.code); =20 if (ret) return ret; =20 - switch (code) { - case MEDIA_BUS_FMT_RGB888_1X24: - case MEDIA_BUS_FMT_UYVY8_1X16: - break; - default: - return -EINVAL; - } - if (format->which =3D=3D V4L2_SUBDEV_FORMAT_TRY) return 0; =20 --=20 2.34.1