xref: /OK3568_Linux_fs/u-boot/drivers/usb/host/xhci-zynqmp.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 2015 Xilinx, Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Zynq USB HOST xHCI Controller
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Author: Siva Durga Prasad Paladugu<sivadur@xilinx.com>
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * This file was reused from Freescale USB xHCI
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <common.h>
14*4882a593Smuzhiyun #include <dm.h>
15*4882a593Smuzhiyun #include <usb.h>
16*4882a593Smuzhiyun #include <linux/errno.h>
17*4882a593Smuzhiyun #include <asm/arch/hardware.h>
18*4882a593Smuzhiyun #include <linux/compat.h>
19*4882a593Smuzhiyun #include <linux/usb/dwc3.h>
20*4882a593Smuzhiyun #include "xhci.h"
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /* Declare global data pointer */
23*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun /* Default to the ZYNQMP XHCI defines */
26*4882a593Smuzhiyun #define USB3_PWRCTL_CLK_CMD_MASK	0x3FE000
27*4882a593Smuzhiyun #define USB3_PWRCTL_CLK_FREQ_MASK	0xFFC
28*4882a593Smuzhiyun #define USB3_PHY_PARTIAL_RX_POWERON     BIT(6)
29*4882a593Smuzhiyun #define USB3_PHY_RX_POWERON		BIT(14)
30*4882a593Smuzhiyun #define USB3_PHY_TX_POWERON		BIT(15)
31*4882a593Smuzhiyun #define USB3_PHY_TX_RX_POWERON	(USB3_PHY_RX_POWERON | USB3_PHY_TX_POWERON)
32*4882a593Smuzhiyun #define USB3_PWRCTL_CLK_CMD_SHIFT   14
33*4882a593Smuzhiyun #define USB3_PWRCTL_CLK_FREQ_SHIFT	22
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /* USBOTGSS_WRAPPER definitions */
36*4882a593Smuzhiyun #define USBOTGSS_WRAPRESET	BIT(17)
37*4882a593Smuzhiyun #define USBOTGSS_DMADISABLE BIT(16)
38*4882a593Smuzhiyun #define USBOTGSS_STANDBYMODE_NO_STANDBY BIT(4)
39*4882a593Smuzhiyun #define USBOTGSS_STANDBYMODE_SMRT		BIT(5)
40*4882a593Smuzhiyun #define USBOTGSS_STANDBYMODE_SMRT_WKUP (0x3 << 4)
41*4882a593Smuzhiyun #define USBOTGSS_IDLEMODE_NOIDLE BIT(2)
42*4882a593Smuzhiyun #define USBOTGSS_IDLEMODE_SMRT BIT(3)
43*4882a593Smuzhiyun #define USBOTGSS_IDLEMODE_SMRT_WKUP (0x3 << 2)
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /* USBOTGSS_IRQENABLE_SET_0 bit */
46*4882a593Smuzhiyun #define USBOTGSS_COREIRQ_EN	BIT(1)
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun /* USBOTGSS_IRQENABLE_SET_1 bits */
49*4882a593Smuzhiyun #define USBOTGSS_IRQ_SET_1_IDPULLUP_FALL_EN	BIT(1)
50*4882a593Smuzhiyun #define USBOTGSS_IRQ_SET_1_DISCHRGVBUS_FALL_EN	BIT(3)
51*4882a593Smuzhiyun #define USBOTGSS_IRQ_SET_1_CHRGVBUS_FALL_EN	BIT(4)
52*4882a593Smuzhiyun #define USBOTGSS_IRQ_SET_1_DRVVBUS_FALL_EN	BIT(5)
53*4882a593Smuzhiyun #define USBOTGSS_IRQ_SET_1_IDPULLUP_RISE_EN	BIT(8)
54*4882a593Smuzhiyun #define USBOTGSS_IRQ_SET_1_DISCHRGVBUS_RISE_EN	BIT(11)
55*4882a593Smuzhiyun #define USBOTGSS_IRQ_SET_1_CHRGVBUS_RISE_EN	BIT(12)
56*4882a593Smuzhiyun #define USBOTGSS_IRQ_SET_1_DRVVBUS_RISE_EN	BIT(13)
57*4882a593Smuzhiyun #define USBOTGSS_IRQ_SET_1_OEVT_EN		BIT(16)
58*4882a593Smuzhiyun #define USBOTGSS_IRQ_SET_1_DMADISABLECLR_EN	BIT(17)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun struct zynqmp_xhci {
61*4882a593Smuzhiyun 	struct usb_platdata usb_plat;
62*4882a593Smuzhiyun 	struct xhci_ctrl ctrl;
63*4882a593Smuzhiyun 	struct xhci_hccr *hcd;
64*4882a593Smuzhiyun 	struct dwc3 *dwc3_reg;
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun struct zynqmp_xhci_platdata {
68*4882a593Smuzhiyun 	fdt_addr_t hcd_base;
69*4882a593Smuzhiyun };
70*4882a593Smuzhiyun 
zynqmp_xhci_core_init(struct zynqmp_xhci * zynqmp_xhci)71*4882a593Smuzhiyun static int zynqmp_xhci_core_init(struct zynqmp_xhci *zynqmp_xhci)
72*4882a593Smuzhiyun {
73*4882a593Smuzhiyun 	int ret = 0;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	ret = dwc3_core_init(zynqmp_xhci->dwc3_reg);
76*4882a593Smuzhiyun 	if (ret) {
77*4882a593Smuzhiyun 		debug("%s:failed to initialize core\n", __func__);
78*4882a593Smuzhiyun 		return ret;
79*4882a593Smuzhiyun 	}
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	/* We are hard-coding DWC3 core to Host Mode */
82*4882a593Smuzhiyun 	dwc3_set_mode(zynqmp_xhci->dwc3_reg, DWC3_GCTL_PRTCAP_HOST);
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 	return ret;
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun 
xhci_hcd_stop(int index)87*4882a593Smuzhiyun void xhci_hcd_stop(int index)
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun 	/*
90*4882a593Smuzhiyun 	 * Currently zynqmp socs do not support PHY shutdown from
91*4882a593Smuzhiyun 	 * sw. But this support may be added in future socs.
92*4882a593Smuzhiyun 	 */
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 	return;
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun 
xhci_usb_probe(struct udevice * dev)97*4882a593Smuzhiyun static int xhci_usb_probe(struct udevice *dev)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun 	struct zynqmp_xhci_platdata *plat = dev_get_platdata(dev);
100*4882a593Smuzhiyun 	struct zynqmp_xhci *ctx = dev_get_priv(dev);
101*4882a593Smuzhiyun 	struct xhci_hcor *hcor;
102*4882a593Smuzhiyun 	int ret;
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	ctx->hcd = (struct xhci_hccr *)plat->hcd_base;
105*4882a593Smuzhiyun 	ctx->dwc3_reg = (struct dwc3 *)((char *)(ctx->hcd) + DWC3_REG_OFFSET);
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	ret = zynqmp_xhci_core_init(ctx);
108*4882a593Smuzhiyun 	if (ret) {
109*4882a593Smuzhiyun 		puts("XHCI: failed to initialize controller\n");
110*4882a593Smuzhiyun 		return -EINVAL;
111*4882a593Smuzhiyun 	}
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	hcor = (struct xhci_hcor *)((ulong)ctx->hcd +
114*4882a593Smuzhiyun 				  HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase)));
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 	return xhci_register(dev, ctx->hcd, hcor);
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun 
xhci_usb_remove(struct udevice * dev)119*4882a593Smuzhiyun static int xhci_usb_remove(struct udevice *dev)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun 	return xhci_deregister(dev);
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun 
xhci_usb_ofdata_to_platdata(struct udevice * dev)124*4882a593Smuzhiyun static int xhci_usb_ofdata_to_platdata(struct udevice *dev)
125*4882a593Smuzhiyun {
126*4882a593Smuzhiyun 	struct zynqmp_xhci_platdata *plat = dev_get_platdata(dev);
127*4882a593Smuzhiyun 	const void *blob = gd->fdt_blob;
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 	/* Get the base address for XHCI controller from the device node */
130*4882a593Smuzhiyun 	plat->hcd_base = fdtdec_get_addr(blob, dev_of_offset(dev), "reg");
131*4882a593Smuzhiyun 	if (plat->hcd_base == FDT_ADDR_T_NONE) {
132*4882a593Smuzhiyun 		debug("Can't get the XHCI register base address\n");
133*4882a593Smuzhiyun 		return -ENXIO;
134*4882a593Smuzhiyun 	}
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	return 0;
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun U_BOOT_DRIVER(dwc3_generic_host) = {
140*4882a593Smuzhiyun 	.name = "dwc3-generic-host",
141*4882a593Smuzhiyun 	.id = UCLASS_USB,
142*4882a593Smuzhiyun 	.ofdata_to_platdata = xhci_usb_ofdata_to_platdata,
143*4882a593Smuzhiyun 	.probe = xhci_usb_probe,
144*4882a593Smuzhiyun 	.remove = xhci_usb_remove,
145*4882a593Smuzhiyun 	.ops = &xhci_usb_ops,
146*4882a593Smuzhiyun 	.platdata_auto_alloc_size = sizeof(struct zynqmp_xhci_platdata),
147*4882a593Smuzhiyun 	.priv_auto_alloc_size = sizeof(struct zynqmp_xhci),
148*4882a593Smuzhiyun 	.flags = DM_FLAG_ALLOC_PRIV_DMA,
149*4882a593Smuzhiyun };
150