Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | ec02820 | 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 | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <usb.h> |
Michal Simek | ec02820 | 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 | 3add69e | 2016-03-31 23:12:23 +0200 | [diff] [blame] | 14 | #include <usb/ehci-ci.h> |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 15 | #include <usb/ulpi.h> |
| 16 | |
| 17 | #include "ehci.h" |
| 18 | |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 19 | struct zynq_ehci_priv { |
| 20 | struct ehci_ctrl ehcictrl; |
| 21 | struct usb_ehci *ehci; |
| 22 | }; |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 23 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 24 | static int ehci_zynq_of_to_plat(struct udevice *dev) |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 25 | { |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 26 | struct zynq_ehci_priv *priv = dev_get_priv(dev); |
| 27 | |
Masahiro Yamada | 32822d0 | 2020-08-04 14:14:43 +0900 | [diff] [blame] | 28 | priv->ehci = dev_read_addr_ptr(dev); |
Simon Glass | 476e63f | 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 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 37 | struct usb_plat *plat = dev_get_plat(dev); |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 38 | struct zynq_ehci_priv *priv = dev_get_priv(dev); |
| 39 | struct ehci_hccr *hccr; |
| 40 | struct ehci_hcor *hcor; |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 41 | struct ulpi_viewport ulpi_vp; |
Michal Simek | ec02820 | 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 | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 44 | int ret; |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 45 | |
Simon Glass | 476e63f | 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 | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 49 | |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 50 | ulpi_vp.viewport_addr = (u32)&priv->ehci->ulpi_viewpoint; |
Michal Simek | ec02820 | 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 | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 72 | return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type); |
Michal Simek | ec02820 | 2014-04-25 12:21:04 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Simon Glass | 476e63f | 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, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 84 | .of_to_plat = ehci_zynq_of_to_plat, |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 85 | .probe = ehci_zynq_probe, |
Masahiro Yamada | d41919b | 2016-09-06 22:17:34 +0900 | [diff] [blame] | 86 | .remove = ehci_deregister, |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 87 | .ops = &ehci_usb_ops, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 88 | .plat_auto = sizeof(struct usb_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 89 | .priv_auto = sizeof(struct zynq_ehci_priv), |
Simon Glass | 476e63f | 2016-07-05 17:10:14 -0600 | [diff] [blame] | 90 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 91 | }; |