1 | /* |
---|
2 | * Copyright (c) 2009-2012 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Obere Lagerstr. 30 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #include <machine/rtems-bsd-kernel-space.h> |
---|
16 | |
---|
17 | #include <bsp.h> |
---|
18 | |
---|
19 | #ifdef LIBBSP_ARM_LPC24XX_BSP_H |
---|
20 | |
---|
21 | #include <bsp/irq.h> |
---|
22 | #include <bsp/io.h> |
---|
23 | #include <bsp/lpc24xx.h> |
---|
24 | |
---|
25 | #include <sys/cdefs.h> |
---|
26 | #include <sys/stdint.h> |
---|
27 | #include <sys/stddef.h> |
---|
28 | #include <rtems/bsd/sys/param.h> |
---|
29 | #include <sys/queue.h> |
---|
30 | #include <rtems/bsd/sys/types.h> |
---|
31 | #include <sys/systm.h> |
---|
32 | #include <sys/kernel.h> |
---|
33 | #include <sys/bus.h> |
---|
34 | #include <sys/linker_set.h> |
---|
35 | #include <sys/module.h> |
---|
36 | #include <rtems/bsd/sys/lock.h> |
---|
37 | #include <sys/mutex.h> |
---|
38 | #include <sys/condvar.h> |
---|
39 | #include <sys/sysctl.h> |
---|
40 | #include <sys/sx.h> |
---|
41 | #include <rtems/bsd/sys/unistd.h> |
---|
42 | #include <sys/callout.h> |
---|
43 | #include <sys/malloc.h> |
---|
44 | #include <sys/priv.h> |
---|
45 | |
---|
46 | #include <dev/usb/usb.h> |
---|
47 | #include <dev/usb/usbdi.h> |
---|
48 | |
---|
49 | #include <dev/usb/usb_core.h> |
---|
50 | #include <dev/usb/usb_busdma.h> |
---|
51 | #include <dev/usb/usb_process.h> |
---|
52 | #include <dev/usb/usb_util.h> |
---|
53 | |
---|
54 | #include <dev/usb/usb_controller.h> |
---|
55 | #include <dev/usb/usb_bus.h> |
---|
56 | #include <dev/usb/controller/ohci.h> |
---|
57 | |
---|
58 | static device_probe_t ohci_lpc24xx_probe; |
---|
59 | static device_attach_t ohci_lpc24xx_attach; |
---|
60 | static device_detach_t ohci_lpc24xx_detach; |
---|
61 | static device_suspend_t ohci_lpc24xx_suspend; |
---|
62 | static device_resume_t ohci_lpc24xx_resume; |
---|
63 | |
---|
64 | static int |
---|
65 | ohci_lpc24xx_suspend(device_t self) |
---|
66 | { |
---|
67 | ohci_softc_t *e = device_get_softc(self); |
---|
68 | int eno = bus_generic_suspend(self); |
---|
69 | |
---|
70 | if (eno != 0) { |
---|
71 | return (eno); |
---|
72 | } |
---|
73 | |
---|
74 | ohci_suspend(e); |
---|
75 | |
---|
76 | return (0); |
---|
77 | } |
---|
78 | |
---|
79 | static int |
---|
80 | ohci_lpc24xx_resume(device_t self) |
---|
81 | { |
---|
82 | ohci_softc_t *e = device_get_softc(self); |
---|
83 | |
---|
84 | ohci_resume(e); |
---|
85 | |
---|
86 | bus_generic_resume(self); |
---|
87 | |
---|
88 | return (0); |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | static int |
---|
93 | ohci_lpc24xx_probe(device_t self) |
---|
94 | { |
---|
95 | device_set_desc(self, "LPC24XX OHCI controller"); |
---|
96 | |
---|
97 | return (0); |
---|
98 | } |
---|
99 | |
---|
100 | static int |
---|
101 | ohci_lpc24xx_attach(device_t self) |
---|
102 | { |
---|
103 | static const lpc24xx_pin_range pins [] = { |
---|
104 | LPC24XX_PIN_USB_D_PLUS_1, |
---|
105 | LPC24XX_PIN_USB_D_MINUS_1, |
---|
106 | LPC24XX_PIN_USB_PPWR_1, |
---|
107 | LPC24XX_PIN_TERMINAL |
---|
108 | }; |
---|
109 | |
---|
110 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
111 | ohci_softc_t *e = device_get_softc(self); |
---|
112 | usb_error_t ue = USB_ERR_NORMAL_COMPLETION; |
---|
113 | int eno = 0; |
---|
114 | |
---|
115 | memset(e, 0, sizeof(*e)); |
---|
116 | |
---|
117 | BSD_PRINTF("XXX\n"); |
---|
118 | |
---|
119 | /* Initialize some bus fields */ |
---|
120 | e->sc_bus.parent = self; |
---|
121 | e->sc_bus.devices = e->sc_devices; |
---|
122 | e->sc_bus.devices_max = OHCI_MAX_DEVICES; |
---|
123 | |
---|
124 | /* Get all DMA memory */ |
---|
125 | if (usb_bus_mem_alloc_all(&e->sc_bus, USB_GET_DMA_TAG(self), &ohci_iterate_hw_softc)) { |
---|
126 | return (ENOMEM); |
---|
127 | } |
---|
128 | e->sc_dev = self; |
---|
129 | |
---|
130 | /* Child device */ |
---|
131 | e->sc_bus.bdev = device_add_child(self, "usbus", -1); |
---|
132 | if (e->sc_bus.bdev == NULL) { |
---|
133 | device_printf(self, "Could not add USB device\n"); |
---|
134 | goto error; |
---|
135 | } |
---|
136 | device_set_ivars(e->sc_bus.bdev, &e->sc_bus); |
---|
137 | device_set_desc(e->sc_bus.bdev, "LPC24XX OHCI bus"); |
---|
138 | snprintf(e->sc_vendor, sizeof(e->sc_vendor), "NXP"); |
---|
139 | |
---|
140 | /* Register space */ |
---|
141 | e->sc_io_tag = 0U; |
---|
142 | e->sc_io_hdl = USBHC_BASE_ADDR; |
---|
143 | e->sc_io_size = 0x5cU; |
---|
144 | |
---|
145 | /* Enable USB module */ |
---|
146 | sc = lpc24xx_module_enable(LPC24XX_MODULE_USB, LPC24XX_MODULE_PCLK_DEFAULT); |
---|
147 | BSD_ASSERT_SC(sc); |
---|
148 | |
---|
149 | /* Enable USB host and AHB clocks */ |
---|
150 | OTG_CLK_CTRL = 0x19; |
---|
151 | while ((OTG_CLK_STAT & 0x19) != 0x19) { |
---|
152 | /* Wait */ |
---|
153 | } |
---|
154 | |
---|
155 | /* Set OTG Status and Control Register */ |
---|
156 | OTG_STAT_CTRL = 0x3; |
---|
157 | |
---|
158 | /* Configure IO pins */ |
---|
159 | sc = lpc24xx_pin_config(&pins [0], LPC24XX_PIN_SET_FUNCTION); |
---|
160 | BSD_ASSERT_SC(sc); |
---|
161 | |
---|
162 | /* Install interrupt handler */ |
---|
163 | sc = rtems_interrupt_server_handler_install( |
---|
164 | RTEMS_ID_NONE, |
---|
165 | LPC24XX_IRQ_USB, |
---|
166 | "USB", |
---|
167 | RTEMS_INTERRUPT_UNIQUE, |
---|
168 | (rtems_interrupt_handler) ohci_interrupt, |
---|
169 | e |
---|
170 | ); |
---|
171 | BSD_ASSERT_SC(sc); |
---|
172 | |
---|
173 | /* OHCI intitialization */ |
---|
174 | ue = ohci_init(e); |
---|
175 | if (ue != USB_ERR_NORMAL_COMPLETION) { |
---|
176 | goto error; |
---|
177 | } |
---|
178 | |
---|
179 | /* Probe and attach child */ |
---|
180 | eno = device_probe_and_attach(e->sc_bus.bdev); |
---|
181 | if (eno != 0) { |
---|
182 | goto error; |
---|
183 | } |
---|
184 | |
---|
185 | return (0); |
---|
186 | |
---|
187 | error: |
---|
188 | ohci_lpc24xx_detach(self); |
---|
189 | return (ENXIO); |
---|
190 | } |
---|
191 | |
---|
192 | static int |
---|
193 | ohci_lpc24xx_detach(device_t self) |
---|
194 | { |
---|
195 | ohci_softc_t *e = device_get_softc(self); |
---|
196 | |
---|
197 | BSD_PRINTF("XXX\n"); |
---|
198 | |
---|
199 | return (0); |
---|
200 | } |
---|
201 | |
---|
202 | static device_method_t ohci_methods [] = { |
---|
203 | /* Device interface */ |
---|
204 | DEVMETHOD(device_probe, ohci_lpc24xx_probe), |
---|
205 | DEVMETHOD(device_attach, ohci_lpc24xx_attach), |
---|
206 | DEVMETHOD(device_detach, ohci_lpc24xx_detach), |
---|
207 | DEVMETHOD(device_suspend, ohci_lpc24xx_suspend), |
---|
208 | DEVMETHOD(device_resume, ohci_lpc24xx_resume), |
---|
209 | DEVMETHOD(device_shutdown, bus_generic_shutdown), |
---|
210 | |
---|
211 | /* Bus interface */ |
---|
212 | DEVMETHOD(bus_print_child, bus_generic_print_child), |
---|
213 | |
---|
214 | {0, 0} |
---|
215 | }; |
---|
216 | |
---|
217 | static driver_t ohci_driver = { |
---|
218 | .name = "ohci", |
---|
219 | .methods = ohci_methods, |
---|
220 | .size = sizeof(struct ohci_softc) |
---|
221 | }; |
---|
222 | |
---|
223 | static devclass_t ohci_devclass; |
---|
224 | |
---|
225 | DRIVER_MODULE(ohci, nexus, ohci_driver, ohci_devclass, 0, 0); |
---|
226 | MODULE_DEPEND(ohci, usb, 1, 1, 1); |
---|
227 | |
---|
228 | #endif /* LIBBSP_ARM_LPC24XX_BSP_H */ |
---|