blob: dfaff5c60f4e46e7a2cf9f7d5394cfb8a5cd00c5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekec028202014-04-25 12:21:04 +02002/*
3 * (C) Copyright 2014, Xilinx, Inc
4 *
5 * USB Low level initialization(Specific to zynq)
Michal Simekec028202014-04-25 12:21:04 +02006 */
7
Simon Glass476e63f2016-07-05 17:10:14 -06008#include <dm.h>
9#include <usb.h>
Michal Simekec028202014-04-25 12:21:04 +020010#include <asm/arch/hardware.h>
11#include <asm/arch/sys_proto.h>
12#include <asm/io.h>
Mateusz Kulikowski3add69e2016-03-31 23:12:23 +020013#include <usb/ehci-ci.h>
Michal Simekec028202014-04-25 12:21:04 +020014#include <usb/ulpi.h>
15
16#include "ehci.h"
17
Simon Glass476e63f2016-07-05 17:10:14 -060018struct zynq_ehci_priv {
19 struct ehci_ctrl ehcictrl;
20 struct usb_ehci *ehci;
21};
Michal Simekec028202014-04-25 12:21:04 +020022
Simon Glassaad29ae2020-12-03 16:55:21 -070023static int ehci_zynq_of_to_plat(struct udevice *dev)
Michal Simekec028202014-04-25 12:21:04 +020024{
Simon Glass476e63f2016-07-05 17:10:14 -060025 struct zynq_ehci_priv *priv = dev_get_priv(dev);
26
Masahiro Yamada32822d02020-08-04 14:14:43 +090027 priv->ehci = dev_read_addr_ptr(dev);
Simon Glass476e63f2016-07-05 17:10:14 -060028 if (!priv->ehci)
29 return -EINVAL;
30
31 return 0;
32}
33
34static int ehci_zynq_probe(struct udevice *dev)
35{
Simon Glassb75b15b2020-12-03 16:55:23 -070036 struct usb_plat *plat = dev_get_plat(dev);
Simon Glass476e63f2016-07-05 17:10:14 -060037 struct zynq_ehci_priv *priv = dev_get_priv(dev);
38 struct ehci_hccr *hccr;
39 struct ehci_hcor *hcor;
Michal Simekec028202014-04-25 12:21:04 +020040 struct ulpi_viewport ulpi_vp;
Michal Simekec028202014-04-25 12:21:04 +020041 /* Used for writing the ULPI data address */
42 struct ulpi_regs *ulpi = (struct ulpi_regs *)0;
Simon Glass476e63f2016-07-05 17:10:14 -060043 int ret;
Michal Simekec028202014-04-25 12:21:04 +020044
Simon Glass476e63f2016-07-05 17:10:14 -060045 hccr = (struct ehci_hccr *)((uint32_t)&priv->ehci->caplength);
46 hcor = (struct ehci_hcor *)((uint32_t) hccr +
47 HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
Michal Simekec028202014-04-25 12:21:04 +020048
Simon Glass476e63f2016-07-05 17:10:14 -060049 ulpi_vp.viewport_addr = (u32)&priv->ehci->ulpi_viewpoint;
Michal Simekec028202014-04-25 12:21:04 +020050 ulpi_vp.port_num = 0;
51
52 ret = ulpi_init(&ulpi_vp);
53 if (ret) {
54 puts("zynq ULPI viewport init failed\n");
55 return -1;
56 }
57
58 /* ULPI set flags */
59 ulpi_write(&ulpi_vp, &ulpi->otg_ctrl,
60 ULPI_OTG_DP_PULLDOWN | ULPI_OTG_DM_PULLDOWN |
61 ULPI_OTG_EXTVBUSIND);
62 ulpi_write(&ulpi_vp, &ulpi->function_ctrl,
63 ULPI_FC_FULL_SPEED | ULPI_FC_OPMODE_NORMAL |
64 ULPI_FC_SUSPENDM);
65 ulpi_write(&ulpi_vp, &ulpi->iface_ctrl, 0);
66
67 /* Set VBus */
68 ulpi_write(&ulpi_vp, &ulpi->otg_ctrl_set,
69 ULPI_OTG_DRVVBUS | ULPI_OTG_DRVVBUS_EXT);
70
Simon Glass476e63f2016-07-05 17:10:14 -060071 return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
Michal Simekec028202014-04-25 12:21:04 +020072}
73
Simon Glass476e63f2016-07-05 17:10:14 -060074static const struct udevice_id ehci_zynq_ids[] = {
75 { .compatible = "xlnx,zynq-usb-2.20a" },
76 { }
77};
78
79U_BOOT_DRIVER(ehci_zynq) = {
80 .name = "ehci_zynq",
81 .id = UCLASS_USB,
82 .of_match = ehci_zynq_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -070083 .of_to_plat = ehci_zynq_of_to_plat,
Simon Glass476e63f2016-07-05 17:10:14 -060084 .probe = ehci_zynq_probe,
Masahiro Yamadad41919b2016-09-06 22:17:34 +090085 .remove = ehci_deregister,
Simon Glass476e63f2016-07-05 17:10:14 -060086 .ops = &ehci_usb_ops,
Simon Glassb75b15b2020-12-03 16:55:23 -070087 .plat_auto = sizeof(struct usb_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -070088 .priv_auto = sizeof(struct zynq_ehci_priv),
Simon Glass476e63f2016-07-05 17:10:14 -060089 .flags = DM_FLAG_ALLOC_PRIV_DMA,
90};