123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579 |
- // SPDX-License-Identifier: GPL-2.0
- #include <linux/clk-provider.h>
- #include <linux/init.h>
- #include <linux/of.h>
- #include <linux/of_device.h>
- #include <linux/platform_device.h>
- #include <dt-bindings/clock/bcm3368-clock.h>
- #include <dt-bindings/clock/bcm6318-clock.h>
- #include <dt-bindings/clock/bcm6328-clock.h>
- #include <dt-bindings/clock/bcm6358-clock.h>
- #include <dt-bindings/clock/bcm6362-clock.h>
- #include <dt-bindings/clock/bcm6368-clock.h>
- #include <dt-bindings/clock/bcm63268-clock.h>
- struct clk_bcm63xx_table_entry {
- const char * const name;
- u8 bit;
- unsigned long flags;
- };
- struct clk_bcm63xx_hw {
- void __iomem *regs;
- spinlock_t lock;
- struct clk_hw_onecell_data data;
- };
- static const struct clk_bcm63xx_table_entry bcm3368_clocks[] = {
- {
- .name = "mac",
- .bit = BCM3368_CLK_MAC,
- }, {
- .name = "tc",
- .bit = BCM3368_CLK_TC,
- }, {
- .name = "us_top",
- .bit = BCM3368_CLK_US_TOP,
- }, {
- .name = "ds_top",
- .bit = BCM3368_CLK_DS_TOP,
- }, {
- .name = "acm",
- .bit = BCM3368_CLK_ACM,
- }, {
- .name = "spi",
- .bit = BCM3368_CLK_SPI,
- }, {
- .name = "usbs",
- .bit = BCM3368_CLK_USBS,
- }, {
- .name = "bmu",
- .bit = BCM3368_CLK_BMU,
- }, {
- .name = "pcm",
- .bit = BCM3368_CLK_PCM,
- }, {
- .name = "ntp",
- .bit = BCM3368_CLK_NTP,
- }, {
- .name = "acp_b",
- .bit = BCM3368_CLK_ACP_B,
- }, {
- .name = "acp_a",
- .bit = BCM3368_CLK_ACP_A,
- }, {
- .name = "emusb",
- .bit = BCM3368_CLK_EMUSB,
- }, {
- .name = "enet0",
- .bit = BCM3368_CLK_ENET0,
- }, {
- .name = "enet1",
- .bit = BCM3368_CLK_ENET1,
- }, {
- .name = "usbsu",
- .bit = BCM3368_CLK_USBSU,
- }, {
- .name = "ephy",
- .bit = BCM3368_CLK_EPHY,
- }, {
- /* sentinel */
- },
- };
- static const struct clk_bcm63xx_table_entry bcm6318_clocks[] = {
- {
- .name = "adsl_asb",
- .bit = BCM6318_CLK_ADSL_ASB,
- }, {
- .name = "usb_asb",
- .bit = BCM6318_CLK_USB_ASB,
- }, {
- .name = "mips_asb",
- .bit = BCM6318_CLK_MIPS_ASB,
- }, {
- .name = "pcie_asb",
- .bit = BCM6318_CLK_PCIE_ASB,
- }, {
- .name = "phymips_asb",
- .bit = BCM6318_CLK_PHYMIPS_ASB,
- }, {
- .name = "robosw_asb",
- .bit = BCM6318_CLK_ROBOSW_ASB,
- }, {
- .name = "sar_asb",
- .bit = BCM6318_CLK_SAR_ASB,
- }, {
- .name = "sdr_asb",
- .bit = BCM6318_CLK_SDR_ASB,
- }, {
- .name = "swreg_asb",
- .bit = BCM6318_CLK_SWREG_ASB,
- }, {
- .name = "periph_asb",
- .bit = BCM6318_CLK_PERIPH_ASB,
- }, {
- .name = "cpubus160",
- .bit = BCM6318_CLK_CPUBUS160,
- }, {
- .name = "adsl",
- .bit = BCM6318_CLK_ADSL,
- }, {
- .name = "sar125",
- .bit = BCM6318_CLK_SAR125,
- }, {
- .name = "mips",
- .bit = BCM6318_CLK_MIPS,
- .flags = CLK_IS_CRITICAL,
- }, {
- .name = "pcie",
- .bit = BCM6318_CLK_PCIE,
- }, {
- .name = "robosw250",
- .bit = BCM6318_CLK_ROBOSW250,
- }, {
- .name = "robosw025",
- .bit = BCM6318_CLK_ROBOSW025,
- }, {
- .name = "sdr",
- .bit = BCM6318_CLK_SDR,
- .flags = CLK_IS_CRITICAL,
- }, {
- .name = "usbd",
- .bit = BCM6318_CLK_USBD,
- }, {
- .name = "hsspi",
- .bit = BCM6318_CLK_HSSPI,
- }, {
- .name = "pcie25",
- .bit = BCM6318_CLK_PCIE25,
- }, {
- .name = "phymips",
- .bit = BCM6318_CLK_PHYMIPS,
- }, {
- .name = "afe",
- .bit = BCM6318_CLK_AFE,
- }, {
- .name = "qproc",
- .bit = BCM6318_CLK_QPROC,
- }, {
- /* sentinel */
- },
- };
- static const struct clk_bcm63xx_table_entry bcm6318_ubus_clocks[] = {
- {
- .name = "adsl-ubus",
- .bit = BCM6318_UCLK_ADSL,
- }, {
- .name = "arb-ubus",
- .bit = BCM6318_UCLK_ARB,
- .flags = CLK_IS_CRITICAL,
- }, {
- .name = "mips-ubus",
- .bit = BCM6318_UCLK_MIPS,
- .flags = CLK_IS_CRITICAL,
- }, {
- .name = "pcie-ubus",
- .bit = BCM6318_UCLK_PCIE,
- }, {
- .name = "periph-ubus",
- .bit = BCM6318_UCLK_PERIPH,
- .flags = CLK_IS_CRITICAL,
- }, {
- .name = "phymips-ubus",
- .bit = BCM6318_UCLK_PHYMIPS,
- }, {
- .name = "robosw-ubus",
- .bit = BCM6318_UCLK_ROBOSW,
- }, {
- .name = "sar-ubus",
- .bit = BCM6318_UCLK_SAR,
- }, {
- .name = "sdr-ubus",
- .bit = BCM6318_UCLK_SDR,
- }, {
- .name = "usb-ubus",
- .bit = BCM6318_UCLK_USB,
- }, {
- /* sentinel */
- },
- };
- static const struct clk_bcm63xx_table_entry bcm6328_clocks[] = {
- {
- .name = "phy_mips",
- .bit = BCM6328_CLK_PHYMIPS,
- }, {
- .name = "adsl_qproc",
- .bit = BCM6328_CLK_ADSL_QPROC,
- }, {
- .name = "adsl_afe",
- .bit = BCM6328_CLK_ADSL_AFE,
- }, {
- .name = "adsl",
- .bit = BCM6328_CLK_ADSL,
- }, {
- .name = "mips",
- .bit = BCM6328_CLK_MIPS,
- .flags = CLK_IS_CRITICAL,
- }, {
- .name = "sar",
- .bit = BCM6328_CLK_SAR,
- }, {
- .name = "pcm",
- .bit = BCM6328_CLK_PCM,
- }, {
- .name = "usbd",
- .bit = BCM6328_CLK_USBD,
- }, {
- .name = "usbh",
- .bit = BCM6328_CLK_USBH,
- }, {
- .name = "hsspi",
- .bit = BCM6328_CLK_HSSPI,
- }, {
- .name = "pcie",
- .bit = BCM6328_CLK_PCIE,
- }, {
- .name = "robosw",
- .bit = BCM6328_CLK_ROBOSW,
- }, {
- /* sentinel */
- },
- };
- static const struct clk_bcm63xx_table_entry bcm6358_clocks[] = {
- {
- .name = "enet",
- .bit = BCM6358_CLK_ENET,
- }, {
- .name = "adslphy",
- .bit = BCM6358_CLK_ADSLPHY,
- }, {
- .name = "pcm",
- .bit = BCM6358_CLK_PCM,
- }, {
- .name = "spi",
- .bit = BCM6358_CLK_SPI,
- }, {
- .name = "usbs",
- .bit = BCM6358_CLK_USBS,
- }, {
- .name = "sar",
- .bit = BCM6358_CLK_SAR,
- }, {
- .name = "emusb",
- .bit = BCM6358_CLK_EMUSB,
- }, {
- .name = "enet0",
- .bit = BCM6358_CLK_ENET0,
- }, {
- .name = "enet1",
- .bit = BCM6358_CLK_ENET1,
- }, {
- .name = "usbsu",
- .bit = BCM6358_CLK_USBSU,
- }, {
- .name = "ephy",
- .bit = BCM6358_CLK_EPHY,
- }, {
- /* sentinel */
- },
- };
- static const struct clk_bcm63xx_table_entry bcm6362_clocks[] = {
- {
- .name = "adsl_qproc",
- .bit = BCM6362_CLK_ADSL_QPROC,
- }, {
- .name = "adsl_afe",
- .bit = BCM6362_CLK_ADSL_AFE,
- }, {
- .name = "adsl",
- .bit = BCM6362_CLK_ADSL,
- }, {
- .name = "mips",
- .bit = BCM6362_CLK_MIPS,
- .flags = CLK_IS_CRITICAL,
- }, {
- .name = "wlan_ocp",
- .bit = BCM6362_CLK_WLAN_OCP,
- }, {
- .name = "swpkt_usb",
- .bit = BCM6362_CLK_SWPKT_USB,
- }, {
- .name = "swpkt_sar",
- .bit = BCM6362_CLK_SWPKT_SAR,
- }, {
- .name = "sar",
- .bit = BCM6362_CLK_SAR,
- }, {
- .name = "robosw",
- .bit = BCM6362_CLK_ROBOSW,
- }, {
- .name = "pcm",
- .bit = BCM6362_CLK_PCM,
- }, {
- .name = "usbd",
- .bit = BCM6362_CLK_USBD,
- }, {
- .name = "usbh",
- .bit = BCM6362_CLK_USBH,
- }, {
- .name = "ipsec",
- .bit = BCM6362_CLK_IPSEC,
- }, {
- .name = "spi",
- .bit = BCM6362_CLK_SPI,
- }, {
- .name = "hsspi",
- .bit = BCM6362_CLK_HSSPI,
- }, {
- .name = "pcie",
- .bit = BCM6362_CLK_PCIE,
- }, {
- .name = "fap",
- .bit = BCM6362_CLK_FAP,
- }, {
- .name = "phymips",
- .bit = BCM6362_CLK_PHYMIPS,
- }, {
- .name = "nand",
- .bit = BCM6362_CLK_NAND,
- }, {
- /* sentinel */
- },
- };
- static const struct clk_bcm63xx_table_entry bcm6368_clocks[] = {
- {
- .name = "vdsl_qproc",
- .bit = BCM6368_CLK_VDSL_QPROC,
- }, {
- .name = "vdsl_afe",
- .bit = BCM6368_CLK_VDSL_AFE,
- }, {
- .name = "vdsl_bonding",
- .bit = BCM6368_CLK_VDSL_BONDING,
- }, {
- .name = "vdsl",
- .bit = BCM6368_CLK_VDSL,
- }, {
- .name = "phymips",
- .bit = BCM6368_CLK_PHYMIPS,
- }, {
- .name = "swpkt_usb",
- .bit = BCM6368_CLK_SWPKT_USB,
- }, {
- .name = "swpkt_sar",
- .bit = BCM6368_CLK_SWPKT_SAR,
- }, {
- .name = "spi",
- .bit = BCM6368_CLK_SPI,
- }, {
- .name = "usbd",
- .bit = BCM6368_CLK_USBD,
- }, {
- .name = "sar",
- .bit = BCM6368_CLK_SAR,
- }, {
- .name = "robosw",
- .bit = BCM6368_CLK_ROBOSW,
- }, {
- .name = "utopia",
- .bit = BCM6368_CLK_UTOPIA,
- }, {
- .name = "pcm",
- .bit = BCM6368_CLK_PCM,
- }, {
- .name = "usbh",
- .bit = BCM6368_CLK_USBH,
- }, {
- .name = "disable_gless",
- .bit = BCM6368_CLK_DIS_GLESS,
- }, {
- .name = "nand",
- .bit = BCM6368_CLK_NAND,
- }, {
- .name = "ipsec",
- .bit = BCM6368_CLK_IPSEC,
- }, {
- /* sentinel */
- },
- };
- static const struct clk_bcm63xx_table_entry bcm63268_clocks[] = {
- {
- .name = "disable_gless",
- .bit = BCM63268_CLK_DIS_GLESS,
- }, {
- .name = "vdsl_qproc",
- .bit = BCM63268_CLK_VDSL_QPROC,
- }, {
- .name = "vdsl_afe",
- .bit = BCM63268_CLK_VDSL_AFE,
- }, {
- .name = "vdsl",
- .bit = BCM63268_CLK_VDSL,
- }, {
- .name = "mips",
- .bit = BCM63268_CLK_MIPS,
- .flags = CLK_IS_CRITICAL,
- }, {
- .name = "wlan_ocp",
- .bit = BCM63268_CLK_WLAN_OCP,
- }, {
- .name = "dect",
- .bit = BCM63268_CLK_DECT,
- }, {
- .name = "fap0",
- .bit = BCM63268_CLK_FAP0,
- }, {
- .name = "fap1",
- .bit = BCM63268_CLK_FAP1,
- }, {
- .name = "sar",
- .bit = BCM63268_CLK_SAR,
- }, {
- .name = "robosw",
- .bit = BCM63268_CLK_ROBOSW,
- }, {
- .name = "pcm",
- .bit = BCM63268_CLK_PCM,
- }, {
- .name = "usbd",
- .bit = BCM63268_CLK_USBD,
- }, {
- .name = "usbh",
- .bit = BCM63268_CLK_USBH,
- }, {
- .name = "ipsec",
- .bit = BCM63268_CLK_IPSEC,
- }, {
- .name = "spi",
- .bit = BCM63268_CLK_SPI,
- }, {
- .name = "hsspi",
- .bit = BCM63268_CLK_HSSPI,
- }, {
- .name = "pcie",
- .bit = BCM63268_CLK_PCIE,
- }, {
- .name = "phymips",
- .bit = BCM63268_CLK_PHYMIPS,
- }, {
- .name = "gmac",
- .bit = BCM63268_CLK_GMAC,
- }, {
- .name = "nand",
- .bit = BCM63268_CLK_NAND,
- }, {
- .name = "tbus",
- .bit = BCM63268_CLK_TBUS,
- }, {
- .name = "robosw250",
- .bit = BCM63268_CLK_ROBOSW250,
- }, {
- /* sentinel */
- },
- };
- static int clk_bcm63xx_probe(struct platform_device *pdev)
- {
- const struct clk_bcm63xx_table_entry *entry, *table;
- struct clk_bcm63xx_hw *hw;
- u8 maxbit = 0;
- int i, ret;
- table = of_device_get_match_data(&pdev->dev);
- if (!table)
- return -EINVAL;
- for (entry = table; entry->name; entry++)
- maxbit = max_t(u8, maxbit, entry->bit);
- maxbit++;
- hw = devm_kzalloc(&pdev->dev, struct_size(hw, data.hws, maxbit),
- GFP_KERNEL);
- if (!hw)
- return -ENOMEM;
- platform_set_drvdata(pdev, hw);
- spin_lock_init(&hw->lock);
- hw->data.num = maxbit;
- for (i = 0; i < maxbit; i++)
- hw->data.hws[i] = ERR_PTR(-ENODEV);
- hw->regs = devm_platform_ioremap_resource(pdev, 0);
- if (IS_ERR(hw->regs))
- return PTR_ERR(hw->regs);
- for (entry = table; entry->name; entry++) {
- struct clk_hw *clk;
- clk = clk_hw_register_gate(&pdev->dev, entry->name, NULL,
- entry->flags, hw->regs, entry->bit,
- CLK_GATE_BIG_ENDIAN, &hw->lock);
- if (IS_ERR(clk)) {
- ret = PTR_ERR(clk);
- goto out_err;
- }
- hw->data.hws[entry->bit] = clk;
- }
- ret = of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get,
- &hw->data);
- if (!ret)
- return 0;
- out_err:
- for (i = 0; i < hw->data.num; i++) {
- if (!IS_ERR(hw->data.hws[i]))
- clk_hw_unregister_gate(hw->data.hws[i]);
- }
- return ret;
- }
- static int clk_bcm63xx_remove(struct platform_device *pdev)
- {
- struct clk_bcm63xx_hw *hw = platform_get_drvdata(pdev);
- int i;
- of_clk_del_provider(pdev->dev.of_node);
- for (i = 0; i < hw->data.num; i++) {
- if (!IS_ERR(hw->data.hws[i]))
- clk_hw_unregister_gate(hw->data.hws[i]);
- }
- return 0;
- }
- static const struct of_device_id clk_bcm63xx_dt_ids[] = {
- { .compatible = "brcm,bcm3368-clocks", .data = &bcm3368_clocks, },
- { .compatible = "brcm,bcm6318-clocks", .data = &bcm6318_clocks, },
- { .compatible = "brcm,bcm6318-ubus-clocks", .data = &bcm6318_ubus_clocks, },
- { .compatible = "brcm,bcm6328-clocks", .data = &bcm6328_clocks, },
- { .compatible = "brcm,bcm6358-clocks", .data = &bcm6358_clocks, },
- { .compatible = "brcm,bcm6362-clocks", .data = &bcm6362_clocks, },
- { .compatible = "brcm,bcm6368-clocks", .data = &bcm6368_clocks, },
- { .compatible = "brcm,bcm63268-clocks", .data = &bcm63268_clocks, },
- { }
- };
- static struct platform_driver clk_bcm63xx = {
- .probe = clk_bcm63xx_probe,
- .remove = clk_bcm63xx_remove,
- .driver = {
- .name = "bcm63xx-clock",
- .of_match_table = clk_bcm63xx_dt_ids,
- },
- };
- builtin_platform_driver(clk_bcm63xx);
|