public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: Mike Looijmans <mike.looijmans@topic.nl>
To: Robert Hancock <robert.hancock@calian.com>,
	mturquette@baylibre.com, sboyd@kernel.org
Cc: devicetree@vger.kernel.org, linux-clk@vger.kernel.org
Subject: Re: [PATCH 4/9] clk: si5341: Check for input clock presence and PLL lock on startup
Date: Fri, 12 Mar 2021 07:47:54 +0100	[thread overview]
Message-ID: <4e81437e-da75-bc76-2b5b-4b7c78ba927a@topic.nl> (raw)
In-Reply-To: <20210311222436.3826800-5-robert.hancock@calian.com>


Met vriendelijke groet / kind regards,

Mike Looijmans
System Expert


TOPIC Embedded Products B.V.
Materiaalweg 4, 5681 RJ Best
The Netherlands

T: +31 (0) 499 33 69 69
E: mike.looijmans@topicproducts.com
W: www.topicproducts.com

Please consider the environment before printing this e-mail
On 11-03-2021 23:24, Robert Hancock wrote:
> After initializing the device, allow sufficient time for the PLL to lock
> (if we reconfigured it) and verify that the input clock is present and the
> PLL has locked before declaring success.
>
> Fixes: 3044a860fd ("clk: Add Si5341/Si5340 driver")
> Signed-off-by: Robert Hancock <robert.hancock@calian.com>
> ---
>   drivers/clk/clk-si5341.c | 46 ++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 46 insertions(+)
>
> diff --git a/drivers/clk/clk-si5341.c b/drivers/clk/clk-si5341.c
> index 2d69b2144acf..5221e431f6cb 100644
> --- a/drivers/clk/clk-si5341.c
> +++ b/drivers/clk/clk-si5341.c
> @@ -92,6 +92,9 @@ struct clk_si5341_output_config {
>   #define SI5341_PN_BASE		0x0002
>   #define SI5341_DEVICE_REV	0x0005
>   #define SI5341_STATUS		0x000C
> +#define SI5341_LOS		0x000D
> +#define SI5341_STATUS_STICKY	0x0011
> +#define SI5341_LOS_STICKY	0x0012
>   #define SI5341_SOFT_RST		0x001C
>   #define SI5341_IN_SEL		0x0021
>   #define SI5341_DEVICE_READY	0x00FE
> @@ -99,6 +102,12 @@ struct clk_si5341_output_config {
>   #define SI5341_IN_EN		0x0949
>   #define SI5341_INX_TO_PFD_EN	0x094A
>   
> +/* Status bits */
> +#define SI5341_STATUS_SYSINCAL	BIT(0)
> +#define SI5341_STATUS_LOSXAXB	BIT(1)
> +#define SI5341_STATUS_LOSREF	BIT(2)
> +#define SI5341_STATUS_LOL	BIT(3)
> +
>   /* Input selection */
>   #define SI5341_IN_SEL_MASK	0x06
>   #define SI5341_IN_SEL_SHIFT	1
> @@ -1403,6 +1412,29 @@ static int si5341_clk_select_active_input(struct clk_si5341 *data)
>   	return res;
>   }
>   
> +static int si5341_check_healthy(struct clk_si5341 *data)
> +{
> +	u32 status;
> +	int res = regmap_read(data->regmap, SI5341_STATUS, &status);
> +
> +	if (res < 0) {
> +		dev_err(&data->i2c_client->dev, "failed to read status\n");
> +		return res;
> +	}
> +
> +	if ((status & SI5341_STATUS_LOSREF)) {
> +		dev_err(&data->i2c_client->dev, "input clock not present\n");
> +		return -EIO;
> +	}
> +
> +	if ((status & SI5341_STATUS_LOL)) {
> +		dev_err(&data->i2c_client->dev, "PLL not locked\n");
> +		return -EIO;
> +	}
> +
> +	return 0;
> +}
> +
>   static int si5341_probe(struct i2c_client *client,
>   		const struct i2c_device_id *id)
>   {
> @@ -1580,6 +1612,20 @@ static int si5341_probe(struct i2c_client *client,
>   		err = si5341_finalize_defaults(data);
>   		if (err < 0)
>   			return err;
> +
> +		/* allow time for PLL to lock */
> +		msleep(250);

Can't this be a poll loop with timeout? Seems rather harsh to just sleep 
here.

> +	}
> +
> +	err = si5341_check_healthy(data);
> +	if (err)
> +		return err;
> +
> +	/* clear sticky alarm bits from initialization */
> +	err = regmap_write(data->regmap, SI5341_STATUS_STICKY, 0);
> +	if (err) {
> +		dev_err(&client->dev, "unable to clear sticky status\n");
> +		return err;
>   	}
>   
>   	/* Free the names, clk framework makes copies */


-- 
Mike Looijmans


  reply	other threads:[~2021-03-12  6:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11 22:24 [PATCH 0/9] Si5341 driver updates Robert Hancock
     [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.a5c64a18-101d-4705-9716-1c41c644d43a@emailsignatures365.codetwo.com>
     [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.b1dc66c0-d7df-44f1-9f1a-e729e77f49c2@emailsignatures365.codetwo.com>
     [not found] ` <1b153bce-a66a-45ee-a5c6-963ea6fb1c82.949ef384-8293-46b8-903f-40a477c056ae.9334a909-9494-43d0-954a-ed0ddcbb7b5d@emailsignatures365.codetwo.com>
2021-03-11 22:24 ` [PATCH 1/9] dt-bindings: clock: clk-si5341: Add new attributes Robert Hancock
2021-03-11 22:24 ` [PATCH 2/9] clk: si5341: Wait for DEVICE_READY on startup Robert Hancock
2021-03-12  6:39   ` Mike Looijmans
2021-03-12 15:23     ` Robert Hancock
2021-03-11 22:24 ` [PATCH 3/9] clk: si5341: Avoid divide errors due to bogus register contents Robert Hancock
2021-03-11 22:24 ` [PATCH 4/9] clk: si5341: Check for input clock presence and PLL lock on startup Robert Hancock
2021-03-12  6:47   ` Mike Looijmans [this message]
2021-03-12 15:23     ` Robert Hancock
2021-03-11 22:24 ` [PATCH 5/9] clk: si5341: Update initialization magic Robert Hancock
2021-03-11 22:24 ` [PATCH 6/9] clk: si5341: Allow different output VDD_SEL values Robert Hancock
2021-03-12  0:09   ` kernel test robot
2021-03-12  0:09   ` [RFC PATCH] clk: si5341: si5341_remove() can be static kernel test robot
2021-03-12  0:48   ` [PATCH 6/9] clk: si5341: Allow different output VDD_SEL values kernel test robot
2021-03-11 22:24 ` [PATCH 7/9] clk: si5341: Add silabs,xaxb-ext-clk property Robert Hancock
2021-03-11 22:24 ` [PATCH 8/9] clk: si5341: Add silabs,iovdd-33 property Robert Hancock
2021-03-12  6:44   ` Mike Looijmans
2021-03-12 15:39     ` Robert Hancock
2021-03-11 22:24 ` [PATCH 9/9] clk: si5341: Add sysfs properties to allow checking/resetting device faults Robert Hancock

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=4e81437e-da75-bc76-2b5b-4b7c78ba927a@topic.nl \
    --to=mike.looijmans@topic.nl \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=robert.hancock@calian.com \
    --cc=sboyd@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox