From: Haylen Chu <heylenay@4d2.org>
To: Alex Elder <elder@riscstar.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Haylen Chu <heylenay@outlook.com>, Yixun Lan <dlan@gentoo.org>
Cc: linux-riscv@lists.infradead.org, linux-clk@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Inochi Amaoto <inochiama@outlook.com>,
Chen Wang <unicornxdotw@foxmail.com>,
Guodong Xu <guodong@riscstar.com>
Subject: Re: [PATCH v4 3/4] clk: spacemit: Add clock support for Spacemit K1 SoC
Date: Mon, 3 Mar 2025 09:41:14 +0000 [thread overview]
Message-ID: <Z8V5OjQTxVeRLAOU@ketchup> (raw)
In-Reply-To: <f8b30551-25e7-4626-8c03-6d8807041d8a@riscstar.com>
On Thu, Feb 13, 2025 at 10:04:10PM -0600, Alex Elder wrote:
> On 1/3/25 3:56 PM, Haylen Chu wrote:
> > The clock tree of K1 SoC contains three main types of clock hardware
> > (PLL/DDN/MIX) and is managed by several independent controllers in
> > different SoC parts (APBC, APBS and etc.), thus different compatible
> > strings are added to distinguish them.
> >
> > Some controllers may share IO region with reset controller and other low
> > speed peripherals like watchdog, so all register operations are done
> > through regmap to avoid competition.
> >
> > Signed-off-by: Haylen Chu <heylenay@4d2.org>
>
> This is a really big patch (over 3000 lines), and a fairly large
> amount of code to review. But I've given it a really thorough
> read and I have a *lot* of review comments for you to consider.
>
> First, a few top-level comments.
> - This driver is very comprehensive. It represents essentially
> *all* of the clocks in the tree diagram shown here:
> https://developer.spacemit.com/resource/file/images?fileName=DkWGb4ed7oAziVxE6PIcbjTLnpd.png
> (I can tell you what's missing but I don't think it matters.)
> - In almost all cases, the names of the clocks match the names
> shown in that diagram, which is very helpful.
> - All of the clocks are implemented using "custom" clock
> implementations. I'm fairly certain that almost all of
> them can use standard clock framework types instead
> (fixed-rate, fixed-factor, fractional-divider, mux, and
> composite). But for now I think there are other things
> more important to improve.
> - A great deal of my commentary below is simply saying that the
> code is more complex than necessary. Some simple (though
> widespread) refactoring would improve things a lot. And
> some of the definitions can be done without having to
> specify nearly so many values.
> - Much of what might be considered generality in the
> implementation actually isn't needed, because it isn't used.
> This is especially true given that there are essentially no
> clocks left unspecified for the K1 SoC.
> - Once the refactoring I suggest has been done, I expect
> that more opportunities for simplification and cleanup will
> become obvious; we'll see.
> - I suggest these changes because the resulting simplicity
> will make the code much more understandable and maintainable
> in the long term. And if it's simpler to understand, it
> should be easier for a maintainer to accept.
>
> I'm not going to comment on the things related to Device Tree
> that have already been mentioned, nor on the Makefile or Kconfig,
> etc. I'm focusing just on the code.
>
> > ---
> > drivers/clk/Kconfig | 1 +
> > drivers/clk/Makefile | 1 +
> > drivers/clk/spacemit/Kconfig | 20 +
> > drivers/clk/spacemit/Makefile | 5 +
> > drivers/clk/spacemit/ccu-k1.c | 1747 +++++++++++++++++++++++++++++
> > drivers/clk/spacemit/ccu_common.h | 51 +
> > drivers/clk/spacemit/ccu_ddn.c | 140 +++
> > drivers/clk/spacemit/ccu_ddn.h | 84 ++
> > drivers/clk/spacemit/ccu_mix.c | 304 +++++
> > drivers/clk/spacemit/ccu_mix.h | 309 +++++
> > drivers/clk/spacemit/ccu_pll.c | 189 ++++
> > drivers/clk/spacemit/ccu_pll.h | 80 ++
> > 12 files changed, 2931 insertions(+)
> > create mode 100644 drivers/clk/spacemit/Kconfig
> > create mode 100644 drivers/clk/spacemit/Makefile
> > create mode 100644 drivers/clk/spacemit/ccu-k1.c
> > create mode 100644 drivers/clk/spacemit/ccu_common.h
> > create mode 100644 drivers/clk/spacemit/ccu_ddn.c
> > create mode 100644 drivers/clk/spacemit/ccu_ddn.h
> > create mode 100644 drivers/clk/spacemit/ccu_mix.c
> > create mode 100644 drivers/clk/spacemit/ccu_mix.h
> > create mode 100644 drivers/clk/spacemit/ccu_pll.c
> > create mode 100644 drivers/clk/spacemit/ccu_pll.h
> >
...
> > diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/ccu-k1.c
> > new file mode 100644
> > index 000000000000..6fb0a12ec261
> > --- /dev/null
> > +++ b/drivers/clk/spacemit/ccu-k1.c
...
> The next set of clocks differ from essentially all others, in that
> they don't encode their frequency in the name. I.e., I would expect
> the first one to be named pll1_d2_1228p8.
I found this change may not be possible: with the frequency appended,
their names conflict with another set of MPMU gates.
>
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d2, "pll1_d2", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(1), BIT(1), 0, 2, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d3, "pll1_d3", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(2), BIT(2), 0, 3, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d4, "pll1_d4", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(3), BIT(3), 0, 4, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d5, "pll1_d5", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(4), BIT(4), 0, 5, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d6, "pll1_d6", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(5), BIT(5), 0, 6, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d7, "pll1_d7", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(6), BIT(6), 0, 7, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d8, "pll1_d8", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(7), BIT(7), 0, 8, 1, 0);
> > +
...
> > +/* MPMU clocks start */
...
> > +static CCU_GATE_DEFINE(pll1_d3_819p2, "pll1_d3_819p2", CCU_PARENT_HW(pll1_d3),
> > + MPMU_ACGR,
> > + BIT(14), BIT(14), 0, 0);
> > +
> > +static CCU_GATE_DEFINE(pll1_d2_1228p8, "pll1_d2_1228p8", CCU_PARENT_HW(pll1_d2),
> > + MPMU_ACGR,
> > + BIT(16), BIT(16), 0, 0);
Here're the conflicts.
Although they don't happen on all the clocks, I prefer to keep the clock
names as is for now to keep the consistency.
Thanks,
Haylen Chu
WARNING: multiple messages have this Message-ID (diff)
From: Haylen Chu <heylenay@4d2.org>
To: Alex Elder <elder@riscstar.com>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Haylen Chu <heylenay@outlook.com>, Yixun Lan <dlan@gentoo.org>
Cc: linux-riscv@lists.infradead.org, linux-clk@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Inochi Amaoto <inochiama@outlook.com>,
Chen Wang <unicornxdotw@foxmail.com>,
Guodong Xu <guodong@riscstar.com>
Subject: Re: [PATCH v4 3/4] clk: spacemit: Add clock support for Spacemit K1 SoC
Date: Mon, 3 Mar 2025 09:41:14 +0000 [thread overview]
Message-ID: <Z8V5OjQTxVeRLAOU@ketchup> (raw)
In-Reply-To: <f8b30551-25e7-4626-8c03-6d8807041d8a@riscstar.com>
On Thu, Feb 13, 2025 at 10:04:10PM -0600, Alex Elder wrote:
> On 1/3/25 3:56 PM, Haylen Chu wrote:
> > The clock tree of K1 SoC contains three main types of clock hardware
> > (PLL/DDN/MIX) and is managed by several independent controllers in
> > different SoC parts (APBC, APBS and etc.), thus different compatible
> > strings are added to distinguish them.
> >
> > Some controllers may share IO region with reset controller and other low
> > speed peripherals like watchdog, so all register operations are done
> > through regmap to avoid competition.
> >
> > Signed-off-by: Haylen Chu <heylenay@4d2.org>
>
> This is a really big patch (over 3000 lines), and a fairly large
> amount of code to review. But I've given it a really thorough
> read and I have a *lot* of review comments for you to consider.
>
> First, a few top-level comments.
> - This driver is very comprehensive. It represents essentially
> *all* of the clocks in the tree diagram shown here:
> https://developer.spacemit.com/resource/file/images?fileName=DkWGb4ed7oAziVxE6PIcbjTLnpd.png
> (I can tell you what's missing but I don't think it matters.)
> - In almost all cases, the names of the clocks match the names
> shown in that diagram, which is very helpful.
> - All of the clocks are implemented using "custom" clock
> implementations. I'm fairly certain that almost all of
> them can use standard clock framework types instead
> (fixed-rate, fixed-factor, fractional-divider, mux, and
> composite). But for now I think there are other things
> more important to improve.
> - A great deal of my commentary below is simply saying that the
> code is more complex than necessary. Some simple (though
> widespread) refactoring would improve things a lot. And
> some of the definitions can be done without having to
> specify nearly so many values.
> - Much of what might be considered generality in the
> implementation actually isn't needed, because it isn't used.
> This is especially true given that there are essentially no
> clocks left unspecified for the K1 SoC.
> - Once the refactoring I suggest has been done, I expect
> that more opportunities for simplification and cleanup will
> become obvious; we'll see.
> - I suggest these changes because the resulting simplicity
> will make the code much more understandable and maintainable
> in the long term. And if it's simpler to understand, it
> should be easier for a maintainer to accept.
>
> I'm not going to comment on the things related to Device Tree
> that have already been mentioned, nor on the Makefile or Kconfig,
> etc. I'm focusing just on the code.
>
> > ---
> > drivers/clk/Kconfig | 1 +
> > drivers/clk/Makefile | 1 +
> > drivers/clk/spacemit/Kconfig | 20 +
> > drivers/clk/spacemit/Makefile | 5 +
> > drivers/clk/spacemit/ccu-k1.c | 1747 +++++++++++++++++++++++++++++
> > drivers/clk/spacemit/ccu_common.h | 51 +
> > drivers/clk/spacemit/ccu_ddn.c | 140 +++
> > drivers/clk/spacemit/ccu_ddn.h | 84 ++
> > drivers/clk/spacemit/ccu_mix.c | 304 +++++
> > drivers/clk/spacemit/ccu_mix.h | 309 +++++
> > drivers/clk/spacemit/ccu_pll.c | 189 ++++
> > drivers/clk/spacemit/ccu_pll.h | 80 ++
> > 12 files changed, 2931 insertions(+)
> > create mode 100644 drivers/clk/spacemit/Kconfig
> > create mode 100644 drivers/clk/spacemit/Makefile
> > create mode 100644 drivers/clk/spacemit/ccu-k1.c
> > create mode 100644 drivers/clk/spacemit/ccu_common.h
> > create mode 100644 drivers/clk/spacemit/ccu_ddn.c
> > create mode 100644 drivers/clk/spacemit/ccu_ddn.h
> > create mode 100644 drivers/clk/spacemit/ccu_mix.c
> > create mode 100644 drivers/clk/spacemit/ccu_mix.h
> > create mode 100644 drivers/clk/spacemit/ccu_pll.c
> > create mode 100644 drivers/clk/spacemit/ccu_pll.h
> >
...
> > diff --git a/drivers/clk/spacemit/ccu-k1.c b/drivers/clk/spacemit/ccu-k1.c
> > new file mode 100644
> > index 000000000000..6fb0a12ec261
> > --- /dev/null
> > +++ b/drivers/clk/spacemit/ccu-k1.c
...
> The next set of clocks differ from essentially all others, in that
> they don't encode their frequency in the name. I.e., I would expect
> the first one to be named pll1_d2_1228p8.
I found this change may not be possible: with the frequency appended,
their names conflict with another set of MPMU gates.
>
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d2, "pll1_d2", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(1), BIT(1), 0, 2, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d3, "pll1_d3", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(2), BIT(2), 0, 3, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d4, "pll1_d4", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(3), BIT(3), 0, 4, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d5, "pll1_d5", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(4), BIT(4), 0, 5, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d6, "pll1_d6", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(5), BIT(5), 0, 6, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d7, "pll1_d7", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(6), BIT(6), 0, 7, 1, 0);
> > +static CCU_GATE_FACTOR_DEFINE(pll1_d8, "pll1_d8", CCU_PARENT_HW(pll1),
> > + APB_SPARE2_REG,
> > + BIT(7), BIT(7), 0, 8, 1, 0);
> > +
...
> > +/* MPMU clocks start */
...
> > +static CCU_GATE_DEFINE(pll1_d3_819p2, "pll1_d3_819p2", CCU_PARENT_HW(pll1_d3),
> > + MPMU_ACGR,
> > + BIT(14), BIT(14), 0, 0);
> > +
> > +static CCU_GATE_DEFINE(pll1_d2_1228p8, "pll1_d2_1228p8", CCU_PARENT_HW(pll1_d2),
> > + MPMU_ACGR,
> > + BIT(16), BIT(16), 0, 0);
Here're the conflicts.
Although they don't happen on all the clocks, I prefer to keep the clock
names as is for now to keep the consistency.
Thanks,
Haylen Chu
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2025-03-03 9:58 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-03 21:56 [PATCH v4 0/4] Add clock controller support for SpacemiT K1 Haylen Chu
2025-01-03 21:56 ` Haylen Chu
2025-01-03 21:56 ` [PATCH v4 1/4] dt-bindings: clock: spacemit: Add clock controllers of Spacemit K1 SoC Haylen Chu
2025-01-03 21:56 ` Haylen Chu
2025-01-04 9:58 ` Krzysztof Kozlowski
2025-01-04 9:58 ` Krzysztof Kozlowski
2025-01-15 7:29 ` Haylen Chu
2025-01-15 7:29 ` Haylen Chu
2025-01-03 21:56 ` [PATCH v4 2/4] dt-bindings: soc: spacemit: Add spacemit,k1-syscon Haylen Chu
2025-01-03 21:56 ` Haylen Chu
2025-01-04 10:07 ` Krzysztof Kozlowski
2025-01-04 10:07 ` Krzysztof Kozlowski
2025-02-11 5:15 ` Haylen Chu
2025-02-11 5:15 ` Haylen Chu
2025-02-11 8:03 ` Krzysztof Kozlowski
2025-02-11 8:03 ` Krzysztof Kozlowski
2025-02-13 11:14 ` Haylen Chu
2025-02-13 11:14 ` Haylen Chu
2025-02-13 18:07 ` Krzysztof Kozlowski
2025-02-13 18:07 ` Krzysztof Kozlowski
2025-02-15 8:41 ` Haylen Chu
2025-02-15 8:41 ` Haylen Chu
2025-02-21 23:40 ` Alex Elder
2025-02-21 23:40 ` Alex Elder
2025-02-22 9:59 ` Krzysztof Kozlowski
2025-02-22 9:59 ` Krzysztof Kozlowski
2025-02-22 10:48 ` Haylen Chu
2025-02-22 10:48 ` Haylen Chu
2025-02-22 11:50 ` Krzysztof Kozlowski
2025-02-22 11:50 ` Krzysztof Kozlowski
2025-02-24 10:17 ` Haylen Chu
2025-02-24 10:17 ` Haylen Chu
2025-02-25 8:12 ` Krzysztof Kozlowski
2025-02-25 8:12 ` Krzysztof Kozlowski
2025-02-25 21:14 ` Alex Elder
2025-02-25 21:14 ` Alex Elder
2025-02-22 9:52 ` Krzysztof Kozlowski
2025-02-22 9:52 ` Krzysztof Kozlowski
2025-02-22 11:36 ` Haylen Chu
2025-02-22 11:36 ` Haylen Chu
2025-01-03 21:56 ` [PATCH v4 3/4] clk: spacemit: Add clock support for Spacemit K1 SoC Haylen Chu
2025-01-03 21:56 ` Haylen Chu
2025-01-16 5:25 ` Samuel Holland
2025-01-16 5:25 ` Samuel Holland
2025-01-21 17:01 ` Haylen Chu
2025-01-21 17:01 ` Haylen Chu
2025-02-14 4:04 ` Alex Elder
2025-02-14 4:04 ` Alex Elder
2025-02-16 11:34 ` Haylen Chu
2025-02-16 11:34 ` Haylen Chu
2025-02-21 21:10 ` Alex Elder
2025-02-21 21:10 ` Alex Elder
2025-02-22 9:57 ` Haylen Chu
2025-02-22 9:57 ` Haylen Chu
2025-02-22 9:40 ` Haylen Chu
2025-02-22 9:40 ` Haylen Chu
2025-03-03 9:41 ` Haylen Chu [this message]
2025-03-03 9:41 ` Haylen Chu
2025-03-03 14:10 ` Alex Elder
2025-03-03 14:10 ` Alex Elder
2025-01-03 21:56 ` [PATCH v4 4/4] riscv: dts: spacemit: Add clock controller for K1 Haylen Chu
2025-01-03 21:56 ` Haylen Chu
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=Z8V5OjQTxVeRLAOU@ketchup \
--to=heylenay@4d2.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlan@gentoo.org \
--cc=elder@riscstar.com \
--cc=guodong@riscstar.com \
--cc=heylenay@outlook.com \
--cc=inochiama@outlook.com \
--cc=krzk+dt@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mturquette@baylibre.com \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=unicornxdotw@foxmail.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.