Skip to contentSkip to conversation

Add Mobileye EyeQ clock support

PATCH Applied Théo Lebrun 2 participants 16 messages Oct 7, 2024 – Oct 29, 2024

Subsystems (3)

v5 of 6 Applied Latest is v6 →

lore
Share & tools
lore

Théo Lebrun

author maintainer
#0 lore raw

v5 cover Add Mobileye EyeQ clock support

This series adds a platform driver dealing with read-only PLLs derived from the main crystal, and some divider clocks based on those PLLs. It also acts at the one instantiating reset and pinctrl auxiliary devices.

One special feature is that some clocks are required before platform bus infrastructure is available; we therefore register some clocks at of_clk_init() stage.

We support EyeQ5, EyeQ6L and EyeQ6H SoCs. The last one is special in that there are seven instances of this system-controller. All of those handle clocks.

The clock driver instantiates reset and pinctrl auxiliary devices present in the same system controller. Those drivers are upstream already, as well as the devicetree patches to switch from static clocks to using this driver:
- 487b1b32e317 ("reset: eyeq: add platform driver") since v6.12-rc1
- 41795aa1f56a ("pinctrl: eyeq5: add platform driver") since v6.12-rc1
- bde4b22dc526 ("dt-bindings: soc: mobileye: add EyeQ OLB system controller") since v6.11-rc1

I had a pending question [0], asking for confirmation that the static linked list to inherit cells from of_clk_init() stage to platform device probe is indeed the right solution. As -rc1 got released I sent the new revision anyway.

This new revision only touches the clk-eyeq driver. We officially declare that we do not support unbinding (using .suppress_bind_attrs) and remove all devres calls.

Have a nice day,
Thanks,
Théo

[0]: https://lore.kernel.org/lkml/[email protected]/

---
Changes in v5:
- Set .suppress_bind_attrs = true.
- Replace devm_platform_ioremap_resource()
by platform_get_resource() + ioremap().
- Use non-devres version of devm_kzalloc().
- Use non-devres version of devm_of_clk_add_hw_provider().
- Remove the eqc_auxdev_unregister() devres action.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- clk-divider:
- Switch flags function arguments from u16 to unsigned long.
- clk-eyeq Kconfig:
- Remove OF dependency that is not required.
- clk-eyeq driver:
- eqc_pll_parse_registers():
- Make clk accuracy computation more explicit using a comment.
- Early return when not spread spectrum, to deindent code.
- Rename eqc_init() to eqc_early_init().
- Remove the early match table. Register a different function in each CLK_OF_DECLARE_DRIVER(), which calls eqc_early_init() with an additional match data argument.
- Add __initconst to early match data structs.
- Remove spinlock on static linked list.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Kconfig: add "depends on 64BIT" because we use readq(). This removes the ability to COMPILE_TEST the driver on 32bit, which is fine as this is a SoC clk platform driver used on 64bit SoCs.
- driver: avoid of_match_node(...)->data because, if !CONFIG_OF, of_match_node(...) is resolved by the preprocessor to NULL. There is still a warning "eqc_early_match_table declared but unused" if !CONFIG_OF. We fix the <linux/of.h> header in a separate patch:
https://lore.kernel.org/lkml/[email protected]/
- Link to v2: see [1]

Changes in v2:
- bindings: take Acked-by: Krzysztof Kozlowski.
- driver: eqc_auxdev_create(): cast the void __iomem *base variable to (void __force *) before putting it in platform_data, to avoid sparse warning.
- Link to v1: see [1]

Changes since OLB v3 [0]:
- MAINTAINERS: Move changes into a separate commit to avoid merge conflicts. This commit is in the MIPS series [3].
- dt-bindings: split include/dt-bindings/ changes into its own commit. It is part of this clk series.
- dt-bindings: Take Reviewed-by: Rob Herring. The include/dt-bindings/ new commit has NOT inherited from it, just to make sure.

---
Théo Lebrun (4):
Revert "dt-bindings: clock: mobileye,eyeq5-clk: add bindings"
dt-bindings: clock: add Mobileye EyeQ6L/EyeQ6H clock indexes
clk: divider: Introduce CLK_DIVIDER_EVEN_INTEGERS flag
clk: eyeq: add driver

 .../bindings/clock/mobileye,eyeq5-clk.yaml         |  51 --
 drivers/clk/Kconfig                                |  12 +
 drivers/clk/Makefile                               |   1 +
 drivers/clk/clk-divider.c                          |  16 +-
 drivers/clk/clk-eyeq.c                             | 779 +++++++++++++++++++++
 include/dt-bindings/clock/mobileye,eyeq5-clk.h     |  21 +
 include/linux/clk-provider.h                       |  15 +-
 7 files changed, 835 insertions(+), 60 deletions(-)

---
base-commit: 31d10adec91d1b3e51d7eaea7fdf294f1ebe83df
change-id: 20240628-mbly-clk-4c6ebc716347

Best regards,

Signature · 1 line
Théo Lebrun <[email protected]>
author maintainer
#1 lore raw

PATCH v5 1/4 Revert "dt-bindings: clock: mobileye,eyeq5-clk: add bindings"

Switch from one sub-node per functionality in the system-controller to a single node representing the entire OLB instance. This is the recommended approach for controllers handling many different functionalities; it is a single controller and should be represented by a single devicetree node.

The clock bindings is removed and all properties will be described by:
soc/mobileye/mobileye,eyeq5-olb.yaml

---
 .../bindings/clock/mobileye,eyeq5-clk.yaml         | 51 ----------------------
 1 file changed, 51 deletions(-)
Documentation/devicetree/bindings/clock/mobileye,eyeq5-clk.yaml deleted +0 -51
deleted file mode 100644
index 2d4f2cde1e589100f19d84db09050a591c6b9644..0000000000000000000000000000000000000000
@@ -1,51 +0,0 @@
-# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
-%YAML 1.2
----
-$id: http://devicetree.org/schemas/clock/mobileye,eyeq5-clk.yaml#
-$schema: http://devicetree.org/meta-schemas/core.yaml#
-
-title: Mobileye EyeQ5 clock controller
-
-description:
-  The EyeQ5 clock controller handles 10 read-only PLLs derived from the main
-  crystal clock. It also exposes one divider clock, a child of one of the PLLs.
-  Its registers live in a shared region called OLB.
-
-maintainers:
-  - Grégory Clement <[email protected]>
-  - Théo Lebrun <[email protected]>
-  - Vladimir Kondratiev <[email protected]>
-
-properties:
-  compatible:
-    const: mobileye,eyeq5-clk
-
-  reg:
-    maxItems: 2
-
-  reg-names:
-    items:
-      - const: plls
-      - const: ospi
-
-  "#clock-cells":
-    const: 1
-
-  clocks:
-    maxItems: 1
-    description:
-      Input parent clock to all PLLs. Expected to be the main crystal.
-
-  clock-names:
-    items:
-      - const: ref
-
-required:
-  - compatible
-  - reg
-  - reg-names
-  - "#clock-cells"
-  - clocks
-  - clock-names
-
-additionalProperties: false
Signature · 1 line
2.46.2
author maintainer
#3 lore raw

PATCH v5 2/4 dt-bindings: clock: add Mobileye EyeQ6L/EyeQ6H clock indexes

In reply to Théo Lebrun

Add #defines for Mobileye EyeQ6L and EyeQ6H SoC clocks.

Constant prefixes are:
- EQ6LC_PLL_: EyeQ6L clock PLLs
- EQ6HC_SOUTH_PLL_: EyeQ6H south OLB PLLs
- EQ6HC_SOUTH_DIV_: EyeQ6H south OLB divider clocks
- EQ6HC_ACC_PLL_: EyeQ6H accelerator OLB PLLs

---
 include/dt-bindings/clock/mobileye,eyeq5-clk.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
include/dt-bindings/clock/mobileye,eyeq5-clk.h +21 -0
index 26d8930335e4b113a74f47575957e39163f02766..b433c1772c28fae818b3a6ba428d1f89000f9206 100644
@@ -19,4 +19,25 @@
 
 #define EQ5C_DIV_OSPI	10
 
+#define EQ6LC_PLL_DDR		0
+#define EQ6LC_PLL_CPU		1
+#define EQ6LC_PLL_PER		2
+#define EQ6LC_PLL_VDI		3
+
+#define EQ6HC_SOUTH_PLL_VDI		0
+#define EQ6HC_SOUTH_PLL_PCIE		1
+#define EQ6HC_SOUTH_PLL_PER		2
+#define EQ6HC_SOUTH_PLL_ISP		3
+
+#define EQ6HC_SOUTH_DIV_EMMC		4
+#define EQ6HC_SOUTH_DIV_OSPI_REF	5
+#define EQ6HC_SOUTH_DIV_OSPI_SYS	6
+#define EQ6HC_SOUTH_DIV_TSU		7
+
+#define EQ6HC_ACC_PLL_XNN		0
+#define EQ6HC_ACC_PLL_VMP		1
+#define EQ6HC_ACC_PLL_PMA		2
+#define EQ6HC_ACC_PLL_MPC		3
+#define EQ6HC_ACC_PLL_NOC		4
+
 #endif
Signature · 1 line
2.46.2
author maintainer
#5 lore raw

PATCH v5 3/4 clk: divider: Introduce CLK_DIVIDER_EVEN_INTEGERS flag

In reply to Théo Lebrun

Add CLK_DIVIDER_EVEN_INTEGERS flag to support divisor of 2, 4, 6, etc. The same divisor can be done using a table, which would be big and wasteful for a clock dividor of width 8 (256 entries).

Require increasing flags size from u8 to u16 because CLK_DIVIDER_EVEN_INTEGERS is the eighth flag. u16 is used inside struct clk_divider; unsigned long is used for function arguments.

---
 drivers/clk/clk-divider.c    | 16 ++++++++++++----
 include/linux/clk-provider.h | 15 ++++++++++-----
 2 files changed, 22 insertions(+), 9 deletions(-)
drivers/clk/clk-divider.c +12 -4
index a2c2b5203b0a95cf1cf651b1fb4e2c24d230d831..c1f426b8a5043cb5a1de08e1da385928ec54a2ed 100644
@@ -72,6 +72,8 @@ static unsigned int _get_maxdiv(const struct clk_div_table *table, u8 width,
 		return clk_div_mask(width);
 	if (flags & CLK_DIVIDER_POWER_OF_TWO)
 		return 1 << clk_div_mask(width);
+	if (flags & CLK_DIVIDER_EVEN_INTEGERS)
+		return 2 * (clk_div_mask(width) + 1);
 	if (table)
 		return _get_table_maxdiv(table, width);
 	return clk_div_mask(width) + 1;
@@ -97,6 +99,8 @@ static unsigned int _get_div(const struct clk_div_table *table,
 		return 1 << val;
 	if (flags & CLK_DIVIDER_MAX_AT_ZERO)
 		return val ? val : clk_div_mask(width) + 1;
+	if (flags & CLK_DIVIDER_EVEN_INTEGERS)
+		return 2 * (val + 1);
 	if (table)
 		return _get_table_div(table, val);
 	return val + 1;
@@ -122,6 +126,8 @@ static unsigned int _get_val(const struct clk_div_table *table,
 		return __ffs(div);
 	if (flags & CLK_DIVIDER_MAX_AT_ZERO)
 		return (div == clk_div_mask(width) + 1) ? 0 : div;
+	if (flags & CLK_DIVIDER_EVEN_INTEGERS)
+		return (div >> 1) - 1;
 	if (table)
 		return  _get_table_val(table, div);
 	return div - 1;
@@ -538,7 +544,8 @@ struct clk_hw *__clk_hw_register_divider(struct device *dev,
 		struct device_node *np, const char *name,
 		const char *parent_name, const struct clk_hw *parent_hw,
 		const struct clk_parent_data *parent_data, unsigned long flags,
-		void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
+		void __iomem *reg, u8 shift, u8 width,
+		unsigned long clk_divider_flags,
 		const struct clk_div_table *table, spinlock_t *lock)
 {
 	struct clk_divider *div;
@@ -610,8 +617,8 @@ EXPORT_SYMBOL_GPL(__clk_hw_register_divider);
 struct clk *clk_register_divider_table(struct device *dev, const char *name,
 		const char *parent_name, unsigned long flags,
 		void __iomem *reg, u8 shift, u8 width,
-		u8 clk_divider_flags, const struct clk_div_table *table,
-		spinlock_t *lock)
+		unsigned long clk_divider_flags,
+		const struct clk_div_table *table, spinlock_t *lock)
 {
 	struct clk_hw *hw;
 
@@ -664,7 +671,8 @@ struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
 		struct device_node *np, const char *name,
 		const char *parent_name, const struct clk_hw *parent_hw,
 		const struct clk_parent_data *parent_data, unsigned long flags,
-		void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
+		void __iomem *reg, u8 shift, u8 width,
+		unsigned long clk_divider_flags,
 		const struct clk_div_table *table, spinlock_t *lock)
 {
 	struct clk_hw **ptr, *hw;
include/linux/clk-provider.h +10 -5
index 7e43caabb54b901d68484b86c8349febfe12ba0f..dbe793964c24ca3ab3a7facd090dfb6ae9df7631 100644
@@ -689,13 +689,15 @@ struct clk_div_table {
  * CLK_DIVIDER_BIG_ENDIAN - By default little endian register accesses are used
  *	for the divider register.  Setting this flag makes the register accesses
  *	big endian.
+ * CLK_DIVIDER_EVEN_INTEGERS - clock divisor is 2, 4, 6, 8, 10, etc.
+ *	Formula is 2 * (value read from hardware + 1).
  */
 struct clk_divider {
 	struct clk_hw	hw;
 	void __iomem	*reg;
 	u8		shift;
 	u8		width;
-	u8		flags;
+	u16		flags;
 	const struct clk_div_table	*table;
 	spinlock_t	*lock;
 };
@@ -711,6 +713,7 @@ struct clk_divider {
 #define CLK_DIVIDER_READ_ONLY		BIT(5)
 #define CLK_DIVIDER_MAX_AT_ZERO		BIT(6)
 #define CLK_DIVIDER_BIG_ENDIAN		BIT(7)
+#define CLK_DIVIDER_EVEN_INTEGERS	BIT(8)
 
 extern const struct clk_ops clk_divider_ops;
 extern const struct clk_ops clk_divider_ro_ops;
@@ -740,19 +743,21 @@ struct clk_hw *__clk_hw_register_divider(struct device *dev,
 		struct device_node *np, const char *name,
 		const char *parent_name, const struct clk_hw *parent_hw,
 		const struct clk_parent_data *parent_data, unsigned long flags,
-		void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
+		void __iomem *reg, u8 shift, u8 width,
+		unsigned long clk_divider_flags,
 		const struct clk_div_table *table, spinlock_t *lock);
 struct clk_hw *__devm_clk_hw_register_divider(struct device *dev,
 		struct device_node *np, const char *name,
 		const char *parent_name, const struct clk_hw *parent_hw,
 		const struct clk_parent_data *parent_data, unsigned long flags,
-		void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags,
+		void __iomem *reg, u8 shift, u8 width,
+		unsigned long clk_divider_flags,
 		const struct clk_div_table *table, spinlock_t *lock);
 struct clk *clk_register_divider_table(struct device *dev, const char *name,
 		const char *parent_name, unsigned long flags,
 		void __iomem *reg, u8 shift, u8 width,
-		u8 clk_divider_flags, const struct clk_div_table *table,
-		spinlock_t *lock);
+		unsigned long clk_divider_flags,
+		const struct clk_div_table *table, spinlock_t *lock);
 /**
  * clk_register_divider - register a divider clock with the clock framework
  * @dev: device registering this clock
Signature · 1 line
2.46.2
author maintainer
#7 lore raw

PATCH v5 4/4 clk: eyeq: add driver

In reply to Théo Lebrun

Add Mobileye EyeQ5, EyeQ6L and EyeQ6H clock controller driver. It is both a platform driver and a hook onto of_clk_init() used for clocks required early (GIC timer, UARTs).

For some compatible, it is both at the same time. eqc_early_init() initialises early PLLs and stores clock array in a static linked list. It marks other clocks as deferred. eqc_probe() retrieves the clock array and adds all remaining clocks.

It exposes read-only PLLs derived from the main crystal on board. It also exposes another type of clocks: divider clocks. They always have even divisors and have one PLL as parent.

This driver also bears the responsability for optional reset and pinctrl auxiliary devices. The match data attached to the devicetree node compatible indicate if such devices should be created. They all get passed a pointer to the start of the OLB region.

---
 drivers/clk/Kconfig    |  12 +
 drivers/clk/Makefile   |   1 +
 drivers/clk/clk-eyeq.c | 779 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 792 insertions(+)
drivers/clk/Kconfig +12 -0
index 299bc678ed1b9fcd9110bb8c5937a1bd1ea60e23..ae7caa28985481ce7280421de7d3f2340f8f9ab3 100644
@@ -226,6 +226,18 @@ config COMMON_CLK_EP93XX
 	help
 	  This driver supports the SoC clocks on the Cirrus Logic ep93xx.
 
+config COMMON_CLK_EYEQ
+	bool "Clock driver for the Mobileye EyeQ platform"
+	depends on 64BIT # for readq()
+	depends on MACH_EYEQ5 || MACH_EYEQ6H || COMPILE_TEST
+	select AUXILIARY_BUS
+	default MACH_EYEQ5 || MACH_EYEQ6H
+	help
+	  This driver provides clocks found on Mobileye EyeQ5, EyeQ6L and Eye6H
+	  SoCs. Controllers live in shared register regions called OLB. Driver
+	  provides read-only PLLs, derived from the main crystal clock (which
+	  must be constant). It also exposes some divider clocks.
+
 config COMMON_CLK_FSL_FLEXSPI
 	tristate "Clock driver for FlexSPI on Layerscape SoCs"
 	depends on ARCH_LAYERSCAPE || COMPILE_TEST
drivers/clk/Makefile +1 -0
index fb8878a5d7d93da6bec487460cdf63f1f764a431..9818a9445254a129e33279ae37a01f87bb9e1196 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_COMMON_CLK_CS2000_CP)	+= clk-cs2000-cp.o
 obj-$(CONFIG_COMMON_CLK_EP93XX)		+= clk-ep93xx.o
 obj-$(CONFIG_ARCH_SPARX5)		+= clk-sparx5.o
 obj-$(CONFIG_COMMON_CLK_EN7523)		+= clk-en7523.o
+obj-$(CONFIG_COMMON_CLK_EYEQ)		+= clk-eyeq.o
 obj-$(CONFIG_COMMON_CLK_FIXED_MMIO)	+= clk-fixed-mmio.o
 obj-$(CONFIG_COMMON_CLK_FSL_FLEXSPI)	+= clk-fsl-flexspi.o
 obj-$(CONFIG_COMMON_CLK_FSL_SAI)	+= clk-fsl-sai.o
drivers/clk/clk-eyeq.c new file +779 -0

779 lines not on this page · raw message

Signature · 1 line
2.46.2
author maintainer
#14 lore raw
In reply to Théo Lebrun

Hello Stephen,

Quoted 3 lines · Théo Lebrun

This series adds a platform driver dealing with read-only PLLs derived from the main crystal, and some divider clocks based on those PLLs. It also acts at the one instantiating reset and pinctrl auxiliary devices.

I'd be curious to get feedback on this series?
Could it make it before the next merge window?

V4 fixed all your comments but one. You implied the linked list might be useless, but I am not convinced:

Quoted 6 lines

I had a pending question [0], asking for confirmation that the static linked list to inherit cells from of_clk_init() stage to platform device probe is indeed the right solution. As -rc1 got released I sent the new revision anyway.

[0]: https://lore.kernel.org/lkml/[email protected]/

Quoting here the original email for full context:

Quoted 30 lines · Théo Lebrun
Quoted 8 lines · Stephen Boyd

Quoting Théo Lebrun (2024-07-30 09:04:46)

Quoted 1 line

+ list_add_tail(&priv->list, &eqc_list);

The list is also kind of unnecessary. Set a bool in the match_data and move on? We could have some sort of static_assert() check to make sure if there's a CLK_OF_DECLARE_DRIVER() then the bool is set in the match_data for the driver. Such a design is cheaper than taking a lock, adding to a list.

This list's main goal is not to know what was early-inited. Its only reason for existence is that we want to get, at eqc_probe(), the cells pointer allocated at eqc_init().

struct eqc_priv {
	/* this field is why we store priv inside a linked list: */
	struct clk_hw_onecell_data	*cells;
	/* the rest, we don't care much: */
	const struct eqc_early_match_data *early_data;
	const struct eqc_match_data	*data;
	void __iomem			*base;
	struct device_node		*np;
	struct list_head		list;
};

I do not see how to do that with a bool. We could put the pointer into the match data, but that would mean we'd have to make them writable (currently static const data). We are talking about a linked list with two items in the worst case (EyeQ6H), accessed twice.

Quoted 5 lines

The reason we store the whole of priv: simpler code and we avoid mapping registers twice (once at eqc_init() and once at eqc_probe()).

Can you confirm the current static linked list approach (without any spinlock) will be good for next revision?

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

maintainer
#15 lore raw

Quoting Théo Lebrun (2024-10-15 01:50:26)

Quoted 13 lines

Hello Stephen,

Quoted 3 lines · Théo Lebrun

This series adds a platform driver dealing with read-only PLLs derived from the main crystal, and some divider clocks based on those PLLs. It also acts at the one instantiating reset and pinctrl auxiliary devices.

I'd be curious to get feedback on this series?
Could it make it before the next merge window?

V4 fixed all your comments but one. You implied the linked list might be useless, but I am not convinced:

Quoted 8 lines
Quoted 6 lines

I had a pending question [0], asking for confirmation that the static linked list to inherit cells from of_clk_init() stage to platform device probe is indeed the right solution. As -rc1 got released I sent the new revision anyway.

[0]: https://lore.kernel.org/lkml/[email protected]/

Quoting here the original email for full context:

Thanks!

Quoted 16 lines · Théo Lebrun
Quoted 14 lines · Stephen Boyd
Quoted 8 lines

Quoting Théo Lebrun (2024-07-30 09:04:46)

Quoted 1 line

+ list_add_tail(&priv->list, &eqc_list);

The list is also kind of unnecessary. Set a bool in the match_data and move on? We could have some sort of static_assert() check to make sure if there's a CLK_OF_DECLARE_DRIVER() then the bool is set in the match_data for the driver. Such a design is cheaper than taking a lock, adding to a list.

This list's main goal is not to know what was early-inited. Its only reason for existence is that we want to get, at eqc_probe(), the cells pointer allocated at eqc_init().

Quoted 5 lines
Quoted 5 lines
struct eqc_priv {
      /* this field is why we store priv inside a linked list: */
      struct clk_hw_onecell_data      *cells;
      /* the rest, we don't care much: */
      const struct eqc_early_match_data *early_data;

This is __initconst and won't be valid after init, which is possible if the driver probe is delayed beyond the time that init memory is freed.

Quoted 10 lines
Quoted 10 lines
      const struct eqc_match_data     *data;
      void __iomem                    *base;
      struct device_node              *np;
      struct list_head                list;

};

I do not see how to do that with a bool. We could put the pointer into the match data, but that would mean we'd have to make them writable (currently static const data). We are talking about a linked list with two items in the worst case (EyeQ6H), accessed twice.

Ah I missed that you were trying to stash the onecell data away. You can register a clk provider for the same node more than once. The first "early" one can return an error pointer for the clk indices that will be registered later. The second onecell data can be registered in the regular driver probe and return the clks that are registered later. See of_clk_get_hw_from_clkspec() and how it keeps trying to find a clk if the provider that matches the node didn't return a valid pointer.

Quoted 3 lines
Quoted 3 lines

The reason we store the whole of priv: simpler code and we avoid mapping registers twice (once at eqc_init() and once at eqc_probe()).

The IO mapping code handles duplicate mappings internally by returning the previous virtual address. It doesn't hurt to call it again.

Quoted 4 lines
Quoted 3 lines

Can you confirm the current static linked list approach (without any spinlock) will be good for next revision?

Getting rid of the list will make the code simpler and avoid the driver probe path from accessing the early data. Please do it!

maintainer
#8 lore raw

Re: [PATCH v5 4/4] clk: eyeq: add driver

In reply to Théo Lebrun

Quoting Théo Lebrun (2024-10-07 06:49:19)

drivers/clk/Kconfig config COMMON_CLK_EP93XX · line 231

Quoted 11 lines
drivers/clk/Kconfig +3 -0
index 299bc678ed1b9fcd9110bb8c5937a1bd1ea60e23..ae7caa28985481ce7280421de7d3f2340f8f9ab3 100644
@@ -226,6 +226,18 @@ config COMMON_CLK_EP93XX
        help
          This driver supports the SoC clocks on the Cirrus Logic ep93xx.
 
+config COMMON_CLK_EYEQ
+       bool "Clock driver for the Mobileye EyeQ platform"
+       depends on 64BIT # for readq()

This makes my build test script blow up. Please just pick one or the other header as you don't really care. I will apply something like this patch either way.

drivers/clk/Kconfig +0 -1
index ae7caa289854..bb8f4fb5f996 100644
@@ -228,7 +228,6 @@ config COMMON_CLK_EP93XX
 
 config COMMON_CLK_EYEQ
 	bool "Clock driver for the Mobileye EyeQ platform"
-	depends on 64BIT # for readq()
 	depends on MACH_EYEQ5 || MACH_EYEQ6H || COMPILE_TEST
 	select AUXILIARY_BUS
 	default MACH_EYEQ5 || MACH_EYEQ6H
drivers/clk/clk-eyeq.c +2 -0
index 762885333c03..2fd44e0d27f6 100644
@@ -28,7 +28,9 @@
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/io-64-nonatomic-hi-lo.h>
 #include <linux/list.h>
+#include <linux/mod_devicetable.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
Quoted 30 lines
drivers/clk/clk-eyeq.c new file +24 -0
new file mode 100644
index 0000000000000000000000000000000000000000..762885333c0336e9ff1162a3677f5fb815fd461a
@@ -0,0 +1,779 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * PLL clock driver for the Mobileye EyeQ5, EyeQ6L and EyeQ6H platforms.
+ *
+ * This controller handles read-only PLLs, all derived from the same main
+ * crystal clock. It also exposes divider clocks, those are children to PLLs.
+ * Parent clock is expected to be constant. This driver's registers live in
+ * a shared region called OLB. Some PLLs are initialised early by of_clk_init().
+ *
+ * We use eqc_ as prefix, as-in "EyeQ Clock", but way shorter.
+ *
+ * Copyright (C) 2024 Mobileye Vision Technologies Ltd.
+ */
+
+/*
+ * Set pr_fmt() for printing from eqc_early_init().
+ * It is called at of_clk_init() stage (read: really early).
+ */
+#define pr_fmt(fmt) "clk-eyeq: " fmt
+
+#include <linux/array_size.h>
+#include <linux/auxiliary_bus.h>
+#include <linux/bitfield.h>
+#include <linux/bits.h>

drivers/clk/clk-eyeq.c line 34

Quoted 10 lines
drivers/clk/clk-eyeq.c new file +10 -0
+#include <linux/clk-provider.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_address.h>

You need mod_devicetable.h as well for of_device_id.

Quoted 14 lines
drivers/clk/clk-eyeq.c new file +14 -0
+#include <linux/overflow.h>
+#include <linux/platform_device.h>
+#include <linux/printk.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/types.h>
+
+#include <dt-bindings/clock/mobileye,eyeq5-clk.h>
+
+#define EQC_MAX_DIV_COUNT              4
+
+/* In frac mode, it enables fractional noise canceling DAC. Else, no function. */
+#define PCSR0_DAC_EN                   BIT(0)
+/* Fractional or integer mode */

[...]

Quoted 15 lines
drivers/clk/clk-eyeq.c new file +15 -0
+
+/* Required early for GIC timer (pll-cpu) and UARTs (pll-per). */
+static const struct eqc_pll eqc_eyeq5_early_plls[] = {
+       { .index = EQ5C_PLL_CPU, .name = "pll-cpu",  .reg64 = 0x02C },
+       { .index = EQ5C_PLL_PER, .name = "pll-per",  .reg64 = 0x05C },
+};
+
+static const struct eqc_early_match_data eqc_eyeq5_early_match_data __initconst = {
+       .early_pll_count        = ARRAY_SIZE(eqc_eyeq5_early_plls),
+       .early_plls             = eqc_eyeq5_early_plls,
+       .nb_late_clks = eqc_eyeq5_match_data.pll_count + eqc_eyeq5_match_data.div_count,
+};
+
+/* Required early for GIC timer. */
+static const struct eqc_pll eqc_eyeq6h_central_early_plls[] = {

drivers/clk/clk-eyeq.c

Quoted 10 lines
drivers/clk/clk-eyeq.c new file +10 -0
+       { .index = 0, .name = "pll-cpu", .reg64 = 0x02C },
+};
+
+static const struct eqc_early_match_data eqc_eyeq6h_central_early_match_data __initconst = {
+       .early_pll_count        = ARRAY_SIZE(eqc_eyeq6h_central_early_plls),
+       .early_plls             = eqc_eyeq6h_central_early_plls,
+       .nb_late_clks = 0,
+};
+
+/* Required early for UART. */

I still don't get this. UART isn't an early device. It's only the interrupt controller and the timer that matter. Does MIPS do something special for UARTs?

Quoted 3 lines
drivers/clk/clk-eyeq.c new file +3 -0
+static const struct eqc_pll eqc_eyeq6h_west_early_plls[] = {
+       { .index = 0, .name = "pll-west", .reg64 = 0x074 },
+};
maintainer Applied
#2 lore raw

Re: [PATCH v5 1/4] Revert "dt-bindings: clock: mobileye,eyeq5-clk: add bindings"

In reply to Théo Lebrun

Quoting Théo Lebrun (2024-10-07 06:49:16)

Quoted 6 lines

Switch from one sub-node per functionality in the system-controller to a single node representing the entire OLB instance. This is the recommended approach for controllers handling many different functionalities; it is a single controller and should be represented by a single devicetree node.

Quoted 6 lines

The clock bindings is removed and all properties will be described by:
soc/mobileye/mobileye,eyeq5-olb.yaml

---

Applied to clk-next

maintainer Applied
#4 lore raw

Re: [PATCH v5 2/4] dt-bindings: clock: add Mobileye EyeQ6L/EyeQ6H clock indexes

In reply to Théo Lebrun

Quoting Théo Lebrun (2024-10-07 06:49:17)

Quoted 11 lines

Add #defines for Mobileye EyeQ6L and EyeQ6H SoC clocks.

Constant prefixes are:
- EQ6LC_PLL_: EyeQ6L clock PLLs
- EQ6HC_SOUTH_PLL_: EyeQ6H south OLB PLLs
- EQ6HC_SOUTH_DIV_: EyeQ6H south OLB divider clocks
- EQ6HC_ACC_PLL_: EyeQ6H accelerator OLB PLLs

---

Applied to clk-next

maintainer Applied
#6 lore raw

Re: [PATCH v5 3/4] clk: divider: Introduce CLK_DIVIDER_EVEN_INTEGERS flag

In reply to Théo Lebrun

Quoting Théo Lebrun (2024-10-07 06:49:18)

Quoted 10 lines

Add CLK_DIVIDER_EVEN_INTEGERS flag to support divisor of 2, 4, 6, etc. The same divisor can be done using a table, which would be big and wasteful for a clock dividor of width 8 (256 entries).

Require increasing flags size from u8 to u16 because CLK_DIVIDER_EVEN_INTEGERS is the eighth flag. u16 is used inside struct clk_divider; unsigned long is used for function arguments.

---

Applied to clk-next

author maintainer
#9 lore raw

Re: [PATCH v5 4/4] clk: eyeq: add driver

In reply to Stephen Boyd

Hello Stephen,

Quoted 21 lines · Stephen Boyd

Quoting Théo Lebrun (2024-10-07 06:49:19)

Quoted 20 lines
(quoted diff) +20 -0
+/* Required early for GIC timer (pll-cpu) and UARTs (pll-per). */
+static const struct eqc_pll eqc_eyeq5_early_plls[] = {
+       { .index = EQ5C_PLL_CPU, .name = "pll-cpu",  .reg64 = 0x02C },
+       { .index = EQ5C_PLL_PER, .name = "pll-per",  .reg64 = 0x05C },
+};
+
+static const struct eqc_early_match_data eqc_eyeq5_early_match_data __initconst = {
+       .early_pll_count        = ARRAY_SIZE(eqc_eyeq5_early_plls),
+       .early_plls             = eqc_eyeq5_early_plls,
+       .nb_late_clks = eqc_eyeq5_match_data.pll_count + eqc_eyeq5_match_data.div_count,
+};
+
+/* Required early for GIC timer. */
+static const struct eqc_pll eqc_eyeq6h_central_early_plls[] = {
+       { .index = 0, .name = "pll-cpu", .reg64 = 0x02C },
+};
+
+static const struct eqc_early_match_data eqc_eyeq6h_central_early_match_data __initconst = {
+       .early_pll_count        = ARRAY_SIZE(eqc_eyeq6h_central_early_plls),
+       .early_plls             = eqc_eyeq6h_central_early_plls,
Quoted 8 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+       .nb_late_clks = 0,
+};
+
+/* Required early for UART. */

I still don't get this. UART isn't an early device. It's only the interrupt controller and the timer that matter. Does MIPS do something special for UARTs?

Our hardware has a PL011. That is AMBA stuff; they get probed before platform devices by of_platform_bus_create(). "pll-per" on EyeQ5 must be available at that time.

In concrete terms, if we don't register pll-per on EyeQ5 at of_clk_init(), we stare at void because the serial fails probing. I haven't digged into why EPROBE_DEFER doesn't do its job. Anyway we don't want our serial to stall for some time during our boot process.

Thanks for the extensive review! New revision is in your inbox.

Thanks,
Théo

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

maintainer
#10 lore raw

Re: [PATCH v5 4/4] clk: eyeq: add driver

Quoting Théo Lebrun (2024-10-23 04:08:31)

Quoted 8 lines · Stephen Boyd
Quoted 6 lines

Quoting Théo Lebrun (2024-10-07 06:49:19)

Quoted 1 line

+/* Required early for UART. */

I still don't get this. UART isn't an early device. It's only the interrupt controller and the timer that matter. Does MIPS do something special for UARTs?

Quoted 9 lines

Our hardware has a PL011. That is AMBA stuff; they get probed before platform devices by of_platform_bus_create(). "pll-per" on EyeQ5 must be available at that time.

In concrete terms, if we don't register pll-per on EyeQ5 at of_clk_init(), we stare at void because the serial fails probing. I haven't digged into why EPROBE_DEFER doesn't do its job. Anyway we don't want our serial to stall for some time during our boot process.

Ok thanks for the details. It sounds like there's a bug in there somewhere. Eventually this should be removed.

Can you dump_stack() in clk_get() when the "pll-per" clk is claimed?

I suspect of_clk_get_hw_from_clkspec() is seeing NULL if of_clk_hw_onecell_get() is being used and the clk_hw pointer isn't set yet. NULL is a valid clk and it will be returned to the consumer. You'll want to write a custom 'get' function for of_clk_add_hw_provider() that returns -EPROBE_DEFER for any clk that isn't registered early. Then the AMBA stuff should defer probe until the "full" clk provider is registered.

author maintainer
#11 lore raw

Re: [PATCH v5 4/4] clk: eyeq: add driver

Hello Stephen, Conor, Krzysztof, Michael, Rob,

Quoted 24 lines · Stephen Boyd

Quoting Théo Lebrun (2024-10-23 04:08:31)

Quoted 8 lines · Stephen Boyd
Quoted 6 lines

Quoting Théo Lebrun (2024-10-07 06:49:19)

Quoted 1 line

+/* Required early for UART. */

I still don't get this. UART isn't an early device. It's only the interrupt controller and the timer that matter. Does MIPS do something special for UARTs?

Quoted 9 lines

Our hardware has a PL011. That is AMBA stuff; they get probed before platform devices by of_platform_bus_create(). "pll-per" on EyeQ5 must be available at that time.

In concrete terms, if we don't register pll-per on EyeQ5 at of_clk_init(), we stare at void because the serial fails probing. I haven't digged into why EPROBE_DEFER doesn't do its job. Anyway we don't want our serial to stall for some time during our boot process.

Ok thanks for the details. It sounds like there's a bug in there somewhere. Eventually this should be removed.

Can you dump_stack() in clk_get() when the "pll-per" clk is claimed?

Quoted 7 lines

I suspect of_clk_get_hw_from_clkspec() is seeing NULL if of_clk_hw_onecell_get() is being used and the clk_hw pointer isn't set yet. NULL is a valid clk and it will be returned to the consumer. You'll want to write a custom 'get' function for of_clk_add_hw_provider() that returns -EPROBE_DEFER for any clk that isn't registered early. Then the AMBA stuff should defer probe until the "full" clk provider is registered.

You encouraged me to keep digging.

The bug is elsewhere: we do get valid clocks from PL011. Both clk_get() calls give proper pointers.

The issue is that we are using compatible = "fixed-factor-clock" clocks in the middle, and those don't wait for their parents to be active.

Simplified clock graph is: pll-per -> occ-periph. pll-per is register by our driver. occ-periph looks like:

	occ_periph: occ-periph {
		compatible = "fixed-factor-clock";
		clocks = <&olb EQ5C_PLL_PER>;
		#clock-cells = <0>;
		clock-div = <16>;
		clock-mult = <1>;
	};

Sequence is:
- eqc_early_init(): it registers a clock provider that will return EPROBE_DEFER for our pll-per.
- _of_fixed_factor_clk_setup(): it registers occ-periph, even though its parent is EPROBE_DEFER. clk_core_populate_parent_map() runs all fine without complaining; logical as it doesn't query the clk_hw for its parent, it only stores indexes.
- amba_get_enable_pclk(): it does a clk_get() which works because occ-periph exists.

Maybe __clk_register() should check the clk_hw for each parent: if any is an EPROBE_DEFER then it should EPROBE_DEFER itself? That looks like a rather big behavioral change.

The other solution is to keep as-is: provide all clocks consumed by fixed-factor-clocks at of_clk_init() stage.

Hoping I provided enough info,
Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

maintainer
#12 lore raw

Re: [PATCH v5 4/4] clk: eyeq: add driver

Quoting Théo Lebrun (2024-10-24 05:50:16)

Quoted 10 lines

The bug is elsewhere: we do get valid clocks from PL011. Both clk_get() calls give proper pointers.

The issue is that we are using compatible = "fixed-factor-clock" clocks in the middle, and those don't wait for their parents to be active.

Simplified clock graph is: pll-per -> occ-periph. pll-per is register by our driver. occ-periph looks like:

Quoted 7 lines
        occ_periph: occ-periph {
                compatible = "fixed-factor-clock";
                clocks = <&olb EQ5C_PLL_PER>;
                #clock-cells = <0>;
                clock-div = <16>;
                clock-mult = <1>;
        };

Why is this fixed factor clk registered from DT vs. from the driver that registers pll-per? Is it useful to describe it in DT because the factor can change? Where does it physically exist? In the SoC?

Quoted 11 lines

Sequence is:
- eqc_early_init(): it registers a clock provider that will return EPROBE_DEFER for our pll-per.
- _of_fixed_factor_clk_setup(): it registers occ-periph, even though its parent is EPROBE_DEFER. clk_core_populate_parent_map() runs all fine without complaining; logical as it doesn't query the clk_hw for its parent, it only stores indexes.
- amba_get_enable_pclk(): it does a clk_get() which works because occ-periph exists.

Quoted 6 lines

Maybe __clk_register() should check the clk_hw for each parent: if any is an EPROBE_DEFER then it should EPROBE_DEFER itself? That looks like a rather big behavioral change.

The other solution is to keep as-is: provide all clocks consumed by fixed-factor-clocks at of_clk_init() stage.

Another solution is to register the fixed factor clk from the pll-per clk provider.

And yet another solution is to return EPROBE_DEFER for orphaned clks. We have everything in place for that but we ran into trouble with consumers wanting to get orphaned clks in their probe or during assigned-clocks handling.

author maintainer
#13 lore raw

Re: [PATCH v5 4/4] clk: eyeq: add driver

Quoted 19 lines · Stephen Boyd

Quoting Théo Lebrun (2024-10-24 05:50:16)

Quoted 10 lines

The bug is elsewhere: we do get valid clocks from PL011. Both clk_get() calls give proper pointers.

The issue is that we are using compatible = "fixed-factor-clock" clocks in the middle, and those don't wait for their parents to be active.

Simplified clock graph is: pll-per -> occ-periph. pll-per is register by our driver. occ-periph looks like:

Quoted 7 lines
        occ_periph: occ-periph {
                compatible = "fixed-factor-clock";
                clocks = <&olb EQ5C_PLL_PER>;
                #clock-cells = <0>;
                clock-div = <16>;
                clock-mult = <1>;
        };
Quoted 3 lines

Why is this fixed factor clk registered from DT vs. from the driver that registers pll-per? Is it useful to describe it in DT because the factor can change? Where does it physically exist? In the SoC?

Those are internal SoC clocks, yes. No reason for them to change from one board to another. Adding them from the driver makes the most sense, I'll patch that up.

Quoted 17 lines
Quoted 10 lines

Sequence is:
- eqc_early_init(): it registers a clock provider that will return EPROBE_DEFER for our pll-per.
- _of_fixed_factor_clk_setup(): it registers occ-periph, even though its parent is EPROBE_DEFER. clk_core_populate_parent_map() runs all fine without complaining; logical as it doesn't query the clk_hw for its parent, it only stores indexes.
- amba_get_enable_pclk(): it does a clk_get() which works because occ-periph exists.

Quoted 6 lines

Maybe __clk_register() should check the clk_hw for each parent: if any is an EPROBE_DEFER then it should EPROBE_DEFER itself? That looks like a rather big behavioral change.

The other solution is to keep as-is: provide all clocks consumed by fixed-factor-clocks at of_clk_init() stage.

Quoted 7 lines

Another solution is to register the fixed factor clk from the pll-per clk provider.

And yet another solution is to return EPROBE_DEFER for orphaned clks. We have everything in place for that but we ran into trouble with consumers wanting to get orphaned clks in their probe or during assigned-clocks handling.

No suprise this kind of edge-case behavior can cause trouble.

Thanks,

--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com