xref: /linux/drivers/usb/host/ehci-ps3.c (revision 6d247e4d)
15fd54aceSGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2ad75a410SGeoff Levand /*
3ad75a410SGeoff Levand  *  PS3 EHCI Host Controller driver
4ad75a410SGeoff Levand  *
5ad75a410SGeoff Levand  *  Copyright (C) 2006 Sony Computer Entertainment Inc.
6ad75a410SGeoff Levand  *  Copyright 2006 Sony Corp.
7ad75a410SGeoff Levand  */
8ad75a410SGeoff Levand 
97a4eb7fdSGeoff Levand #include <asm/firmware.h>
10ad75a410SGeoff Levand #include <asm/ps3.h>
11ad75a410SGeoff Levand 
ps3_ehci_setup_insnreg(struct ehci_hcd * ehci)129187bef2SGeoff Levand static void ps3_ehci_setup_insnreg(struct ehci_hcd *ehci)
139187bef2SGeoff Levand {
149187bef2SGeoff Levand 	/* PS3 HC internal setup register offsets. */
159187bef2SGeoff Levand 
169187bef2SGeoff Levand 	enum ps3_ehci_hc_insnreg {
179187bef2SGeoff Levand 		ps3_ehci_hc_insnreg01 = 0x084,
189187bef2SGeoff Levand 		ps3_ehci_hc_insnreg02 = 0x088,
199187bef2SGeoff Levand 		ps3_ehci_hc_insnreg03 = 0x08c,
209187bef2SGeoff Levand 	};
219187bef2SGeoff Levand 
229187bef2SGeoff Levand 	/* PS3 EHCI HC errata fix 316 - The PS3 EHCI HC will reset its
239187bef2SGeoff Levand 	 * internal INSNREGXX setup regs back to the chip default values
249187bef2SGeoff Levand 	 * on Host Controller Reset (CMD_RESET) or Light Host Controller
259187bef2SGeoff Levand 	 * Reset (CMD_LRESET).  The work-around for this is for the HC
269187bef2SGeoff Levand 	 * driver to re-initialise these regs when ever the HC is reset.
279187bef2SGeoff Levand 	 */
289187bef2SGeoff Levand 
299187bef2SGeoff Levand 	/* Set burst transfer counts to 256 out, 32 in. */
309187bef2SGeoff Levand 
319187bef2SGeoff Levand 	writel_be(0x01000020, (void __iomem *)ehci->regs +
329187bef2SGeoff Levand 		ps3_ehci_hc_insnreg01);
339187bef2SGeoff Levand 
349187bef2SGeoff Levand 	/* Enable burst transfer counts. */
359187bef2SGeoff Levand 
369187bef2SGeoff Levand 	writel_be(0x00000001, (void __iomem *)ehci->regs +
379187bef2SGeoff Levand 		ps3_ehci_hc_insnreg03);
389187bef2SGeoff Levand }
399187bef2SGeoff Levand 
ps3_ehci_hc_reset(struct usb_hcd * hcd)40ad75a410SGeoff Levand static int ps3_ehci_hc_reset(struct usb_hcd *hcd)
41ad75a410SGeoff Levand {
42ad75a410SGeoff Levand 	int result;
43ad75a410SGeoff Levand 	struct ehci_hcd *ehci = hcd_to_ehci(hcd);
44ad75a410SGeoff Levand 
45ad75a410SGeoff Levand 	ehci->big_endian_mmio = 1;
46ad75a410SGeoff Levand 	ehci->caps = hcd->regs;
47ad75a410SGeoff Levand 
481a49e2acSAlan Stern 	result = ehci_setup(hcd);
49ad75a410SGeoff Levand 	if (result)
50ad75a410SGeoff Levand 		return result;
51ad75a410SGeoff Levand 
529187bef2SGeoff Levand 	ps3_ehci_setup_insnreg(ehci);
539187bef2SGeoff Levand 
54ad75a410SGeoff Levand 	return result;
55ad75a410SGeoff Levand }
56ad75a410SGeoff Levand 
57ad75a410SGeoff Levand static const struct hc_driver ps3_ehci_hc_driver = {
58ad75a410SGeoff Levand 	.description		= hcd_name,
59ad75a410SGeoff Levand 	.product_desc		= "PS3 EHCI Host Controller",
60ad75a410SGeoff Levand 	.hcd_priv_size		= sizeof(struct ehci_hcd),
61ad75a410SGeoff Levand 	.irq			= ehci_irq,
627b81cb6bSChristoph Hellwig 	.flags			= HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH,
63ad75a410SGeoff Levand 	.reset			= ps3_ehci_hc_reset,
64ad75a410SGeoff Levand 	.start			= ehci_run,
65ad75a410SGeoff Levand 	.stop			= ehci_stop,
66ad75a410SGeoff Levand 	.shutdown		= ehci_shutdown,
67ad75a410SGeoff Levand 	.urb_enqueue		= ehci_urb_enqueue,
68ad75a410SGeoff Levand 	.urb_dequeue		= ehci_urb_dequeue,
69ad75a410SGeoff Levand 	.endpoint_disable	= ehci_endpoint_disable,
70b18ffd49SAlan Stern 	.endpoint_reset		= ehci_endpoint_reset,
71ad75a410SGeoff Levand 	.get_frame_number	= ehci_get_frame,
72ad75a410SGeoff Levand 	.hub_status_data	= ehci_hub_status_data,
73ad75a410SGeoff Levand 	.hub_control		= ehci_hub_control,
74ad75a410SGeoff Levand #if defined(CONFIG_PM)
75ad75a410SGeoff Levand 	.bus_suspend		= ehci_bus_suspend,
76ad75a410SGeoff Levand 	.bus_resume		= ehci_bus_resume,
77ad75a410SGeoff Levand #endif
7890da096eSBalaji Rao 	.relinquish_port	= ehci_relinquish_port,
793a31155cSAlan Stern 	.port_handed_over	= ehci_port_handed_over,
80914b7012SAlan Stern 
81914b7012SAlan Stern 	.clear_tt_buffer_complete	= ehci_clear_tt_buffer_complete,
82ad75a410SGeoff Levand };
83ad75a410SGeoff Levand 
ps3_ehci_probe(struct ps3_system_bus_device * dev)8441ac7b3aSBill Pemberton static int ps3_ehci_probe(struct ps3_system_bus_device *dev)
85ad75a410SGeoff Levand {
86ad75a410SGeoff Levand 	int result;
87ad75a410SGeoff Levand 	struct usb_hcd *hcd;
88ad75a410SGeoff Levand 	unsigned int virq;
8948e91846SGeoff Levand 	static u64 dummy_mask;
90ad75a410SGeoff Levand 
91ad75a410SGeoff Levand 	if (usb_disabled()) {
92ad75a410SGeoff Levand 		result = -ENODEV;
93ad75a410SGeoff Levand 		goto fail_start;
94ad75a410SGeoff Levand 	}
95ad75a410SGeoff Levand 
967a4eb7fdSGeoff Levand 	result = ps3_open_hv_device(dev);
977a4eb7fdSGeoff Levand 
987a4eb7fdSGeoff Levand 	if (result) {
997a4eb7fdSGeoff Levand 		dev_dbg(&dev->core, "%s:%d: ps3_open_hv_device failed\n",
1007a4eb7fdSGeoff Levand 			__func__, __LINE__);
1017a4eb7fdSGeoff Levand 		goto fail_open;
1027a4eb7fdSGeoff Levand 	}
1037a4eb7fdSGeoff Levand 
1047a4eb7fdSGeoff Levand 	result = ps3_dma_region_create(dev->d_region);
1057a4eb7fdSGeoff Levand 
1067a4eb7fdSGeoff Levand 	if (result) {
1077a4eb7fdSGeoff Levand 		dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: "
1087a4eb7fdSGeoff Levand 			"(%d)\n", __func__, __LINE__, result);
1097a4eb7fdSGeoff Levand 		BUG_ON("check region type");
1107a4eb7fdSGeoff Levand 		goto fail_dma_region;
1117a4eb7fdSGeoff Levand 	}
1127a4eb7fdSGeoff Levand 
113ad75a410SGeoff Levand 	result = ps3_mmio_region_create(dev->m_region);
114ad75a410SGeoff Levand 
115ad75a410SGeoff Levand 	if (result) {
116ad75a410SGeoff Levand 		dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
117ad75a410SGeoff Levand 			__func__, __LINE__);
118ad75a410SGeoff Levand 		result = -EPERM;
1197a4eb7fdSGeoff Levand 		goto fail_mmio_region;
120ad75a410SGeoff Levand 	}
121ad75a410SGeoff Levand 
122ad75a410SGeoff Levand 	dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
123ad75a410SGeoff Levand 		__LINE__, dev->m_region->lpar_addr);
124ad75a410SGeoff Levand 
125dc4f60c2SGeoff Levand 	result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
126ad75a410SGeoff Levand 
127ad75a410SGeoff Levand 	if (result) {
128ad75a410SGeoff Levand 		dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
129ad75a410SGeoff Levand 			__func__, __LINE__, virq);
130ad75a410SGeoff Levand 		result = -EPERM;
131ad75a410SGeoff Levand 		goto fail_irq;
132ad75a410SGeoff Levand 	}
133ad75a410SGeoff Levand 
13448e91846SGeoff Levand 	dummy_mask = DMA_BIT_MASK(32);
13548e91846SGeoff Levand 	dev->core.dma_mask = &dummy_mask;
13648e91846SGeoff Levand 	dma_set_coherent_mask(&dev->core, dummy_mask);
137ad75a410SGeoff Levand 
1387071a3ceSKay Sievers 	hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev_name(&dev->core));
139ad75a410SGeoff Levand 
140ad75a410SGeoff Levand 	if (!hcd) {
141ad75a410SGeoff Levand 		dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
142ad75a410SGeoff Levand 			__LINE__);
143ad75a410SGeoff Levand 		result = -ENOMEM;
144ad75a410SGeoff Levand 		goto fail_create_hcd;
145ad75a410SGeoff Levand 	}
146ad75a410SGeoff Levand 
147ad75a410SGeoff Levand 	hcd->rsrc_start = dev->m_region->lpar_addr;
148ad75a410SGeoff Levand 	hcd->rsrc_len = dev->m_region->len;
1497a4eb7fdSGeoff Levand 
1507a4eb7fdSGeoff Levand 	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name))
1517a4eb7fdSGeoff Levand 		dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n",
1527a4eb7fdSGeoff Levand 			__func__, __LINE__);
1537a4eb7fdSGeoff Levand 
154ad75a410SGeoff Levand 	hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
155ad75a410SGeoff Levand 
156ad75a410SGeoff Levand 	if (!hcd->regs) {
157ad75a410SGeoff Levand 		dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
158ad75a410SGeoff Levand 			__LINE__);
159ad75a410SGeoff Levand 		result = -EPERM;
160ad75a410SGeoff Levand 		goto fail_ioremap;
161ad75a410SGeoff Levand 	}
162ad75a410SGeoff Levand 
163ad75a410SGeoff Levand 	dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
164ad75a410SGeoff Levand 		(unsigned long)hcd->rsrc_start);
165ad75a410SGeoff Levand 	dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len   %lxh\n", __func__, __LINE__,
166ad75a410SGeoff Levand 		(unsigned long)hcd->rsrc_len);
167ad75a410SGeoff Levand 	dev_dbg(&dev->core, "%s:%d: hcd->regs       %lxh\n", __func__, __LINE__,
168ad75a410SGeoff Levand 		(unsigned long)hcd->regs);
169ad75a410SGeoff Levand 	dev_dbg(&dev->core, "%s:%d: virq            %lu\n", __func__, __LINE__,
170ad75a410SGeoff Levand 		(unsigned long)virq);
171ad75a410SGeoff Levand 
17203fa68c2SGeert Uytterhoeven 	ps3_system_bus_set_drvdata(dev, hcd);
173ad75a410SGeoff Levand 
174b5dd18d8SYong Zhang 	result = usb_add_hcd(hcd, virq, 0);
175ad75a410SGeoff Levand 
176ad75a410SGeoff Levand 	if (result) {
177ad75a410SGeoff Levand 		dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
178ad75a410SGeoff Levand 			__func__, __LINE__, result);
179ad75a410SGeoff Levand 		goto fail_add_hcd;
180ad75a410SGeoff Levand 	}
181ad75a410SGeoff Levand 
1823c9740a1SPeter Chen 	device_wakeup_enable(hcd->self.controller);
183ad75a410SGeoff Levand 	return result;
184ad75a410SGeoff Levand 
185ad75a410SGeoff Levand fail_add_hcd:
186ad75a410SGeoff Levand 	iounmap(hcd->regs);
187ad75a410SGeoff Levand fail_ioremap:
1887a4eb7fdSGeoff Levand 	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
189ad75a410SGeoff Levand 	usb_put_hcd(hcd);
190ad75a410SGeoff Levand fail_create_hcd:
191dc4f60c2SGeoff Levand 	ps3_io_irq_destroy(virq);
192ad75a410SGeoff Levand fail_irq:
193ad75a410SGeoff Levand 	ps3_free_mmio_region(dev->m_region);
1947a4eb7fdSGeoff Levand fail_mmio_region:
1957a4eb7fdSGeoff Levand 	ps3_dma_region_free(dev->d_region);
1967a4eb7fdSGeoff Levand fail_dma_region:
1977a4eb7fdSGeoff Levand 	ps3_close_hv_device(dev);
1987a4eb7fdSGeoff Levand fail_open:
199ad75a410SGeoff Levand fail_start:
200ad75a410SGeoff Levand 	return result;
201ad75a410SGeoff Levand }
202ad75a410SGeoff Levand 
ps3_ehci_remove(struct ps3_system_bus_device * dev)203*6d247e4dSUwe Kleine-König static void ps3_ehci_remove(struct ps3_system_bus_device *dev)
204ad75a410SGeoff Levand {
2057a4eb7fdSGeoff Levand 	unsigned int tmp;
20603fa68c2SGeert Uytterhoeven 	struct usb_hcd *hcd = ps3_system_bus_get_drvdata(dev);
207ad75a410SGeoff Levand 
2087a4eb7fdSGeoff Levand 	BUG_ON(!hcd);
2097a4eb7fdSGeoff Levand 
2107a4eb7fdSGeoff Levand 	dev_dbg(&dev->core, "%s:%d: regs %p\n", __func__, __LINE__, hcd->regs);
2117a4eb7fdSGeoff Levand 	dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq);
2127a4eb7fdSGeoff Levand 
2137a4eb7fdSGeoff Levand 	tmp = hcd->irq;
2147a4eb7fdSGeoff Levand 
2157a4eb7fdSGeoff Levand 	usb_remove_hcd(hcd);
2167a4eb7fdSGeoff Levand 
21703fa68c2SGeert Uytterhoeven 	ps3_system_bus_set_drvdata(dev, NULL);
218ad75a410SGeoff Levand 
2197a4eb7fdSGeoff Levand 	BUG_ON(!hcd->regs);
2207a4eb7fdSGeoff Levand 	iounmap(hcd->regs);
2217a4eb7fdSGeoff Levand 
2227a4eb7fdSGeoff Levand 	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
2237a4eb7fdSGeoff Levand 	usb_put_hcd(hcd);
2247a4eb7fdSGeoff Levand 
2257a4eb7fdSGeoff Levand 	ps3_io_irq_destroy(tmp);
2267a4eb7fdSGeoff Levand 	ps3_free_mmio_region(dev->m_region);
2277a4eb7fdSGeoff Levand 
2287a4eb7fdSGeoff Levand 	ps3_dma_region_free(dev->d_region);
2297a4eb7fdSGeoff Levand 	ps3_close_hv_device(dev);
230ad75a410SGeoff Levand }
231ad75a410SGeoff Levand 
ps3_ehci_driver_register(struct ps3_system_bus_driver * drv)23231348517SGeert Uytterhoeven static int __init ps3_ehci_driver_register(struct ps3_system_bus_driver *drv)
2337a4eb7fdSGeoff Levand {
2347a4eb7fdSGeoff Levand 	return firmware_has_feature(FW_FEATURE_PS3_LV1)
2357a4eb7fdSGeoff Levand 		? ps3_system_bus_driver_register(drv)
2367a4eb7fdSGeoff Levand 		: 0;
2377a4eb7fdSGeoff Levand }
238ad75a410SGeoff Levand 
ps3_ehci_driver_unregister(struct ps3_system_bus_driver * drv)2397a4eb7fdSGeoff Levand static void ps3_ehci_driver_unregister(struct ps3_system_bus_driver *drv)
2407a4eb7fdSGeoff Levand {
2417a4eb7fdSGeoff Levand 	if (firmware_has_feature(FW_FEATURE_PS3_LV1))
2427a4eb7fdSGeoff Levand 		ps3_system_bus_driver_unregister(drv);
2437a4eb7fdSGeoff Levand }
2447a4eb7fdSGeoff Levand 
2457a4eb7fdSGeoff Levand MODULE_ALIAS(PS3_MODULE_ALIAS_EHCI);
2467a4eb7fdSGeoff Levand 
2477a4eb7fdSGeoff Levand static struct ps3_system_bus_driver ps3_ehci_driver = {
2487a4eb7fdSGeoff Levand 	.core.name = "ps3-ehci-driver",
2497a4eb7fdSGeoff Levand 	.core.owner = THIS_MODULE,
250ad75a410SGeoff Levand 	.match_id = PS3_MATCH_ID_EHCI,
2517a4eb7fdSGeoff Levand 	.probe = ps3_ehci_probe,
2527a4eb7fdSGeoff Levand 	.remove = ps3_ehci_remove,
2537a4eb7fdSGeoff Levand 	.shutdown = ps3_ehci_remove,
254ad75a410SGeoff Levand };
255