Michael Buesch | c604e85 | 2007-10-09 23:47:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Sonics Silicon Backplane |
| 3 | * Broadcom USB-core OHCI driver |
| 4 | * |
| 5 | * Copyright 2007 Michael Buesch <mb@bu3sch.de> |
| 6 | * |
| 7 | * Derived from the OHCI-PCI driver |
| 8 | * Copyright 1999 Roman Weissgaerber |
| 9 | * Copyright 2000-2002 David Brownell |
| 10 | * Copyright 1999 Linus Torvalds |
| 11 | * Copyright 1999 Gregory P. Smith |
| 12 | * |
| 13 | * Derived from the USBcore related parts of Broadcom-SB |
| 14 | * Copyright 2005 Broadcom Corporation |
| 15 | * |
| 16 | * Licensed under the GNU/GPL. See COPYING for details. |
| 17 | */ |
| 18 | #include <linux/ssb/ssb.h> |
| 19 | |
| 20 | |
| 21 | #define SSB_OHCI_TMSLOW_HOSTMODE (1 << 29) |
| 22 | |
| 23 | struct ssb_ohci_device { |
| 24 | struct ohci_hcd ohci; /* _must_ be at the beginning. */ |
| 25 | |
| 26 | u32 enable_flags; |
| 27 | }; |
| 28 | |
| 29 | static inline |
| 30 | struct ssb_ohci_device *hcd_to_ssb_ohci(struct usb_hcd *hcd) |
| 31 | { |
| 32 | return (struct ssb_ohci_device *)(hcd->hcd_priv); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | static int ssb_ohci_reset(struct usb_hcd *hcd) |
| 37 | { |
| 38 | struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd); |
| 39 | struct ohci_hcd *ohci = &ohcidev->ohci; |
| 40 | int err; |
| 41 | |
| 42 | ohci_hcd_init(ohci); |
| 43 | err = ohci_init(ohci); |
| 44 | |
| 45 | return err; |
| 46 | } |
| 47 | |
| 48 | static int ssb_ohci_start(struct usb_hcd *hcd) |
| 49 | { |
| 50 | struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd); |
| 51 | struct ohci_hcd *ohci = &ohcidev->ohci; |
| 52 | int err; |
| 53 | |
| 54 | err = ohci_run(ohci); |
| 55 | if (err < 0) { |
| 56 | ohci_err(ohci, "can't start\n"); |
| 57 | ohci_stop(hcd); |
| 58 | } |
| 59 | |
| 60 | return err; |
| 61 | } |
| 62 | |
Michael Buesch | c604e85 | 2007-10-09 23:47:17 -0700 | [diff] [blame] | 63 | static const struct hc_driver ssb_ohci_hc_driver = { |
| 64 | .description = "ssb-usb-ohci", |
| 65 | .product_desc = "SSB OHCI Controller", |
| 66 | .hcd_priv_size = sizeof(struct ssb_ohci_device), |
| 67 | |
| 68 | .irq = ohci_irq, |
| 69 | .flags = HCD_MEMORY | HCD_USB11, |
| 70 | |
| 71 | .reset = ssb_ohci_reset, |
| 72 | .start = ssb_ohci_start, |
| 73 | .stop = ohci_stop, |
| 74 | .shutdown = ohci_shutdown, |
| 75 | |
Michael Buesch | c604e85 | 2007-10-09 23:47:17 -0700 | [diff] [blame] | 76 | .urb_enqueue = ohci_urb_enqueue, |
| 77 | .urb_dequeue = ohci_urb_dequeue, |
| 78 | .endpoint_disable = ohci_endpoint_disable, |
| 79 | |
| 80 | .get_frame_number = ohci_get_frame, |
| 81 | |
| 82 | .hub_status_data = ohci_hub_status_data, |
| 83 | .hub_control = ohci_hub_control, |
Al Viro | 4735b37 | 2007-10-13 22:29:47 +0100 | [diff] [blame] | 84 | #ifdef CONFIG_PM |
Michael Buesch | c604e85 | 2007-10-09 23:47:17 -0700 | [diff] [blame] | 85 | .bus_suspend = ohci_bus_suspend, |
| 86 | .bus_resume = ohci_bus_resume, |
Al Viro | 4735b37 | 2007-10-13 22:29:47 +0100 | [diff] [blame] | 87 | #endif |
Michael Buesch | c604e85 | 2007-10-09 23:47:17 -0700 | [diff] [blame] | 88 | |
| 89 | .start_port_reset = ohci_start_port_reset, |
| 90 | }; |
| 91 | |
| 92 | static void ssb_ohci_detach(struct ssb_device *dev) |
| 93 | { |
| 94 | struct usb_hcd *hcd = ssb_get_drvdata(dev); |
| 95 | |
| 96 | usb_remove_hcd(hcd); |
| 97 | iounmap(hcd->regs); |
| 98 | usb_put_hcd(hcd); |
| 99 | ssb_device_disable(dev, 0); |
| 100 | } |
| 101 | |
| 102 | static int ssb_ohci_attach(struct ssb_device *dev) |
| 103 | { |
| 104 | struct ssb_ohci_device *ohcidev; |
| 105 | struct usb_hcd *hcd; |
| 106 | int err = -ENOMEM; |
| 107 | u32 tmp, flags = 0; |
| 108 | |
| 109 | if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV) |
| 110 | flags |= SSB_OHCI_TMSLOW_HOSTMODE; |
| 111 | |
| 112 | ssb_device_enable(dev, flags); |
| 113 | |
| 114 | hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev, |
Kay Sievers | 7071a3c | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 115 | dev_name(dev->dev)); |
Michael Buesch | c604e85 | 2007-10-09 23:47:17 -0700 | [diff] [blame] | 116 | if (!hcd) |
| 117 | goto err_dev_disable; |
| 118 | ohcidev = hcd_to_ssb_ohci(hcd); |
| 119 | ohcidev->enable_flags = flags; |
| 120 | |
| 121 | tmp = ssb_read32(dev, SSB_ADMATCH0); |
| 122 | hcd->rsrc_start = ssb_admatch_base(tmp); |
| 123 | hcd->rsrc_len = ssb_admatch_size(tmp); |
| 124 | hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); |
| 125 | if (!hcd->regs) |
| 126 | goto err_put_hcd; |
Alan Stern | 442258e | 2007-12-06 14:47:08 -0500 | [diff] [blame] | 127 | err = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED); |
Michael Buesch | c604e85 | 2007-10-09 23:47:17 -0700 | [diff] [blame] | 128 | if (err) |
| 129 | goto err_iounmap; |
| 130 | |
| 131 | ssb_set_drvdata(dev, hcd); |
| 132 | |
| 133 | return err; |
| 134 | |
| 135 | err_iounmap: |
| 136 | iounmap(hcd->regs); |
| 137 | err_put_hcd: |
| 138 | usb_put_hcd(hcd); |
| 139 | err_dev_disable: |
| 140 | ssb_device_disable(dev, flags); |
| 141 | return err; |
| 142 | } |
| 143 | |
| 144 | static int ssb_ohci_probe(struct ssb_device *dev, |
| 145 | const struct ssb_device_id *id) |
| 146 | { |
| 147 | int err; |
| 148 | u16 chipid_top; |
| 149 | |
| 150 | /* USBcores are only connected on embedded devices. */ |
| 151 | chipid_top = (dev->bus->chip_id & 0xFF00); |
| 152 | if (chipid_top != 0x4700 && chipid_top != 0x5300) |
| 153 | return -ENODEV; |
| 154 | |
| 155 | /* TODO: Probably need checks here; is the core connected? */ |
| 156 | |
| 157 | if (usb_disabled()) |
| 158 | return -ENODEV; |
| 159 | |
| 160 | /* We currently always attach SSB_DEV_USB11_HOSTDEV |
| 161 | * as HOST OHCI. If we want to attach it as Client device, |
| 162 | * we must branch here and call into the (yet to |
| 163 | * be written) Client mode driver. Same for remove(). */ |
| 164 | |
| 165 | err = ssb_ohci_attach(dev); |
| 166 | |
| 167 | return err; |
| 168 | } |
| 169 | |
| 170 | static void ssb_ohci_remove(struct ssb_device *dev) |
| 171 | { |
| 172 | ssb_ohci_detach(dev); |
| 173 | } |
| 174 | |
| 175 | #ifdef CONFIG_PM |
| 176 | |
| 177 | static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state) |
| 178 | { |
| 179 | ssb_device_disable(dev, 0); |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | static int ssb_ohci_resume(struct ssb_device *dev) |
| 185 | { |
| 186 | struct usb_hcd *hcd = ssb_get_drvdata(dev); |
| 187 | struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd); |
| 188 | |
| 189 | ssb_device_enable(dev, ohcidev->enable_flags); |
| 190 | |
Alan Stern | 43bbb7e | 2008-04-03 18:03:17 -0400 | [diff] [blame] | 191 | ohci_finish_controller_resume(hcd); |
Michael Buesch | c604e85 | 2007-10-09 23:47:17 -0700 | [diff] [blame] | 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | #else /* !CONFIG_PM */ |
| 196 | #define ssb_ohci_suspend NULL |
| 197 | #define ssb_ohci_resume NULL |
| 198 | #endif /* CONFIG_PM */ |
| 199 | |
| 200 | static const struct ssb_device_id ssb_ohci_table[] = { |
| 201 | SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV), |
| 202 | SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV), |
| 203 | SSB_DEVTABLE_END |
| 204 | }; |
| 205 | MODULE_DEVICE_TABLE(ssb, ssb_ohci_table); |
| 206 | |
| 207 | static struct ssb_driver ssb_ohci_driver = { |
| 208 | .name = KBUILD_MODNAME, |
| 209 | .id_table = ssb_ohci_table, |
| 210 | .probe = ssb_ohci_probe, |
| 211 | .remove = ssb_ohci_remove, |
| 212 | .suspend = ssb_ohci_suspend, |
| 213 | .resume = ssb_ohci_resume, |
| 214 | }; |