2 * Copyright (C) 2015 Alexey Brodkin <abrodkin@synopsys.com>
4 * SPDX-License-Identifier: GPL-2.0+
16 * Even though here we don't explicitly use "struct ehci_ctrl"
17 * ehci_register() expects it to be the first thing that resides in
18 * device's private data.
21 struct ehci_ctrl ctrl;
23 struct reset_ctl *resets;
28 static int ehci_usb_probe(struct udevice *dev)
30 struct generic_ehci *priv = dev_get_priv(dev);
31 struct ehci_hccr *hccr;
32 struct ehci_hcor *hcor;
33 int i, err, ret, clock_nb, reset_nb;
36 priv->clock_count = 0;
37 clock_nb = ofnode_count_phandle_with_args(dev_ofnode(dev), "clocks",
40 priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk),
45 for (i = 0; i < clock_nb; i++) {
46 err = clk_get_by_index(dev, i, &priv->clocks[i]);
50 err = clk_enable(&priv->clocks[i]);
52 error("failed to enable clock %d\n", i);
53 clk_free(&priv->clocks[i]);
59 if (clock_nb != -ENOENT) {
60 error("failed to get clock phandle(%d)\n", clock_nb);
65 priv->reset_count = 0;
66 reset_nb = ofnode_count_phandle_with_args(dev_ofnode(dev), "resets",
69 priv->resets = devm_kcalloc(dev, reset_nb,
70 sizeof(struct reset_ctl),
75 for (i = 0; i < reset_nb; i++) {
76 err = reset_get_by_index(dev, i, &priv->resets[i]);
80 if (reset_deassert(&priv->resets[i])) {
81 error("failed to deassert reset %d\n", i);
82 reset_free(&priv->resets[i]);
88 if (reset_nb != -ENOENT) {
89 error("failed to get reset phandle(%d)\n", reset_nb);
94 hccr = map_physmem(devfdt_get_addr(dev), 0x100, MAP_NOCACHE);
95 hcor = (struct ehci_hcor *)((uintptr_t)hccr +
96 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
98 err = ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
105 ret = reset_release_all(priv->resets, priv->reset_count);
107 error("failed to assert all resets\n");
109 ret = clk_release_all(priv->clocks, priv->clock_count);
111 error("failed to disable all clocks\n");
116 static int ehci_usb_remove(struct udevice *dev)
118 struct generic_ehci *priv = dev_get_priv(dev);
121 ret = ehci_deregister(dev);
125 ret = reset_release_all(priv->resets, priv->reset_count);
129 return clk_release_all(priv->clocks, priv->clock_count);
132 static const struct udevice_id ehci_usb_ids[] = {
133 { .compatible = "generic-ehci" },
137 U_BOOT_DRIVER(ehci_generic) = {
138 .name = "ehci_generic",
140 .of_match = ehci_usb_ids,
141 .probe = ehci_usb_probe,
142 .remove = ehci_usb_remove,
143 .ops = &ehci_usb_ops,
144 .priv_auto_alloc_size = sizeof(struct generic_ehci),
145 .flags = DM_FLAG_ALLOC_PRIV_DMA,