Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | // SPDX-License-Identifier: GPL-2.0+ /* * Copyright (c) 2021 Nuvoton Technology Corp. */ #include <dm.h> #include <generic-phy.h> #include <reset.h> #include <asm/io.h> #include <dm/device_compat.h> #include <linux/delay.h> #include "ehci.h" struct npcm_ehci_priv { struct ehci_ctrl ctrl; struct ehci_hccr *hcd; struct phy phy; }; static int npcm_ehci_setup_phy(struct udevice *dev, struct phy *phy) { int ret; if (!phy) return 0; ret = generic_phy_get_by_index(dev, 0, phy); if (ret) { if (ret != -ENOENT) { dev_err(dev, "failed to get usb phy\n"); return ret; } } else { ret = generic_phy_init(phy); if (ret) { dev_err(dev, "failed to init usb phy\n"); return ret; } } return 0; } static int npcm_ehci_init(struct udevice *dev) { struct npcm_ehci_priv *priv = dev_get_priv(dev); struct reset_ctl reset; int ret; ret = reset_get_by_index(dev, 0, &reset); if (ret && ret != -ENOENT && ret != -ENOTSUPP) { dev_err(dev, "failed to get reset\n"); return ret; } /* reset controller */ if (reset_valid(&reset)) reset_assert(&reset); /* setup phy */ ret = npcm_ehci_setup_phy(dev, &priv->phy); if (ret) return ret; /* release controller from reset */ if (reset_valid(&reset)) reset_deassert(&reset); return 0; } static int npcm_ehci_probe(struct udevice *dev) { struct npcm_ehci_priv *priv = dev_get_priv(dev); struct ehci_hcor *hcor; enum usb_init_type type = dev_get_driver_data(dev); int ret; ret = npcm_ehci_init(dev); if (ret) return ret; priv->hcd = (struct ehci_hccr *)dev_read_addr_ptr(dev); debug("USB HCD @0x%p\n", priv->hcd); hcor = (struct ehci_hcor *)((uintptr_t)priv->hcd + HC_LENGTH(ehci_readl(&priv->hcd->cr_capbase))); return ehci_register(dev, priv->hcd, hcor, NULL, 0, type); } static int npcm_ehci_remove(struct udevice *dev) { struct npcm_ehci_priv *priv = dev_get_priv(dev); generic_phy_exit(&priv->phy); return ehci_deregister(dev); } static const struct udevice_id npcm_ehci_ids[] = { { .compatible = "nuvoton,npcm845-ehci", .data = USB_INIT_HOST }, { .compatible = "nuvoton,npcm845-udc", .data = USB_INIT_DEVICE }, { .compatible = "nuvoton,npcm750-ehci", .data = USB_INIT_HOST }, { .compatible = "nuvoton,npcm750-udc", .data = USB_INIT_DEVICE }, { } }; U_BOOT_DRIVER(ehci_npcm) = { .name = "ehci_npcm", .id = UCLASS_USB, .of_match = npcm_ehci_ids, .probe = npcm_ehci_probe, .remove = npcm_ehci_remove, .ops = &ehci_usb_ops, .priv_auto = sizeof(struct npcm_ehci_priv), .plat_auto = sizeof(struct usb_plat), .flags = DM_FLAG_ALLOC_PRIV_DMA, }; |