Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2014, Xilinx, Inc |
| 3 | * |
| 4 | * USB Low level initialization(Specific to zynq) |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0+ |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 10 | #include <dm.h> |
| 11 | #include <usb.h> |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 12 | #include <asm/arch/hardware.h> |
| 13 | #include <asm/arch/sys_proto.h> |
| 14 | #include <asm/io.h> |
Mateusz Kulikowski | 3add69e | 2016-03-31 23:12:23 +0200 | [diff] [blame] | 15 | #include <usb/ehci-ci.h> |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 16 | #include <usb/ulpi.h> |
| 17 | |
| 18 | #include "ehci.h" |
| 19 | |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 20 | struct zynq_ehci_priv { |
| 21 | struct ehci_ctrl ehcictrl; |
| 22 | struct usb_ehci *ehci; |
| 23 | }; |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 24 | |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 25 | static int ehci_zynq_ofdata_to_platdata(struct udevice *dev) |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 26 | { |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 27 | struct zynq_ehci_priv *priv = dev_get_priv(dev); |
| 28 | |
| 29 | priv->ehci = (struct usb_ehci *)dev_get_addr_ptr(dev); |
| 30 | if (!priv->ehci) |
| 31 | return -EINVAL; |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static int ehci_zynq_probe(struct udevice *dev) |
| 37 | { |
| 38 | struct usb_platdata *plat = dev_get_platdata(dev); |
| 39 | struct zynq_ehci_priv *priv = dev_get_priv(dev); |
| 40 | struct ehci_hccr *hccr; |
| 41 | struct ehci_hcor *hcor; |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 42 | struct ulpi_viewport ulpi_vp; |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 43 | /* Used for writing the ULPI data address */ |
| 44 | struct ulpi_regs *ulpi = (struct ulpi_regs *)0; |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 45 | int ret; |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 46 | |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 47 | hccr = (struct ehci_hccr *)((uint32_t)&priv->ehci->caplength); |
| 48 | hcor = (struct ehci_hcor *)((uint32_t) hccr + |
| 49 | HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 50 | |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 51 | ulpi_vp.viewport_addr = (u32)&priv->ehci->ulpi_viewpoint; |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 52 | ulpi_vp.port_num = 0; |
| 53 | |
| 54 | ret = ulpi_init(&ulpi_vp); |
| 55 | if (ret) { |
| 56 | puts("zynq ULPI viewport init failed\n"); |
| 57 | return -1; |
| 58 | } |
| 59 | |
| 60 | /* ULPI set flags */ |
| 61 | ulpi_write(&ulpi_vp, &ulpi->otg_ctrl, |
| 62 | ULPI_OTG_DP_PULLDOWN | ULPI_OTG_DM_PULLDOWN | |
| 63 | ULPI_OTG_EXTVBUSIND); |
| 64 | ulpi_write(&ulpi_vp, &ulpi->function_ctrl, |
| 65 | ULPI_FC_FULL_SPEED | ULPI_FC_OPMODE_NORMAL | |
| 66 | ULPI_FC_SUSPENDM); |
| 67 | ulpi_write(&ulpi_vp, &ulpi->iface_ctrl, 0); |
| 68 | |
| 69 | /* Set VBus */ |
| 70 | ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set, |
| 71 | ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT); |
| 72 | |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 73 | return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type); |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 74 | } |
| 75 | |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 76 | static int ehci_zynq_remove(struct udevice *dev) |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 77 | { |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 78 | int ret; |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 79 | |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 80 | ret = ehci_deregister(dev); |
| 81 | if (ret) |
| 82 | return ret; |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 83 | |
| 84 | return 0; |
| 85 | } |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 86 | |
| 87 | static const struct udevice_id ehci_zynq_ids[] = { |
| 88 | { .compatible = "xlnx,zynq-usb-2.20a" }, |
| 89 | { } |
| 90 | }; |
| 91 | |
| 92 | U_BOOT_DRIVER(ehci_zynq) = { |
| 93 | .name = "ehci_zynq", |
| 94 | .id = UCLASS_USB, |
| 95 | .of_match = ehci_zynq_ids, |
| 96 | .ofdata_to_platdata = ehci_zynq_ofdata_to_platdata, |
| 97 | .probe = ehci_zynq_probe, |
| 98 | .remove = ehci_zynq_remove, |
| 99 | .ops = &ehci_usb_ops, |
| 100 | .platdata_auto_alloc_size = sizeof(struct usb_platdata), |
| 101 | .priv_auto_alloc_size = sizeof(struct zynq_ehci_priv), |
| 102 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 103 | }; |