Devicetree
 help / color / mirror / Atom feed
From: "Jernej Škrabec" <jernej.skrabec-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org,
	megous-5qf/QAjKc83QT0dZR+AlfA@public.gmane.org
Cc: Alessandro Zummo
	<a.zummo-BfzFCNDTiLLj+vYz1yj4TQ@public.gmane.org>,
	Alexandre Belloni
	<alexandre.belloni-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	Maxime Ripard
	<maxime.ripard-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>,
	Chen-Yu Tsai <wens-jdAy2FN1RRM@public.gmane.org>,
	linux-rtc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2 2/3] rtc: sun6i: Add support for H6 RTC
Date: Sat, 24 Aug 2019 14:32:32 +0200	[thread overview]
Message-ID: <10586215.O0B29uHg7A@jernej-laptop> (raw)
In-Reply-To: <20190820151934.3860-3-megous-5qf/QAjKc83QT0dZR+AlfA@public.gmane.org>

Hi!

Dne torek, 20. avgust 2019 ob 17:19:33 CEST je megous-5qf/QAjKc83QT0dZR+AlfA@public.gmane.org napisal(a):
> From: Ondrej Jirman <megous-5qf/QAjKc83QT0dZR+AlfA@public.gmane.org>
> 
> RTC on H6 is mostly the same as on H5 and H3. It has slight differences
> mostly in features that are not yet supported by this driver.
> 
> Some differences are already stated in the comments in existing code.
> One other difference is that H6 has extra bit in LOSC_CTRL_REG, called
> EXT_LOSC_EN to enable/disable external low speed crystal oscillator.
> 
> It also has bit EXT_LOSC_STA in LOSC_AUTO_SWT_STA_REG, to check whether
> external low speed oscillator is working correctly.
> 
> This patch adds support for enabling LOSC when necessary:
> 
> - during reparenting
> - when probing the clock
> 
> H6 also has capacbility to automatically reparent RTC clock from
> external crystal oscillator, to internal RC oscillator, if external
> oscillator fails. This is enabled by default. Disable it during
> probe.
> 
> Signed-off-by: Ondrej Jirman <megous-5qf/QAjKc83QT0dZR+AlfA@public.gmane.org>
> Reviewed-by: Chen-Yu Tsai <wens-jdAy2FN1RRM@public.gmane.org>
> ---
>  drivers/rtc/rtc-sun6i.c | 40 ++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 38 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c
> index d50ee023b559..b0c3752bed3f 100644
> --- a/drivers/rtc/rtc-sun6i.c
> +++ b/drivers/rtc/rtc-sun6i.c
> @@ -32,9 +32,11 @@
>  /* Control register */
>  #define SUN6I_LOSC_CTRL				0x0000
>  #define SUN6I_LOSC_CTRL_KEY			(0x16aa << 16)
> +#define SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS		BIT(15)

User manual says that above field is bit 14.

Best regards,
Jernej

>  #define SUN6I_LOSC_CTRL_ALM_DHMS_ACC		BIT(9)
>  #define SUN6I_LOSC_CTRL_RTC_HMS_ACC		BIT(8)
>  #define SUN6I_LOSC_CTRL_RTC_YMD_ACC		BIT(7)
> +#define SUN6I_LOSC_CTRL_EXT_LOSC_EN		BIT(4)
>  #define SUN6I_LOSC_CTRL_EXT_OSC			BIT(0)
>  #define SUN6I_LOSC_CTRL_ACC_MASK		GENMASK(9, 7)
> 
> @@ -128,6 +130,8 @@ struct sun6i_rtc_clk_data {
>  	unsigned int has_prescaler : 1;
>  	unsigned int has_out_clk : 1;
>  	unsigned int export_iosc : 1;
> +	unsigned int has_losc_en : 1;
> +	unsigned int has_auto_swt : 1;
>  };
> 
>  struct sun6i_rtc_dev {
> @@ -190,6 +194,10 @@ static int sun6i_rtc_osc_set_parent(struct clk_hw *hw,
> u8 index) val &= ~SUN6I_LOSC_CTRL_EXT_OSC;
>  	val |= SUN6I_LOSC_CTRL_KEY;
>  	val |= index ? SUN6I_LOSC_CTRL_EXT_OSC : 0;
> +	if (rtc->data->has_losc_en) {
> +		val &= ~SUN6I_LOSC_CTRL_EXT_LOSC_EN;
> +		val |= index ? SUN6I_LOSC_CTRL_EXT_LOSC_EN : 0;
> +	}
>  	writel(val, rtc->base + SUN6I_LOSC_CTRL);
>  	spin_unlock_irqrestore(&rtc->lock, flags);
> 
> @@ -215,6 +223,7 @@ static void __init sun6i_rtc_clk_init(struct device_node
> *node, const char *iosc_name = "rtc-int-osc";
>  	const char *clkout_name = "osc32k-out";
>  	const char *parents[2];
> +	u32 reg;
> 
>  	rtc = kzalloc(sizeof(*rtc), GFP_KERNEL);
>  	if (!rtc)
> @@ -235,9 +244,18 @@ static void __init sun6i_rtc_clk_init(struct
> device_node *node, goto err;
>  	}
> 
> +	reg = SUN6I_LOSC_CTRL_KEY;
> +	if (rtc->data->has_auto_swt) {
> +		/* Bypass auto-switch to int osc, on ext losc failure */
> +		reg |= SUN6I_LOSC_CTRL_AUTO_SWT_BYPASS;
> +		writel(reg, rtc->base + SUN6I_LOSC_CTRL);
> +	}
> +
>  	/* Switch to the external, more precise, oscillator */
> -	writel(SUN6I_LOSC_CTRL_KEY | SUN6I_LOSC_CTRL_EXT_OSC,
> -	       rtc->base + SUN6I_LOSC_CTRL);
> +	reg |= SUN6I_LOSC_CTRL_EXT_OSC;
> +	if (rtc->data->has_losc_en)
> +		reg |= SUN6I_LOSC_CTRL_EXT_LOSC_EN;
> +	writel(reg, rtc->base + SUN6I_LOSC_CTRL);
> 
>  	/* Yes, I know, this is ugly. */
>  	sun6i_rtc = rtc;
> @@ -345,6 +363,23 @@ CLK_OF_DECLARE_DRIVER(sun8i_h3_rtc_clk,
> "allwinner,sun8i-h3-rtc", CLK_OF_DECLARE_DRIVER(sun50i_h5_rtc_clk,
> "allwinner,sun50i-h5-rtc", sun8i_h3_rtc_clk_init);
> 
> +static const struct sun6i_rtc_clk_data sun50i_h6_rtc_data = {
> +	.rc_osc_rate = 16000000,
> +	.fixed_prescaler = 32,
> +	.has_prescaler = 1,
> +	.has_out_clk = 1,
> +	.export_iosc = 1,
> +	.has_losc_en = 1,
> +	.has_auto_swt = 1,
> +};
> +
> +static void __init sun50i_h6_rtc_clk_init(struct device_node *node)
> +{
> +	sun6i_rtc_clk_init(node, &sun50i_h6_rtc_data);
> +}
> +CLK_OF_DECLARE_DRIVER(sun50i_h6_rtc_clk, "allwinner,sun50i-h6-rtc",
> +		      sun50i_h6_rtc_clk_init);
> +
>  static const struct sun6i_rtc_clk_data sun8i_v3_rtc_data = {
>  	.rc_osc_rate = 32000,
>  	.has_out_clk = 1,
> @@ -675,6 +710,7 @@ static const struct of_device_id sun6i_rtc_dt_ids[] = {
>  	{ .compatible = "allwinner,sun8i-r40-rtc" },
>  	{ .compatible = "allwinner,sun8i-v3-rtc" },
>  	{ .compatible = "allwinner,sun50i-h5-rtc" },
> +	{ .compatible = "allwinner,sun50i-h6-rtc" },
>  	{ /* sentinel */ },
>  };
>  MODULE_DEVICE_TABLE(of, sun6i_rtc_dt_ids);

  parent reply	other threads:[~2019-08-24 12:32 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-20 15:19 [PATCH v2 0/3] Add basic support for RTC on Allwinner H6 SoC megous-5qf/QAjKc83QT0dZR+AlfA
     [not found] ` <20190820151934.3860-1-megous-5qf/QAjKc83QT0dZR+AlfA@public.gmane.org>
2019-08-20 15:19   ` [PATCH v2 1/3] dt-bindings: Add compatible for H6 RTC megous-5qf/QAjKc83QT0dZR+AlfA
     [not found]     ` <20190820151934.3860-2-megous-5qf/QAjKc83QT0dZR+AlfA@public.gmane.org>
2019-08-22 21:15       ` Alexandre Belloni
2019-08-20 15:19   ` [PATCH v2 2/3] rtc: sun6i: Add support " megous-5qf/QAjKc83QT0dZR+AlfA
2019-08-22 21:16     ` Alexandre Belloni
     [not found]     ` <20190820151934.3860-3-megous-5qf/QAjKc83QT0dZR+AlfA@public.gmane.org>
2019-08-24 12:32       ` Jernej Škrabec [this message]
2019-08-24 12:46         ` Ondřej Jirman
     [not found]           ` <20190824124654.nqtlkam2gsaqsj77-9v8tmBix7cb9zxVx7UNMDg@public.gmane.org>
2019-08-24 12:51             ` Jernej Škrabec
2019-08-24 13:05               ` Ondřej Jirman
     [not found]                 ` <20190824130544.kxypq3siv7kffidp-9v8tmBix7cb9zxVx7UNMDg@public.gmane.org>
2019-08-24 13:16                   ` Jernej Škrabec
2019-08-24 13:30                     ` Ondřej Jirman
     [not found]                       ` <20190824133057.rhpj3xuzr3vymdiy-9v8tmBix7cb9zxVx7UNMDg@public.gmane.org>
2019-08-24 21:09                         ` Jernej Škrabec
2019-08-24 21:27                           ` Ondřej Jirman
     [not found]                             ` <20190824212746.a5pyilkrrvysjjbd-9v8tmBix7cb9zxVx7UNMDg@public.gmane.org>
2019-08-24 21:36                               ` Jernej Škrabec
2019-08-24 22:16                                 ` [linux-sunxi] " Ondřej Jirman
2019-08-20 15:19   ` [PATCH v2 3/3] arm64: dts: sun50i-h6: Add support for RTC and fix the clock tree megous-5qf/QAjKc83QT0dZR+AlfA
     [not found]     ` <20190820151934.3860-4-megous-5qf/QAjKc83QT0dZR+AlfA@public.gmane.org>
2019-08-23  8:19       ` Maxime Ripard
2019-08-24  8:04   ` [PATCH v2 0/3] Add basic support for RTC on Allwinner H6 SoC Jernej Škrabec
2019-08-24  8:06     ` Jernej Škrabec
2019-08-24 12:56       ` Ondřej Jirman
     [not found]         ` <20190824125612.zq5qsay2wv62wykt-9v8tmBix7cb9zxVx7UNMDg@public.gmane.org>
2019-08-24 12:58           ` Jernej Škrabec

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=10586215.O0B29uHg7A@jernej-laptop \
    --to=jernej.skrabec-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=a.zummo-BfzFCNDTiLLj+vYz1yj4TQ@public.gmane.org \
    --cc=alexandre.belloni-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-rtc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=maxime.ripard-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org \
    --cc=megous-5qf/QAjKc83QT0dZR+AlfA@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=wens-jdAy2FN1RRM@public.gmane.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