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