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 21*7a4eb7fdSGeoff 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; 32ad75a410SGeoff Levand ehci->regs = hcd->regs + HC_LENGTH(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 50ad75a410SGeoff Levand ehci_port_power(ehci, 0); 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, 68ad75a410SGeoff Levand .get_frame_number = ehci_get_frame, 69ad75a410SGeoff Levand .hub_status_data = ehci_hub_status_data, 70ad75a410SGeoff Levand .hub_control = ehci_hub_control, 71ad75a410SGeoff Levand #if defined(CONFIG_PM) 72ad75a410SGeoff Levand .bus_suspend = ehci_bus_suspend, 73ad75a410SGeoff Levand .bus_resume = ehci_bus_resume, 74ad75a410SGeoff Levand #endif 75ad75a410SGeoff Levand }; 76ad75a410SGeoff Levand 77*7a4eb7fdSGeoff Levand static int ps3_ehci_probe(struct ps3_system_bus_device *dev) 78ad75a410SGeoff Levand { 79ad75a410SGeoff Levand int result; 80ad75a410SGeoff Levand struct usb_hcd *hcd; 81ad75a410SGeoff Levand unsigned int virq; 82ad75a410SGeoff Levand static u64 dummy_mask = DMA_32BIT_MASK; 83ad75a410SGeoff Levand 84ad75a410SGeoff Levand if (usb_disabled()) { 85ad75a410SGeoff Levand result = -ENODEV; 86ad75a410SGeoff Levand goto fail_start; 87ad75a410SGeoff Levand } 88ad75a410SGeoff Levand 89*7a4eb7fdSGeoff Levand result = ps3_open_hv_device(dev); 90*7a4eb7fdSGeoff Levand 91*7a4eb7fdSGeoff Levand if (result) { 92*7a4eb7fdSGeoff Levand dev_dbg(&dev->core, "%s:%d: ps3_open_hv_device failed\n", 93*7a4eb7fdSGeoff Levand __func__, __LINE__); 94*7a4eb7fdSGeoff Levand goto fail_open; 95*7a4eb7fdSGeoff Levand } 96*7a4eb7fdSGeoff Levand 97*7a4eb7fdSGeoff Levand result = ps3_dma_region_create(dev->d_region); 98*7a4eb7fdSGeoff Levand 99*7a4eb7fdSGeoff Levand if (result) { 100*7a4eb7fdSGeoff Levand dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: " 101*7a4eb7fdSGeoff Levand "(%d)\n", __func__, __LINE__, result); 102*7a4eb7fdSGeoff Levand BUG_ON("check region type"); 103*7a4eb7fdSGeoff Levand goto fail_dma_region; 104*7a4eb7fdSGeoff Levand } 105*7a4eb7fdSGeoff Levand 106ad75a410SGeoff Levand result = ps3_mmio_region_create(dev->m_region); 107ad75a410SGeoff Levand 108ad75a410SGeoff Levand if (result) { 109ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n", 110ad75a410SGeoff Levand __func__, __LINE__); 111ad75a410SGeoff Levand result = -EPERM; 112*7a4eb7fdSGeoff Levand goto fail_mmio_region; 113ad75a410SGeoff Levand } 114ad75a410SGeoff Levand 115ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__, 116ad75a410SGeoff Levand __LINE__, dev->m_region->lpar_addr); 117ad75a410SGeoff Levand 118dc4f60c2SGeoff Levand result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq); 119ad75a410SGeoff Levand 120ad75a410SGeoff Levand if (result) { 121ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n", 122ad75a410SGeoff Levand __func__, __LINE__, virq); 123ad75a410SGeoff Levand result = -EPERM; 124ad75a410SGeoff Levand goto fail_irq; 125ad75a410SGeoff Levand } 126ad75a410SGeoff Levand 127ad75a410SGeoff Levand dev->core.power.power_state = PMSG_ON; 128ad75a410SGeoff Levand dev->core.dma_mask = &dummy_mask; /* FIXME: for improper usb code */ 129ad75a410SGeoff Levand 130ad75a410SGeoff Levand hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev->core.bus_id); 131ad75a410SGeoff Levand 132ad75a410SGeoff Levand if (!hcd) { 133ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__, 134ad75a410SGeoff Levand __LINE__); 135ad75a410SGeoff Levand result = -ENOMEM; 136ad75a410SGeoff Levand goto fail_create_hcd; 137ad75a410SGeoff Levand } 138ad75a410SGeoff Levand 139ad75a410SGeoff Levand hcd->rsrc_start = dev->m_region->lpar_addr; 140ad75a410SGeoff Levand hcd->rsrc_len = dev->m_region->len; 141*7a4eb7fdSGeoff Levand 142*7a4eb7fdSGeoff Levand if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) 143*7a4eb7fdSGeoff Levand dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n", 144*7a4eb7fdSGeoff Levand __func__, __LINE__); 145*7a4eb7fdSGeoff Levand 146ad75a410SGeoff Levand hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len); 147ad75a410SGeoff Levand 148ad75a410SGeoff Levand if (!hcd->regs) { 149ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__, 150ad75a410SGeoff Levand __LINE__); 151ad75a410SGeoff Levand result = -EPERM; 152ad75a410SGeoff Levand goto fail_ioremap; 153ad75a410SGeoff Levand } 154ad75a410SGeoff Levand 155ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__, 156ad75a410SGeoff Levand (unsigned long)hcd->rsrc_start); 157ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len %lxh\n", __func__, __LINE__, 158ad75a410SGeoff Levand (unsigned long)hcd->rsrc_len); 159ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: hcd->regs %lxh\n", __func__, __LINE__, 160ad75a410SGeoff Levand (unsigned long)hcd->regs); 161ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: virq %lu\n", __func__, __LINE__, 162ad75a410SGeoff Levand (unsigned long)virq); 163ad75a410SGeoff Levand 164ad75a410SGeoff Levand ps3_system_bus_set_driver_data(dev, hcd); 165ad75a410SGeoff Levand 166ad75a410SGeoff Levand result = usb_add_hcd(hcd, virq, IRQF_DISABLED); 167ad75a410SGeoff Levand 168ad75a410SGeoff Levand if (result) { 169ad75a410SGeoff Levand dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n", 170ad75a410SGeoff Levand __func__, __LINE__, result); 171ad75a410SGeoff Levand goto fail_add_hcd; 172ad75a410SGeoff Levand } 173ad75a410SGeoff Levand 174ad75a410SGeoff Levand return result; 175ad75a410SGeoff Levand 176ad75a410SGeoff Levand fail_add_hcd: 177ad75a410SGeoff Levand iounmap(hcd->regs); 178ad75a410SGeoff Levand fail_ioremap: 179*7a4eb7fdSGeoff Levand release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 180ad75a410SGeoff Levand usb_put_hcd(hcd); 181ad75a410SGeoff Levand fail_create_hcd: 182dc4f60c2SGeoff Levand ps3_io_irq_destroy(virq); 183ad75a410SGeoff Levand fail_irq: 184ad75a410SGeoff Levand ps3_free_mmio_region(dev->m_region); 185*7a4eb7fdSGeoff Levand fail_mmio_region: 186*7a4eb7fdSGeoff Levand ps3_dma_region_free(dev->d_region); 187*7a4eb7fdSGeoff Levand fail_dma_region: 188*7a4eb7fdSGeoff Levand ps3_close_hv_device(dev); 189*7a4eb7fdSGeoff Levand fail_open: 190ad75a410SGeoff Levand fail_start: 191ad75a410SGeoff Levand return result; 192ad75a410SGeoff Levand } 193ad75a410SGeoff Levand 194*7a4eb7fdSGeoff Levand static int ps3_ehci_remove(struct ps3_system_bus_device *dev) 195ad75a410SGeoff Levand { 196*7a4eb7fdSGeoff Levand unsigned int tmp; 197ad75a410SGeoff Levand struct usb_hcd *hcd = 198ad75a410SGeoff Levand (struct usb_hcd *)ps3_system_bus_get_driver_data(dev); 199ad75a410SGeoff Levand 200*7a4eb7fdSGeoff Levand BUG_ON(!hcd); 201*7a4eb7fdSGeoff Levand 202*7a4eb7fdSGeoff Levand dev_dbg(&dev->core, "%s:%d: regs %p\n", __func__, __LINE__, hcd->regs); 203*7a4eb7fdSGeoff Levand dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq); 204*7a4eb7fdSGeoff Levand 205*7a4eb7fdSGeoff Levand tmp = hcd->irq; 206*7a4eb7fdSGeoff Levand 207*7a4eb7fdSGeoff Levand usb_remove_hcd(hcd); 208*7a4eb7fdSGeoff Levand 209ad75a410SGeoff Levand ps3_system_bus_set_driver_data(dev, NULL); 210ad75a410SGeoff Levand 211*7a4eb7fdSGeoff Levand BUG_ON(!hcd->regs); 212*7a4eb7fdSGeoff Levand iounmap(hcd->regs); 213*7a4eb7fdSGeoff Levand 214*7a4eb7fdSGeoff Levand release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 215*7a4eb7fdSGeoff Levand usb_put_hcd(hcd); 216*7a4eb7fdSGeoff Levand 217*7a4eb7fdSGeoff Levand ps3_io_irq_destroy(tmp); 218*7a4eb7fdSGeoff Levand ps3_free_mmio_region(dev->m_region); 219*7a4eb7fdSGeoff Levand 220*7a4eb7fdSGeoff Levand ps3_dma_region_free(dev->d_region); 221*7a4eb7fdSGeoff Levand ps3_close_hv_device(dev); 222*7a4eb7fdSGeoff Levand 223ad75a410SGeoff Levand return 0; 224ad75a410SGeoff Levand } 225ad75a410SGeoff Levand 226*7a4eb7fdSGeoff Levand static int ps3_ehci_driver_register(struct ps3_system_bus_driver *drv) 227*7a4eb7fdSGeoff Levand { 228*7a4eb7fdSGeoff Levand return firmware_has_feature(FW_FEATURE_PS3_LV1) 229*7a4eb7fdSGeoff Levand ? ps3_system_bus_driver_register(drv) 230*7a4eb7fdSGeoff Levand : 0; 231*7a4eb7fdSGeoff Levand } 232ad75a410SGeoff Levand 233*7a4eb7fdSGeoff Levand static void ps3_ehci_driver_unregister(struct ps3_system_bus_driver *drv) 234*7a4eb7fdSGeoff Levand { 235*7a4eb7fdSGeoff Levand if (firmware_has_feature(FW_FEATURE_PS3_LV1)) 236*7a4eb7fdSGeoff Levand ps3_system_bus_driver_unregister(drv); 237*7a4eb7fdSGeoff Levand } 238*7a4eb7fdSGeoff Levand 239*7a4eb7fdSGeoff Levand MODULE_ALIAS(PS3_MODULE_ALIAS_EHCI); 240*7a4eb7fdSGeoff Levand 241*7a4eb7fdSGeoff Levand static struct ps3_system_bus_driver ps3_ehci_driver = { 242*7a4eb7fdSGeoff Levand .core.name = "ps3-ehci-driver", 243*7a4eb7fdSGeoff Levand .core.owner = THIS_MODULE, 244ad75a410SGeoff Levand .match_id = PS3_MATCH_ID_EHCI, 245*7a4eb7fdSGeoff Levand .probe = ps3_ehci_probe, 246*7a4eb7fdSGeoff Levand .remove = ps3_ehci_remove, 247*7a4eb7fdSGeoff Levand .shutdown = ps3_ehci_remove, 248ad75a410SGeoff Levand }; 249