0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <asm/firmware.h>
0010 #include <asm/ps3.h>
0011
0012 static int ps3_ohci_hc_reset(struct usb_hcd *hcd)
0013 {
0014 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
0015
0016 ohci->flags |= OHCI_QUIRK_BE_MMIO;
0017 ohci_hcd_init(ohci);
0018 return ohci_init(ohci);
0019 }
0020
0021 static int ps3_ohci_hc_start(struct usb_hcd *hcd)
0022 {
0023 int result;
0024 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
0025
0026
0027
0028
0029 ohci_writel(ohci, 0x7f000000 | RH_A_PSM | RH_A_OCPM,
0030 &ohci->regs->roothub.a);
0031 ohci_writel(ohci, 0x00060000, &ohci->regs->roothub.b);
0032
0033 result = ohci_run(ohci);
0034
0035 if (result < 0) {
0036 dev_err(hcd->self.controller, "can't start %s\n",
0037 hcd->self.bus_name);
0038 ohci_stop(hcd);
0039 }
0040
0041 return result;
0042 }
0043
0044 static const struct hc_driver ps3_ohci_hc_driver = {
0045 .description = hcd_name,
0046 .product_desc = "PS3 OHCI Host Controller",
0047 .hcd_priv_size = sizeof(struct ohci_hcd),
0048 .irq = ohci_irq,
0049 .flags = HCD_MEMORY | HCD_DMA | HCD_USB11,
0050 .reset = ps3_ohci_hc_reset,
0051 .start = ps3_ohci_hc_start,
0052 .stop = ohci_stop,
0053 .shutdown = ohci_shutdown,
0054 .urb_enqueue = ohci_urb_enqueue,
0055 .urb_dequeue = ohci_urb_dequeue,
0056 .endpoint_disable = ohci_endpoint_disable,
0057 .get_frame_number = ohci_get_frame,
0058 .hub_status_data = ohci_hub_status_data,
0059 .hub_control = ohci_hub_control,
0060 .start_port_reset = ohci_start_port_reset,
0061 #if defined(CONFIG_PM)
0062 .bus_suspend = ohci_bus_suspend,
0063 .bus_resume = ohci_bus_resume,
0064 #endif
0065 };
0066
0067 static int ps3_ohci_probe(struct ps3_system_bus_device *dev)
0068 {
0069 int result;
0070 struct usb_hcd *hcd;
0071 unsigned int virq;
0072 static u64 dummy_mask;
0073
0074 if (usb_disabled()) {
0075 result = -ENODEV;
0076 goto fail_start;
0077 }
0078
0079 result = ps3_open_hv_device(dev);
0080
0081 if (result) {
0082 dev_dbg(&dev->core, "%s:%d: ps3_open_hv_device failed: %s\n",
0083 __func__, __LINE__, ps3_result(result));
0084 result = -EPERM;
0085 goto fail_open;
0086 }
0087
0088 result = ps3_dma_region_create(dev->d_region);
0089
0090 if (result) {
0091 dev_dbg(&dev->core, "%s:%d: ps3_dma_region_create failed: "
0092 "(%d)\n", __func__, __LINE__, result);
0093 BUG_ON("check region type");
0094 goto fail_dma_region;
0095 }
0096
0097 result = ps3_mmio_region_create(dev->m_region);
0098
0099 if (result) {
0100 dev_dbg(&dev->core, "%s:%d: ps3_map_mmio_region failed\n",
0101 __func__, __LINE__);
0102 result = -EPERM;
0103 goto fail_mmio_region;
0104 }
0105
0106 dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
0107 __LINE__, dev->m_region->lpar_addr);
0108
0109 result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
0110
0111 if (result) {
0112 dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
0113 __func__, __LINE__, virq);
0114 result = -EPERM;
0115 goto fail_irq;
0116 }
0117
0118 dummy_mask = DMA_BIT_MASK(32);
0119 dev->core.dma_mask = &dummy_mask;
0120 dma_set_coherent_mask(&dev->core, dummy_mask);
0121
0122 hcd = usb_create_hcd(&ps3_ohci_hc_driver, &dev->core, dev_name(&dev->core));
0123
0124 if (!hcd) {
0125 dev_dbg(&dev->core, "%s:%d: usb_create_hcd failed\n", __func__,
0126 __LINE__);
0127 result = -ENOMEM;
0128 goto fail_create_hcd;
0129 }
0130
0131 hcd->rsrc_start = dev->m_region->lpar_addr;
0132 hcd->rsrc_len = dev->m_region->len;
0133
0134 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name))
0135 dev_dbg(&dev->core, "%s:%d: request_mem_region failed\n",
0136 __func__, __LINE__);
0137
0138 hcd->regs = ioremap(dev->m_region->lpar_addr, dev->m_region->len);
0139
0140 if (!hcd->regs) {
0141 dev_dbg(&dev->core, "%s:%d: ioremap failed\n", __func__,
0142 __LINE__);
0143 result = -EPERM;
0144 goto fail_ioremap;
0145 }
0146
0147 dev_dbg(&dev->core, "%s:%d: hcd->rsrc_start %lxh\n", __func__, __LINE__,
0148 (unsigned long)hcd->rsrc_start);
0149 dev_dbg(&dev->core, "%s:%d: hcd->rsrc_len %lxh\n", __func__, __LINE__,
0150 (unsigned long)hcd->rsrc_len);
0151 dev_dbg(&dev->core, "%s:%d: hcd->regs %lxh\n", __func__, __LINE__,
0152 (unsigned long)hcd->regs);
0153 dev_dbg(&dev->core, "%s:%d: virq %lu\n", __func__, __LINE__,
0154 (unsigned long)virq);
0155
0156 ps3_system_bus_set_drvdata(dev, hcd);
0157
0158 result = usb_add_hcd(hcd, virq, 0);
0159
0160 if (result) {
0161 dev_dbg(&dev->core, "%s:%d: usb_add_hcd failed (%d)\n",
0162 __func__, __LINE__, result);
0163 goto fail_add_hcd;
0164 }
0165
0166 device_wakeup_enable(hcd->self.controller);
0167 return result;
0168
0169 fail_add_hcd:
0170 iounmap(hcd->regs);
0171 fail_ioremap:
0172 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
0173 usb_put_hcd(hcd);
0174 fail_create_hcd:
0175 ps3_io_irq_destroy(virq);
0176 fail_irq:
0177 ps3_free_mmio_region(dev->m_region);
0178 fail_mmio_region:
0179 ps3_dma_region_free(dev->d_region);
0180 fail_dma_region:
0181 ps3_close_hv_device(dev);
0182 fail_open:
0183 fail_start:
0184 return result;
0185 }
0186
0187 static void ps3_ohci_remove(struct ps3_system_bus_device *dev)
0188 {
0189 unsigned int tmp;
0190 struct usb_hcd *hcd = ps3_system_bus_get_drvdata(dev);
0191
0192 BUG_ON(!hcd);
0193
0194 dev_dbg(&dev->core, "%s:%d: regs %p\n", __func__, __LINE__, hcd->regs);
0195 dev_dbg(&dev->core, "%s:%d: irq %u\n", __func__, __LINE__, hcd->irq);
0196
0197 tmp = hcd->irq;
0198
0199 ohci_shutdown(hcd);
0200 usb_remove_hcd(hcd);
0201
0202 ps3_system_bus_set_drvdata(dev, NULL);
0203
0204 BUG_ON(!hcd->regs);
0205 iounmap(hcd->regs);
0206
0207 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
0208 usb_put_hcd(hcd);
0209
0210 ps3_io_irq_destroy(tmp);
0211 ps3_free_mmio_region(dev->m_region);
0212
0213 ps3_dma_region_free(dev->d_region);
0214 ps3_close_hv_device(dev);
0215 }
0216
0217 static int __init ps3_ohci_driver_register(struct ps3_system_bus_driver *drv)
0218 {
0219 return firmware_has_feature(FW_FEATURE_PS3_LV1)
0220 ? ps3_system_bus_driver_register(drv)
0221 : 0;
0222 }
0223
0224 static void ps3_ohci_driver_unregister(struct ps3_system_bus_driver *drv)
0225 {
0226 if (firmware_has_feature(FW_FEATURE_PS3_LV1))
0227 ps3_system_bus_driver_unregister(drv);
0228 }
0229
0230 MODULE_ALIAS(PS3_MODULE_ALIAS_OHCI);
0231
0232 static struct ps3_system_bus_driver ps3_ohci_driver = {
0233 .core.name = "ps3-ohci-driver",
0234 .core.owner = THIS_MODULE,
0235 .match_id = PS3_MATCH_ID_OHCI,
0236 .probe = ps3_ohci_probe,
0237 .remove = ps3_ohci_remove,
0238 .shutdown = ps3_ohci_remove,
0239 };