xref: /OK3568_Linux_fs/u-boot/drivers/usb/host/xhci-mvebu.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (C) 2015 Marvell International Ltd.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * MVEBU USB HOST xHCI Controller
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <common.h>
10*4882a593Smuzhiyun #include <dm.h>
11*4882a593Smuzhiyun #include <fdtdec.h>
12*4882a593Smuzhiyun #include <usb.h>
13*4882a593Smuzhiyun #include <power/regulator.h>
14*4882a593Smuzhiyun #include <asm/gpio.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include <usb/xhci.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun struct mvebu_xhci_platdata {
21*4882a593Smuzhiyun 	fdt_addr_t hcd_base;
22*4882a593Smuzhiyun };
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun /**
25*4882a593Smuzhiyun  * Contains pointers to register base addresses
26*4882a593Smuzhiyun  * for the usb controller.
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun struct mvebu_xhci {
29*4882a593Smuzhiyun 	struct xhci_ctrl ctrl;	/* Needs to come first in this struct! */
30*4882a593Smuzhiyun 	struct usb_platdata usb_plat;
31*4882a593Smuzhiyun 	struct xhci_hccr *hcd;
32*4882a593Smuzhiyun };
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /*
35*4882a593Smuzhiyun  * Dummy implementation that can be overwritten by a board
36*4882a593Smuzhiyun  * specific function
37*4882a593Smuzhiyun  */
board_xhci_enable(fdt_addr_t base)38*4882a593Smuzhiyun __weak int board_xhci_enable(fdt_addr_t base)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun 	return 0;
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun 
xhci_usb_probe(struct udevice * dev)43*4882a593Smuzhiyun static int xhci_usb_probe(struct udevice *dev)
44*4882a593Smuzhiyun {
45*4882a593Smuzhiyun 	struct mvebu_xhci_platdata *plat = dev_get_platdata(dev);
46*4882a593Smuzhiyun 	struct mvebu_xhci *ctx = dev_get_priv(dev);
47*4882a593Smuzhiyun 	struct xhci_hcor *hcor;
48*4882a593Smuzhiyun 	int len, ret;
49*4882a593Smuzhiyun 	struct udevice *regulator;
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 	ctx->hcd = (struct xhci_hccr *)plat->hcd_base;
52*4882a593Smuzhiyun 	len = HC_LENGTH(xhci_readl(&ctx->hcd->cr_capbase));
53*4882a593Smuzhiyun 	hcor = (struct xhci_hcor *)((uintptr_t)ctx->hcd + len);
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	ret = device_get_supply_regulator(dev, "vbus-supply", &regulator);
56*4882a593Smuzhiyun 	if (!ret) {
57*4882a593Smuzhiyun 		ret = regulator_set_enable(regulator, true);
58*4882a593Smuzhiyun 		if (ret) {
59*4882a593Smuzhiyun 			printf("Failed to turn ON the VBUS regulator\n");
60*4882a593Smuzhiyun 			return ret;
61*4882a593Smuzhiyun 		}
62*4882a593Smuzhiyun 	}
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	/* Enable USB xHCI (VBUS, reset etc) in board specific code */
65*4882a593Smuzhiyun 	board_xhci_enable(devfdt_get_addr_index(dev, 1));
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	return xhci_register(dev, ctx->hcd, hcor);
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun 
xhci_usb_ofdata_to_platdata(struct udevice * dev)70*4882a593Smuzhiyun static int xhci_usb_ofdata_to_platdata(struct udevice *dev)
71*4882a593Smuzhiyun {
72*4882a593Smuzhiyun 	struct mvebu_xhci_platdata *plat = dev_get_platdata(dev);
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	/*
75*4882a593Smuzhiyun 	 * Get the base address for XHCI controller from the device node
76*4882a593Smuzhiyun 	 */
77*4882a593Smuzhiyun 	plat->hcd_base = devfdt_get_addr(dev);
78*4882a593Smuzhiyun 	if (plat->hcd_base == FDT_ADDR_T_NONE) {
79*4882a593Smuzhiyun 		debug("Can't get the XHCI register base address\n");
80*4882a593Smuzhiyun 		return -ENXIO;
81*4882a593Smuzhiyun 	}
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	return 0;
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun static const struct udevice_id xhci_usb_ids[] = {
87*4882a593Smuzhiyun 	{ .compatible = "marvell,armada3700-xhci" },
88*4882a593Smuzhiyun 	{ .compatible = "marvell,armada-380-xhci" },
89*4882a593Smuzhiyun 	{ .compatible = "marvell,armada-8k-xhci" },
90*4882a593Smuzhiyun 	{ }
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun U_BOOT_DRIVER(usb_xhci) = {
94*4882a593Smuzhiyun 	.name	= "xhci_mvebu",
95*4882a593Smuzhiyun 	.id	= UCLASS_USB,
96*4882a593Smuzhiyun 	.of_match = xhci_usb_ids,
97*4882a593Smuzhiyun 	.ofdata_to_platdata = xhci_usb_ofdata_to_platdata,
98*4882a593Smuzhiyun 	.probe = xhci_usb_probe,
99*4882a593Smuzhiyun 	.remove = xhci_deregister,
100*4882a593Smuzhiyun 	.ops	= &xhci_usb_ops,
101*4882a593Smuzhiyun 	.platdata_auto_alloc_size = sizeof(struct mvebu_xhci_platdata),
102*4882a593Smuzhiyun 	.priv_auto_alloc_size = sizeof(struct mvebu_xhci),
103*4882a593Smuzhiyun 	.flags	= DM_FLAG_ALLOC_PRIV_DMA,
104*4882a593Smuzhiyun };
105