1ad75a410SGeoff Levand /* 2ad75a410SGeoff Levand * PS3 EHCI Host Controller driver 3ad75a410SGeoff Levand * 4ad75a410SGeoff Levand * Copyright (C) 2006 Sony Computer Entertainment Inc. 5ad75a410SGeoff Levand * Copyright 2006 Sony Corp. 6ad75a410SGeoff Levand * 7ad75a410SGeoff Levand * This program is free software; you can redistribute it and/or modify 8ad75a410SGeoff Levand * it under the terms of the GNU General Public License as published by 9ad75a410SGeoff Levand * the Free Software Foundation; version 2 of the License. 10ad75a410SGeoff Levand * 11ad75a410SGeoff Levand * This program is distributed in the hope that it will be useful, 12ad75a410SGeoff Levand * but WITHOUT ANY WARRANTY; without even the implied warranty of 13ad75a410SGeoff Levand * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14ad75a410SGeoff Levand * GNU General Public License for more details. 15ad75a410SGeoff Levand * 16ad75a410SGeoff Levand * You should have received a copy of the GNU General Public License 17ad75a410SGeoff Levand * along with this program; if not, write to the Free Software 18ad75a410SGeoff Levand * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19ad75a410SGeoff Levand */ 20ad75a410SGeoff Levand 217a4eb7fdSGeoff Levand #include <asm/firmware.h> 22ad75a410SGeoff Levand #include <asm/ps3.h> 23ad75a410SGeoff Levand 24ad75a410SGeoff Levand static int ps3_ehci_hc_reset(struct usb_hcd *hcd) 25ad75a410SGeoff Levand { 26ad75a410SGeoff Levand int result; 27ad75a410SGeoff Levand struct ehci_hcd *ehci = hcd_to_ehci(hcd); 28ad75a410SGeoff Levand 29ad75a410SGeoff Levand ehci->big_endian_mmio = 1; 30ad75a410SGeoff Levand 31ad75a410SGeoff Levand ehci->caps = hcd->regs; 32c430131aSJan Andersson ehci->regs = hcd->regs + HC_LENGTH(ehci, ehci_readl(ehci, 33ad75a410SGeoff Levand &ehci->caps->hc_capbase)); 34ad75a410SGeoff Levand 35ad75a410SGeoff Levand dbg_hcs_params(ehci, "reset"); 36ad75a410SGeoff Levand dbg_hcc_params(ehci, "reset"); 37ad75a410SGeoff Levand 38ad75a410SGeoff Levand ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); 39ad75a410SGeoff Levand 40ad75a410SGeoff Levand result = ehci_halt(ehci); 41ad75a410SGeoff Levand 42ad75a410SGeoff Levand if (result) 43ad75a410SGeoff Levand return result; 44ad75a410SGeoff Levand 45ad75a410SGeoff Levand result = ehci_init(hcd); 46ad75a410SGeoff Levand 47ad75a410SGeoff Levand if (result) 48ad75a410SGeoff Levand return result; 49ad75a410SGeoff Levand 50af1c51fcSMarcelo Tosatti ehci_reset(ehci); 51ad75a410SGeoff Levand 52ad75a410SGeoff Levand return result; 53ad75a410SGeoff Levand } 54ad75a410SGeoff Levand 55ad75a410SGeoff Levand static const struct hc_driver ps3_ehci_hc_driver = { 56ad75a410SGeoff Levand .description = hcd_name, 57ad75a410SGeoff Levand .product_desc = "PS3 EHCI Host Controller", 58ad75a410SGeoff Levand .hcd_priv_size = sizeof(struct ehci_hcd), 59ad75a410SGeoff Levand .irq = ehci_irq, 60ad75a410SGeoff Levand .flags = HCD_MEMORY | HCD_USB2, 61ad75a410SGeoff Levand .reset = ps3_ehci_hc_reset, 62ad75a410SGeoff Levand .start = ehci_run, 63ad75a410SGeoff Levand .stop = ehci_stop, 64ad75a410SGeoff Levand .shutdown = ehci_shutdown, 65ad75a410SGeoff Levand .urb_enqueue = ehci_urb_enqueue, 66ad75a410SGeoff Levand .urb_dequeue = ehci_urb_dequeue, 67ad75a410SGeoff Levand .endpoint_disable = ehci_endpoint_disable, 68b18ffd49SAlan Stern .endpoint_reset = ehci_endpoint_reset, 69ad75a410SGeoff Levand .get_frame_number = ehci_get_frame, 70ad75a410SGeoff Levand .hub_status_data = ehci_hub_status_data, 71ad75a410SGeoff Levand .hub_control = ehci_hub_control, 72ad75a410SGeoff Levand #if defined(CONFIG_PM) 73ad75a410SGeoff Levand .bus_suspend = ehci_bus_suspend, 74ad75a410SGeoff Levand .bus_resume = ehci_bus_resume, 75ad75a410SGeoff Levand #endif 7690da096eSBalaji Rao .relinquish_port = ehci_relinquish_port, 773a31155cSAlan Stern .port_handed_over = ehci_port_handed_over, 78914b7012SAlan Stern 79914b7012SAlan Stern .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 80ad75a410SGeoff Levand }; 81ad75a410SGeoff Levand 8231348517SGeert Uytterhoeven static int __devinit ps3_ehci_probe(struct ps3_system_bus_device *dev) 83ad75a410SGeoff Levand { 84ad75a410SGeoff Levand int result; 85ad75a410SGeoff Levand struct usb_hcd *hcd; 86ad75a410SGeoff Levand unsigned int virq; 87284901a9SYang Hongyang static u64 dummy_mask = DMA_BIT_MASK(32); 88ad75a410SGeoff Levand 89ad75a410SGeoff Levand if (usb_disabled()) { 90ad75a410SGeoff Levand result = -ENODEV; 91ad75a410SGeoff Levand goto fail_start; 92ad75a410SGeoff Levand } 93ad75a410SGeoff Levand 947a4eb7fdSGeoff Levand result = ps3_open_hv_device(dev); 957a4eb7fdSGeoff Levand 967a4eb7fdSGeoff Levand if (result) { 977a4eb7fdSGeoff Levand dev_dbg(&dev->core, "%s:%d: ps3_open_hv_device failed\n", 987a4eb7fdSGeoff Levand __func__, __LINE__); 997a4eb7fdSGeoff Levand goto fail_open; 1007a4eb7fdSGeoff Levand } 1017a4eb7fdSGeoff Levand 1027a4eb7fdSGeoff Levand result = ps3_dma_region_create(dev->d_region); 1037a4eb7fdSGeoff Levand 1047a4eb7fdSGeoff Levand if (result) { 1057a4eb7fdSGeoff Levand dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: " 1067a4eb7fdSGeoff Levand "(%d)\n", __func__, __LINE__, result); 1077a4eb7fdSGeoff Levand BUG_ON("check region type"); 1087a4eb7fdSGeoff Levand goto fail_dma_region; 1097a4eb7fdSGeoff Levand } 1107a4eb7fdSGeoff Levand 111ad75a410SGeoff Levand result = ps3_mmio_region_create(dev->m_region); 112ad75a410SGeoff Levand 113ad75a410SGeoff Levand if (result) { 114ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n", 115ad75a410SGeoff Levand __func__, __LINE__); 116ad75a410SGeoff Levand result = -EPERM; 1177a4eb7fdSGeoff Levand goto fail_mmio_region; 118ad75a410SGeoff Levand } 119ad75a410SGeoff Levand 120ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__, 121ad75a410SGeoff Levand __LINE__, dev->m_region->lpar_addr); 122ad75a410SGeoff Levand 123dc4f60c2SGeoff Levand result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq); 124ad75a410SGeoff Levand 125ad75a410SGeoff Levand if (result) { 126ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n", 127ad75a410SGeoff Levand __func__, __LINE__, virq); 128ad75a410SGeoff Levand result = -EPERM; 129ad75a410SGeoff Levand goto fail_irq; 130ad75a410SGeoff Levand } 131ad75a410SGeoff Levand 132ad75a410SGeoff Levand dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */ 133ad75a410SGeoff Levand 1347071a3ceSKay Sievers hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev_name(&dev->core)); 135ad75a410SGeoff Levand 136ad75a410SGeoff Levand if (!hcd) { 137ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__, 138ad75a410SGeoff Levand __LINE__); 139ad75a410SGeoff Levand result = -ENOMEM; 140ad75a410SGeoff Levand goto fail_create_hcd; 141ad75a410SGeoff Levand } 142ad75a410SGeoff Levand 143ad75a410SGeoff Levand hcd->rsrc_start = dev->m_region->lpar_addr; 144ad75a410SGeoff Levand hcd->rsrc_len = dev->m_region->len; 1457a4eb7fdSGeoff Levand 1467a4eb7fdSGeoff Levand if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) 1477a4eb7fdSGeoff Levand dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n", 1487a4eb7fdSGeoff Levand __func__, __LINE__); 1497a4eb7fdSGeoff Levand 150ad75a410SGeoff Levand hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len); 151ad75a410SGeoff Levand 152ad75a410SGeoff Levand if (!hcd->regs) { 153ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__, 154ad75a410SGeoff Levand __LINE__); 155ad75a410SGeoff Levand result = -EPERM; 156ad75a410SGeoff Levand goto fail_ioremap; 157ad75a410SGeoff Levand } 158ad75a410SGeoff Levand 159ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__, 160ad75a410SGeoff Levand (unsigned long)hcd->rsrc_start); 161ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len %lxh\n", __func__, __LINE__, 162ad75a410SGeoff Levand (unsigned long)hcd->rsrc_len); 163ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: hcd->regs %lxh\n", __func__, __LINE__, 164ad75a410SGeoff Levand (unsigned long)hcd->regs); 165ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: virq %lu\n", __func__, __LINE__, 166ad75a410SGeoff Levand (unsigned long)virq); 167ad75a410SGeoff Levand 16803fa68c2SGeert Uytterhoeven ps3_system_bus_set_drvdata(dev, hcd); 169ad75a410SGeoff Levand 170*b5dd18d8SYong Zhang result = usb_add_hcd(hcd, virq, 0); 171ad75a410SGeoff Levand 172ad75a410SGeoff Levand if (result) { 173ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n", 174ad75a410SGeoff Levand __func__, __LINE__, result); 175ad75a410SGeoff Levand goto fail_add_hcd; 176ad75a410SGeoff Levand } 177ad75a410SGeoff Levand 178ad75a410SGeoff Levand return result; 179ad75a410SGeoff Levand 180ad75a410SGeoff Levand fail_add_hcd: 181ad75a410SGeoff Levand iounmap(hcd->regs); 182ad75a410SGeoff Levand fail_ioremap: 1837a4eb7fdSGeoff Levand release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 184ad75a410SGeoff Levand usb_put_hcd(hcd); 185ad75a410SGeoff Levand fail_create_hcd: 186dc4f60c2SGeoff Levand ps3_io_irq_destroy(virq); 187ad75a410SGeoff Levand fail_irq: 188ad75a410SGeoff Levand ps3_free_mmio_region(dev->m_region); 1897a4eb7fdSGeoff Levand fail_mmio_region: 1907a4eb7fdSGeoff Levand ps3_dma_region_free(dev->d_region); 1917a4eb7fdSGeoff Levand fail_dma_region: 1927a4eb7fdSGeoff Levand ps3_close_hv_device(dev); 1937a4eb7fdSGeoff Levand fail_open: 194ad75a410SGeoff Levand fail_start: 195ad75a410SGeoff Levand return result; 196ad75a410SGeoff Levand } 197ad75a410SGeoff Levand 1987a4eb7fdSGeoff Levand static int ps3_ehci_remove(struct ps3_system_bus_device *dev) 199ad75a410SGeoff Levand { 2007a4eb7fdSGeoff Levand unsigned int tmp; 20103fa68c2SGeert Uytterhoeven struct usb_hcd *hcd = ps3_system_bus_get_drvdata(dev); 202ad75a410SGeoff Levand 2037a4eb7fdSGeoff Levand BUG_ON(!hcd); 2047a4eb7fdSGeoff Levand 2057a4eb7fdSGeoff Levand dev_dbg(&dev->core, "%s:%d: regs %p\n", __func__, __LINE__, hcd->regs); 2067a4eb7fdSGeoff Levand dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq); 2077a4eb7fdSGeoff Levand 2087a4eb7fdSGeoff Levand tmp = hcd->irq; 2097a4eb7fdSGeoff Levand 210ddcb01ffSGeoff Levand ehci_shutdown(hcd); 2117a4eb7fdSGeoff Levand usb_remove_hcd(hcd); 2127a4eb7fdSGeoff Levand 21303fa68c2SGeert Uytterhoeven ps3_system_bus_set_drvdata(dev, NULL); 214ad75a410SGeoff Levand 2157a4eb7fdSGeoff Levand BUG_ON(!hcd->regs); 2167a4eb7fdSGeoff Levand iounmap(hcd->regs); 2177a4eb7fdSGeoff Levand 2187a4eb7fdSGeoff Levand release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 2197a4eb7fdSGeoff Levand usb_put_hcd(hcd); 2207a4eb7fdSGeoff Levand 2217a4eb7fdSGeoff Levand ps3_io_irq_destroy(tmp); 2227a4eb7fdSGeoff Levand ps3_free_mmio_region(dev->m_region); 2237a4eb7fdSGeoff Levand 2247a4eb7fdSGeoff Levand ps3_dma_region_free(dev->d_region); 2257a4eb7fdSGeoff Levand ps3_close_hv_device(dev); 2267a4eb7fdSGeoff Levand 227ad75a410SGeoff Levand return 0; 228ad75a410SGeoff Levand } 229ad75a410SGeoff Levand 23031348517SGeert Uytterhoeven static int __init ps3_ehci_driver_register(struct ps3_system_bus_driver *drv) 2317a4eb7fdSGeoff Levand { 2327a4eb7fdSGeoff Levand return firmware_has_feature(FW_FEATURE_PS3_LV1) 2337a4eb7fdSGeoff Levand ? ps3_system_bus_driver_register(drv) 2347a4eb7fdSGeoff Levand : 0; 2357a4eb7fdSGeoff Levand } 236ad75a410SGeoff Levand 2377a4eb7fdSGeoff Levand static void ps3_ehci_driver_unregister(struct ps3_system_bus_driver *drv) 2387a4eb7fdSGeoff Levand { 2397a4eb7fdSGeoff Levand if (firmware_has_feature(FW_FEATURE_PS3_LV1)) 2407a4eb7fdSGeoff Levand ps3_system_bus_driver_unregister(drv); 2417a4eb7fdSGeoff Levand } 2427a4eb7fdSGeoff Levand 2437a4eb7fdSGeoff Levand MODULE_ALIAS(PS3_MODULE_ALIAS_EHCI); 2447a4eb7fdSGeoff Levand 2457a4eb7fdSGeoff Levand static struct ps3_system_bus_driver ps3_ehci_driver = { 2467a4eb7fdSGeoff Levand .core.name = "ps3-ehci-driver", 2477a4eb7fdSGeoff Levand .core.owner = THIS_MODULE, 248ad75a410SGeoff Levand .match_id = PS3_MATCH_ID_EHCI, 2497a4eb7fdSGeoff Levand .probe = ps3_ehci_probe, 2507a4eb7fdSGeoff Levand .remove = ps3_ehci_remove, 2517a4eb7fdSGeoff Levand .shutdown = ps3_ehci_remove, 252ad75a410SGeoff Levand }; 253