blob: 939c30999eeb18b24f7a9273520491e731675b0d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekeb8c54b2014-04-25 12:21:04 +02002/*
3 * (C) Copyright 2014, Xilinx, Inc
4 *
5 * USB Low level initialization(Specific to zynq)
Michal Simekeb8c54b2014-04-25 12:21:04 +02006 */
7
8#include <common.h>
Simon Glassdec49e82016-07-05 17:10:14 -06009#include <dm.h>
10#include <usb.h>
Michal Simekeb8c54b2014-04-25 12:21:04 +020011#include <asm/arch/hardware.h>
12#include <asm/arch/sys_proto.h>
13#include <asm/io.h>
Mateusz Kulikowskie162c6b2016-03-31 23:12:23 +020014#include <usb/ehci-ci.h>
Michal Simekeb8c54b2014-04-25 12:21:04 +020015#include <usb/ulpi.h>
16
17#include "ehci.h"
18
Simon Glassdec49e82016-07-05 17:10:14 -060019struct zynq_ehci_priv {
20 struct ehci_ctrl ehcictrl;
Michal Simekeb8c54b2014-04-25 12:21:04 +020021 struct usb_ehci *ehci;
Simon Glassdec49e82016-07-05 17:10:14 -060022};
23
24static int ehci_zynq_ofdata_to_platdata(struct udevice *dev)
25{
26 struct zynq_ehci_priv *priv = dev_get_priv(dev);
27
Simon Glassa821c4a2017-05-17 17:18:05 -060028 priv->ehci = (struct usb_ehci *)devfdt_get_addr_ptr(dev);
Simon Glassdec49e82016-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{
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 Simekeb8c54b2014-04-25 12:21:04 +020041 struct ulpi_viewport ulpi_vp;
Michal Simekeb8c54b2014-04-25 12:21:04 +020042 /* Used for writing the ULPI data address */
43 struct ulpi_regs *ulpi = (struct ulpi_regs *)0;
Simon Glassdec49e82016-07-05 17:10:14 -060044 int ret;
Michal Simekeb8c54b2014-04-25 12:21:04 +020045
Simon Glassdec49e82016-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 Simekeb8c54b2014-04-25 12:21:04 +020049
Simon Glassdec49e82016-07-05 17:10:14 -060050 ulpi_vp.viewport_addr = (u32)&priv->ehci->ulpi_viewpoint;
Michal Simekeb8c54b2014-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 Glassdec49e82016-07-05 17:10:14 -060072 return ehci_register(dev, hccr, hcor, NULL, 0, plat->init_type);
Michal Simekeb8c54b2014-04-25 12:21:04 +020073}
74
Simon Glassdec49e82016-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,
84 .ofdata_to_platdata = ehci_zynq_ofdata_to_platdata,
85 .probe = ehci_zynq_probe,
Masahiro Yamada40527342016-09-06 22:17:34 +090086 .remove = ehci_deregister,
Simon Glassdec49e82016-07-05 17:10:14 -060087 .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};