public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
From: "Junhui Liu" <junhui.liu@pigmoral.tech>
To: <wens@kernel.org>, "Junhui Liu" <junhui.liu@pigmoral.tech>
Cc: "Michael Turquette" <mturquette@baylibre.com>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Jernej Skrabec" <jernej.skrabec@gmail.com>,
	"Samuel Holland" <samuel@sholland.org>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Maxime Ripard" <mripard@kernel.org>,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-rtc@vger.kernel.org, devicetree@vger.kernel.org,
	"André Przywara" <andre.przywara@arm.com>
Subject: Re: [PATCH 7/7] clk: sunxi-ng: Add Allwinner A733 RTC CCU support
Date: Fri, 10 Apr 2026 17:49:49 +0800	[thread overview]
Message-ID: <DHPDQG786QZJ.BPIOZITGMHKR@pigmoral.tech> (raw)
In-Reply-To: <CAGb2v64euL+QNXiJdTn0JygYLXg0WoguPSprKT4sKGZGVZbwug@mail.gmail.com>

On Sat Mar 28, 2026 at 10:41 PM CST, Chen-Yu Tsai wrote:
> On Wed, Jan 21, 2026 at 7:04 PM Junhui Liu <junhui.liu@pigmoral.tech> wrote:
>>
>> Add support for the internal CCU found in the RTC module of the Allwinner
>> A733 SoC. While the basic 16MHz (IOSC) and 32kHz logic remains compatible
>> with older SoCs like the sun6i, the A733 introduces several new features.
>>
>> The A733 RTC CCU supports choosing one of three external crystal
>> frequencies: 19.2MHz, 24MHz, and 26MHz. It features hardware detection
>> logic to automatically identify the frequency used on the board and
>> exports this DCXO signal as the "hosc" clock.
>>
>> Furthermore, the driver implements logic to derive a 32kHz reference
>> from the HOSC. This is achieved through a muxed clock path using fixed
>> pre-dividers to normalize the different crystal frequencies to ~32kHz.
>
> Have you tested whether the actually normalizes the frequency, i.e.
> selects a different divider based on the DCXO frequency? Otherwise
> we're just lying about the frequency.

I only have A733 boards with 26MHz crystals, so I couldn't test all
crystal configurations. However, I exported the "hosc_32k" clock
(referred to as dcxo24M_div32k_clk in the vendor driver) to a physical
pin via the fanout path and measured it with the oscilloscope.

Observations:

- Normal conditions: The frequency remains stable within the 32.744 kHz
  to 32.791 kHz range.
- Forced condition: I grounded the R24 resistor on radxa A7A board to
  trick the SoC into detecting a 24MHz crystal while the actual input
  remained 26MHz. In this case, the frequency became unstable but still
  stayed around the 32.2 kHz to 33.3 kHz range.

Based on these results, it appears the hardware does attempt to
normalize the frequency towards 32.768 kHz via some internal logic.

>
>> This path reuses the same hardware mux registers as the HOSC clock.
>>
>> Additionally, this CCU provides several gate clocks for specific
>> peripherals, including SerDes, HDMI, and UFS. The driver is implemented
>> as an auxiliary driver to be bound to the sun6i-rtc driver.
>>
>> Signed-off-by: Junhui Liu <junhui.liu@pigmoral.tech>
>> ---
>>  drivers/clk/sunxi-ng/Kconfig               |   5 +
>>  drivers/clk/sunxi-ng/Makefile              |   2 +
>>  drivers/clk/sunxi-ng/ccu-sun60i-a733-rtc.c | 204 +++++++++++++++++++++++++++++
>>  drivers/clk/sunxi-ng/ccu-sun60i-a733-rtc.h |  18 +++
>>  drivers/clk/sunxi-ng/ccu_rtc.h             |   7 +
>>  5 files changed, 236 insertions(+)
>>

[...]

>> +
>> +static const struct clk_parent_data hosc_parents[] = {
>> +       { .fw_name = "osc24M" },
>> +       { .fw_name = "osc19M" },
>> +       { .fw_name = "osc26M" },
>> +       { .fw_name = "osc24M" },
>> +};
>
> As mentioned in my reply to the binding, this is wrong. There is only
> one input.
>
> The most you can do is check the rate of the parent clock against the
> detected one, and _scream_ that the DT is wrong. And maybe override
> the reported frequency.

I will add a warning message if the frequency detected by the driver
does not match the one in the DT.

>
> If you want to do the latter, you could add a new fixed rate gated
> clock type to our library. You would fill in the rate before the
> clocks get registered. I probably wouldn't go that far. We want people
> to have correct hardware descriptions.
>
> Funnily enough Allwinner's BSP actually implements a fixed rate gate
> for the next 24M-to-32k divider clock.

Yes, I noticed that as well. I agree, and I will model this path as a
simple fixed-rate clock (32768Hz) in v2.

>
>> +
>> +struct ccu_mux hosc_clk = {
>> +       .enable = DCXO_CTRL_DCXO_EN,
>> +       .mux    = _SUNXI_CCU_MUX(14, 2),
>> +       .common = {
>> +               .reg            = DCXO_CTRL_REG,
>> +               .hw.init        = CLK_HW_INIT_PARENTS_DATA("hosc",
>> +                                                          hosc_parents,
>> +                                                          &ccu_mux_ro_ops,
>> +                                                          0),
>> +       },
>> +};
>
> So this is wrong.
>
>> +
>> +static const struct ccu_mux_fixed_prediv hosc_32k_predivs[] = {
>> +       { .index = 0, .div = 732 },
>
> Why is it 732 instead of 750?

As mentioned above, the target frequency is 32.768kHz rather than
32.0kHz. However, since I will drop this prediv array and use a
fixed-rate clock instead, I think this will no longer be an issue.

-- 
Best regards,
Junhui Liu


  reply	other threads:[~2026-04-10  9:50 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-21 10:59 [PATCH 0/7] rtc: sun6i: Add support for Allwinner A733 SoC Junhui Liu
2026-01-21 10:59 ` [PATCH 1/7] dt-bindings: rtc: sun6i: Add Allwinner A733 support Junhui Liu
2026-01-21 16:56   ` Rob Herring (Arm)
2026-03-28 12:37   ` Chen-Yu Tsai
2026-04-10  9:18     ` Junhui Liu
2026-01-21 10:59 ` [PATCH 2/7] rtc: sun6i: Bind internal CCU via auxiliary bus Junhui Liu
2026-01-22  2:18   ` kernel test robot
2026-01-21 10:59 ` [PATCH 3/7] clk: sunxi-ng: sun6i-rtc: Add feature bit for IOSC calibration Junhui Liu
2026-01-21 10:59 ` [PATCH 4/7] clk: sunxi-ng: Extract common RTC CCU clock logic Junhui Liu
2026-01-25  4:07   ` kernel test robot
2026-01-25  4:32   ` Chen-Yu Tsai
2026-01-25  5:50     ` Junhui Liu
2026-01-21 10:59 ` [PATCH 5/7] clk: sunxi-ng: mux: Add mux read-only clock operations Junhui Liu
2026-01-21 10:59 ` [PATCH 6/7] rtc: sun6i: Add support for A733 RTC Junhui Liu
2026-03-28 12:40   ` Chen-Yu Tsai
2026-01-21 10:59 ` [PATCH 7/7] clk: sunxi-ng: Add Allwinner A733 RTC CCU support Junhui Liu
2026-03-28 14:41   ` Chen-Yu Tsai
2026-04-10  9:49     ` Junhui Liu [this message]
2026-02-22 10:41 ` [PATCH 0/7] rtc: sun6i: Add support for Allwinner A733 SoC Jernej Škrabec
2026-02-25 12:02   ` Junhui Liu

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=DHPDQG786QZJ.BPIOZITGMHKR@pigmoral.tech \
    --to=junhui.liu@pigmoral.tech \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andre.przywara@arm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=mripard@kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=robh@kernel.org \
    --cc=samuel@sholland.org \
    --cc=sboyd@kernel.org \
    --cc=wens@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