From patchwork Tue Sep 3 08:39:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juerg Haefliger X-Patchwork-Id: 1979916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WyfGH04GTz1yZ9 for ; Tue, 3 Sep 2024 18:40:39 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1slP5T-0001mp-CQ; Tue, 03 Sep 2024 08:40:31 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1slP5N-0001WQ-QY for kernel-team@lists.ubuntu.com; Tue, 03 Sep 2024 08:40:25 +0000 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id B5CC23F183 for ; Tue, 3 Sep 2024 08:40:25 +0000 (UTC) Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a8691010836so374703366b.2 for ; Tue, 03 Sep 2024 01:40:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725352825; x=1725957625; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uaYQpzwfOXQ011Plhuqhb1pyvRaM4QKyRWrgwSawzDI=; b=n4cPSiwB8aAF02DWH0FQm8X85WbaaUEwkHqVPbZEoEqjcbdJDyTxRTg8F262Og6iuZ AMlYxq67XcGpToeG2QqepY/f1aGTZy1bH2I+A4wVR7QdKkrTQ1/180CiaxRdxASsGS2f hSDU/zp2gkJHJ4qw1D9LY7k5l44gASLrxcGvXupiT3Pc54ZNj5TB/XCtoBnm+wzDQBr8 oyhIUhZ2UC0GACtwT/oAhG80y0tYod7uAjBECaGFsi6hs7JUOfPqdCyzjp5umPGToNIA 94mSUC59M/PEQV+ELIPiz9ugg9G7Bx4xWzDSdJNb11UWWaXKXW//x6az4vAI8DYMvtpt WOIA== X-Gm-Message-State: AOJu0Yxqh/dcGRqSJShxY7exx/3jZjGI4d23pYh9Aoa1Tj174JHpAQVY 8pkg4/mI0iSQXmH0OONWL3YdZO0l1D28XH+qNnycRHTXxf0Eul3Ccj8bImZTLiT8F+211+j+J72 qlYN0wv+f7x7IJdC3A4r0b+kMa2ljx/LI6yOfOjgX3HtRFLbgZ7pfHBp2xP3c2y4ttiMKu8c9DL TmAktqpd5i1g== X-Received: by 2002:a17:906:fd88:b0:a86:b923:4a04 with SMTP id a640c23a62f3a-a89a379cf80mr1168110866b.50.1725352825157; Tue, 03 Sep 2024 01:40:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0gGUj7AaCOtOPPvubEWmy5WA4xSELXep5S7pge8yGdDrxj7GdxLGsD6hqM2TpuWZtXv8QKA== X-Received: by 2002:a17:906:fd88:b0:a86:b923:4a04 with SMTP id a640c23a62f3a-a89a379cf80mr1168107466b.50.1725352824513; Tue, 03 Sep 2024 01:40:24 -0700 (PDT) Received: from localhost ([81.221.247.52]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a89891daeb1sm655826266b.169.2024.09.03.01.40.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 01:40:24 -0700 (PDT) From: Juerg Haefliger To: kernel-team@lists.ubuntu.com Subject: [O][PATCH 09/21] UBUNTU: SAUCE: media: ov5675: Fix power on/off delay timings Date: Tue, 3 Sep 2024 10:39:58 +0200 Message-ID: <20240903084010.3746280-10-juerg.haefliger@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240903084010.3746280-1-juerg.haefliger@canonical.com> References: <20240903084010.3746280-1-juerg.haefliger@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Bryan O'Donoghue The ov5675 specification says that the gap between XSHUTDN deassert and the first I2C transaction should be a minimum of 8192 XVCLK cycles. Right now we use a usleep_rage() that gives a sleep time of between about 430 and 860 microseconds. On the Lenovo X13s we have observed that in about 1/20 cases the current timing is too tight and we start transacting before the ov5675's reset cycle completes, leading to I2C bus transaction failures. The reset racing is sometimes triggered at initial chip probe but, more usually on a subsequent power-off/power-on cycle e.g. [ 71.451662] ov5675 24-0010: failed to write reg 0x0103. error = -5 [ 71.451686] ov5675 24-0010: failed to set plls The current quiescence period we have is too tight. Instead of expressing the post reset delay in terms of the current XVCLK this patch converts the power-on and power-off delays to the maximum theoretical delay @ 6 MHz with an additional buffer. 1.365 milliseconds on the power-on path is 1.5 milliseconds with grace. 85.3 microseconds on the power-off path is 90 microseconds with grace. Fixes: 49d9ad719e89 ("media: ov5675: add device-tree support and support runtime PM") Cc: stable@vger.kernel.org Signed-off-by: Bryan O'Donoghue Link: https://lore.kernel.org/r/20240713-linux-next-ov5675-v3-1-527f5b985836@linaro.org Signed-off-by: Johan Hovold (cherry picked from commit 719ec29fceda2f19c833d2784b1574638320400f linuxtv.org/media_stage) Signed-off-by: Juerg Haefliger --- drivers/media/i2c/ov5675.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/ov5675.c b/drivers/media/i2c/ov5675.c index 3641911bc73f..5b5127f8953f 100644 --- a/drivers/media/i2c/ov5675.c +++ b/drivers/media/i2c/ov5675.c @@ -972,12 +972,10 @@ static int ov5675_set_stream(struct v4l2_subdev *sd, int enable) static int ov5675_power_off(struct device *dev) { - /* 512 xvclk cycles after the last SCCB transation or MIPI frame end */ - u32 delay_us = DIV_ROUND_UP(512, OV5675_XVCLK_19_2 / 1000 / 1000); struct v4l2_subdev *sd = dev_get_drvdata(dev); struct ov5675 *ov5675 = to_ov5675(sd); - usleep_range(delay_us, delay_us * 2); + usleep_range(90, 100); clk_disable_unprepare(ov5675->xvclk); gpiod_set_value_cansleep(ov5675->reset_gpio, 1); @@ -988,7 +986,6 @@ static int ov5675_power_off(struct device *dev) static int ov5675_power_on(struct device *dev) { - u32 delay_us = DIV_ROUND_UP(8192, OV5675_XVCLK_19_2 / 1000 / 1000); struct v4l2_subdev *sd = dev_get_drvdata(dev); struct ov5675 *ov5675 = to_ov5675(sd); int ret; @@ -1014,8 +1011,11 @@ static int ov5675_power_on(struct device *dev) gpiod_set_value_cansleep(ov5675->reset_gpio, 0); - /* 8192 xvclk cycles prior to the first SCCB transation */ - usleep_range(delay_us, delay_us * 2); + /* Worst case quiesence gap is 1.365 milliseconds @ 6MHz XVCLK + * Add an additional threshold grace period to ensure reset + * completion before initiating our first I2C transaction. + */ + usleep_range(1500, 1600); return 0; }