Lines Matching full:udc
3 * snps_udc_plat.c - Synopsys UDC Platform Driver
20 #define UDC_MOD_DESCRIPTION "Synopsys UDC platform driver"
22 static void start_udc(struct udc *udc) in start_udc() argument
24 if (udc->driver) { in start_udc()
25 dev_info(udc->dev, "Connecting...\n"); in start_udc()
26 udc_enable_dev_setup_interrupts(udc); in start_udc()
27 udc_basic_init(udc); in start_udc()
28 udc->connected = 1; in start_udc()
32 static void stop_udc(struct udc *udc) in stop_udc() argument
37 spin_lock(&udc->lock); in stop_udc()
40 reg = readl(&udc->regs->ctl); in stop_udc()
42 writel(reg, &udc->regs->ctl); in stop_udc()
44 reg = readl(&udc->regs->ctl); in stop_udc()
46 writel(reg, &udc->regs->ctl); in stop_udc()
47 dev_dbg(udc->dev, "ep rx queue flushed\n"); in stop_udc()
50 * UDC is connected to a DRD phy. in stop_udc()
52 udc_mask_unused_interrupts(udc); in stop_udc()
55 if (udc->driver) { in stop_udc()
56 spin_unlock(&udc->lock); in stop_udc()
57 udc->driver->disconnect(&udc->gadget); in stop_udc()
58 spin_lock(&udc->lock); in stop_udc()
62 empty_req_queue(&udc->ep[tmp]); in stop_udc()
64 udc->connected = 0; in stop_udc()
66 spin_unlock(&udc->lock); in stop_udc()
67 dev_info(udc->dev, "Device disconnected\n"); in stop_udc()
72 struct udc *udc; in udc_drd_work() local
74 udc = container_of(to_delayed_work(work), in udc_drd_work()
75 struct udc, drd_work); in udc_drd_work()
77 if (udc->conn_type) { in udc_drd_work()
78 dev_dbg(udc->dev, "idle -> device\n"); in udc_drd_work()
79 start_udc(udc); in udc_drd_work()
81 dev_dbg(udc->dev, "device -> idle\n"); in udc_drd_work()
82 stop_udc(udc); in udc_drd_work()
89 struct udc *udc = container_of(self, struct udc, nb); in usbd_connect_notify() local
91 dev_dbg(udc->dev, "%s: event: %lu\n", __func__, event); in usbd_connect_notify()
93 udc->conn_type = event; in usbd_connect_notify()
95 schedule_delayed_work(&udc->drd_work, 0); in usbd_connect_notify()
104 struct udc *udc; in udc_plat_probe() local
107 udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL); in udc_plat_probe()
108 if (!udc) in udc_plat_probe()
111 spin_lock_init(&udc->lock); in udc_plat_probe()
112 udc->dev = dev; in udc_plat_probe()
114 udc->virt_addr = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in udc_plat_probe()
115 if (IS_ERR(udc->virt_addr)) in udc_plat_probe()
116 return PTR_ERR(udc->virt_addr); in udc_plat_probe()
118 /* udc csr registers base */ in udc_plat_probe()
119 udc->csr = udc->virt_addr + UDC_CSR_ADDR; in udc_plat_probe()
122 udc->regs = udc->virt_addr + UDC_DEVCFG_ADDR; in udc_plat_probe()
125 udc->ep_regs = udc->virt_addr + UDC_EPREGS_ADDR; in udc_plat_probe()
128 udc->rxfifo = (u32 __iomem *)(udc->virt_addr + UDC_RXFIFO_ADDR); in udc_plat_probe()
129 udc->txfifo = (u32 __iomem *)(udc->virt_addr + UDC_TXFIFO_ADDR); in udc_plat_probe()
131 udc->phys_addr = (unsigned long)res->start; in udc_plat_probe()
133 udc->irq = irq_of_parse_and_map(dev->of_node, 0); in udc_plat_probe()
134 if (udc->irq <= 0) { in udc_plat_probe()
139 udc->udc_phy = devm_of_phy_get_by_index(dev, dev->of_node, 0); in udc_plat_probe()
140 if (IS_ERR(udc->udc_phy)) { in udc_plat_probe()
142 return PTR_ERR(udc->udc_phy); in udc_plat_probe()
145 ret = phy_init(udc->udc_phy); in udc_plat_probe()
147 dev_err(dev, "UDC phy init failed"); in udc_plat_probe()
151 ret = phy_power_on(udc->udc_phy); in udc_plat_probe()
153 dev_err(dev, "UDC phy power on failed"); in udc_plat_probe()
154 phy_exit(udc->udc_phy); in udc_plat_probe()
160 udc->edev = extcon_get_edev_by_phandle(dev, 0); in udc_plat_probe()
161 if (IS_ERR(udc->edev)) { in udc_plat_probe()
162 if (PTR_ERR(udc->edev) == -EPROBE_DEFER) in udc_plat_probe()
165 ret = PTR_ERR(udc->edev); in udc_plat_probe()
169 udc->nb.notifier_call = usbd_connect_notify; in udc_plat_probe()
170 ret = extcon_register_notifier(udc->edev, EXTCON_USB, in udc_plat_probe()
171 &udc->nb); in udc_plat_probe()
177 ret = extcon_get_state(udc->edev, EXTCON_USB); in udc_plat_probe()
182 udc->conn_type = ret; in udc_plat_probe()
184 INIT_DELAYED_WORK(&udc->drd_work, udc_drd_work); in udc_plat_probe()
189 ret = init_dma_pools(udc); in udc_plat_probe()
194 ret = devm_request_irq(dev, udc->irq, udc_irq, IRQF_SHARED, in udc_plat_probe()
195 "snps-udc", udc); in udc_plat_probe()
197 dev_err(dev, "Request irq %d failed for UDC\n", udc->irq); in udc_plat_probe()
201 platform_set_drvdata(pdev, udc); in udc_plat_probe()
202 udc->chiprev = UDC_BCM_REV; in udc_plat_probe()
204 if (udc_probe(udc)) { in udc_plat_probe()
208 dev_info(dev, "Synopsys UDC platform driver probe successful\n"); in udc_plat_probe()
214 free_dma_pools(udc); in udc_plat_probe()
216 if (udc->edev) in udc_plat_probe()
217 extcon_unregister_notifier(udc->edev, EXTCON_USB, &udc->nb); in udc_plat_probe()
219 if (udc->udc_phy) { in udc_plat_probe()
220 phy_power_off(udc->udc_phy); in udc_plat_probe()
221 phy_exit(udc->udc_phy); in udc_plat_probe()
228 struct udc *dev; in udc_plat_remove()
248 dev_info(&pdev->dev, "Synopsys UDC platform driver removed\n"); in udc_plat_remove()
254 struct udc *udc; in udc_plat_suspend() local
256 udc = dev_get_drvdata(dev); in udc_plat_suspend()
257 stop_udc(udc); in udc_plat_suspend()
259 if (extcon_get_state(udc->edev, EXTCON_USB) > 0) { in udc_plat_suspend()
260 dev_dbg(udc->dev, "device -> idle\n"); in udc_plat_suspend()
261 stop_udc(udc); in udc_plat_suspend()
263 phy_power_off(udc->udc_phy); in udc_plat_suspend()
264 phy_exit(udc->udc_phy); in udc_plat_suspend()
271 struct udc *udc; in udc_plat_resume() local
274 udc = dev_get_drvdata(dev); in udc_plat_resume()
276 ret = phy_init(udc->udc_phy); in udc_plat_resume()
278 dev_err(udc->dev, "UDC phy init failure"); in udc_plat_resume()
282 ret = phy_power_on(udc->udc_phy); in udc_plat_resume()
284 dev_err(udc->dev, "UDC phy power on failure"); in udc_plat_resume()
285 phy_exit(udc->udc_phy); in udc_plat_resume()
289 if (extcon_get_state(udc->edev, EXTCON_USB) > 0) { in udc_plat_resume()
290 dev_dbg(udc->dev, "idle -> device\n"); in udc_plat_resume()
291 start_udc(udc); in udc_plat_resume()
303 { .compatible = "brcm,ns2-udc", },
304 { .compatible = "brcm,cygnus-udc", },
305 { .compatible = "brcm,iproc-udc", },
314 .name = "snps-udc-plat",