Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: stm32mp1: Add parent_data to ETHRX clock

Pass parent_data to ETHRX clock with new fw_name = "ETH_RX_CLK/ETH_REF_CLK".
By default, this change has no impact on the operation of the clock driver.
However, due to the fw_name, it permits DT to override ETHRX clock parent,
which might be needed in case the ETHRX clock are supplied by external clock
source.

Example of MCO2 supplying clock to ETH_RX_CLK via external pad-to-pad wire:
&rcc {
clocks = <&rcc CK_MCO2>;
clock-names = "ETH_RX_CLK/ETH_REF_CLK";
};

Note that while this patch permits to implement this rare usecase, the issue
with ethernet RX and TX input clock modeling on MP1 is far more complex and
requires more core plumbing.

[1] STM32MP1 Reference Manual RM0436 Rev 3, Page 574,
Figure 83. Peripheral clock distribution for Ethernet
https://www.st.com/resource/en/reference_manual/dm00327659-stm32mp157-advanced-armbased-32bit-mpus-stmicroelectronics.pdf

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Christophe Roullier <christophe.roullier@foss.st.com>
Cc: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
Cc: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Cc: linux-clk@vger.kernel.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Link: https://lore.kernel.org/r/20220118202958.1840431-2-marex@denx.de
Tested-by: Johann Neuhauser <jneuhauser@dh-electronics.com>
Acked-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Marek Vasut and committed by
Stephen Boyd
e9ed1ef1 e33b88b6

+32 -4
+32 -4
drivers/clk/clk-stm32mp1.c
··· 155 155 "pll4_p", "pll3_q" 156 156 }; 157 157 158 + const struct clk_parent_data ethrx_src[] = { 159 + { .name = "ethck_k", .fw_name = "ETH_RX_CLK/ETH_REF_CLK" }, 160 + }; 161 + 158 162 static const char * const rng_src[] = { 159 163 "ck_csi", "pll4_r", "ck_lse", "ck_lsi" 160 164 }; ··· 321 317 const char *name; 322 318 const char *parent_name; 323 319 const char * const *parent_names; 320 + const struct clk_parent_data *parent_data; 324 321 int num_parents; 325 322 unsigned long flags; 326 323 void *cfg; ··· 581 576 clk_stm32_register_gate_ops(struct device *dev, 582 577 const char *name, 583 578 const char *parent_name, 579 + const struct clk_parent_data *parent_data, 584 580 unsigned long flags, 585 581 void __iomem *base, 586 582 const struct stm32_gate_cfg *cfg, ··· 592 586 int ret; 593 587 594 588 init.name = name; 595 - init.parent_names = &parent_name; 589 + if (parent_name) 590 + init.parent_names = &parent_name; 591 + if (parent_data) 592 + init.parent_data = parent_data; 596 593 init.num_parents = 1; 597 594 init.flags = flags; 598 595 ··· 620 611 static struct clk_hw * 621 612 clk_stm32_register_composite(struct device *dev, 622 613 const char *name, const char * const *parent_names, 614 + const struct clk_parent_data *parent_data, 623 615 int num_parents, void __iomem *base, 624 616 const struct stm32_composite_cfg *cfg, 625 617 unsigned long flags, spinlock_t *lock) ··· 1145 1135 return clk_stm32_register_gate_ops(dev, 1146 1136 cfg->name, 1147 1137 cfg->parent_name, 1138 + cfg->parent_data, 1148 1139 cfg->flags, 1149 1140 base, 1150 1141 cfg->cfg, ··· 1159 1148 const struct clock_config *cfg) 1160 1149 { 1161 1150 return clk_stm32_register_composite(dev, cfg->name, cfg->parent_names, 1162 - cfg->num_parents, base, cfg->cfg, 1163 - cfg->flags, lock); 1151 + cfg->parent_data, cfg->num_parents, 1152 + base, cfg->cfg, cfg->flags, lock); 1164 1153 } 1165 1154 1166 1155 #define GATE(_id, _name, _parent, _flags, _offset, _bit_idx, _gate_flags)\ ··· 1269 1258 .func = _clk_stm32_register_gate,\ 1270 1259 } 1271 1260 1261 + #define STM32_GATE_PDATA(_id, _name, _parent, _flags, _gate)\ 1262 + {\ 1263 + .id = _id,\ 1264 + .name = _name,\ 1265 + .parent_data = _parent,\ 1266 + .flags = _flags,\ 1267 + .cfg = (struct stm32_gate_cfg *) {_gate},\ 1268 + .func = _clk_stm32_register_gate,\ 1269 + } 1270 + 1272 1271 #define _STM32_GATE(_gate_offset, _gate_bit_idx, _gate_flags, _mgate, _ops)\ 1273 1272 (&(struct stm32_gate_cfg) {\ 1274 1273 &(struct gate_cfg) {\ ··· 1310 1289 1311 1290 #define MGATE_MP1(_id, _name, _parent, _flags, _mgate)\ 1312 1291 STM32_GATE(_id, _name, _parent, _flags,\ 1292 + _STM32_MGATE(_mgate)) 1293 + 1294 + #define MGATE_MP1_PDATA(_id, _name, _parent, _flags, _mgate)\ 1295 + STM32_GATE_PDATA(_id, _name, _parent, _flags,\ 1313 1296 _STM32_MGATE(_mgate)) 1314 1297 1315 1298 #define _STM32_DIV(_div_offset, _div_shift, _div_width,\ ··· 1378 1353 1379 1354 #define PCLK(_id, _name, _parent, _flags, _mgate)\ 1380 1355 MGATE_MP1(_id, _name, _parent, _flags, _mgate) 1356 + 1357 + #define PCLK_PDATA(_id, _name, _parent, _flags, _mgate)\ 1358 + MGATE_MP1_PDATA(_id, _name, _parent, _flags, _mgate) 1381 1359 1382 1360 #define KCLK(_id, _name, _parents, _flags, _mgate, _mmux)\ 1383 1361 COMPOSITE(_id, _name, _parents, CLK_OPS_PARENT_ENABLE |\ ··· 1979 1951 PCLK(MDMA, "mdma", "ck_axi", 0, G_MDMA), 1980 1952 PCLK(GPU, "gpu", "ck_axi", 0, G_GPU), 1981 1953 PCLK(ETHTX, "ethtx", "ck_axi", 0, G_ETHTX), 1982 - PCLK(ETHRX, "ethrx", "ck_axi", 0, G_ETHRX), 1954 + PCLK_PDATA(ETHRX, "ethrx", ethrx_src, 0, G_ETHRX), 1983 1955 PCLK(ETHMAC, "ethmac", "ck_axi", 0, G_ETHMAC), 1984 1956 PCLK(FMC, "fmc", "ck_axi", CLK_IGNORE_UNUSED, G_FMC), 1985 1957 PCLK(QSPI, "qspi", "ck_axi", CLK_IGNORE_UNUSED, G_QSPI),