3 * Atmel Semiconductor <www.atmel.com>
4 * Written-by: Bo Shen <voice.shen@atmel.com>
6 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/arch/clk.h>
18 DECLARE_GLOBAL_DATA_PTR;
22 int ehci_hcd_init(int index, enum usb_init_type init,
23 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
26 if (at91_upll_clk_enable())
29 /* Enable USB Host clock */
30 at91_periph_clk_enable(ATMEL_ID_UHPHS);
32 *hccr = (struct ehci_hccr *)ATMEL_BASE_EHCI;
33 *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
34 HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
39 int ehci_hcd_stop(int index)
41 /* Disable USB Host Clock */
42 at91_periph_clk_disable(ATMEL_ID_UHPHS);
44 /* Disable UTMI PLL */
45 if (at91_upll_clk_disable())
53 struct ehci_atmel_priv {
54 struct ehci_ctrl ehci;
57 static int ehci_atmel_enable_clk(struct udevice *dev)
59 struct udevice *dev_clk;
64 ret = clk_get_by_index(dev, 0, &clk);
68 ret = clk_enable(&clk);
72 ret = clk_get_by_index(dev, 1, &clk);
76 periph = fdtdec_get_uint(gd->fdt_blob, clk.dev->of_offset, "reg", -1);
80 dev_clk = dev_get_parent(clk.dev);
84 ret = clk_request(dev_clk, &clk);
89 ret = clk_enable(&clk);
98 static int ehci_atmel_probe(struct udevice *dev)
100 struct ehci_hccr *hccr;
101 struct ehci_hcor *hcor;
105 ret = ehci_atmel_enable_clk(dev);
107 debug("Failed to enable USB Host clock\n");
112 * Get the base address for EHCI controller from the device node
114 hcd_base = dev_get_addr(dev);
115 if (hcd_base == FDT_ADDR_T_NONE) {
116 debug("Can't get the EHCI register base address\n");
120 hccr = (struct ehci_hccr *)hcd_base;
121 hcor = (struct ehci_hcor *)
122 ((u32)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
124 debug("echi-atmel: init hccr %x and hcor %x hc_length %d\n",
125 (u32)hccr, (u32)hcor,
126 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
128 return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
131 static int ehci_atmel_remove(struct udevice *dev)
135 ret = ehci_deregister(dev);
142 static const struct udevice_id ehci_usb_ids[] = {
143 { .compatible = "atmel,at91sam9g45-ehci", },
147 U_BOOT_DRIVER(ehci_atmel) = {
148 .name = "ehci_atmel",
150 .of_match = ehci_usb_ids,
151 .probe = ehci_atmel_probe,
152 .remove = ehci_atmel_remove,
153 .ops = &ehci_usb_ops,
154 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
155 .priv_auto_alloc_size = sizeof(struct ehci_atmel_priv),
156 .flags = DM_FLAG_ALLOC_PRIV_DMA,