blob: a27a5833ddd4a573b2c57e29da782304401cc2ea [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mateusz Kulikowski5a822112016-03-31 23:12:26 +02002/*
3 * Qualcomm EHCI driver
4 *
5 * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
6 *
7 * Based on Linux driver
Mateusz Kulikowski5a822112016-03-31 23:12:26 +02008 */
9
10#include <common.h>
11#include <dm.h>
12#include <errno.h>
13#include <fdtdec.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090014#include <linux/libfdt.h>
Mateusz Kulikowski5a822112016-03-31 23:12:26 +020015#include <usb.h>
16#include <usb/ehci-ci.h>
17#include <usb/ulpi.h>
18#include <wait_bit.h>
19#include <asm/gpio.h>
20#include <asm/io.h>
21#include <linux/compat.h>
22#include "ehci.h"
23
Mateusz Kulikowski5a822112016-03-31 23:12:26 +020024struct msm_ehci_priv {
25 struct ehci_ctrl ctrl; /* Needed by EHCI */
26 struct usb_ehci *ehci; /* Start of IP core*/
27 struct ulpi_viewport ulpi_vp; /* ULPI Viewport */
Ramon Fried0ac0b6e2018-09-21 13:35:50 +030028 struct phy phy;
Mateusz Kulikowski5a822112016-03-31 23:12:26 +020029};
30
Mateusz Kulikowski5a822112016-03-31 23:12:26 +020031static int msm_init_after_reset(struct ehci_ctrl *dev)
32{
33 struct msm_ehci_priv *p = container_of(dev, struct msm_ehci_priv, ctrl);
34 struct usb_ehci *ehci = p->ehci;
35
Ramon Fried0ac0b6e2018-09-21 13:35:50 +030036 generic_phy_reset(&p->phy);
Mateusz Kulikowski5a822112016-03-31 23:12:26 +020037
38 /* set mode to host controller */
39 writel(CM_HOST, &ehci->usbmode);
40
41 return 0;
42}
43
44static const struct ehci_ops msm_ehci_ops = {
45 .init_after_reset = msm_init_after_reset
46};
47
48static int ehci_usb_probe(struct udevice *dev)
49{
50 struct msm_ehci_priv *p = dev_get_priv(dev);
51 struct usb_ehci *ehci = p->ehci;
52 struct ehci_hccr *hccr;
53 struct ehci_hcor *hcor;
54 int ret;
55
56 hccr = (struct ehci_hccr *)((phys_addr_t)&ehci->caplength);
57 hcor = (struct ehci_hcor *)((phys_addr_t)hccr +
58 HC_LENGTH(ehci_readl(&(hccr)->cr_capbase)));
59
Ramon Fried0ac0b6e2018-09-21 13:35:50 +030060 ret = ehci_setup_phy(dev, &p->phy, 0);
61 if (ret)
62 return ret;
63
Ramon Friedcd8c3ae2018-09-21 13:35:43 +030064 ret = board_usb_init(0, USB_INIT_HOST);
Mateusz Kulikowski5a822112016-03-31 23:12:26 +020065 if (ret < 0)
66 return ret;
67
68 return ehci_register(dev, hccr, hcor, &msm_ehci_ops, 0, USB_INIT_HOST);
69}
70
71static int ehci_usb_remove(struct udevice *dev)
72{
73 struct msm_ehci_priv *p = dev_get_priv(dev);
74 struct usb_ehci *ehci = p->ehci;
75 int ret;
76
77 ret = ehci_deregister(dev);
78 if (ret)
79 return ret;
80
81 /* Stop controller. */
82 clrbits_le32(&ehci->usbcmd, CMD_RUN);
83
Ramon Fried0ac0b6e2018-09-21 13:35:50 +030084 ret = ehci_shutdown_phy(dev, &p->phy);
85 if (ret)
86 return ret;
Mateusz Kulikowski5a822112016-03-31 23:12:26 +020087
Ramon Friedcd8c3ae2018-09-21 13:35:43 +030088 ret = board_usb_init(0, USB_INIT_DEVICE); /* Board specific hook */
Mateusz Kulikowski5a822112016-03-31 23:12:26 +020089 if (ret < 0)
90 return ret;
91
92 /* Reset controller */
93 setbits_le32(&ehci->usbcmd, CMD_RESET);
94
95 /* Wait for reset */
Álvaro Fernández Rojas48263502018-01-23 17:14:55 +010096 if (wait_for_bit_le32(&ehci->usbcmd, CMD_RESET, false, 30, false)) {
Mateusz Kulikowski5a822112016-03-31 23:12:26 +020097 printf("Stuck on USB reset.\n");
98 return -ETIMEDOUT;
99 }
100
101 return 0;
102}
103
104static int ehci_usb_ofdata_to_platdata(struct udevice *dev)
105{
106 struct msm_ehci_priv *priv = dev_get_priv(dev);
107
108 priv->ulpi_vp.port_num = 0;
Simon Glassa821c4a2017-05-17 17:18:05 -0600109 priv->ehci = (void *)devfdt_get_addr(dev);
Mateusz Kulikowski5a822112016-03-31 23:12:26 +0200110
111 if (priv->ehci == (void *)FDT_ADDR_T_NONE)
112 return -EINVAL;
113
114 /* Warning: this will not work if viewport address is > 64 bit due to
115 * ULPI design.
116 */
117 priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint;
118
119 return 0;
120}
121
122static const struct udevice_id ehci_usb_ids[] = {
123 { .compatible = "qcom,ehci-host", },
124 { }
125};
126
127U_BOOT_DRIVER(usb_ehci) = {
128 .name = "ehci_msm",
129 .id = UCLASS_USB,
130 .of_match = ehci_usb_ids,
131 .ofdata_to_platdata = ehci_usb_ofdata_to_platdata,
132 .probe = ehci_usb_probe,
133 .remove = ehci_usb_remove,
134 .ops = &ehci_usb_ops,
135 .priv_auto_alloc_size = sizeof(struct msm_ehci_priv),
Ramon Fried2df49232018-09-21 13:35:44 +0300136 .platdata_auto_alloc_size = sizeof(struct usb_platdata),
Mateusz Kulikowski5a822112016-03-31 23:12:26 +0200137 .flags = DM_FLAG_ALLOC_PRIV_DMA,
138};