Revert "USB: don't explicitly reenable root-hub status interrupts"
[linux-2.6/kmemtrace.git] / drivers / usb / host / ohci-ssb.c
blob7275186db31556baf8278ec300da9d0d8600a98f
1 /*
2 * Sonics Silicon Backplane
3 * Broadcom USB-core OHCI driver
5 * Copyright 2007 Michael Buesch <mb@bu3sch.de>
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
13 * Derived from the USBcore related parts of Broadcom-SB
14 * Copyright 2005 Broadcom Corporation
16 * Licensed under the GNU/GPL. See COPYING for details.
18 #include <linux/ssb/ssb.h>
21 #define SSB_OHCI_TMSLOW_HOSTMODE (1 << 29)
23 struct ssb_ohci_device {
24 struct ohci_hcd ohci; /* _must_ be at the beginning. */
26 u32 enable_flags;
29 static inline
30 struct ssb_ohci_device *hcd_to_ssb_ohci(struct usb_hcd *hcd)
32 return (struct ssb_ohci_device *)(hcd->hcd_priv);
36 static int ssb_ohci_reset(struct usb_hcd *hcd)
38 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
39 struct ohci_hcd *ohci = &ohcidev->ohci;
40 int err;
42 ohci_hcd_init(ohci);
43 err = ohci_init(ohci);
45 return err;
48 static int ssb_ohci_start(struct usb_hcd *hcd)
50 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
51 struct ohci_hcd *ohci = &ohcidev->ohci;
52 int err;
54 err = ohci_run(ohci);
55 if (err < 0) {
56 ohci_err(ohci, "can't start\n");
57 ohci_stop(hcd);
60 return err;
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),
68 .irq = ohci_irq,
69 .flags = HCD_MEMORY | HCD_USB11,
71 .reset = ssb_ohci_reset,
72 .start = ssb_ohci_start,
73 .stop = ohci_stop,
74 .shutdown = ohci_shutdown,
76 .urb_enqueue = ohci_urb_enqueue,
77 .urb_dequeue = ohci_urb_dequeue,
78 .endpoint_disable = ohci_endpoint_disable,
80 .get_frame_number = ohci_get_frame,
82 .hub_status_data = ohci_hub_status_data,
83 .hub_control = ohci_hub_control,
84 .hub_irq_enable = ohci_rhsc_enable,
85 #ifdef CONFIG_PM
86 .bus_suspend = ohci_bus_suspend,
87 .bus_resume = ohci_bus_resume,
88 #endif
90 .start_port_reset = ohci_start_port_reset,
93 static void ssb_ohci_detach(struct ssb_device *dev)
95 struct usb_hcd *hcd = ssb_get_drvdata(dev);
97 usb_remove_hcd(hcd);
98 iounmap(hcd->regs);
99 usb_put_hcd(hcd);
100 ssb_device_disable(dev, 0);
103 static int ssb_ohci_attach(struct ssb_device *dev)
105 struct ssb_ohci_device *ohcidev;
106 struct usb_hcd *hcd;
107 int err = -ENOMEM;
108 u32 tmp, flags = 0;
110 if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
111 flags |= SSB_OHCI_TMSLOW_HOSTMODE;
113 ssb_device_enable(dev, flags);
115 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
116 dev->dev->bus_id);
117 if (!hcd)
118 goto err_dev_disable;
119 ohcidev = hcd_to_ssb_ohci(hcd);
120 ohcidev->enable_flags = flags;
122 tmp = ssb_read32(dev, SSB_ADMATCH0);
123 hcd->rsrc_start = ssb_admatch_base(tmp);
124 hcd->rsrc_len = ssb_admatch_size(tmp);
125 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
126 if (!hcd->regs)
127 goto err_put_hcd;
128 err = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
129 if (err)
130 goto err_iounmap;
132 ssb_set_drvdata(dev, hcd);
134 return err;
136 err_iounmap:
137 iounmap(hcd->regs);
138 err_put_hcd:
139 usb_put_hcd(hcd);
140 err_dev_disable:
141 ssb_device_disable(dev, flags);
142 return err;
145 static int ssb_ohci_probe(struct ssb_device *dev,
146 const struct ssb_device_id *id)
148 int err;
149 u16 chipid_top;
151 /* USBcores are only connected on embedded devices. */
152 chipid_top = (dev->bus->chip_id & 0xFF00);
153 if (chipid_top != 0x4700 && chipid_top != 0x5300)
154 return -ENODEV;
156 /* TODO: Probably need checks here; is the core connected? */
158 if (usb_disabled())
159 return -ENODEV;
161 /* We currently always attach SSB_DEV_USB11_HOSTDEV
162 * as HOST OHCI. If we want to attach it as Client device,
163 * we must branch here and call into the (yet to
164 * be written) Client mode driver. Same for remove(). */
166 err = ssb_ohci_attach(dev);
168 return err;
171 static void ssb_ohci_remove(struct ssb_device *dev)
173 ssb_ohci_detach(dev);
176 #ifdef CONFIG_PM
178 static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
180 ssb_device_disable(dev, 0);
182 return 0;
185 static int ssb_ohci_resume(struct ssb_device *dev)
187 struct usb_hcd *hcd = ssb_get_drvdata(dev);
188 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
190 ssb_device_enable(dev, ohcidev->enable_flags);
192 ohci_finish_controller_resume(hcd);
193 return 0;
196 #else /* !CONFIG_PM */
197 #define ssb_ohci_suspend NULL
198 #define ssb_ohci_resume NULL
199 #endif /* CONFIG_PM */
201 static const struct ssb_device_id ssb_ohci_table[] = {
202 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
203 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
204 SSB_DEVTABLE_END
206 MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
208 static struct ssb_driver ssb_ohci_driver = {
209 .name = KBUILD_MODNAME,
210 .id_table = ssb_ohci_table,
211 .probe = ssb_ohci_probe,
212 .remove = ssb_ohci_remove,
213 .suspend = ssb_ohci_suspend,
214 .resume = ssb_ohci_resume,