blob: a081f71b187d9ee63202f1b556f753f4e2bec9d6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mateusz Kulikowskidc381172016-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 Kulikowskidc381172016-03-31 23:12:26 +02008 */
9
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020010#include <dm.h>
Caleb Connolly154ed1d2024-02-26 17:26:21 +000011#include <dm/lists.h>
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020012#include <errno.h>
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020013#include <usb.h>
14#include <usb/ehci-ci.h>
15#include <usb/ulpi.h>
16#include <wait_bit.h>
17#include <asm/gpio.h>
18#include <asm/io.h>
19#include <linux/compat.h>
20#include "ehci.h"
21
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020022struct msm_ehci_priv {
23 struct ehci_ctrl ctrl; /* Needed by EHCI */
24 struct usb_ehci *ehci; /* Start of IP core*/
25 struct ulpi_viewport ulpi_vp; /* ULPI Viewport */
Ramon Fried7e365962018-09-21 13:35:50 +030026 struct phy phy;
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020027};
28
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020029static int msm_init_after_reset(struct ehci_ctrl *dev)
30{
31 struct msm_ehci_priv *p = container_of(dev, struct msm_ehci_priv, ctrl);
32 struct usb_ehci *ehci = p->ehci;
33
Ramon Fried7e365962018-09-21 13:35:50 +030034 generic_phy_reset(&p->phy);
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020035
36 /* set mode to host controller */
37 writel(CM_HOST, &ehci->usbmode);
38
39 return 0;
40}
41
42static const struct ehci_ops msm_ehci_ops = {
43 .init_after_reset = msm_init_after_reset
44};
45
46static int ehci_usb_probe(struct udevice *dev)
47{
48 struct msm_ehci_priv *p = dev_get_priv(dev);
49 struct usb_ehci *ehci = p->ehci;
Simon Glassb75b15b2020-12-03 16:55:23 -070050 struct usb_plat *plat = dev_get_plat(dev);
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020051 struct ehci_hccr *hccr;
52 struct ehci_hcor *hcor;
53 int ret;
54
55 hccr = (struct ehci_hccr *)((phys_addr_t)&ehci->caplength);
56 hcor = (struct ehci_hcor *)((phys_addr_t)hccr +
57 HC_LENGTH(ehci_readl(&(hccr)->cr_capbase)));
58
Patrice Chotard343ff752022-09-06 08:15:28 +020059 ret = generic_setup_phy(dev, &p->phy, 0);
Ramon Fried7e365962018-09-21 13:35:50 +030060 if (ret)
61 return ret;
62
Ramon Fried7b0334f2018-09-21 13:35:51 +030063 ret = board_usb_init(0, plat->init_type);
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020064 if (ret < 0)
65 return ret;
66
Ramon Fried7b0334f2018-09-21 13:35:51 +030067 return ehci_register(dev, hccr, hcor, &msm_ehci_ops, 0,
68 plat->init_type);
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020069}
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
Patrice Chotard343ff752022-09-06 08:15:28 +020084 ret = generic_shutdown_phy(&p->phy);
Ramon Fried7e365962018-09-21 13:35:50 +030085 if (ret)
86 return ret;
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020087
Ramon Friedbc866cc82018-09-21 13:35:43 +030088 ret = board_usb_init(0, USB_INIT_DEVICE); /* Board specific hook */
Mateusz Kulikowskidc381172016-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 Rojas918de032018-01-23 17:14:55 +010096 if (wait_for_bit_le32(&ehci->usbcmd, CMD_RESET, false, 30, false)) {
Mateusz Kulikowskidc381172016-03-31 23:12:26 +020097 printf("Stuck on USB reset.\n");
98 return -ETIMEDOUT;
99 }
100
101 return 0;
102}
103
Simon Glassaad29ae2020-12-03 16:55:21 -0700104static int ehci_usb_of_to_plat(struct udevice *dev)
Mateusz Kulikowskidc381172016-03-31 23:12:26 +0200105{
106 struct msm_ehci_priv *priv = dev_get_priv(dev);
107
108 priv->ulpi_vp.port_num = 0;
Kever Yangd24b1542020-03-04 08:59:49 +0800109 priv->ehci = dev_read_addr_ptr(dev);
Mateusz Kulikowskidc381172016-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
Caleb Connolly154ed1d2024-02-26 17:26:21 +0000122static int ehci_usb_of_bind(struct udevice *dev)
123{
124 ofnode ulpi_node = ofnode_first_subnode(dev_ofnode(dev));
125 ofnode phy_node;
126
127 if (!ofnode_valid(ulpi_node))
128 return 0;
129
130 phy_node = ofnode_first_subnode(ulpi_node);
131 if (!ofnode_valid(phy_node)) {
132 printf("%s: ulpi subnode with no phy\n", __func__);
133 return -ENOENT;
134 }
135
136 return device_bind_driver_to_node(dev, "msm8916_usbphy", "msm8916_usbphy",
137 phy_node, NULL);
138}
139
Ramon Friedcbee9082018-09-21 13:35:53 +0300140#if defined(CONFIG_CI_UDC)
141/* Little quirk that MSM needs with Chipidea controller
142 * Must reinit phy after reset
143 */
144void ci_init_after_reset(struct ehci_ctrl *ctrl)
145{
146 struct msm_ehci_priv *p = ctrl->priv;
147
148 generic_phy_reset(&p->phy);
149}
150#endif
151
Mateusz Kulikowskidc381172016-03-31 23:12:26 +0200152static const struct udevice_id ehci_usb_ids[] = {
Caleb Connolly154ed1d2024-02-26 17:26:21 +0000153 { .compatible = "qcom,ci-hdrc", },
Mateusz Kulikowskidc381172016-03-31 23:12:26 +0200154 { }
155};
156
157U_BOOT_DRIVER(usb_ehci) = {
158 .name = "ehci_msm",
159 .id = UCLASS_USB,
160 .of_match = ehci_usb_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -0700161 .of_to_plat = ehci_usb_of_to_plat,
Caleb Connolly154ed1d2024-02-26 17:26:21 +0000162 .bind = ehci_usb_of_bind,
Mateusz Kulikowskidc381172016-03-31 23:12:26 +0200163 .probe = ehci_usb_probe,
164 .remove = ehci_usb_remove,
165 .ops = &ehci_usb_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700166 .priv_auto = sizeof(struct msm_ehci_priv),
Simon Glassb75b15b2020-12-03 16:55:23 -0700167 .plat_auto = sizeof(struct usb_plat),
Mateusz Kulikowskidc381172016-03-31 23:12:26 +0200168 .flags = DM_FLAG_ALLOC_PRIV_DMA,
169};