1 // SPDX-License-Identifier: GPL-2.0+
4 * Atmel Semiconductor <www.atmel.com>
15 #include <asm/arch/clk.h>
19 #if !CONFIG_IS_ENABLED(DM_USB)
21 int ehci_hcd_init(int index, enum usb_init_type init,
22 struct ehci_hccr **hccr, struct ehci_hcor **hcor)
25 if (at91_upll_clk_enable())
28 /* Enable USB Host clock */
29 at91_periph_clk_enable(ATMEL_ID_UHPHS);
31 *hccr = (struct ehci_hccr *)ATMEL_BASE_EHCI;
32 *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
33 HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
38 int ehci_hcd_stop(int index)
40 /* Disable USB Host Clock */
41 at91_periph_clk_disable(ATMEL_ID_UHPHS);
43 /* Disable UTMI PLL */
44 if (at91_upll_clk_disable())
52 struct ehci_atmel_priv {
53 struct ehci_ctrl ehci;
56 static int ehci_atmel_enable_clk(struct udevice *dev)
61 ret = clk_get_by_index(dev, 0, &clk);
65 ret = clk_enable(&clk);
69 ret = clk_get_by_index(dev, 1, &clk);
73 ret = clk_enable(&clk);
82 static int ehci_atmel_probe(struct udevice *dev)
84 struct ehci_hccr *hccr;
85 struct ehci_hcor *hcor;
89 ret = ehci_atmel_enable_clk(dev);
91 debug("Failed to enable USB Host clock\n");
96 * Get the base address for EHCI controller from the device node
98 hcd_base = dev_read_addr(dev);
99 if (hcd_base == FDT_ADDR_T_NONE) {
100 debug("Can't get the EHCI register base address\n");
104 hccr = (struct ehci_hccr *)hcd_base;
105 hcor = (struct ehci_hcor *)
106 ((u32)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
108 debug("echi-atmel: init hccr %x and hcor %x hc_length %d\n",
109 (u32)hccr, (u32)hcor,
110 (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
112 return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
115 static const struct udevice_id ehci_usb_ids[] = {
116 { .compatible = "atmel,at91sam9g45-ehci", },
120 U_BOOT_DRIVER(ehci_atmel) = {
121 .name = "ehci_atmel",
123 .of_match = ehci_usb_ids,
124 .probe = ehci_atmel_probe,
125 .remove = ehci_deregister,
126 .ops = &ehci_usb_ops,
127 .plat_auto = sizeof(struct usb_plat),
128 .priv_auto = sizeof(struct ehci_atmel_priv),
129 .flags = DM_FLAG_ALLOC_PRIV_DMA,