162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2016 Chen-Yu Tsai. All rights reserved. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#include <linux/clk.h> 762306a36Sopenharmony_ci#include <linux/clk-provider.h> 862306a36Sopenharmony_ci#include <linux/module.h> 962306a36Sopenharmony_ci#include <linux/platform_device.h> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include "ccu_common.h" 1262306a36Sopenharmony_ci#include "ccu_gate.h" 1362306a36Sopenharmony_ci#include "ccu_reset.h" 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include "ccu-sun9i-a80-usb.h" 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_cistatic const struct clk_parent_data clk_parent_hosc[] = { 1862306a36Sopenharmony_ci { .fw_name = "hosc" }, 1962306a36Sopenharmony_ci}; 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_cistatic const struct clk_parent_data clk_parent_bus[] = { 2262306a36Sopenharmony_ci { .fw_name = "bus" }, 2362306a36Sopenharmony_ci}; 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(bus_hci0_clk, "bus-hci0", clk_parent_bus, 0x0, BIT(1), 0); 2662306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(usb_ohci0_clk, "usb-ohci0", clk_parent_hosc, 0x0, BIT(2), 0); 2762306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(bus_hci1_clk, "bus-hci1", clk_parent_bus, 0x0, BIT(3), 0); 2862306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(bus_hci2_clk, "bus-hci2", clk_parent_bus, 0x0, BIT(5), 0); 2962306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(usb_ohci2_clk, "usb-ohci2", clk_parent_hosc, 0x0, BIT(6), 0); 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(usb0_phy_clk, "usb0-phy", clk_parent_hosc, 0x4, BIT(1), 0); 3262306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(usb1_hsic_clk, "usb1-hsic", clk_parent_hosc, 0x4, BIT(2), 0); 3362306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(usb1_phy_clk, "usb1-phy", clk_parent_hosc, 0x4, BIT(3), 0); 3462306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(usb2_hsic_clk, "usb2-hsic", clk_parent_hosc, 0x4, BIT(4), 0); 3562306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(usb2_phy_clk, "usb2-phy", clk_parent_hosc, 0x4, BIT(5), 0); 3662306a36Sopenharmony_cistatic SUNXI_CCU_GATE_DATA(usb_hsic_clk, "usb-hsic", clk_parent_hosc, 0x4, BIT(10), 0); 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_cistatic struct ccu_common *sun9i_a80_usb_clks[] = { 3962306a36Sopenharmony_ci &bus_hci0_clk.common, 4062306a36Sopenharmony_ci &usb_ohci0_clk.common, 4162306a36Sopenharmony_ci &bus_hci1_clk.common, 4262306a36Sopenharmony_ci &bus_hci2_clk.common, 4362306a36Sopenharmony_ci &usb_ohci2_clk.common, 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci &usb0_phy_clk.common, 4662306a36Sopenharmony_ci &usb1_hsic_clk.common, 4762306a36Sopenharmony_ci &usb1_phy_clk.common, 4862306a36Sopenharmony_ci &usb2_hsic_clk.common, 4962306a36Sopenharmony_ci &usb2_phy_clk.common, 5062306a36Sopenharmony_ci &usb_hsic_clk.common, 5162306a36Sopenharmony_ci}; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_cistatic struct clk_hw_onecell_data sun9i_a80_usb_hw_clks = { 5462306a36Sopenharmony_ci .hws = { 5562306a36Sopenharmony_ci [CLK_BUS_HCI0] = &bus_hci0_clk.common.hw, 5662306a36Sopenharmony_ci [CLK_USB_OHCI0] = &usb_ohci0_clk.common.hw, 5762306a36Sopenharmony_ci [CLK_BUS_HCI1] = &bus_hci1_clk.common.hw, 5862306a36Sopenharmony_ci [CLK_BUS_HCI2] = &bus_hci2_clk.common.hw, 5962306a36Sopenharmony_ci [CLK_USB_OHCI2] = &usb_ohci2_clk.common.hw, 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci [CLK_USB0_PHY] = &usb0_phy_clk.common.hw, 6262306a36Sopenharmony_ci [CLK_USB1_HSIC] = &usb1_hsic_clk.common.hw, 6362306a36Sopenharmony_ci [CLK_USB1_PHY] = &usb1_phy_clk.common.hw, 6462306a36Sopenharmony_ci [CLK_USB2_HSIC] = &usb2_hsic_clk.common.hw, 6562306a36Sopenharmony_ci [CLK_USB2_PHY] = &usb2_phy_clk.common.hw, 6662306a36Sopenharmony_ci [CLK_USB_HSIC] = &usb_hsic_clk.common.hw, 6762306a36Sopenharmony_ci }, 6862306a36Sopenharmony_ci .num = CLK_NUMBER, 6962306a36Sopenharmony_ci}; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_cistatic struct ccu_reset_map sun9i_a80_usb_resets[] = { 7262306a36Sopenharmony_ci [RST_USB0_HCI] = { 0x0, BIT(17) }, 7362306a36Sopenharmony_ci [RST_USB1_HCI] = { 0x0, BIT(18) }, 7462306a36Sopenharmony_ci [RST_USB2_HCI] = { 0x0, BIT(19) }, 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci [RST_USB0_PHY] = { 0x4, BIT(17) }, 7762306a36Sopenharmony_ci [RST_USB1_HSIC] = { 0x4, BIT(18) }, 7862306a36Sopenharmony_ci [RST_USB1_PHY] = { 0x4, BIT(19) }, 7962306a36Sopenharmony_ci [RST_USB2_HSIC] = { 0x4, BIT(20) }, 8062306a36Sopenharmony_ci [RST_USB2_PHY] = { 0x4, BIT(21) }, 8162306a36Sopenharmony_ci}; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_cistatic const struct sunxi_ccu_desc sun9i_a80_usb_clk_desc = { 8462306a36Sopenharmony_ci .ccu_clks = sun9i_a80_usb_clks, 8562306a36Sopenharmony_ci .num_ccu_clks = ARRAY_SIZE(sun9i_a80_usb_clks), 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci .hw_clks = &sun9i_a80_usb_hw_clks, 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci .resets = sun9i_a80_usb_resets, 9062306a36Sopenharmony_ci .num_resets = ARRAY_SIZE(sun9i_a80_usb_resets), 9162306a36Sopenharmony_ci}; 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_cistatic int sun9i_a80_usb_clk_probe(struct platform_device *pdev) 9462306a36Sopenharmony_ci{ 9562306a36Sopenharmony_ci struct clk *bus_clk; 9662306a36Sopenharmony_ci void __iomem *reg; 9762306a36Sopenharmony_ci int ret; 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci reg = devm_platform_ioremap_resource(pdev, 0); 10062306a36Sopenharmony_ci if (IS_ERR(reg)) 10162306a36Sopenharmony_ci return PTR_ERR(reg); 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci bus_clk = devm_clk_get(&pdev->dev, "bus"); 10462306a36Sopenharmony_ci if (IS_ERR(bus_clk)) 10562306a36Sopenharmony_ci return dev_err_probe(&pdev->dev, PTR_ERR(bus_clk), 10662306a36Sopenharmony_ci "Couldn't get bus clk\n"); 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci /* The bus clock needs to be enabled for us to access the registers */ 10962306a36Sopenharmony_ci ret = clk_prepare_enable(bus_clk); 11062306a36Sopenharmony_ci if (ret) { 11162306a36Sopenharmony_ci dev_err(&pdev->dev, "Couldn't enable bus clk: %d\n", ret); 11262306a36Sopenharmony_ci return ret; 11362306a36Sopenharmony_ci } 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci ret = devm_sunxi_ccu_probe(&pdev->dev, reg, &sun9i_a80_usb_clk_desc); 11662306a36Sopenharmony_ci if (ret) 11762306a36Sopenharmony_ci goto err_disable_clk; 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci return 0; 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_cierr_disable_clk: 12262306a36Sopenharmony_ci clk_disable_unprepare(bus_clk); 12362306a36Sopenharmony_ci return ret; 12462306a36Sopenharmony_ci} 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_cistatic const struct of_device_id sun9i_a80_usb_clk_ids[] = { 12762306a36Sopenharmony_ci { .compatible = "allwinner,sun9i-a80-usb-clks" }, 12862306a36Sopenharmony_ci { } 12962306a36Sopenharmony_ci}; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_cistatic struct platform_driver sun9i_a80_usb_clk_driver = { 13262306a36Sopenharmony_ci .probe = sun9i_a80_usb_clk_probe, 13362306a36Sopenharmony_ci .driver = { 13462306a36Sopenharmony_ci .name = "sun9i-a80-usb-clks", 13562306a36Sopenharmony_ci .of_match_table = sun9i_a80_usb_clk_ids, 13662306a36Sopenharmony_ci }, 13762306a36Sopenharmony_ci}; 13862306a36Sopenharmony_cimodule_platform_driver(sun9i_a80_usb_clk_driver); 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ciMODULE_IMPORT_NS(SUNXI_CCU); 14162306a36Sopenharmony_ciMODULE_LICENSE("GPL"); 142