1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/clk-provider.h>
4 #include <linux/init.h>
6 #include <linux/platform_device.h>
8 #include <dt-bindings/clock/bcm3368-clock.h>
9 #include <dt-bindings/clock/bcm6318-clock.h>
10 #include <dt-bindings/clock/bcm6328-clock.h>
11 #include <dt-bindings/clock/bcm6358-clock.h>
12 #include <dt-bindings/clock/bcm6362-clock.h>
13 #include <dt-bindings/clock/bcm6368-clock.h>
14 #include <dt-bindings/clock/bcm63268-clock.h>
16 struct clk_bcm63xx_table_entry {
17 const char * const name;
22 struct clk_bcm63xx_hw {
26 struct clk_hw_onecell_data data;
29 static const struct clk_bcm63xx_table_entry bcm3368_clocks[] = {
32 .bit = BCM3368_CLK_MAC,
35 .bit = BCM3368_CLK_TC,
38 .bit = BCM3368_CLK_US_TOP,
41 .bit = BCM3368_CLK_DS_TOP,
44 .bit = BCM3368_CLK_ACM,
47 .bit = BCM3368_CLK_SPI,
50 .bit = BCM3368_CLK_USBS,
53 .bit = BCM3368_CLK_BMU,
56 .bit = BCM3368_CLK_PCM,
59 .bit = BCM3368_CLK_NTP,
62 .bit = BCM3368_CLK_ACP_B,
65 .bit = BCM3368_CLK_ACP_A,
68 .bit = BCM3368_CLK_EMUSB,
71 .bit = BCM3368_CLK_ENET0,
74 .bit = BCM3368_CLK_ENET1,
77 .bit = BCM3368_CLK_USBSU,
80 .bit = BCM3368_CLK_EPHY,
86 static const struct clk_bcm63xx_table_entry bcm6318_clocks[] = {
89 .bit = BCM6318_CLK_ADSL_ASB,
92 .bit = BCM6318_CLK_USB_ASB,
95 .bit = BCM6318_CLK_MIPS_ASB,
98 .bit = BCM6318_CLK_PCIE_ASB,
100 .name = "phymips_asb",
101 .bit = BCM6318_CLK_PHYMIPS_ASB,
103 .name = "robosw_asb",
104 .bit = BCM6318_CLK_ROBOSW_ASB,
107 .bit = BCM6318_CLK_SAR_ASB,
110 .bit = BCM6318_CLK_SDR_ASB,
113 .bit = BCM6318_CLK_SWREG_ASB,
115 .name = "periph_asb",
116 .bit = BCM6318_CLK_PERIPH_ASB,
119 .bit = BCM6318_CLK_CPUBUS160,
122 .bit = BCM6318_CLK_ADSL,
125 .bit = BCM6318_CLK_SAR125,
128 .bit = BCM6318_CLK_MIPS,
129 .flags = CLK_IS_CRITICAL,
132 .bit = BCM6318_CLK_PCIE,
135 .bit = BCM6318_CLK_ROBOSW250,
138 .bit = BCM6318_CLK_ROBOSW025,
141 .bit = BCM6318_CLK_SDR,
142 .flags = CLK_IS_CRITICAL,
145 .bit = BCM6318_CLK_USBD,
148 .bit = BCM6318_CLK_HSSPI,
151 .bit = BCM6318_CLK_PCIE25,
154 .bit = BCM6318_CLK_PHYMIPS,
157 .bit = BCM6318_CLK_AFE,
160 .bit = BCM6318_CLK_QPROC,
166 static const struct clk_bcm63xx_table_entry bcm6318_ubus_clocks[] = {
169 .bit = BCM6318_UCLK_ADSL,
172 .bit = BCM6318_UCLK_ARB,
173 .flags = CLK_IS_CRITICAL,
176 .bit = BCM6318_UCLK_MIPS,
177 .flags = CLK_IS_CRITICAL,
180 .bit = BCM6318_UCLK_PCIE,
182 .name = "periph-ubus",
183 .bit = BCM6318_UCLK_PERIPH,
184 .flags = CLK_IS_CRITICAL,
186 .name = "phymips-ubus",
187 .bit = BCM6318_UCLK_PHYMIPS,
189 .name = "robosw-ubus",
190 .bit = BCM6318_UCLK_ROBOSW,
193 .bit = BCM6318_UCLK_SAR,
196 .bit = BCM6318_UCLK_SDR,
199 .bit = BCM6318_UCLK_USB,
205 static const struct clk_bcm63xx_table_entry bcm6328_clocks[] = {
208 .bit = BCM6328_CLK_PHYMIPS,
210 .name = "adsl_qproc",
211 .bit = BCM6328_CLK_ADSL_QPROC,
214 .bit = BCM6328_CLK_ADSL_AFE,
217 .bit = BCM6328_CLK_ADSL,
220 .bit = BCM6328_CLK_MIPS,
221 .flags = CLK_IS_CRITICAL,
224 .bit = BCM6328_CLK_SAR,
227 .bit = BCM6328_CLK_PCM,
230 .bit = BCM6328_CLK_USBD,
233 .bit = BCM6328_CLK_USBH,
236 .bit = BCM6328_CLK_HSSPI,
239 .bit = BCM6328_CLK_PCIE,
242 .bit = BCM6328_CLK_ROBOSW,
248 static const struct clk_bcm63xx_table_entry bcm6358_clocks[] = {
251 .bit = BCM6358_CLK_ENET,
254 .bit = BCM6358_CLK_ADSLPHY,
257 .bit = BCM6358_CLK_PCM,
260 .bit = BCM6358_CLK_SPI,
263 .bit = BCM6358_CLK_USBS,
266 .bit = BCM6358_CLK_SAR,
269 .bit = BCM6358_CLK_EMUSB,
272 .bit = BCM6358_CLK_ENET0,
275 .bit = BCM6358_CLK_ENET1,
278 .bit = BCM6358_CLK_USBSU,
281 .bit = BCM6358_CLK_EPHY,
287 static const struct clk_bcm63xx_table_entry bcm6362_clocks[] = {
289 .name = "adsl_qproc",
290 .bit = BCM6362_CLK_ADSL_QPROC,
293 .bit = BCM6362_CLK_ADSL_AFE,
296 .bit = BCM6362_CLK_ADSL,
299 .bit = BCM6362_CLK_MIPS,
300 .flags = CLK_IS_CRITICAL,
303 .bit = BCM6362_CLK_WLAN_OCP,
306 .bit = BCM6362_CLK_SWPKT_USB,
309 .bit = BCM6362_CLK_SWPKT_SAR,
312 .bit = BCM6362_CLK_SAR,
315 .bit = BCM6362_CLK_ROBOSW,
318 .bit = BCM6362_CLK_PCM,
321 .bit = BCM6362_CLK_USBD,
324 .bit = BCM6362_CLK_USBH,
327 .bit = BCM6362_CLK_IPSEC,
330 .bit = BCM6362_CLK_SPI,
333 .bit = BCM6362_CLK_HSSPI,
336 .bit = BCM6362_CLK_PCIE,
339 .bit = BCM6362_CLK_FAP,
342 .bit = BCM6362_CLK_PHYMIPS,
345 .bit = BCM6362_CLK_NAND,
351 static const struct clk_bcm63xx_table_entry bcm6368_clocks[] = {
353 .name = "vdsl_qproc",
354 .bit = BCM6368_CLK_VDSL_QPROC,
357 .bit = BCM6368_CLK_VDSL_AFE,
359 .name = "vdsl_bonding",
360 .bit = BCM6368_CLK_VDSL_BONDING,
363 .bit = BCM6368_CLK_VDSL,
366 .bit = BCM6368_CLK_PHYMIPS,
369 .bit = BCM6368_CLK_SWPKT_USB,
372 .bit = BCM6368_CLK_SWPKT_SAR,
375 .bit = BCM6368_CLK_SPI,
378 .bit = BCM6368_CLK_USBD,
381 .bit = BCM6368_CLK_SAR,
384 .bit = BCM6368_CLK_ROBOSW,
387 .bit = BCM6368_CLK_UTOPIA,
390 .bit = BCM6368_CLK_PCM,
393 .bit = BCM6368_CLK_USBH,
395 .name = "disable_gless",
396 .bit = BCM6368_CLK_DIS_GLESS,
399 .bit = BCM6368_CLK_NAND,
402 .bit = BCM6368_CLK_IPSEC,
408 static const struct clk_bcm63xx_table_entry bcm63268_clocks[] = {
410 .name = "disable_gless",
411 .bit = BCM63268_CLK_DIS_GLESS,
413 .name = "vdsl_qproc",
414 .bit = BCM63268_CLK_VDSL_QPROC,
417 .bit = BCM63268_CLK_VDSL_AFE,
420 .bit = BCM63268_CLK_VDSL,
423 .bit = BCM63268_CLK_MIPS,
424 .flags = CLK_IS_CRITICAL,
427 .bit = BCM63268_CLK_WLAN_OCP,
430 .bit = BCM63268_CLK_DECT,
433 .bit = BCM63268_CLK_FAP0,
436 .bit = BCM63268_CLK_FAP1,
439 .bit = BCM63268_CLK_SAR,
442 .bit = BCM63268_CLK_ROBOSW,
445 .bit = BCM63268_CLK_PCM,
448 .bit = BCM63268_CLK_USBD,
451 .bit = BCM63268_CLK_USBH,
454 .bit = BCM63268_CLK_IPSEC,
457 .bit = BCM63268_CLK_SPI,
460 .bit = BCM63268_CLK_HSSPI,
463 .bit = BCM63268_CLK_PCIE,
466 .bit = BCM63268_CLK_PHYMIPS,
469 .bit = BCM63268_CLK_GMAC,
472 .bit = BCM63268_CLK_NAND,
475 .bit = BCM63268_CLK_TBUS,
478 .bit = BCM63268_CLK_ROBOSW250,
484 static int clk_bcm63xx_probe(struct platform_device *pdev)
486 const struct clk_bcm63xx_table_entry *entry, *table;
487 struct clk_bcm63xx_hw *hw;
491 table = of_device_get_match_data(&pdev->dev);
495 for (entry = table; entry->name; entry++)
496 maxbit = max_t(u8, maxbit, entry->bit);
499 hw = devm_kzalloc(&pdev->dev, struct_size(hw, data.hws, maxbit),
504 platform_set_drvdata(pdev, hw);
506 spin_lock_init(&hw->lock);
508 hw->data.num = maxbit;
509 for (i = 0; i < maxbit; i++)
510 hw->data.hws[i] = ERR_PTR(-ENODEV);
512 hw->regs = devm_platform_ioremap_resource(pdev, 0);
513 if (IS_ERR(hw->regs))
514 return PTR_ERR(hw->regs);
516 for (entry = table; entry->name; entry++) {
519 clk = clk_hw_register_gate(&pdev->dev, entry->name, NULL,
520 entry->flags, hw->regs, entry->bit,
521 CLK_GATE_BIG_ENDIAN, &hw->lock);
527 hw->data.hws[entry->bit] = clk;
530 ret = of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get,
535 for (i = 0; i < hw->data.num; i++) {
536 if (!IS_ERR(hw->data.hws[i]))
537 clk_hw_unregister_gate(hw->data.hws[i]);
543 static void clk_bcm63xx_remove(struct platform_device *pdev)
545 struct clk_bcm63xx_hw *hw = platform_get_drvdata(pdev);
548 of_clk_del_provider(pdev->dev.of_node);
550 for (i = 0; i < hw->data.num; i++) {
551 if (!IS_ERR(hw->data.hws[i]))
552 clk_hw_unregister_gate(hw->data.hws[i]);
556 static const struct of_device_id clk_bcm63xx_dt_ids[] = {
557 { .compatible = "brcm,bcm3368-clocks", .data = &bcm3368_clocks, },
558 { .compatible = "brcm,bcm6318-clocks", .data = &bcm6318_clocks, },
559 { .compatible = "brcm,bcm6318-ubus-clocks", .data = &bcm6318_ubus_clocks, },
560 { .compatible = "brcm,bcm6328-clocks", .data = &bcm6328_clocks, },
561 { .compatible = "brcm,bcm6358-clocks", .data = &bcm6358_clocks, },
562 { .compatible = "brcm,bcm6362-clocks", .data = &bcm6362_clocks, },
563 { .compatible = "brcm,bcm6368-clocks", .data = &bcm6368_clocks, },
564 { .compatible = "brcm,bcm63268-clocks", .data = &bcm63268_clocks, },
568 static struct platform_driver clk_bcm63xx = {
569 .probe = clk_bcm63xx_probe,
570 .remove_new = clk_bcm63xx_remove,
572 .name = "bcm63xx-clock",
573 .of_match_table = clk_bcm63xx_dt_ids,
576 builtin_platform_driver(clk_bcm63xx);