ehci-ps3.c revision ad75a41085d80c8ce5e885962c15779935f8267e
1ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand/*
2ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  PS3 EHCI Host Controller driver
3ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *
4ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  Copyright (C) 2006 Sony Computer Entertainment Inc.
5ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  Copyright 2006 Sony Corp.
6ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *
7ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  This program is free software; you can redistribute it and/or modify
8ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  it under the terms of the GNU General Public License as published by
9ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  the Free Software Foundation; version 2 of the License.
10ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *
11ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  This program is distributed in the hope that it will be useful,
12ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  GNU General Public License for more details.
15ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *
16ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  You should have received a copy of the GNU General Public License
17ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  along with this program; if not, write to the Free Software
18ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand */
20ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
21ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand#include <asm/ps3.h>
22ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
23ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandstatic int ps3_ehci_hc_reset(struct usb_hcd *hcd)
24ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand{
25ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	int result;
26ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
27ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
28ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	ehci->big_endian_mmio = 1;
29ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
30ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	ehci->caps = hcd->regs;
31ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci,
32ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		&ehci->caps->hc_capbase));
33ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
34ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	dbg_hcs_params(ehci, "reset");
35ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	dbg_hcc_params(ehci, "reset");
36ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
37ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
38ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
39ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	result = ehci_halt(ehci);
40ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
41ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	if (result)
42ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		return result;
43ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
44ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	result = ehci_init(hcd);
45ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
46ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	if (result)
47ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		return result;
48ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
49ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	ehci_port_power(ehci, 0);
50ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
51ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	return result;
52ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand}
53ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
54ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandstatic const struct hc_driver ps3_ehci_hc_driver = {
55ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.description		= hcd_name,
56ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.product_desc		= "PS3 EHCI Host Controller",
57ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.hcd_priv_size		= sizeof(struct ehci_hcd),
58ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.irq			= ehci_irq,
59ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.flags			= HCD_MEMORY | HCD_USB2,
60ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.reset			= ps3_ehci_hc_reset,
61ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.start			= ehci_run,
62ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.stop			= ehci_stop,
63ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.shutdown		= ehci_shutdown,
64ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.urb_enqueue		= ehci_urb_enqueue,
65ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.urb_dequeue		= ehci_urb_dequeue,
66ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.endpoint_disable	= ehci_endpoint_disable,
67ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.get_frame_number	= ehci_get_frame,
68ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.hub_status_data	= ehci_hub_status_data,
69ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.hub_control		= ehci_hub_control,
70ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand#if defined(CONFIG_PM)
71ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.bus_suspend		= ehci_bus_suspend,
72ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.bus_resume		= ehci_bus_resume,
73ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand#endif
74ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand};
75ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
76ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand#if !defined(DEBUG)
77ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand#undef dev_dbg
78ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandstatic inline int __attribute__ ((format (printf, 2, 3))) dev_dbg(
79ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	const struct device *_dev, const char *fmt, ...) {return 0;}
80ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand#endif
81ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
82ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
83ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandstatic int ps3_ehci_sb_probe(struct ps3_system_bus_device *dev)
84ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand{
85ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	int result;
86ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	struct usb_hcd *hcd;
87ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	unsigned int virq;
88ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	static u64 dummy_mask = DMA_32BIT_MASK;
89ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
90ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	if (usb_disabled()) {
91ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		result = -ENODEV;
92ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		goto fail_start;
93ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	}
94ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
95ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	result = ps3_mmio_region_create(dev->m_region);
96ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
97ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	if (result) {
98ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
99ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand			__func__, __LINE__);
100ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		result = -EPERM;
101ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		goto fail_mmio;
102ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	}
103ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
104ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
105ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		__LINE__, dev->m_region->lpar_addr);
106ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
107ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	result = ps3_alloc_io_irq(dev->interrupt_id, &virq);
108ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
109ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	if (result) {
110ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
111ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand			__func__, __LINE__, virq);
112ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		result = -EPERM;
113ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		goto fail_irq;
114ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	}
115ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
116ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	dev->core.power.power_state = PMSG_ON;
117ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */
118ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
119ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev->core.bus_id);
120ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
121ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	if (!hcd) {
122ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
123ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand			__LINE__);
124ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		result = -ENOMEM;
125ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		goto fail_create_hcd;
126ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	}
127ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
128ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	hcd->rsrc_start = dev->m_region->lpar_addr;
129ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	hcd->rsrc_len = dev->m_region->len;
130ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
131ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
132ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	if (!hcd->regs) {
133ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
134ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand			__LINE__);
135ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		result = -EPERM;
136ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		goto fail_ioremap;
137ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	}
138ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
139ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
140ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		(unsigned long)hcd->rsrc_start);
141ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len   %lxh\n", __func__, __LINE__,
142ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		(unsigned long)hcd->rsrc_len);
143ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	dev_dbg(&dev->core, "%s:%d: hcd->regs       %lxh\n", __func__, __LINE__,
144ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		(unsigned long)hcd->regs);
145ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	dev_dbg(&dev->core, "%s:%d: virq            %lu\n", __func__, __LINE__,
146ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		(unsigned long)virq);
147ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
148ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	ps3_system_bus_set_driver_data(dev, hcd);
149ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
150ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	result = usb_add_hcd(hcd, virq, IRQF_DISABLED);
151ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
152ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	if (result) {
153ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
154ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand			__func__, __LINE__, result);
155ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		goto fail_add_hcd;
156ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	}
157ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
158ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	return result;
159ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
160ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandfail_add_hcd:
161ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	iounmap(hcd->regs);
162ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandfail_ioremap:
163ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	usb_put_hcd(hcd);
164ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandfail_create_hcd:
165ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	ps3_free_io_irq(virq);
166ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandfail_irq:
167ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	ps3_free_mmio_region(dev->m_region);
168ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandfail_mmio:
169ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandfail_start:
170ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	return result;
171ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand}
172ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
173ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandstatic int ps3_ehci_sb_remove(struct ps3_system_bus_device *dev)
174ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand{
175ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	struct usb_hcd *hcd =
176ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		(struct usb_hcd *)ps3_system_bus_get_driver_data(dev);
177ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
178ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	usb_put_hcd(hcd);
179ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	ps3_system_bus_set_driver_data(dev, NULL);
180ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
181ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	return 0;
182ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand}
183ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
184ad75a41085d80c8ce5e885962c15779935f8267eGeoff LevandMODULE_ALIAS("ps3-ehci");
185ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand
186ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levandstatic struct ps3_system_bus_driver ps3_ehci_sb_driver = {
187ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.match_id = PS3_MATCH_ID_EHCI,
188ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.core = {
189ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand		.name = "ps3-ehci-driver",
190ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	},
191ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.probe = ps3_ehci_sb_probe,
192ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand	.remove = ps3_ehci_sb_remove,
193ad75a41085d80c8ce5e885962c15779935f8267eGeoff Levand};
194