1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2016 Chen-Yu Tsai. All rights reserved.
7 #include <linux/clk-provider.h>
8 #include <linux/of_address.h>
9 #include <linux/platform_device.h>
11 #include "ccu_common.h"
13 #include "ccu_reset.h"
15 #include "ccu-sun9i-a80-usb.h"
17 static SUNXI_CCU_GATE(bus_hci0_clk, "bus-hci0", "bus-usb", 0x0, BIT(1), 0);
18 static SUNXI_CCU_GATE(usb_ohci0_clk, "usb-ohci0", "osc24M", 0x0, BIT(2), 0);
19 static SUNXI_CCU_GATE(bus_hci1_clk, "bus-hci1", "bus-usb", 0x0, BIT(3), 0);
20 static SUNXI_CCU_GATE(bus_hci2_clk, "bus-hci2", "bus-usb", 0x0, BIT(5), 0);
21 static SUNXI_CCU_GATE(usb_ohci2_clk, "usb-ohci2", "osc24M", 0x0, BIT(6), 0);
23 static SUNXI_CCU_GATE(usb0_phy_clk, "usb0-phy", "osc24M", 0x4, BIT(1), 0);
24 static SUNXI_CCU_GATE(usb1_hsic_clk, "usb1-hsic", "osc24M", 0x4, BIT(2), 0);
25 static SUNXI_CCU_GATE(usb1_phy_clk, "usb1-phy", "osc24M", 0x4, BIT(3), 0);
26 static SUNXI_CCU_GATE(usb2_hsic_clk, "usb2-hsic", "osc24M", 0x4, BIT(4), 0);
27 static SUNXI_CCU_GATE(usb2_phy_clk, "usb2-phy", "osc24M", 0x4, BIT(5), 0);
28 static SUNXI_CCU_GATE(usb_hsic_clk, "usb-hsic", "osc24M", 0x4, BIT(10), 0);
30 static struct ccu_common *sun9i_a80_usb_clks[] = {
32 &usb_ohci0_clk.common,
35 &usb_ohci2_clk.common,
38 &usb1_hsic_clk.common,
40 &usb2_hsic_clk.common,
45 static struct clk_hw_onecell_data sun9i_a80_usb_hw_clks = {
47 [CLK_BUS_HCI0] = &bus_hci0_clk.common.hw,
48 [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw,
49 [CLK_BUS_HCI1] = &bus_hci1_clk.common.hw,
50 [CLK_BUS_HCI2] = &bus_hci2_clk.common.hw,
51 [CLK_USB_OHCI2] = &usb_ohci2_clk.common.hw,
53 [CLK_USB0_PHY] = &usb0_phy_clk.common.hw,
54 [CLK_USB1_HSIC] = &usb1_hsic_clk.common.hw,
55 [CLK_USB1_PHY] = &usb1_phy_clk.common.hw,
56 [CLK_USB2_HSIC] = &usb2_hsic_clk.common.hw,
57 [CLK_USB2_PHY] = &usb2_phy_clk.common.hw,
58 [CLK_USB_HSIC] = &usb_hsic_clk.common.hw,
63 static struct ccu_reset_map sun9i_a80_usb_resets[] = {
64 [RST_USB0_HCI] = { 0x0, BIT(17) },
65 [RST_USB1_HCI] = { 0x0, BIT(18) },
66 [RST_USB2_HCI] = { 0x0, BIT(19) },
68 [RST_USB0_PHY] = { 0x4, BIT(17) },
69 [RST_USB1_HSIC] = { 0x4, BIT(18) },
70 [RST_USB1_PHY] = { 0x4, BIT(19) },
71 [RST_USB2_HSIC] = { 0x4, BIT(20) },
72 [RST_USB2_PHY] = { 0x4, BIT(21) },
75 static const struct sunxi_ccu_desc sun9i_a80_usb_clk_desc = {
76 .ccu_clks = sun9i_a80_usb_clks,
77 .num_ccu_clks = ARRAY_SIZE(sun9i_a80_usb_clks),
79 .hw_clks = &sun9i_a80_usb_hw_clks,
81 .resets = sun9i_a80_usb_resets,
82 .num_resets = ARRAY_SIZE(sun9i_a80_usb_resets),
85 static int sun9i_a80_usb_clk_probe(struct platform_device *pdev)
92 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
93 reg = devm_ioremap_resource(&pdev->dev, res);
97 bus_clk = devm_clk_get(&pdev->dev, "bus");
98 if (IS_ERR(bus_clk)) {
99 ret = PTR_ERR(bus_clk);
100 if (ret != -EPROBE_DEFER)
101 dev_err(&pdev->dev, "Couldn't get bus clk: %d\n", ret);
105 /* The bus clock needs to be enabled for us to access the registers */
106 ret = clk_prepare_enable(bus_clk);
108 dev_err(&pdev->dev, "Couldn't enable bus clk: %d\n", ret);
112 ret = sunxi_ccu_probe(pdev->dev.of_node, reg,
113 &sun9i_a80_usb_clk_desc);
115 goto err_disable_clk;
120 clk_disable_unprepare(bus_clk);
124 static const struct of_device_id sun9i_a80_usb_clk_ids[] = {
125 { .compatible = "allwinner,sun9i-a80-usb-clks" },
129 static struct platform_driver sun9i_a80_usb_clk_driver = {
130 .probe = sun9i_a80_usb_clk_probe,
132 .name = "sun9i-a80-usb-clks",
133 .of_match_table = sun9i_a80_usb_clk_ids,
136 builtin_platform_driver(sun9i_a80_usb_clk_driver);