Add Mobileye EyeQ clock support
Subsystems (3)
Théo Lebrun
maintainerv3 cover Add Mobileye EyeQ clock support
This is a new iteration on the clock part of the Mobileye system-controller series. It used to be sent as a single series [0], but has been split in the previous revisions (see [1], [2], [3], [4]) to faciliate merging.
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 the 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.
Only clock is receiving a v3; other driver series (reset, pinctrl) stay at v2. MIPS [4] has been taken in the MIPS tree [5].
Have a nice day,
Théo
[0]: https://lore.kernel.org/lkml/[email protected]/
[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: https://lore.kernel.org/lkml/[email protected]/
[4]: https://lore.kernel.org/lkml/[email protected]/
[5]: https://lore.kernel.org/lkml/[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 | 13 + drivers/clk/Makefile | 1 + drivers/clk/clk-divider.c | 12 +- drivers/clk/clk-eyeq.c | 793 +++++++++++++++++++++ include/dt-bindings/clock/mobileye,eyeq5-clk.h | 21 + include/linux/clk-provider.h | 11 +- 7 files changed, 844 insertions(+), 58 deletions(-)
---
base-commit: 256abd8e550ce977b728be79a74e1729438b4948
change-id: 20240628-mbly-clk-4c6ebc716347
Best regards,
Signature · 1 line
Théo Lebrun <[email protected]>
Théo Lebrun
maintainerPATCH RESEND v3 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
@@ -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.45.2
Théo Lebrun
maintainerPATCH RESEND v3 2/4 dt-bindings: clock: add Mobileye EyeQ6L/EyeQ6H clock indexes
In reply to Théo LebrunAdd #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
@@ -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.45.2
Théo Lebrun
maintainerPATCH RESEND v3 3/4 clk: divider: Introduce CLK_DIVIDER_EVEN_INTEGERS flag
In reply to Théo LebrunAdd 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.
--- drivers/clk/clk-divider.c | 12 +++++++++--- include/linux/clk-provider.h | 11 +++++++---- 2 files changed, 16 insertions(+), 7 deletions(-)
drivers/clk/clk-divider.c +9 -3
@@ -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,7 @@ 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, u16 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock) { struct clk_divider *div;
@@ -610,7 +616,7 @@ 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, +u16 clk_divider_flags,const struct clk_div_table *table,spinlock_t *lock) {struct clk_hw *hw;
@@ -664,7 +670,7 @@ 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, u16 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock) { struct clk_hw **ptr, *hw;
include/linux/clk-provider.h +7 -4
@@ -675,13 +675,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; };
@@ -697,6 +699,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;
@@ -726,18 +729,18 @@ 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, u16 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,u16 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, +u16 clk_divider_flags,const struct clk_div_table *table,spinlock_t *lock);/** * clk_register_divider - register a divider clock with the clock framework
Signature · 1 line
2.45.2
Stephen Boyd
maintainerRe: [PATCH RESEND v3 3/4] clk: divider: Introduce CLK_DIVIDER_EVEN_INTEGERS flag
Quoting Théo Lebrun (2024-07-30 09:04:45)
drivers/clk/clk-divider.c struct clk_hw *__clk_hw_register_divider(struct device *dev, · line 547
Quoted 6 lines
drivers/clk/clk-divider.c +1
-1@@ -538,7 +544,7 @@ 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, u16 clk_divider_flags,
It would be better to make this unsigned long instead of u16 (for all the registration wrappers) so that if we add more flags we don't have to change these lines again. Seems unlikely we'll have more than 32 flags, but I could be wrong.
Quoted 29 lines
drivers/clk/clk-divider.c +2
-2const struct clk_div_table *table, spinlock_t *lock) { struct clk_divider *div;@@ -610,7 +616,7 @@ 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, +u16 clk_divider_flags,const struct clk_div_table *table,spinlock_t *lock) {struct clk_hw *hw;@@ -664,7 +670,7 @@ 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, u16 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock) { struct clk_hw **ptr, *hw;include/linux/clk-provider.h +0
-0@@ -675,13 +675,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.
include/linux/clk-provider.h struct clk_div_table { · line 686
Quoted 10 lines
include/linux/clk-provider.h +3
-1+* 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;
This can stay as u16 to save space of course.
Quoted 3 lines
include/linux/clk-provider.h +0
-0const struct clk_div_table *table;spinlock_t *lock; };
Théo Lebrun
maintainerPATCH RESEND v3 4/4 clk: eyeq: add driver
In reply to Théo LebrunAdd 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_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 | 13 + drivers/clk/Makefile | 1 + drivers/clk/clk-eyeq.c | 793 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 807 insertions(+)
drivers/clk/Kconfig +13 -0
@@ -218,6 +218,19 @@ config COMMON_CLK_EN7523 This driver provides the fixed clocks and gates present on Airoha ARM silicon. +config COMMON_CLK_EYEQ + bool "Clock driver for the Mobileye EyeQ platform" + depends on 64BIT # for readq() + depends on OF || COMPILE_TEST + 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
@@ -32,6 +32,7 @@ obj-$(CONFIG_ARCH_CLPS711X) += clk-clps711x.o obj-$(CONFIG_COMMON_CLK_CS2000_CP) += clk-cs2000-cp.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 +793 -0
793 lines not on this page · raw message
Signature · 1 line
2.45.2
Stephen Boyd
maintainerRe: [PATCH RESEND v3 4/4] clk: eyeq: add driver
Quoting Théo Lebrun (2024-07-30 09:04:46)
drivers/clk/Kconfig config COMMON_CLK_EN7523 · line 224
Quoted 12 lines
drivers/clk/Kconfig +4
-0@@ -218,6 +218,19 @@ config COMMON_CLK_EN7523 This driver provides the fixed clocks and gates present on Airoha ARM silicon. +config COMMON_CLK_EYEQ + bool "Clock driver for the Mobileye EyeQ platform" + depends on 64BIT # for readq() + depends on OF || COMPILE_TEST
What's the OF build dependency? If there isn't one please remove this line.
Quoted 16 lines
drivers/clk/Kconfig +9
-0+ 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. +drivers/clk/clk-eyeq.c new file +1
-0@@ -0,0 +1,793 @@ +// SPDX-License-Identifier: GPL-2.0-only
[...]
Quoted 12 lines
drivers/clk/clk-eyeq.c new file +12
-0+ +static int eqc_pll_parse_registers (u32 r0,u32 r1,unsigned long *mult, +unsigned long *div,unsigned long *acc) +{ +if (r0 &PCSR0_BYPASS ) { + *mult =1 ; + *div =1 ; + *acc =0 ; +return 0 ; + } + +if (!(r0 &PCSR0_PLL_LOCKED ))
drivers/clk/clk-eyeq.c line 182
Quoted 10 lines
drivers/clk/clk-eyeq.c new file +10
-0+return -EINVAL ; + + *mult =FIELD_GET (PCSR0_INTIN , r0); + *div =FIELD_GET (PCSR0_REF_DIV , r0); +if (r0 &PCSR0_FOUTPOSTDIV_EN ) + *div *=FIELD_GET (PCSR0_POST_DIV1 , r0) *FIELD_GET (PCSR0_POST_DIV2 , r0); + +/* Fractional mode, in 2^20 (0x100000) parts. */ +if (r0 &PCSR0_DSM_EN ) { + *div *=0x100000 ;
I'd think 1 << 20 is more idiomatic to represent 2^20 because we don't have to count the zeroes to make sure this is right.
Quoted 5 lines
drivers/clk/clk-eyeq.c new file +5
-0+ *mult = *mult *0x100000 +FIELD_GET (PCSR1_FRAC_IN , r1); + } + +if (!*mult || !*div) +return -EINVAL ;
drivers/clk/clk-eyeq.c line 197
Quoted 10 lines
drivers/clk/clk-eyeq.c new file +10
-0+ +/* Spread spectrum. */ +if (!(r1 & (PCSR1_RESET |PCSR1_DIS_SSCG ))) { +/* +* Spread is 1/1000 parts of frequency, accuracy is half of +* that. To get accuracy, convert to ppb (parts per billion). +*/ +u32 spread =FIELD_GET (PCSR1_SPREAD , r1); + + *acc = spread *500000 ;
Where does 500000 come from? Half a billion?
Quoted 6 lines
drivers/clk/clk-eyeq.c new file +6
-0+if (r1 &PCSR1_DOWN_SPREAD ) { +/* +* Downspreading: the central frequency is half a +* spread lower. +*/ + *mult *=2000 - spread;
drivers/clk/clk-eyeq.c line 213
Quoted 10 lines
drivers/clk/clk-eyeq.c new file +10
-0+ *div *=2000 ; + +/* +* Previous operation might overflow 32 bits. If it +* does, throw away the least amount of low bits. +*/ +eqc_pll_downshift_factors (mult, div); + } + }else { + *acc =0 ;
I'd de-indent by inverting this and returning early when *acc = 0.
Quoted 5 lines
drivers/clk/clk-eyeq.c new file +5
-0+ } + +return 0 ; +} +
[...]
drivers/clk/clk-eyeq.c line 608
Quoted 13 lines
drivers/clk/clk-eyeq.c new file +13
-0+ +static const struct of_device_id eqc_match_table[] = { + { .compatible ="mobileye,eyeq5-olb" , .data = &eqc_eyeq5_match_data }, + { .compatible ="mobileye,eyeq6l-olb" , .data = &eqc_eyeq6l_match_data }, + { .compatible ="mobileye,eyeq6h-west-olb" , .data = &eqc_eyeq6h_west_match_data }, + { .compatible ="mobileye,eyeq6h-east-olb" , .data = &eqc_eyeq6h_east_match_data }, + { .compatible ="mobileye,eyeq6h-south-olb" , .data = &eqc_eyeq6h_south_match_data }, + { .compatible ="mobileye,eyeq6h-ddr0-olb" , .data = &eqc_eyeq6h_ddr0_match_data }, + { .compatible ="mobileye,eyeq6h-ddr1-olb" , .data = &eqc_eyeq6h_ddr1_match_data }, + { .compatible ="mobileye,eyeq6h-acc-olb" , .data = &eqc_eyeq6h_acc_match_data }, + {} +}; +MODULE_DEVICE_TABLE (of, eqc_match_table);
Module device table should be removed as this can't be a module.
Quoted 24 lines
drivers/clk/clk-eyeq.c new file +24
-0+ +static struct platform_driver eqc_driver = { + .probe = eqc_probe, + .driver = { + .name ="clk-eyeq" , + .of_match_table = eqc_match_table, + }, +}; +builtin_platform_driver (eqc_driver); + +/* 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 = { + .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 line 642
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 = { + .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. */
Is this required for earlycon? Where is the UART not a device driver that needs to get clks early?
drivers/clk/clk-eyeq.c line 653
Quoted 11 lines
drivers/clk/clk-eyeq.c new file +11
-0+static const struct eqc_pll eqc_eyeq6h_west_early_plls[] = { + { .index =0 , .name ="pll-west" , .reg64 =0x074 }, +}; + +static const struct eqc_early_match_data eqc_eyeq6h_west_early_match_data = { + .early_pll_count =ARRAY_SIZE (eqc_eyeq6h_west_early_plls), + .early_plls = eqc_eyeq6h_west_early_plls, + .nb_late_clks =0 , +}; + +static const struct of_device_id eqc_early_match_table[] = {
Can be __initconst
Quoted 5 lines
drivers/clk/clk-eyeq.c new file +5
-0+ { + .compatible = "mobileye,eyeq5-olb", + .data = &eqc_eyeq5_early_match_data, + }, + {
drivers/clk/clk-eyeq.c line 668
Quoted 10 lines
drivers/clk/clk-eyeq.c new file +10
-0+ .compatible = "mobileye,eyeq6h-central-olb", + .data = &eqc_eyeq6h_central_early_match_data, + }, + { + .compatible = "mobileye,eyeq6h-west-olb", + .data = &eqc_eyeq6h_west_early_match_data, + }, + {} +}; +MODULE_DEVICE_TABLE (of, eqc_early_match_table);
This isn't needed because this isn't a module.
drivers/clk/clk-eyeq.c line 674
Quoted 6 lines
drivers/clk/clk-eyeq.c new file +6
-0+ +static void __init eqc_init (struct device_node *np) +{ +const struct eqc_early_match_data *early_data; +const struct of_device_id *early_match_data; +unsigned int nb_clks =0 ;
Drop useless assignment please.
drivers/clk/clk-eyeq.c line 680
Quoted 6 lines
drivers/clk/clk-eyeq.c new file +6
-0+struct eqc_priv *priv; +void __iomem *base; +unsigned int i; +int ret; + + early_match_data =of_match_node (eqc_early_match_table, np);
We've already matched before calling this function. I'd prefer a wrapper
static void __init eqc_init(struct device_node *np, const struct eqc_early_match_data *early_data)
{
}
static void __init eqc_eyeq5_early_init(struct device_node *np)
{
eqc_init(np, &eqc_eyeq5_early_match_data);
}then we don't need a match table, and skip the string comparison again.
drivers/clk/clk-eyeq.c line 687
Quoted 7 lines
drivers/clk/clk-eyeq.c new file +7
-0+if (!early_match_data) +return ; + + early_data = early_match_data->data; +/* No reason to early init this clock provider. Delay until probe. */ +if (!early_data || early_data->early_pll_count ==0 ) +return ;
I suspect this code can be removed too because it's purely defensive.
Quoted 61 lines
drivers/clk/clk-eyeq.c new file +61
-0+ + priv =kzalloc (sizeof (*priv),GFP_KERNEL ); +if (!priv) { + ret = -ENOMEM ; + goto err; + } + + priv->np = np; + priv->early_data = early_data; + + nb_clks = early_data->early_pll_count + early_data->nb_late_clks; + priv->cells =kzalloc (struct_size (priv->cells, hws, nb_clks),GFP_KERNEL ); +if (!priv->cells) { + ret = -ENOMEM ; + goto err; + } + + priv->cells->num = nb_clks; + +/* +* Mark all clocks as deferred; some are registered here, the rest at +* platform device probe. +*/ +for (i =0 ; i < nb_clks; i++) + priv->cells->hws[i] =ERR_PTR (-EPROBE_DEFER ); + +/* Offsets (reg64) of early PLLs are relative to OLB block. */ + base =of_iomap (np,0 ); +if (!base) { + ret = -ENODEV ; + goto err; + } + +for (i =0 ; i < early_data->early_pll_count; i++) { +const struct eqc_pll *pll = &early_data->early_plls[i]; +unsigned long mult, div, acc; +struct clk_hw *hw; +u32 r0, r1; +u64 val; + + val =readq (base + pll->reg64); + r0 = val; + r1 = val >>32 ; + + ret =eqc_pll_parse_registers (r0, r1, &mult, &div, &acc); +if (ret) { +pr_err ("failed parsing state of %s\n" , pll->name); + goto err; + } + + hw =clk_hw_register_fixed_factor_with_accuracy_fwname (NULL , + np, pll->name,"ref" ,0 , mult, div, acc); + priv->cells->hws[pll->index] = hw; +if (IS_ERR (hw)) { +pr_err ("failed registering %s: %pe\n" , pll->name, hw); + ret =PTR_ERR (hw); + goto err; + } + } + +/* When providing a single clock, require no cell. */
drivers/clk/clk-eyeq.c line 758
Quoted 10 lines
drivers/clk/clk-eyeq.c new file +10
-0+if (nb_clks ==1 ) + ret =of_clk_add_hw_provider (np, of_clk_hw_simple_get, priv->cells->hws[0 ]); +else + ret =of_clk_add_hw_provider (np, of_clk_hw_onecell_get, priv->cells); +if (ret) { +pr_err ("failed registering clk provider: %d\n" , ret); + goto err; + } + +spin_lock (&eqc_list_slock);
I don't see how the spinlock provides any value. This function will run before any struct devices have been created.
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.
Quoted 4 lines
drivers/clk/clk-eyeq.c new file +4
-0+spin_unlock (&eqc_list_slock); + +return ; +
Théo Lebrun
maintainerRe: [PATCH RESEND v3 4/4] clk: eyeq: add driver
Hello Stephen,
Only answering to questions to which I have answers. The rest is addressed for next revision.
Quoted 9 lines · Stephen Boyd
Quoting Théo Lebrun (2024-07-30 09:04:46)
Quoted 8 lines
drivers/clk/Kconfig +0
-0@@ -218,6 +218,19 @@ config COMMON_CLK_EN7523 This driver provides the fixed clocks and gates present on Airoha ARM silicon.
Quoted 7 lines
drivers/clk/Kconfig config COMMON_CLK_EN7523 · line 224
Quoted 4 lines
drivers/clk/Kconfig +4
-0+config COMMON_CLK_EYEQ + bool "Clock driver for the Mobileye EyeQ platform" + depends on 64BIT # for readq() + depends on OF || COMPILE_TESTWhat's the OF build dependency? If there isn't one please remove this line.
There is none (at least we have a compat layer that means we can build even with CONFIG_OF=n). Removed in next revision.
Quoted 10 lines
Quoted 10 lines
drivers/clk/Kconfig +9
-0+ *mult = *mult * 0x100000 + FIELD_GET(PCSR1_FRAC_IN, r1); + } + + if (!*mult || !*div) + return -EINVAL; + + /* Spread spectrum. */ + if (!(r1 & (PCSR1_RESET | PCSR1_DIS_SSCG))) { + /*
Quoted 8 lines
drivers/clk/Kconfig config COMMON_CLK_EN7523
Quoted 6 lines
drivers/clk/Kconfig +6
-0+ * Spread is 1/1000 parts of frequency, accuracy is half of + * that. To get accuracy, convert to ppb (parts per billion). + */ + u32 spread = FIELD_GET(PCSR1_SPREAD, r1); + + *acc = spread * 500000;Where does 500000 come from? Half a billion?
In addition to the above comment, I added this to clarify:
* acc = spread * 1e6 / 2
* with acc in parts per billion and,
* spread in parts per thousand.
[...]
Quoted 11 lines
drivers/clk/Kconfig
Quoted 8 lines
drivers/clk/Kconfig +8
-0+ +static const struct eqc_early_match_data eqc_eyeq6h_central_early_match_data = { + .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. */Is this required for earlycon? Where is the UART not a device driver that needs to get clks early?
The UART is PL011. It is an AMBA device, those get probed before platform devices by of_platform_bus_create(). "pll-per" must be available at that time.
[...]
Quoted 1 line
Quoted 1 line
+static void
__initeqc_init(struct device_node *np)
[...]
Quoted 4 lines
Quoted 1 line
+
spin_lock(&eqc_list_slock);I don't see how the spinlock provides any value. This function will run before any struct devices have been created.
Indeed no clash can happen. Will remove.
Quoted 8 lines
Quoted 2 lines
+
list_add_tail(&priv->list, &eqc_list);The list is also kind of unnecessary. Set a bool in the
match_dataand move on? We could have some sort ofstatic_assert()check to make sure if there's aCLK_OF_DECLARE_DRIVER()then the bool is set in thematch_datafor 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.
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
Théo Lebrun
maintainerHello all,
Quoted 4 lines · Théo Lebrun
This is a new iteration on the clock part of the Mobileye system-controller series. It used to be sent as a single series [0], but has been split in the previous revisions (see [1], [2], [3], [4]) to faciliate merging.
This is a friendly RESEND of the Mobileye system-controller series, now that v6.11-rc1 is out. It applies just fine, and has been tested on real hardware.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Théo Lebrun
maintainerHi Stephen,
Quoted 4 lines · Théo Lebrun
This is a new iteration on the clock part of the Mobileye system-controller series. It used to be sent as a single series [0], but has been split in the previous revisions (see [1], [2], [3], [4]) to faciliate merging.
What's your state of mind on this series? I am happy at how it turned out and believe the whole system-controller for the platform is modeled properly now. It works as expected on real hardware. Pinctrl got in.
Thanks,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com