summaryrefslogtreecommitdiffstats
path: root/target/linux/brcm63xx/files/drivers/usb/host/ehci-bcm63xx.c
blob: 2fef5716e3ff581187317ff70668de61358edb82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
 */

#include <linux/init.h>
#include <linux/platform_device.h>
#include <bcm63xx_cpu.h>
#include <bcm63xx_regs.h>
#include <bcm63xx_io.h>

static int ehci_bcm63xx_setup(struct usb_hcd *hcd)
{
	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
	int retval;

	retval = ehci_halt(ehci);
	if (retval)
		return retval;

	retval = ehci_init(hcd);
	if (retval)
		return retval;

	hcd->has_tt = 1;
	ehci_reset(ehci);
	ehci_port_power(ehci, 0);

	return retval;
}


static const struct hc_driver ehci_bcm63xx_hc_driver = {
	.description =		hcd_name,
	.product_desc =		"BCM63XX integrated EHCI controller",
	.hcd_priv_size =	sizeof(struct ehci_hcd),

	.irq =			ehci_irq,
	.flags =		HCD_MEMORY | HCD_USB2,

	.reset =		ehci_bcm63xx_setup,
	.start =		ehci_run,
	.stop =			ehci_stop,
	.shutdown =		ehci_shutdown,

	.urb_enqueue =		ehci_urb_enqueue,
	.urb_dequeue =		ehci_urb_dequeue,
	.endpoint_disable =	ehci_endpoint_disable,

	.get_frame_number =	ehci_get_frame,

	.hub_status_data =	ehci_hub_status_data,
	.hub_control =		ehci_hub_control,
	.bus_suspend =		ehci_bus_suspend,
	.bus_resume =		ehci_bus_resume,
	.relinquish_port =	ehci_relinquish_port,
	.port_handed_over =	ehci_port_handed_over,
};

static int __devinit ehci_hcd_bcm63xx_drv_probe(struct platform_device *pdev)
{
	struct resource *res_mem, *res_irq;
	struct usb_hcd *hcd;
	struct ehci_hcd *ehci;
	u32 reg;
	int ret;

	res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
	if (!res_mem || !res_irq)
		return -ENODEV;

	reg = bcm_rset_readl(RSET_USBH_PRIV, USBH_PRIV_SWAP_REG);
	reg &= ~USBH_PRIV_SWAP_EHCI_DATA_MASK;
	reg |= USBH_PRIV_SWAP_EHCI_ENDN_MASK;
	bcm_rset_writel(RSET_USBH_PRIV, reg, USBH_PRIV_SWAP_REG);

	/* don't ask... */
	bcm_rset_writel(RSET_USBH_PRIV, 0x1c0020, USBH_PRIV_TEST_REG);

	hcd = usb_create_hcd(&ehci_bcm63xx_hc_driver, &pdev->dev, "bcm63xx");
	if (!hcd)
		return -ENOMEM;
	hcd->rsrc_start = res_mem->start;
	hcd->rsrc_len = res_mem->end - res_mem->start + 1;

	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
		pr_debug("request_mem_region failed\n");
		ret = -EBUSY;
		goto out;
	}

	hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
	if (!hcd->regs) {
		pr_debug("ioremap failed\n");
		ret = -EIO;
		goto out1;
	}

	ehci = hcd_to_ehci(hcd);
	ehci->big_endian_mmio = 1;
	ehci->big_endian_desc = 0;
	ehci->caps = hcd->regs;
	ehci->regs = hcd->regs +
		HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
	ehci->sbrn = 0x20;

	ret = usb_add_hcd(hcd, res_irq->start, IRQF_DISABLED);
	if (ret)
		goto out2;

	platform_set_drvdata(pdev, hcd);
	return 0;

out2:
	iounmap(hcd->regs);
out1:
	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
out:
	usb_put_hcd(hcd);
	return ret;
}

static int __devexit ehci_hcd_bcm63xx_drv_remove(struct platform_device *pdev)
{
	struct usb_hcd *hcd;

	hcd = platform_get_drvdata(pdev);
	usb_remove_hcd(hcd);
	iounmap(hcd->regs);
	usb_put_hcd(hcd);
	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
	platform_set_drvdata(pdev, NULL);
	return 0;
}

static struct platform_driver ehci_hcd_bcm63xx_driver = {
	.probe		= ehci_hcd_bcm63xx_drv_probe,
	.remove		= __devexit_p(ehci_hcd_bcm63xx_drv_remove),
	.shutdown	= usb_hcd_platform_shutdown,
	.driver		= {
		.name	= "bcm63xx_ehci",
		.owner	= THIS_MODULE,
		.bus	= &platform_bus_type
	},
};

MODULE_ALIAS("platform:bcm63xx_ehci");