xref: /OK3568_Linux_fs/kernel/drivers/usb/host/ohci-ps3.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  PS3 OHCI Host Controller driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  Copyright (C) 2006 Sony Computer Entertainment Inc.
6*4882a593Smuzhiyun  *  Copyright 2006 Sony Corp.
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <asm/firmware.h>
10*4882a593Smuzhiyun #include <asm/ps3.h>
11*4882a593Smuzhiyun 
ps3_ohci_hc_reset(struct usb_hcd * hcd)12*4882a593Smuzhiyun static int ps3_ohci_hc_reset(struct usb_hcd *hcd)
13*4882a593Smuzhiyun {
14*4882a593Smuzhiyun 	struct ohci_hcd *ohci = hcd_to_ohci(hcd);
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun 	ohci->flags |= OHCI_QUIRK_BE_MMIO;
17*4882a593Smuzhiyun 	ohci_hcd_init(ohci);
18*4882a593Smuzhiyun 	return ohci_init(ohci);
19*4882a593Smuzhiyun }
20*4882a593Smuzhiyun 
ps3_ohci_hc_start(struct usb_hcd * hcd)21*4882a593Smuzhiyun static int ps3_ohci_hc_start(struct usb_hcd *hcd)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun 	int result;
24*4882a593Smuzhiyun 	struct ohci_hcd *ohci = hcd_to_ohci(hcd);
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun 	/* Handle root hub init quirk in spider south bridge. */
27*4882a593Smuzhiyun 	/* Also set PwrOn2PwrGood to 0x7f (254ms). */
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun 	ohci_writel(ohci, 0x7f000000 | RH_A_PSM | RH_A_OCPM,
30*4882a593Smuzhiyun 		&ohci->regs->roothub.a);
31*4882a593Smuzhiyun 	ohci_writel(ohci, 0x00060000, &ohci->regs->roothub.b);
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun 	result = ohci_run(ohci);
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun 	if (result < 0) {
36*4882a593Smuzhiyun 		dev_err(hcd->self.controller, "can't start %s\n",
37*4882a593Smuzhiyun 			hcd->self.bus_name);
38*4882a593Smuzhiyun 		ohci_stop(hcd);
39*4882a593Smuzhiyun 	}
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun 	return result;
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun static const struct hc_driver ps3_ohci_hc_driver = {
45*4882a593Smuzhiyun 	.description		= hcd_name,
46*4882a593Smuzhiyun 	.product_desc		= "PS3 OHCI Host Controller",
47*4882a593Smuzhiyun 	.hcd_priv_size		= sizeof(struct ohci_hcd),
48*4882a593Smuzhiyun 	.irq			= ohci_irq,
49*4882a593Smuzhiyun 	.flags			= HCD_MEMORY | HCD_DMA | HCD_USB11,
50*4882a593Smuzhiyun 	.reset			= ps3_ohci_hc_reset,
51*4882a593Smuzhiyun 	.start			= ps3_ohci_hc_start,
52*4882a593Smuzhiyun 	.stop			= ohci_stop,
53*4882a593Smuzhiyun 	.shutdown		= ohci_shutdown,
54*4882a593Smuzhiyun 	.urb_enqueue		= ohci_urb_enqueue,
55*4882a593Smuzhiyun 	.urb_dequeue		= ohci_urb_dequeue,
56*4882a593Smuzhiyun 	.endpoint_disable	= ohci_endpoint_disable,
57*4882a593Smuzhiyun 	.get_frame_number	= ohci_get_frame,
58*4882a593Smuzhiyun 	.hub_status_data	= ohci_hub_status_data,
59*4882a593Smuzhiyun 	.hub_control		= ohci_hub_control,
60*4882a593Smuzhiyun 	.start_port_reset	= ohci_start_port_reset,
61*4882a593Smuzhiyun #if defined(CONFIG_PM)
62*4882a593Smuzhiyun 	.bus_suspend 		= ohci_bus_suspend,
63*4882a593Smuzhiyun 	.bus_resume 		= ohci_bus_resume,
64*4882a593Smuzhiyun #endif
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun 
ps3_ohci_probe(struct ps3_system_bus_device * dev)67*4882a593Smuzhiyun static int ps3_ohci_probe(struct ps3_system_bus_device *dev)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun 	int result;
70*4882a593Smuzhiyun 	struct usb_hcd *hcd;
71*4882a593Smuzhiyun 	unsigned int virq;
72*4882a593Smuzhiyun 	static u64 dummy_mask;
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun 	if (usb_disabled()) {
75*4882a593Smuzhiyun 		result = -ENODEV;
76*4882a593Smuzhiyun 		goto fail_start;
77*4882a593Smuzhiyun 	}
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun 	result = ps3_open_hv_device(dev);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	if (result) {
82*4882a593Smuzhiyun 		dev_dbg(&dev->core, "%s:%d: ps3_open_hv_device failed: %s\n",
83*4882a593Smuzhiyun 			__func__, __LINE__, ps3_result(result));
84*4882a593Smuzhiyun 		result = -EPERM;
85*4882a593Smuzhiyun 		goto fail_open;
86*4882a593Smuzhiyun 	}
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun 	result = ps3_dma_region_create(dev->d_region);
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 	if (result) {
91*4882a593Smuzhiyun 		dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: "
92*4882a593Smuzhiyun 			"(%d)\n", __func__, __LINE__, result);
93*4882a593Smuzhiyun 		BUG_ON("check region type");
94*4882a593Smuzhiyun 		goto fail_dma_region;
95*4882a593Smuzhiyun 	}
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun 	result = ps3_mmio_region_create(dev->m_region);
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun 	if (result) {
100*4882a593Smuzhiyun 		dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
101*4882a593Smuzhiyun 			__func__, __LINE__);
102*4882a593Smuzhiyun 		result = -EPERM;
103*4882a593Smuzhiyun 		goto fail_mmio_region;
104*4882a593Smuzhiyun 	}
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun 	dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
107*4882a593Smuzhiyun 		__LINE__, dev->m_region->lpar_addr);
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun 	result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 	if (result) {
112*4882a593Smuzhiyun 		dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
113*4882a593Smuzhiyun 			__func__, __LINE__, virq);
114*4882a593Smuzhiyun 		result = -EPERM;
115*4882a593Smuzhiyun 		goto fail_irq;
116*4882a593Smuzhiyun 	}
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun 	dummy_mask = DMA_BIT_MASK(32);
119*4882a593Smuzhiyun 	dev->core.dma_mask = &dummy_mask;
120*4882a593Smuzhiyun 	dma_set_coherent_mask(&dev->core, dummy_mask);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	hcd = usb_create_hcd(&ps3_ohci_hc_driver, &dev->core, dev_name(&dev->core));
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun 	if (!hcd) {
125*4882a593Smuzhiyun 		dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
126*4882a593Smuzhiyun 			__LINE__);
127*4882a593Smuzhiyun 		result = -ENOMEM;
128*4882a593Smuzhiyun 		goto fail_create_hcd;
129*4882a593Smuzhiyun 	}
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun 	hcd->rsrc_start = dev->m_region->lpar_addr;
132*4882a593Smuzhiyun 	hcd->rsrc_len = dev->m_region->len;
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun 	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name))
135*4882a593Smuzhiyun 		dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n",
136*4882a593Smuzhiyun 			__func__, __LINE__);
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 	hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	if (!hcd->regs) {
141*4882a593Smuzhiyun 		dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
142*4882a593Smuzhiyun 			__LINE__);
143*4882a593Smuzhiyun 		result = -EPERM;
144*4882a593Smuzhiyun 		goto fail_ioremap;
145*4882a593Smuzhiyun 	}
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun 	dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
148*4882a593Smuzhiyun 		(unsigned long)hcd->rsrc_start);
149*4882a593Smuzhiyun 	dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len   %lxh\n", __func__, __LINE__,
150*4882a593Smuzhiyun 		(unsigned long)hcd->rsrc_len);
151*4882a593Smuzhiyun 	dev_dbg(&dev->core, "%s:%d: hcd->regs       %lxh\n", __func__, __LINE__,
152*4882a593Smuzhiyun 		(unsigned long)hcd->regs);
153*4882a593Smuzhiyun 	dev_dbg(&dev->core, "%s:%d: virq            %lu\n", __func__, __LINE__,
154*4882a593Smuzhiyun 		(unsigned long)virq);
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun 	ps3_system_bus_set_drvdata(dev, hcd);
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun 	result = usb_add_hcd(hcd, virq, 0);
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun 	if (result) {
161*4882a593Smuzhiyun 		dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
162*4882a593Smuzhiyun 			__func__, __LINE__, result);
163*4882a593Smuzhiyun 		goto fail_add_hcd;
164*4882a593Smuzhiyun 	}
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	device_wakeup_enable(hcd->self.controller);
167*4882a593Smuzhiyun 	return result;
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun fail_add_hcd:
170*4882a593Smuzhiyun 	iounmap(hcd->regs);
171*4882a593Smuzhiyun fail_ioremap:
172*4882a593Smuzhiyun 	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
173*4882a593Smuzhiyun 	usb_put_hcd(hcd);
174*4882a593Smuzhiyun fail_create_hcd:
175*4882a593Smuzhiyun 	ps3_io_irq_destroy(virq);
176*4882a593Smuzhiyun fail_irq:
177*4882a593Smuzhiyun 	ps3_free_mmio_region(dev->m_region);
178*4882a593Smuzhiyun fail_mmio_region:
179*4882a593Smuzhiyun 	ps3_dma_region_free(dev->d_region);
180*4882a593Smuzhiyun fail_dma_region:
181*4882a593Smuzhiyun 	ps3_close_hv_device(dev);
182*4882a593Smuzhiyun fail_open:
183*4882a593Smuzhiyun fail_start:
184*4882a593Smuzhiyun 	return result;
185*4882a593Smuzhiyun }
186*4882a593Smuzhiyun 
ps3_ohci_remove(struct ps3_system_bus_device * dev)187*4882a593Smuzhiyun static int ps3_ohci_remove(struct ps3_system_bus_device *dev)
188*4882a593Smuzhiyun {
189*4882a593Smuzhiyun 	unsigned int tmp;
190*4882a593Smuzhiyun 	struct usb_hcd *hcd = ps3_system_bus_get_drvdata(dev);
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	BUG_ON(!hcd);
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun 	dev_dbg(&dev->core, "%s:%d: regs %p\n", __func__, __LINE__, hcd->regs);
195*4882a593Smuzhiyun 	dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq);
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun 	tmp = hcd->irq;
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 	ohci_shutdown(hcd);
200*4882a593Smuzhiyun 	usb_remove_hcd(hcd);
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	ps3_system_bus_set_drvdata(dev, NULL);
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun 	BUG_ON(!hcd->regs);
205*4882a593Smuzhiyun 	iounmap(hcd->regs);
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
208*4882a593Smuzhiyun 	usb_put_hcd(hcd);
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun 	ps3_io_irq_destroy(tmp);
211*4882a593Smuzhiyun 	ps3_free_mmio_region(dev->m_region);
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun 	ps3_dma_region_free(dev->d_region);
214*4882a593Smuzhiyun 	ps3_close_hv_device(dev);
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun 	return 0;
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun 
ps3_ohci_driver_register(struct ps3_system_bus_driver * drv)219*4882a593Smuzhiyun static int __init ps3_ohci_driver_register(struct ps3_system_bus_driver *drv)
220*4882a593Smuzhiyun {
221*4882a593Smuzhiyun 	return firmware_has_feature(FW_FEATURE_PS3_LV1)
222*4882a593Smuzhiyun 		? ps3_system_bus_driver_register(drv)
223*4882a593Smuzhiyun 		: 0;
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun 
ps3_ohci_driver_unregister(struct ps3_system_bus_driver * drv)226*4882a593Smuzhiyun static void ps3_ohci_driver_unregister(struct ps3_system_bus_driver *drv)
227*4882a593Smuzhiyun {
228*4882a593Smuzhiyun 	if (firmware_has_feature(FW_FEATURE_PS3_LV1))
229*4882a593Smuzhiyun 		ps3_system_bus_driver_unregister(drv);
230*4882a593Smuzhiyun }
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun MODULE_ALIAS(PS3_MODULE_ALIAS_OHCI);
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun static struct ps3_system_bus_driver ps3_ohci_driver = {
235*4882a593Smuzhiyun 	.core.name = "ps3-ohci-driver",
236*4882a593Smuzhiyun 	.core.owner = THIS_MODULE,
237*4882a593Smuzhiyun 	.match_id = PS3_MATCH_ID_OHCI,
238*4882a593Smuzhiyun 	.probe = ps3_ohci_probe,
239*4882a593Smuzhiyun 	.remove = ps3_ohci_remove,
240*4882a593Smuzhiyun 	.shutdown = ps3_ohci_remove,
241*4882a593Smuzhiyun };
242