Re: [PATCH v7 06/19] rtc: sun6i: Add support for RTCs without external LOSCs

Maxime Ripard
2021-07-26T14:59:28Z

[-- Attachment #1: Type: text/plain, Size: 3449 bytes --]

On Fri, Jul 23, 2021 at 12:17:21AM +0100, Andre Przywara wrote:
> On Wed, 16 Jun 2021 11:14:31 +0200
> Maxime Ripard <maxime@cerno.tech> wrote:
>
> Hi Maxime,
>
> > On Tue, Jun 15, 2021 at 12:06:23PM +0100, Andre Przywara wrote:
> > > Some newer Allwinner RTCs (for instance the one in the H616 SoC) lack
> > > a pin for an external 32768 Hz oscillator. As a consequence, this LOSC
> > > can't be selected as the RTC clock source, and we must rely on the
> > > internal RC oscillator.
> > > To allow additions of clocks to the RTC node, add a feature bit to ignore
> > > any provided clocks for now (the current code would think this is the
> > > external LOSC). Later DTs and code can then for instance add the PLL
> > > based clock input, and older kernel won't get confused.
> > >
> > > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> >
> > Honestly, I don't really know if it's worth it at this point.
> >
> > If we sums this up:
> >
> > - The RTC has 2 features that we use, mostly centered around 2
> > registers set plus a global one
> >
> > - Those 2 features are programmed in a completely different way
> >
> > - Even the common part is different, given the discussion around the
> > clocks that we have.
> >
> > What is there to share in that driver aside from the probe, and maybe
> > the interrupt handling? Instead of complicating this further with more
> > special case that you were (rightfully) complaining about, shouldn't we
> > just acknowledge the fact that it's a completely separate design and
> > should be treated as such, with a completely separate driver?
>
> So I had a look, and I don't think it justifies a separate driver:
> - Indeed it looks like the core functionality is different, but there
> are a lot of commonalities, with all the RTC and driver boilerplate,
> register offsets, and also the special access pattern (rtc_wait and
> rtc_setaie).
> - The actual difference is really in the way the *date* is stored
> (the time is still in 24h H/M/S format), and the missing LOSC input
> clock - which is already optional for existing devices. The two
> patches just make this obvious, by using if() statements at the parts
> where they differ.

My point was that the code that is shared, like the driver boilerplate,
is much more complicated than it can be precisely because it's shared.

I'd take two simple-but-with-some-redundancy drivers over one big,
shared but complicated driver any day.

But fine, I guess.

> So we would end up with possibly some shared .c file, and two driver
> front-end files, which I am not sure is really worth it.
>
> Next I thought about providing separate rtc_class_ops, but even they
> share a lot of code, so they would be possibly be calling a shared
> function each. I don't think that is really better.
>
> If you dislike the rather large if/else branches in the previous two
> patches, I could move that out into separate functions, but I feel this
> is more code, for no real benefit.
>
> So for now I am tempted to keep it shared. I think Samuel had ideas for
> bigger changes in the clock part, at which point we could revisit this
> decision - for instance keep the RTC part (still quite similar) mostly
> in a shared file, while modelling the clocks in separate files - in a
> more "common clock" style for the new SoCs.

What's the plan?

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]