All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benoit Parrot <bparrot@ti.com>
To: Tomi Valkeinen <tomi.valkeinen@ti.com>, <linux-media@vger.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Hans Verkuil <hverkuil@xs4all.nl>
Subject: Re: [PATCH v2 19/19] media: ti-vpe: cal: fix stop state timeout
Date: Thu, 19 Mar 2020 17:53:42 -0500	[thread overview]
Message-ID: <cf253130-7e3b-7f19-0001-08d27d25dcc1@ti.com> (raw)
In-Reply-To: <20200319075023.22151-20-tomi.valkeinen@ti.com>

Tomi,

Thanks for the patch.

On 3/19/20 2:50 AM, Tomi Valkeinen wrote:
> The stop-state timeout needs to be over 100us as per CSI spec. With the
> CAL fclk of 266 MHZ on DRA76, with the current value the driver uses,
> the timeout is 24us. Too small timeout will cause failure to enable the
> streaming.
> 
> Also, the fclk can be different on other SoCs, as is the case with AM65x
> where the fclk is 250 MHz.
> 
> This patch fixes the timeout by calculating it correctly based on the
> fclk rate.
> 

Isn't this in relation to the clock sourcing the PHY module which is fixed
at 96Mhz (LVDSRX_96M_GFCLK)?

Benoit

> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
> Tested-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  drivers/media/platform/ti-vpe/cal.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/ti-vpe/cal.c b/drivers/media/platform/ti-vpe/cal.c
> index 0f90078ee8c2..d935c628597b 100644
> --- a/drivers/media/platform/ti-vpe/cal.c
> +++ b/drivers/media/platform/ti-vpe/cal.c
> @@ -6,6 +6,7 @@
>   * Benoit Parrot, <bparrot@ti.com>
>   */
>  
> +#include <linux/clk.h>
>  #include <linux/interrupt.h>
>  #include <linux/io.h>
>  #include <linux/ioctl.h>
> @@ -340,6 +341,7 @@ static const struct cal_data am654_cal_data = {
>   * all instances.
>   */
>  struct cal_dev {
> +	struct clk		*fclk;
>  	int			irq;
>  	void __iomem		*base;
>  	struct resource		*res;
> @@ -767,6 +769,7 @@ static void csi2_phy_config(struct cal_ctx *ctx);
>  static void csi2_phy_init(struct cal_ctx *ctx)
>  {
>  	u32 val;
> +	u32 sscounter;
>  
>  	/* Steps
>  	 *  1. Configure D-PHY mode and enable required lanes
> @@ -803,10 +806,20 @@ static void csi2_phy_init(struct cal_ctx *ctx)
>  	csi2_phy_config(ctx);
>  
>  	/* 3.B. Program Stop States */
> +	/*
> +	 * The stop-state-counter is based on fclk cycles, and we always use
> +	 * the x16 and x4 settings, so stop-state-timeout =
> +	 * fclk-cycle * 16 * 4 * counter.
> +	 *
> +	 * Stop-state-timeout must be more than 100us as per CSI2 spec, so we
> +	 * calculate a timeout that's 100us (rounding up).
> +	 */
> +	sscounter = DIV_ROUND_UP(clk_get_rate(ctx->dev->fclk), 10000 *  16 * 4);
> +
>  	val = reg_read(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port));
>  	set_field(&val, 1, CAL_CSI2_TIMING_STOP_STATE_X16_IO1_MASK);
> -	set_field(&val, 0, CAL_CSI2_TIMING_STOP_STATE_X4_IO1_MASK);
> -	set_field(&val, 407, CAL_CSI2_TIMING_STOP_STATE_COUNTER_IO1_MASK);
> +	set_field(&val, 1, CAL_CSI2_TIMING_STOP_STATE_X4_IO1_MASK);
> +	set_field(&val, sscounter, CAL_CSI2_TIMING_STOP_STATE_COUNTER_IO1_MASK);
>  	reg_write(ctx->dev, CAL_CSI2_TIMING(ctx->csi2_port), val);
>  	ctx_dbg(3, ctx, "CAL_CSI2_TIMING(%d) = 0x%08x Stop States\n",
>  		ctx->csi2_port,
> @@ -2257,6 +2270,12 @@ static int cal_probe(struct platform_device *pdev)
>  	/* save pdev pointer */
>  	dev->pdev = pdev;
>  
> +	dev->fclk = devm_clk_get(&pdev->dev, "fck");
> +	if (IS_ERR(dev->fclk)) {
> +		dev_err(&pdev->dev, "cannot get CAL fclk\n");
> +		return PTR_ERR(dev->fclk);
> +	}
> +
>  	syscon_camerrx = syscon_regmap_lookup_by_phandle(parent,
>  							 "ti,camerrx-control");
>  	ret = of_property_read_u32_index(parent, "ti,camerrx-control", 1,
> 

  reply	other threads:[~2020-03-19 22:53 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-19  7:50 [PATCH v2 00/19] CAL fixes and improvements Tomi Valkeinen
2020-03-19  7:50 ` [PATCH v2 01/19] media: ti-vpe: cal: fix DMA memory corruption Tomi Valkeinen
2020-03-19 21:41   ` Benoit Parrot
2020-03-19 21:46     ` Benoit Parrot
2020-03-19 22:25   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 02/19] media: ti-vpe: cal: improve enable_irqs Tomi Valkeinen
2020-03-19 22:26   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 03/19] media: ti-vpe: cal: fix use of wrong macro Tomi Valkeinen
2020-03-19 22:27   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 04/19] media: ti-vpe: cal: use runtime_resume for errata handling Tomi Valkeinen
2020-03-19 22:28   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 05/19] media: ti-vpe: cal: drop cal_runtime_get/put Tomi Valkeinen
2020-03-19 22:29   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 06/19] media: ti-vpe: cal: catch error irqs and print errors Tomi Valkeinen
2020-03-19 22:32   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 07/19] media: ti-vpe: cal: print errors on timeouts Tomi Valkeinen
2020-03-19 22:38   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 08/19] media: ti-vpe: cal: simplify irq handling Tomi Valkeinen
2020-03-19 22:39   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 09/19] media: ti-vpe: cal: remove useless CAL_GEN_* macros Tomi Valkeinen
2020-03-19 22:40   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 10/19] media: ti-vpe: cal: remove useless IRQ defines Tomi Valkeinen
2020-03-19 22:40   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 11/19] media: ti-vpe: cal: use reg_write_field Tomi Valkeinen
2020-03-19 22:41   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 12/19] media: ti-vpe: cal: cleanup CIO power enable/disable Tomi Valkeinen
2020-03-19 22:42   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 13/19] media: ti-vpe: cal: fix dummy read to phy Tomi Valkeinen
2020-03-19 22:43   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 14/19] media: ti-vpe: cal: program number of lines properly Tomi Valkeinen
2020-03-19 22:44   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 15/19] media: ti-vpe: cal: set DMA max seg size Tomi Valkeinen
2020-03-19 22:44   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 16/19] media: ti-vpe: cal: move code to separate functions Tomi Valkeinen
2020-03-19 22:45   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 17/19] media: ti-vpe: cal: improve wait for CIO resetdone Tomi Valkeinen
2020-03-19 22:46   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 18/19] media: ti-vpe: cal: improve wait for stop-state Tomi Valkeinen
2020-03-19 22:46   ` Benoit Parrot
2020-03-19  7:50 ` [PATCH v2 19/19] media: ti-vpe: cal: fix stop state timeout Tomi Valkeinen
2020-03-19 22:53   ` Benoit Parrot [this message]
2020-03-20  9:33     ` Tomi Valkeinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cf253130-7e3b-7f19-0001-08d27d25dcc1@ti.com \
    --to=bparrot@ti.com \
    --cc=hverkuil@xs4all.nl \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=tomi.valkeinen@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.