PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / usb / host / ohci-octeon.c
blob15af8954085e687b4b67cbe33bd6e89afc333f7f
1 /*
2 * EHCI HCD glue for Cavium Octeon II SOCs.
4 * Loosely based on ehci-au1xxx.c
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
10 * Copyright (C) 2010 Cavium Networks
14 #include <linux/platform_device.h>
16 #include <asm/octeon/octeon.h>
17 #include <asm/octeon/cvmx-uctlx-defs.h>
19 #define OCTEON_OHCI_HCD_NAME "octeon-ohci"
21 /* Common clock init code. */
22 void octeon2_usb_clocks_start(void);
23 void octeon2_usb_clocks_stop(void);
25 static void ohci_octeon_hw_start(void)
27 union cvmx_uctlx_ohci_ctl ohci_ctl;
29 octeon2_usb_clocks_start();
31 ohci_ctl.u64 = cvmx_read_csr(CVMX_UCTLX_OHCI_CTL(0));
32 ohci_ctl.s.l2c_addr_msb = 0;
33 ohci_ctl.s.l2c_buff_emod = 1; /* Byte swapped. */
34 ohci_ctl.s.l2c_desc_emod = 1; /* Byte swapped. */
35 cvmx_write_csr(CVMX_UCTLX_OHCI_CTL(0), ohci_ctl.u64);
39 static void ohci_octeon_hw_stop(void)
41 /* Undo ohci_octeon_start() */
42 octeon2_usb_clocks_stop();
45 static int ohci_octeon_start(struct usb_hcd *hcd)
47 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
48 int ret;
50 ret = ohci_init(ohci);
52 if (ret < 0)
53 return ret;
55 ret = ohci_run(ohci);
57 if (ret < 0) {
58 ohci_err(ohci, "can't start %s", hcd->self.bus_name);
59 ohci_stop(hcd);
60 return ret;
63 return 0;
66 static const struct hc_driver ohci_octeon_hc_driver = {
67 .description = hcd_name,
68 .product_desc = "Octeon OHCI",
69 .hcd_priv_size = sizeof(struct ohci_hcd),
72 * generic hardware linkage
74 .irq = ohci_irq,
75 .flags = HCD_USB11 | HCD_MEMORY,
78 * basic lifecycle operations
80 .start = ohci_octeon_start,
81 .stop = ohci_stop,
82 .shutdown = ohci_shutdown,
85 * managing i/o requests and associated device resources
87 .urb_enqueue = ohci_urb_enqueue,
88 .urb_dequeue = ohci_urb_dequeue,
89 .endpoint_disable = ohci_endpoint_disable,
92 * scheduling support
94 .get_frame_number = ohci_get_frame,
97 * root hub support
99 .hub_status_data = ohci_hub_status_data,
100 .hub_control = ohci_hub_control,
102 .start_port_reset = ohci_start_port_reset,
105 static int ohci_octeon_drv_probe(struct platform_device *pdev)
107 struct usb_hcd *hcd;
108 struct ohci_hcd *ohci;
109 void *reg_base;
110 struct resource *res_mem;
111 int irq;
112 int ret;
114 if (usb_disabled())
115 return -ENODEV;
117 irq = platform_get_irq(pdev, 0);
118 if (irq < 0) {
119 dev_err(&pdev->dev, "No irq assigned\n");
120 return -ENODEV;
123 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
124 if (res_mem == NULL) {
125 dev_err(&pdev->dev, "No register space assigned\n");
126 return -ENODEV;
129 /* Ohci is a 32-bit device. */
130 ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
131 if (ret)
132 return ret;
134 hcd = usb_create_hcd(&ohci_octeon_hc_driver, &pdev->dev, "octeon");
135 if (!hcd)
136 return -ENOMEM;
138 hcd->rsrc_start = res_mem->start;
139 hcd->rsrc_len = resource_size(res_mem);
141 reg_base = devm_ioremap_resource(&pdev->dev, res_mem);
142 if (IS_ERR(reg_base)) {
143 ret = PTR_ERR(reg_base);
144 goto err1;
147 ohci_octeon_hw_start();
149 hcd->regs = reg_base;
151 ohci = hcd_to_ohci(hcd);
153 /* Octeon OHCI matches CPU endianness. */
154 #ifdef __BIG_ENDIAN
155 ohci->flags |= OHCI_QUIRK_BE_MMIO;
156 #endif
158 ohci_hcd_init(ohci);
160 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
161 if (ret) {
162 dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret);
163 goto err2;
166 device_wakeup_enable(hcd->self.controller);
168 platform_set_drvdata(pdev, hcd);
170 return 0;
172 err2:
173 ohci_octeon_hw_stop();
175 err1:
176 usb_put_hcd(hcd);
177 return ret;
180 static int ohci_octeon_drv_remove(struct platform_device *pdev)
182 struct usb_hcd *hcd = platform_get_drvdata(pdev);
184 usb_remove_hcd(hcd);
186 ohci_octeon_hw_stop();
187 usb_put_hcd(hcd);
189 return 0;
192 static struct platform_driver ohci_octeon_driver = {
193 .probe = ohci_octeon_drv_probe,
194 .remove = ohci_octeon_drv_remove,
195 .shutdown = usb_hcd_platform_shutdown,
196 .driver = {
197 .name = OCTEON_OHCI_HCD_NAME,
198 .owner = THIS_MODULE,
202 MODULE_ALIAS("platform:" OCTEON_OHCI_HCD_NAME);