blob: f7e458cb15a2b05e1f29e4571bdfc755ddd5277d [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
8#include <common.h>
Simon Glass476e63f2016-07-05 17:10:14 -06009#include <dm.h>
10#include <usb.h>
Michal Simekec028202014-04-25 12:21:04 +020011#include <asm/arch/hardware.h>
12#include <asm/arch/sys_proto.h>
13#include <asm/io.h>
Mateusz Kulikowski3add69e2016-03-31 23:12:23 +020014#include <usb/ehci-ci.h>
Michal Simekec028202014-04-25 12:21:04 +020015#include <usb/ulpi.h>
16
17#include "ehci.h"
18
Simon Glass476e63f2016-07-05 17:10:14 -060019struct zynq_ehci_priv {
20 struct ehci_ctrl ehcictrl;
21 struct usb_ehci *ehci;
22};
Michal Simekec028202014-04-25 12:21:04 +020023
Simon Glassaad29ae2020-12-03 16:55:21 -070024static int ehci_zynq_of_to_plat(struct udevice *dev)
Michal Simekec028202014-04-25 12:21:04 +020025{
Simon Glass476e63f2016-07-05 17:10:14 -060026 struct zynq_ehci_priv *priv = dev_get_priv(dev);
27
Masahiro Yamada32822d02020-08-04 14:14:43 +090028 priv->ehci = dev_read_addr_ptr(dev);
Simon Glass476e63f2016-07-05 17:10:14 -060029 if (!priv->ehci)
30 return -EINVAL;
31
32 return 0;
33}
34
35static int ehci_zynq_probe(struct udevice *dev)
36{
Simon Glassb75b15b2020-12-03 16:55:23 -070037 struct usb_plat *plat = dev_get_plat(dev);
Simon Glass476e63f2016-07-05 17:10:14 -060038 struct zynq_ehci_priv *priv = dev_get_priv(dev);
39 struct ehci_hccr *hccr;
40 struct ehci_hcor *hcor;
Michal Simekec028202014-04-25 12:21:04 +020041 struct ulpi_viewport ulpi_vp;
Michal Simekec028202014-04-25 12:21:04 +020042 /* Used for writing the ULPI data address */
43 struct ulpi_regs *ulpi = (struct ulpi_regs *)0;
Simon Glass476e63f2016-07-05 17:10:14 -060044 int ret;
Michal Simekec028202014-04-25 12:21:04 +020045
Simon Glass476e63f2016-07-05 17:10:14 -060046 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 Simekec028202014-04-25 12:21:04 +020049
Simon Glass476e63f2016-07-05 17:10:14 -060050 ulpi_vp.viewport_addr = (u32)&priv->ehci->ulpi_viewpoint;
Michal Simekec028202014-04-25 12:21:04 +020051 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 Glass476e63f2016-07-05 17:10:14 -060072 return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
Michal Simekec028202014-04-25 12:21:04 +020073}
74
Simon Glass476e63f2016-07-05 17:10:14 -060075static const struct udevice_id ehci_zynq_ids[] = {
76 { .compatible = "xlnx,zynq-usb-2.20a" },
77 { }
78};
79
80U_BOOT_DRIVER(ehci_zynq) = {
81 .name = "ehci_zynq",
82 .id = UCLASS_USB,
83 .of_match = ehci_zynq_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -070084 .of_to_plat = ehci_zynq_of_to_plat,
Simon Glass476e63f2016-07-05 17:10:14 -060085 .probe = ehci_zynq_probe,
Masahiro Yamadad41919b2016-09-06 22:17:34 +090086 .remove = ehci_deregister,
Simon Glass476e63f2016-07-05 17:10:14 -060087 .ops = &ehci_usb_ops,
Simon Glassb75b15b2020-12-03 16:55:23 -070088 .plat_auto = sizeof(struct usb_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -070089 .priv_auto = sizeof(struct zynq_ehci_priv),
Simon Glass476e63f2016-07-05 17:10:14 -060090 .flags = DM_FLAG_ALLOC_PRIV_DMA,
91};