From patchwork Thu Jul 11 10:20:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 13730302 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 DE0811586D5 for ; Thu, 11 Jul 2024 10:20:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720693205; cv=none; b=eR16p8Z+Hg9+ym60T+8ecmjoMpEVRjODDVYOZIlJeliQ2svW++gHojGMPG3BwRu3Wy6iPfmbcukDi2KA/mBRUC8Qp7tIULbSh8mTkT1XMFOM1Vt89RpSpE5Q3hoQ+9XppDX4UpE1DvVjmxc7UfyflAuzzq4rnher763ByoMIOf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720693205; c=relaxed/simple; bh=ZDIWCtJoTPpqgSB2DOYJ2lRtvYa0iBWUcVLT0ATuLSA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UbsBerCyNZUM7Kveq+gYUI+IAcjUzHDkYpgs+olacYHbI6XdwuDUuG6XOHEkIj6q7oY2FQXtgAX+tRH1DU6TaqGNoMxzXMECAjx81m2i0vbkDeewiSUe33Tz+iXT5LNe2VjqVrdwXgx6O2KQdyn7RL1H6V0w5k8HXqJAcNjEEtU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=spJ3uAlD; arc=none smtp.client-ip=209.85.208.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="spJ3uAlD" Received: by mail-lj1-f173.google.com with SMTP id 38308e7fff4ca-2eea7e2b0e6so7798671fa.3 for ; Thu, 11 Jul 2024 03:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720693202; x=1721298002; 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=koV68SqPyU3UAlRmC6Mum6YXdK1Ua2t3zfx/aiRtqyk=; b=spJ3uAlDKfr4M9oYlQNSaHYLMZHB1Xdc2AsvIOPgiWfFng/4huu1LUDwVE+K1cjlKK W/WCVh7wHg7X7sIjrh/nWz4HulHYzEIDDNFbmB10jSsqjUUr7r+vxQNqX0MithqC32Ni oebS6IHrRh74MEFwt9GpG/h4hzgphXGB9MSYpKqbMMUxsnOty72r0MBspUhr0vCSYjQN TifUQlqEK+JDlrsg2eenKk5uAG/ibIFPLqut244ZK4dHKqA+nOJ34gaHTYNMocXGW0xB f8d/T/85HR6vyr/6+pnIw9KIufZzuYN5IjORhuxysqc4UmO7SMy/gW6P3JHGkw2I+Qch iKqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720693202; x=1721298002; 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=koV68SqPyU3UAlRmC6Mum6YXdK1Ua2t3zfx/aiRtqyk=; b=RZ3+yWq5ozK0wplT8wAlusIZE5UOq72Hvqh77XOSFqkvkBT7LzKrq4pPZRPG8dG1a0 /hsLjjRIYUhshjq7nkDlW1M8z1/OCm/JwsPPUk1J89WO+1vWH3P0crQgW9z2H2Qn2t7j biQXrGNk6Ssi+CfLW5jFdY05tmDHFDvi4azbt/1+PKR0xlBQnKKWzorwUK5hhPsEjrsc wEWtDBQQMTKr1J8FA2gpAn0kAHo1x42j/p64WZU6OAdRte8M8Yhlva3XTNYMbg92Nrxe 7Iu2RySrn75GFhmg42tDtLOwbYu2o+3mDCdDPBZ40WQQNo1ADOlNt06Bl011AkdY48Aj BCsA== X-Forwarded-Encrypted: i=1; AJvYcCU3mBmmpdSO9aGoDbaQyscYoSz3UUN1KvcTzI+/eqj6o2Nt/TLaArG88XizslKu37VNBIcncCPmoaQjMnZ57yC5UhjSBa5VxTcgCGs= X-Gm-Message-State: AOJu0YyMc+6QNxq7jAIbX2wRc1B0HxQcmaO0LibFOV3//OrEBTkzYsYo LqBrsVdg5Suafbp/Pa4SKj0MmIJT+qrsW6iQa34OHRraEiF3niJvJpO0HLZZ0SI= X-Google-Smtp-Source: AGHT+IG4lGOEP0ObrRCkbO66rKar4kb9gm5MrDgJ4yrSwAmZ7O8Q6KboQB+IJXQ95N9D6jwYagmyoA== X-Received: by 2002:a05:6512:3b8c:b0:52c:6461:e913 with SMTP id 2adb3069b0e04-52eb999623amr5603923e87.16.1720693202115; Thu, 11 Jul 2024 03:20:02 -0700 (PDT) Received: from [127.0.1.1] ([176.61.106.227]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4266e861339sm125270025e9.12.2024.07.11.03.20.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 03:20:01 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 11 Jul 2024 11:20:01 +0100 Subject: [PATCH 1/2] media: ov5675: Derive delay cycles from the clock rate reported Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-linux-next-ov5675-v1-1-69e9b6c62c16@linaro.org> References: <20240711-linux-next-ov5675-v1-0-69e9b6c62c16@linaro.org> In-Reply-To: <20240711-linux-next-ov5675-v1-0-69e9b6c62c16@linaro.org> To: Sakari Ailus , Mauro Carvalho Chehab , Quentin Schulz , Jacopo Mondi Cc: Johan Hovold , Kieran Bingham , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Bryan O'Donoghue X-Mailer: b4 0.15-dev-13183 The ov5675 driver expresses its reset delays in terms of XVCLK cycles as per the ov5675 specification. XVCLK can be anything in the range of 6 MHz to 24 MHz inclusive. Upstream we use 19.2 MHz however, since the delays are calculated in terms of clock cycles as opposed to fixed intervals it makes sense to facilitate any potential clock we might support. Do so by reading the XVCLK rate and using the returned rate instead of operating from a static definition. Signed-off-by: Bryan O'Donoghue Reviewed-by: Quentin Schulz --- drivers/media/i2c/ov5675.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/media/i2c/ov5675.c b/drivers/media/i2c/ov5675.c index 3641911bc73f..92bd35133a5d 100644 --- a/drivers/media/i2c/ov5675.c +++ b/drivers/media/i2c/ov5675.c @@ -497,6 +497,7 @@ struct ov5675 { struct media_pad pad; struct v4l2_ctrl_handler ctrl_handler; struct clk *xvclk; + u32 xvclk_rate; struct gpio_desc *reset_gpio; struct regulator_bulk_data supplies[OV5675_NUM_SUPPLIES]; @@ -973,10 +974,11 @@ 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); + u32 delay_us; + delay_us = DIV_ROUND_UP(512, ov5675->xvclk_rate / 1000 / 1000); usleep_range(delay_us, delay_us * 2); clk_disable_unprepare(ov5675->xvclk); @@ -988,11 +990,13 @@ 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); + u32 delay_us; int ret; + delay_us = DIV_ROUND_UP(8192, ov5675->xvclk_rate / 1000 / 1000); + ret = clk_prepare_enable(ov5675->xvclk); if (ret < 0) { dev_err(dev, "failed to enable xvclk: %d\n", ret); @@ -1178,7 +1182,6 @@ static int ov5675_get_hwcfg(struct ov5675 *ov5675, struct device *dev) struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = V4L2_MBUS_CSI2_DPHY }; - u32 xvclk_rate; int ret; unsigned int i, j; @@ -1192,10 +1195,10 @@ static int ov5675_get_hwcfg(struct ov5675 *ov5675, struct device *dev) PTR_ERR(ov5675->xvclk)); if (ov5675->xvclk) { - xvclk_rate = clk_get_rate(ov5675->xvclk); + ov5675->xvclk_rate = clk_get_rate(ov5675->xvclk); } else { ret = fwnode_property_read_u32(fwnode, "clock-frequency", - &xvclk_rate); + &ov5675->xvclk_rate); if (ret) { dev_err(dev, "can't get clock frequency"); @@ -1203,9 +1206,9 @@ static int ov5675_get_hwcfg(struct ov5675 *ov5675, struct device *dev) } } - if (xvclk_rate != OV5675_XVCLK_19_2) { + if (ov5675->xvclk_rate != OV5675_XVCLK_19_2) { dev_err(dev, "external clock rate %u is unsupported", - xvclk_rate); + ov5675->xvclk_rate); return -EINVAL; } From patchwork Thu Jul 11 10:20:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 13730304 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.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 F31A115887C for ; Thu, 11 Jul 2024 10:20:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720693207; cv=none; b=RE+kvVLasN5FAmbu6ilvz0fJXdjKP8qmglhamSjWmZPoUKbgFWdNVuVUtVi0GF+1Gs1Hx2WD8aaE5EhFTJwfYj6GKyF79rJmgdxr2r9+4LjuWnqcfaApqcLgyvJPG6xHMmizl/13xZ5UBrmgH9+nX3hsXl1HIjJub89E3LXPhzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720693207; c=relaxed/simple; bh=bKIdUuVmWv5FJkFDtu2H6clQsAHCUTFbn8+qyaw6hHg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N6NU3XawD3fLsPPC+BiZGsqklsXtYYSyYgTlh/EQA0nWERhK/8i/cIGTwx6D1rVRfkcNNbeR4ITp+KvdnwbV8Mgf6KBKEmaJPB0hSjBHsFftIo17DTX1dM8AKiu0qG1DhcIzwb+/Zb5QdW8UR3JQv217jU9n1SZ01WeHsX+nXe0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=AeDeOfgq; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AeDeOfgq" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4279c924ca7so35395e9.2 for ; Thu, 11 Jul 2024 03:20:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1720693203; x=1721298003; 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=Jw6bLyA4dVnYszcIqA96Q05ikE6tm67ysRPS44gZ2Bo=; b=AeDeOfgqmtP6YqYtgTpYNinb9oqMQl3i7j38vK4+io3o2BdQ00xqcjagYE4jzCULnB E4zK8QAZ7vgI18tg4Wl9bxBcVnzYW/fUdzoUskWQc+r5st4WQBPQ18QdyrnbNCK/CkK9 9by3L7M9izvLBeYybfLp7EGrHzIkly9reeppj256TLUcJTas4KaaYGDeL6blF2Xj67po 7JmFAm3A3hjbGCAd7Q45WmwhiU9R7cNAbVHuzPXOMnlorAPMeRcyY1KCUJmq8r2iA7vm Jmdj+/wNpcM5s0aaCWbWTgk2OVrKksnQfoAsrNXjLVa1Ng0pN2u+TS64yQ0ie+9HuytJ lUbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720693203; x=1721298003; 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=Jw6bLyA4dVnYszcIqA96Q05ikE6tm67ysRPS44gZ2Bo=; b=Jw6ev/WrFlZjf73GPlzCavoVlW8KlbV3iEvAZVXT3RT7hO1Fp1LtfRjRT/jdGC+ia9 gS/STO3VMq0Et2caiGpB9QiTij7zaVI7QZaL7ozO2A57ldqnYfiIEHPO1d02RGnOBT/H eqXe6Zlg/tF4+1A8WWkzqA+BFmR2gu0FrK/sR1cmXDiZZV9/uDNZvNrl4fzwZsEqBR8j kGzj+du3tIVbMv4oOY4pSCpSml1WSqKYWOa8CczvhLYsg2sVysfst/Fe9hwRK8xi5dnV StBsLNES2stGdfJv3XjsS9ytzNuRZ4jjaDkM62eGlVgGoV1P6YhCC4CRd8TtSS7tEhT2 orwQ== X-Forwarded-Encrypted: i=1; AJvYcCUF2z9XLRwSMXYyurjvy9j/pAoBX/nm0JF/0A/IHg8etp8i4+kG3q7jzfr+Gy/KEqLlq68b081WEkBQ9x1CcVBtR0w3kDQm+vepoS4= X-Gm-Message-State: AOJu0YxRI0mcQc0G4WsOOj3gBcWG6qN73rwt+vDGgBx1URePWSrzEqKH GzgUltx4uGkabjd5Z4wLHT3b0nYRibSbjY6DCsrUDF9GguI/c3Jj2NT5GBOxAj4= X-Google-Smtp-Source: AGHT+IEPG6ALVrKC0vxITNNnj0AxUU2b5IhohOK+zwxcy7Y2DoKsbVYQ4rwu1v3iMbA9+oXaQb0Gcw== X-Received: by 2002:a05:600c:228f:b0:426:668f:5eca with SMTP id 5b1f17b1804b1-426706c6878mr52146665e9.7.1720693203327; Thu, 11 Jul 2024 03:20:03 -0700 (PDT) Received: from [127.0.1.1] ([176.61.106.227]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4266e861339sm125270025e9.12.2024.07.11.03.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jul 2024 03:20:02 -0700 (PDT) From: Bryan O'Donoghue Date: Thu, 11 Jul 2024 11:20:02 +0100 Subject: [PATCH 2/2] media: ov5675: Elongate reset to first transaction minimum gap Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240711-linux-next-ov5675-v1-2-69e9b6c62c16@linaro.org> References: <20240711-linux-next-ov5675-v1-0-69e9b6c62c16@linaro.org> In-Reply-To: <20240711-linux-next-ov5675-v1-0-69e9b6c62c16@linaro.org> To: Sakari Ailus , Mauro Carvalho Chehab , Quentin Schulz , Jacopo Mondi Cc: Johan Hovold , Kieran Bingham , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Bryan O'Donoghue , stable@vger.kernel.org X-Mailer: b4 0.15-dev-13183 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, doubling the minimum appears to fix the issue observed on X13s. Fixes: 49d9ad719e89 ("media: ov5675: add device-tree support and support runtime PM") Cc: stable@vger.kernel.org Signed-off-by: Bryan O'Donoghue --- drivers/media/i2c/ov5675.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov5675.c b/drivers/media/i2c/ov5675.c index 92bd35133a5d..0498f8f3064d 100644 --- a/drivers/media/i2c/ov5675.c +++ b/drivers/media/i2c/ov5675.c @@ -1018,8 +1018,13 @@ 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); + /* The spec calls for a minimum delay of 8192 XVCLK cycles prior to + * transacting on the I2C bus, which translates to about 430 + * microseconds at 19.2 MHz. + * Testing shows the range 8192 - 16384 cycles to be unreliable. + * Grant a more liberal 2x -3x clock cycle grace time. + */ + usleep_range(delay_us * 2, delay_us * 3); return 0; }