add gateway 7001 support patch from #1918
[openwrt/openwrt.git] / target / linux / brcm47xx-2.6 / files / drivers / usb / host / ohci-ssb.c
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
19 #include <linux/ssb/ssb.h>
20
21
22 #define SSB_OHCI_TMSLOW_HOSTMODE (1 << 29)
23
24 struct ssb_ohci_device {
25 struct ohci_hcd ohci; /* _must_ be at the beginning. */
26
27 u32 enable_flags;
28 };
29
30
31 static inline
32 struct ssb_ohci_device * hcd_to_ssb_ohci(struct usb_hcd *hcd)
33 {
34 return (struct ssb_ohci_device *)(hcd->hcd_priv);
35 }
36
37
38 static const struct ssb_device_id ssb_ohci_table[] = {
39 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
40 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
41 SSB_DEVTABLE_END
42 };
43 MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
44
45
46 static int ssb_ohci_reset(struct usb_hcd *hcd)
47 {
48 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
49 struct ohci_hcd *ohci = &ohcidev->ohci;
50 int err;
51
52 ohci_hcd_init(ohci);
53 err = ohci_init(ohci);
54
55 return err;
56 }
57
58 static int ssb_ohci_start(struct usb_hcd *hcd)
59 {
60 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
61 struct ohci_hcd *ohci = &ohcidev->ohci;
62 int err;
63
64 err = ohci_run(ohci);
65 if (err < 0) {
66 ohci_err(ohci, "can't start\n");
67 ohci_stop(hcd);
68 }
69
70 return err;
71 }
72
73 #ifdef CONFIG_PM
74 static int ssb_ohci_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
75 {
76 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
77 struct ohci_hcd *ohci = &ohcidev->ohci;
78 unsigned long flags;
79
80 spin_lock_irqsave(&ohci->lock, flags);
81
82 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
83 ohci_readl(ohci, &ohci->regs->intrdisable); /* commit write */
84
85 /* make sure snapshot being resumed re-enumerates everything */
86 if (message.event == PM_EVENT_PRETHAW)
87 ohci_usb_reset(ohci);
88
89 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
90
91 spin_unlock_irqrestore(&ohci->lock, flags);
92
93 return 0;
94 }
95
96 static int ssb_ohci_hcd_resume(struct usb_hcd *hcd)
97 {
98 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
99 usb_hcd_resume_root_hub(hcd);
100 return 0;
101 }
102 #endif /* CONFIG_PM */
103
104 static const struct hc_driver ssb_ohci_hc_driver = {
105 .description = "ssb-usb-ohci",
106 .product_desc = "SSB OHCI Controller",
107 .hcd_priv_size = sizeof(struct ssb_ohci_device),
108
109 .irq = ohci_irq,
110 .flags = HCD_MEMORY | HCD_USB11,
111
112 .reset = ssb_ohci_reset,
113 .start = ssb_ohci_start,
114 .stop = ohci_stop,
115 .shutdown = ohci_shutdown,
116
117 #ifdef CONFIG_PM
118 .suspend = ssb_ohci_hcd_suspend,
119 .resume = ssb_ohci_hcd_resume,
120 #endif
121
122 .urb_enqueue = ohci_urb_enqueue,
123 .urb_dequeue = ohci_urb_dequeue,
124 .endpoint_disable = ohci_endpoint_disable,
125
126 .get_frame_number = ohci_get_frame,
127
128 .hub_status_data = ohci_hub_status_data,
129 .hub_control = ohci_hub_control,
130 .hub_irq_enable = ohci_rhsc_enable,
131
132 #ifdef CONFIG_PM
133 .bus_suspend = ohci_bus_suspend,
134 .bus_resume = ohci_bus_resume,
135 #endif
136
137 .start_port_reset = ohci_start_port_reset,
138 };
139
140
141 static void ssb_ohci_detach(struct ssb_device *dev)
142 {
143 struct usb_hcd *hcd = ssb_get_drvdata(dev);
144
145 usb_remove_hcd(hcd);
146 iounmap(hcd->regs);
147 usb_put_hcd(hcd);
148 ssb_device_disable(dev, 0);
149 }
150
151 static int ssb_ohci_attach(struct ssb_device *dev)
152 {
153 struct ssb_ohci_device *ohcidev;
154 struct usb_hcd *hcd;
155 int err = -ENOMEM;
156 u32 tmp, flags = 0;
157
158 if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
159 flags |= SSB_OHCI_TMSLOW_HOSTMODE;
160
161 ssb_device_enable(dev, flags);
162
163 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
164 dev->dev->bus_id);
165 if (!hcd)
166 goto err_dev_disable;
167 ohcidev = hcd_to_ssb_ohci(hcd);
168 ohcidev->enable_flags = flags;
169
170 tmp = ssb_read32(dev, SSB_ADMATCH0);
171 hcd->rsrc_start = ssb_admatch_base(tmp);
172 hcd->rsrc_len = ssb_admatch_size(tmp);
173 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
174 if (!hcd->regs)
175 goto err_put_hcd;
176 err = usb_add_hcd(hcd, dev->irq, IRQF_SHARED);
177 if (err)
178 goto err_iounmap;
179
180 ssb_set_drvdata(dev, hcd);
181
182 return err;
183
184 err_iounmap:
185 iounmap(hcd->regs);
186 err_put_hcd:
187 usb_put_hcd(hcd);
188 err_dev_disable:
189 ssb_device_disable(dev, flags);
190 return err;
191 }
192
193 static int ssb_ohci_probe(struct ssb_device *dev,
194 const struct ssb_device_id *id)
195 {
196 int err;
197 u16 chipid_top;
198
199 chipid_top = (dev->bus->chip_id & 0xFF00);
200 if (chipid_top != 0x4700 &&
201 chipid_top != 0x5300) {
202 /* USBcores are only connected on embedded devices. */
203 return -ENODEV;
204 }
205 /* TODO: Probably need more checks here whether the core is connected. */
206
207 if (usb_disabled())
208 return -ENODEV;
209
210 /* We currently always attach SSB_DEV_USB11_HOSTDEV
211 * as HOST OHCI. If we want to attach it as Client device,
212 * we must branch here and call into the (yet to
213 * be written) Client mode driver. Same for remove(). */
214
215 err = ssb_ohci_attach(dev);
216
217 return err;
218 }
219
220 static void ssb_ohci_remove(struct ssb_device *dev)
221 {
222 ssb_ohci_detach(dev);
223 }
224
225 #ifdef CONFIG_PM
226 static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
227 {
228 ssb_device_disable(dev, 0);
229
230 return 0;
231 }
232
233 static int ssb_ohci_resume(struct ssb_device *dev)
234 {
235 struct usb_hcd *hcd = ssb_get_drvdata(dev);
236 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
237
238 ssb_device_enable(dev, ohcidev->enable_flags);
239
240 return 0;
241 }
242 #else /* CONFIG_PM */
243 # define ssb_ohci_suspend NULL
244 # define ssb_ohci_resume NULL
245 #endif /* CONFIG_PM */
246
247 static struct ssb_driver ssb_ohci_driver = {
248 .name = KBUILD_MODNAME,
249 .id_table = ssb_ohci_table,
250 .probe = ssb_ohci_probe,
251 .remove = ssb_ohci_remove,
252 .suspend = ssb_ohci_suspend,
253 .resume = ssb_ohci_resume,
254 };