Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  *  PS3 EHCI Host Controller driver
0004  *
0005  *  Copyright (C) 2006 Sony Computer Entertainment Inc.
0006  *  Copyright 2006 Sony Corp.
0007  */
0008 
0009 #include <asm/firmware.h>
0010 #include <asm/ps3.h>
0011 
0012 static void ps3_ehci_setup_insnreg(struct ehci_hcd *ehci)
0013 {
0014     /* PS3 HC internal setup register offsets. */
0015 
0016     enum ps3_ehci_hc_insnreg {
0017         ps3_ehci_hc_insnreg01 = 0x084,
0018         ps3_ehci_hc_insnreg02 = 0x088,
0019         ps3_ehci_hc_insnreg03 = 0x08c,
0020     };
0021 
0022     /* PS3 EHCI HC errata fix 316 - The PS3 EHCI HC will reset its
0023      * internal INSNREGXX setup regs back to the chip default values
0024      * on Host Controller Reset (CMD_RESET) or Light Host Controller
0025      * Reset (CMD_LRESET).  The work-around for this is for the HC
0026      * driver to re-initialise these regs when ever the HC is reset.
0027      */
0028 
0029     /* Set burst transfer counts to 256 out, 32 in. */
0030 
0031     writel_be(0x01000020, (void __iomem *)ehci->regs +
0032         ps3_ehci_hc_insnreg01);
0033 
0034     /* Enable burst transfer counts. */
0035 
0036     writel_be(0x00000001, (void __iomem *)ehci->regs +
0037         ps3_ehci_hc_insnreg03);
0038 }
0039 
0040 static int ps3_ehci_hc_reset(struct usb_hcd *hcd)
0041 {
0042     int result;
0043     struct ehci_hcd *ehci = hcd_to_ehci(hcd);
0044 
0045     ehci->big_endian_mmio = 1;
0046     ehci->caps = hcd->regs;
0047 
0048     result = ehci_setup(hcd);
0049     if (result)
0050         return result;
0051 
0052     ps3_ehci_setup_insnreg(ehci);
0053 
0054     return result;
0055 }
0056 
0057 static const struct hc_driver ps3_ehci_hc_driver = {
0058     .description        = hcd_name,
0059     .product_desc       = "PS3 EHCI Host Controller",
0060     .hcd_priv_size      = sizeof(struct ehci_hcd),
0061     .irq            = ehci_irq,
0062     .flags          = HCD_MEMORY | HCD_DMA | HCD_USB2 | HCD_BH,
0063     .reset          = ps3_ehci_hc_reset,
0064     .start          = ehci_run,
0065     .stop           = ehci_stop,
0066     .shutdown       = ehci_shutdown,
0067     .urb_enqueue        = ehci_urb_enqueue,
0068     .urb_dequeue        = ehci_urb_dequeue,
0069     .endpoint_disable   = ehci_endpoint_disable,
0070     .endpoint_reset     = ehci_endpoint_reset,
0071     .get_frame_number   = ehci_get_frame,
0072     .hub_status_data    = ehci_hub_status_data,
0073     .hub_control        = ehci_hub_control,
0074 #if defined(CONFIG_PM)
0075     .bus_suspend        = ehci_bus_suspend,
0076     .bus_resume     = ehci_bus_resume,
0077 #endif
0078     .relinquish_port    = ehci_relinquish_port,
0079     .port_handed_over   = ehci_port_handed_over,
0080 
0081     .clear_tt_buffer_complete   = ehci_clear_tt_buffer_complete,
0082 };
0083 
0084 static int ps3_ehci_probe(struct ps3_system_bus_device *dev)
0085 {
0086     int result;
0087     struct usb_hcd *hcd;
0088     unsigned int virq;
0089     static u64 dummy_mask;
0090 
0091     if (usb_disabled()) {
0092         result = -ENODEV;
0093         goto fail_start;
0094     }
0095 
0096     result = ps3_open_hv_device(dev);
0097 
0098     if (result) {
0099         dev_dbg(&dev->core, "%s:%d: ps3_open_hv_device failed\n",
0100             __func__, __LINE__);
0101         goto fail_open;
0102     }
0103 
0104     result = ps3_dma_region_create(dev->d_region);
0105 
0106     if (result) {
0107         dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: "
0108             "(%d)\n", __func__, __LINE__, result);
0109         BUG_ON("check region type");
0110         goto fail_dma_region;
0111     }
0112 
0113     result = ps3_mmio_region_create(dev->m_region);
0114 
0115     if (result) {
0116         dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
0117             __func__, __LINE__);
0118         result = -EPERM;
0119         goto fail_mmio_region;
0120     }
0121 
0122     dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
0123         __LINE__, dev->m_region->lpar_addr);
0124 
0125     result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
0126 
0127     if (result) {
0128         dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
0129             __func__, __LINE__, virq);
0130         result = -EPERM;
0131         goto fail_irq;
0132     }
0133 
0134     dummy_mask = DMA_BIT_MASK(32);
0135     dev->core.dma_mask = &dummy_mask;
0136     dma_set_coherent_mask(&dev->core, dummy_mask);
0137 
0138     hcd = usb_create_hcd(&ps3_ehci_hc_driver, &dev->core, dev_name(&dev->core));
0139 
0140     if (!hcd) {
0141         dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
0142             __LINE__);
0143         result = -ENOMEM;
0144         goto fail_create_hcd;
0145     }
0146 
0147     hcd->rsrc_start = dev->m_region->lpar_addr;
0148     hcd->rsrc_len = dev->m_region->len;
0149 
0150     if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name))
0151         dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n",
0152             __func__, __LINE__);
0153 
0154     hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
0155 
0156     if (!hcd->regs) {
0157         dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
0158             __LINE__);
0159         result = -EPERM;
0160         goto fail_ioremap;
0161     }
0162 
0163     dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
0164         (unsigned long)hcd->rsrc_start);
0165     dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len   %lxh\n", __func__, __LINE__,
0166         (unsigned long)hcd->rsrc_len);
0167     dev_dbg(&dev->core, "%s:%d: hcd->regs       %lxh\n", __func__, __LINE__,
0168         (unsigned long)hcd->regs);
0169     dev_dbg(&dev->core, "%s:%d: virq            %lu\n", __func__, __LINE__,
0170         (unsigned long)virq);
0171 
0172     ps3_system_bus_set_drvdata(dev, hcd);
0173 
0174     result = usb_add_hcd(hcd, virq, 0);
0175 
0176     if (result) {
0177         dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
0178             __func__, __LINE__, result);
0179         goto fail_add_hcd;
0180     }
0181 
0182     device_wakeup_enable(hcd->self.controller);
0183     return result;
0184 
0185 fail_add_hcd:
0186     iounmap(hcd->regs);
0187 fail_ioremap:
0188     release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
0189     usb_put_hcd(hcd);
0190 fail_create_hcd:
0191     ps3_io_irq_destroy(virq);
0192 fail_irq:
0193     ps3_free_mmio_region(dev->m_region);
0194 fail_mmio_region:
0195     ps3_dma_region_free(dev->d_region);
0196 fail_dma_region:
0197     ps3_close_hv_device(dev);
0198 fail_open:
0199 fail_start:
0200     return result;
0201 }
0202 
0203 static void ps3_ehci_remove(struct ps3_system_bus_device *dev)
0204 {
0205     unsigned int tmp;
0206     struct usb_hcd *hcd = ps3_system_bus_get_drvdata(dev);
0207 
0208     BUG_ON(!hcd);
0209 
0210     dev_dbg(&dev->core, "%s:%d: regs %p\n", __func__, __LINE__, hcd->regs);
0211     dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq);
0212 
0213     tmp = hcd->irq;
0214 
0215     usb_remove_hcd(hcd);
0216 
0217     ps3_system_bus_set_drvdata(dev, NULL);
0218 
0219     BUG_ON(!hcd->regs);
0220     iounmap(hcd->regs);
0221 
0222     release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
0223     usb_put_hcd(hcd);
0224 
0225     ps3_io_irq_destroy(tmp);
0226     ps3_free_mmio_region(dev->m_region);
0227 
0228     ps3_dma_region_free(dev->d_region);
0229     ps3_close_hv_device(dev);
0230 }
0231 
0232 static int __init ps3_ehci_driver_register(struct ps3_system_bus_driver *drv)
0233 {
0234     return firmware_has_feature(FW_FEATURE_PS3_LV1)
0235         ? ps3_system_bus_driver_register(drv)
0236         : 0;
0237 }
0238 
0239 static void ps3_ehci_driver_unregister(struct ps3_system_bus_driver *drv)
0240 {
0241     if (firmware_has_feature(FW_FEATURE_PS3_LV1))
0242         ps3_system_bus_driver_unregister(drv);
0243 }
0244 
0245 MODULE_ALIAS(PS3_MODULE_ALIAS_EHCI);
0246 
0247 static struct ps3_system_bus_driver ps3_ehci_driver = {
0248     .core.name = "ps3-ehci-driver",
0249     .core.owner = THIS_MODULE,
0250     .match_id = PS3_MATCH_ID_EHCI,
0251     .probe = ps3_ehci_probe,
0252     .remove = ps3_ehci_remove,
0253     .shutdown = ps3_ehci_remove,
0254 };