pcmcia: CompactFlash driver for PA Semi Electra boards
[pv_ops_mirror.git] / drivers / usb / host / ohci-ssb.c
blobfe70e72340de4e0735d40f67279a5d4ebcb6ce08
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 #ifdef CONFIG_PM
64 static int ssb_ohci_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
66 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
67 struct ohci_hcd *ohci = &ohcidev->ohci;
68 unsigned long flags;
70 spin_lock_irqsave(&ohci->lock, flags);
72 ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
73 ohci_readl(ohci, &ohci->regs->intrdisable); /* commit write */
75 /* make sure snapshot being resumed re-enumerates everything */
76 if (message.event == PM_EVENT_PRETHAW)
77 ohci_usb_reset(ohci);
79 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
81 spin_unlock_irqrestore(&ohci->lock, flags);
82 return 0;
85 static int ssb_ohci_hcd_resume(struct usb_hcd *hcd)
87 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
88 usb_hcd_resume_root_hub(hcd);
89 return 0;
91 #endif /* CONFIG_PM */
93 static const struct hc_driver ssb_ohci_hc_driver = {
94 .description = "ssb-usb-ohci",
95 .product_desc = "SSB OHCI Controller",
96 .hcd_priv_size = sizeof(struct ssb_ohci_device),
98 .irq = ohci_irq,
99 .flags = HCD_MEMORY | HCD_USB11,
101 .reset = ssb_ohci_reset,
102 .start = ssb_ohci_start,
103 .stop = ohci_stop,
104 .shutdown = ohci_shutdown,
106 #ifdef CONFIG_PM
107 .suspend = ssb_ohci_hcd_suspend,
108 .resume = ssb_ohci_hcd_resume,
109 #endif
111 .urb_enqueue = ohci_urb_enqueue,
112 .urb_dequeue = ohci_urb_dequeue,
113 .endpoint_disable = ohci_endpoint_disable,
115 .get_frame_number = ohci_get_frame,
117 .hub_status_data = ohci_hub_status_data,
118 .hub_control = ohci_hub_control,
119 .hub_irq_enable = ohci_rhsc_enable,
120 #ifdef CONFIG_PM
121 .bus_suspend = ohci_bus_suspend,
122 .bus_resume = ohci_bus_resume,
123 #endif
125 .start_port_reset = ohci_start_port_reset,
128 static void ssb_ohci_detach(struct ssb_device *dev)
130 struct usb_hcd *hcd = ssb_get_drvdata(dev);
132 usb_remove_hcd(hcd);
133 iounmap(hcd->regs);
134 usb_put_hcd(hcd);
135 ssb_device_disable(dev, 0);
138 static int ssb_ohci_attach(struct ssb_device *dev)
140 struct ssb_ohci_device *ohcidev;
141 struct usb_hcd *hcd;
142 int err = -ENOMEM;
143 u32 tmp, flags = 0;
145 if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
146 flags |= SSB_OHCI_TMSLOW_HOSTMODE;
148 ssb_device_enable(dev, flags);
150 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
151 dev->dev->bus_id);
152 if (!hcd)
153 goto err_dev_disable;
154 ohcidev = hcd_to_ssb_ohci(hcd);
155 ohcidev->enable_flags = flags;
157 tmp = ssb_read32(dev, SSB_ADMATCH0);
158 hcd->rsrc_start = ssb_admatch_base(tmp);
159 hcd->rsrc_len = ssb_admatch_size(tmp);
160 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
161 if (!hcd->regs)
162 goto err_put_hcd;
163 err = usb_add_hcd(hcd, dev->irq, IRQF_SHARED);
164 if (err)
165 goto err_iounmap;
167 ssb_set_drvdata(dev, hcd);
169 return err;
171 err_iounmap:
172 iounmap(hcd->regs);
173 err_put_hcd:
174 usb_put_hcd(hcd);
175 err_dev_disable:
176 ssb_device_disable(dev, flags);
177 return err;
180 static int ssb_ohci_probe(struct ssb_device *dev,
181 const struct ssb_device_id *id)
183 int err;
184 u16 chipid_top;
186 /* USBcores are only connected on embedded devices. */
187 chipid_top = (dev->bus->chip_id & 0xFF00);
188 if (chipid_top != 0x4700 && chipid_top != 0x5300)
189 return -ENODEV;
191 /* TODO: Probably need checks here; is the core connected? */
193 if (usb_disabled())
194 return -ENODEV;
196 /* We currently always attach SSB_DEV_USB11_HOSTDEV
197 * as HOST OHCI. If we want to attach it as Client device,
198 * we must branch here and call into the (yet to
199 * be written) Client mode driver. Same for remove(). */
201 err = ssb_ohci_attach(dev);
203 return err;
206 static void ssb_ohci_remove(struct ssb_device *dev)
208 ssb_ohci_detach(dev);
211 #ifdef CONFIG_PM
213 static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
215 ssb_device_disable(dev, 0);
217 return 0;
220 static int ssb_ohci_resume(struct ssb_device *dev)
222 struct usb_hcd *hcd = ssb_get_drvdata(dev);
223 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
225 ssb_device_enable(dev, ohcidev->enable_flags);
227 return 0;
230 #else /* !CONFIG_PM */
231 #define ssb_ohci_suspend NULL
232 #define ssb_ohci_resume NULL
233 #endif /* CONFIG_PM */
235 static const struct ssb_device_id ssb_ohci_table[] = {
236 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
237 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
238 SSB_DEVTABLE_END
240 MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
242 static struct ssb_driver ssb_ohci_driver = {
243 .name = KBUILD_MODNAME,
244 .id_table = ssb_ohci_table,
245 .probe = ssb_ohci_probe,
246 .remove = ssb_ohci_remove,
247 .suspend = ssb_ohci_suspend,
248 .resume = ssb_ohci_resume,